"use strict";
var fs = require("fs");
var path = require("path");
var os = require("os");
function resolveSpecifiedPath(specified) {
    if (specified === '') {
        return '';
    }
    if (specified[0] === '~') {
        var home = os.homedir();
        if (home === '') {
            return '';
        }
        return resolveSpecifiedPath(home + specified.slice(1));
    }
    if (!fs.existsSync(specified)) {
        console.log('Path specified in default_watch_path in config.yml does not exist:', specified);
        return '';
    }
    return specified;
}
function defaultPath(user_config_path) {
    var specified = resolveSpecifiedPath(user_config_path);
    if (specified !== '') {
        return specified;
    }
    var cwd = process.cwd();
    if (process.platform === 'darwin' && cwd === '/') {
        var doc_dir = path.join(process.env.HOME, 'Documents');
        if (fs.existsSync(doc_dir)) {
            return doc_dir;
        }
        else {
            return path.join(process.resourcesPath, 'README.md');
        }
    }
    return cwd;
}
module.exports = function initial_path(specified) {
    var executable = process.argv[0];
    var directly_executed = executable.endsWith(process.platform === 'win32' ? 'Shiba.exe' : 'Shiba');
    if (process.argv.length <= (directly_executed ? 1 : 2)) {
        return defaultPath(specified);
    }
    var last_arg = process.argv[process.argv.length - 1];
    if (fs.existsSync(last_arg)) {
        return path.resolve(last_arg);
    }
    else {
        console.log("Specified path '" + last_arg + "' not found. Ignored.");
        return defaultPath(specified);
    }
};
//# sourceMappingURL=initial_path.js.map