@semo/cli
Version:
A command line tools dispatcher
65 lines • 2.84 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.handler = exports.builder = exports.aliases = exports.desc = exports.command = exports.plugin = exports.disabled = void 0;
const path_1 = __importDefault(require("path"));
const core_1 = require("@semo/core");
const child_process_1 = require("child_process");
const fs_extra_1 = __importDefault(require("fs-extra"));
const shelljs_1 = __importDefault(require("shelljs"));
exports.disabled = false; // Set to true to disable this command temporarily
exports.plugin = 'semo';
exports.command = ['list', '$0'];
exports.desc = 'List configs';
exports.aliases = ['ls', 'l'];
// export const middleware = (argv) => {}
const builder = function (yargs) {
yargs.option('watch', {
describe: 'Watch config change, maybe only work on Mac',
});
// yargs.commandDir('list')
};
exports.builder = builder;
const handler = function (argv) {
return __awaiter(this, void 0, void 0, function* () {
const scriptName = argv.scriptName || 'semo';
let configPath;
if (argv.global) {
configPath = process.env.HOME
? path_1.default.resolve(process.env.HOME, '.' + scriptName, '.' + scriptName + 'rc.yml')
: '';
}
else {
configPath = path_1.default.resolve(process.cwd(), '.' + scriptName + 'rc.yml');
}
if (!configPath || !fs_extra_1.default.existsSync(configPath)) {
core_1.Utils.error('Config file not found.');
return;
}
if (argv.watch && shelljs_1.default.which('watch')) {
(0, child_process_1.spawn)(`watch cat ${configPath}`, {
stdio: 'inherit',
shell: true,
});
}
else {
(0, child_process_1.spawn)(`cat ${configPath} | less -r`, {
stdio: 'inherit',
shell: true,
});
}
});
};
exports.handler = handler;
//# sourceMappingURL=list.js.map