UNPKG

zents-cli

Version:

ZenTS is a Node.js & TypeScript MVC-Framework for building rich web applications, released as free and open-source software under the MIT License. It is designed for building web applications with modern tools and design patterns.

96 lines (95 loc) 3.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AbstractCommand = void 0; const tslib_1 = require("tslib"); const command_1 = require("@oclif/command"); const cosmiconfig_1 = require("cosmiconfig"); const yeoman_environment_1 = require("yeoman-environment"); const path_1 = require("path"); const lodash_merge_1 = tslib_1.__importDefault(require("lodash.merge")); const yosay_1 = tslib_1.__importDefault(require("yosay")); class AbstractCommand extends command_1.Command { async generate(generatorKey, options = {}) { const key = `zen:${generatorKey}`; const env = yeoman_environment_1.createEnv(); env.register(require.resolve(`./../generators/${generatorKey}`), key); await new Promise((resolve, reject) => { env.run(key, options, (err) => { if (err) { return reject(err); } return resolve(); }); }); } async getViewDirectories() { var _a, _b; const base = await this.getCompilerDirectories(); const defaultDirectory = 'view'; const defaultViewDirectories = { src: path_1.join(base.src, defaultDirectory), dist: path_1.join(base.dist, defaultDirectory), }; const config = await this.getZenConfig(); if (!config) { return defaultViewDirectories; } const view = (_b = (_a = config.config) === null || _a === void 0 ? void 0 : _a.paths) === null || _b === void 0 ? void 0 : _b.view; if (typeof view !== 'string') { return defaultViewDirectories; } return { src: path_1.join(base.src, view), dist: path_1.join(base.dist, view), }; } async getCompilerDirectories() { var _a, _b, _c, _d, _e, _f, _g, _h; const defaultDirectories = { src: path_1.join(process.cwd(), 'src'), dist: path_1.join(process.cwd(), 'dist'), }; const config = await this.getZenConfig(); if (!config) { return defaultDirectories; } return { src: (_d = (_c = (_b = (_a = config.config) === null || _a === void 0 ? void 0 : _a.paths) === null || _b === void 0 ? void 0 : _b.base) === null || _c === void 0 ? void 0 : _c.src) !== null && _d !== void 0 ? _d : defaultDirectories.src, dist: (_h = (_g = (_f = (_e = config.config) === null || _e === void 0 ? void 0 : _e.paths) === null || _f === void 0 ? void 0 : _f.base) === null || _g === void 0 ? void 0 : _g.dist) !== null && _h !== void 0 ? _h : defaultDirectories.dist, }; } async getZenConfig() { const baseExplorer = cosmiconfig_1.cosmiconfig('zen', { searchPlaces: [ 'package.json', '.zenrc', '.zenrc.js', 'zen.json', 'zen.yaml', 'zen.yml', 'zen.config.json', 'zen.config.js', 'zen.config.yaml', 'zen.config.yml', ], }); const baseConfig = (await baseExplorer.search(process.cwd())); const envExplorer = cosmiconfig_1.cosmiconfig('zen', { searchPlaces: [ 'zen.development.json', 'zen.development.yaml', 'zen.development.yml', 'zen.development.config.json', 'zen.development.config.js', 'zen.development.config.yaml', 'zen.development.config.yml', ], }); const envConfig = (await envExplorer.search(process.cwd())); return lodash_merge_1.default({}, baseConfig ? baseConfig.config : {}, envConfig ? envConfig.config : {}); } welcome(msg) { this.log(yosay_1.default(msg)); } } exports.AbstractCommand = AbstractCommand;