UNPKG

@leanup/cli

Version:

This CLI brings along all required tools to serve, test and build multi framework SPAs

156 lines 7.8 kB
(function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define(["require", "exports", "./abstract-cli"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CommonCLI = exports.serveOptions = exports.buildOptions = exports.webpackOptions = exports.commonOptions = void 0; const abstract_cli_1 = require("./abstract-cli"); exports.commonOptions = [ { flags: '-s, --silent', description: 'minimal consoles spending', }, ]; exports.webpackOptions = [ { flags: '-a, --analyze', description: 'Visualize size of webpack output files' }, { flags: '-e, --environment <environment>', description: '[DEPRECATED] technical environment (CMS)' }, { flags: '-t, --template <template>', description: '[DEPRECATED] corporate design (Style)' }, { flags: '-i, --include <include>', description: '[DEPRECATED] add node_modules to webpack loader' }, ]; exports.buildOptions = exports.webpackOptions.concat([ { flags: '-m, --mode [development|production]', description: 'webpack transformation mode', default: 'production' }, ]); exports.serveOptions = exports.webpackOptions.concat([ { flags: '-h, --hot', description: 'Enables Hot Module Replacement' }, { flags: '-m, --mode [development|production]', description: 'webpack transformation mode', default: 'development' }, ]); class CommonCLI extends abstract_cli_1.AbstractCLI { constructor(name, version) { super(name, version); this.addCommand('create', 'Create a new project.', [ { flags: '-n, --namespace <namespace>', description: 'individual npm namespace (@.../)' }, { flags: '-o, --overwrite', description: 'do overwrite existing files' }, { flags: '--no-install', description: 'do not install dependencies after creation' }, { flags: '--only-config', description: 'copy or update only config files' }, ].concat(exports.commonOptions), (options) => { this.consoleLog(`Project name: ${abstract_cli_1.getProjectName(options.namespace)}`, options.silent); if (options.install) { return ['npm', 'install', '--loglevel=error', '--prefer-offline', '--no-audit']; } else { return ['npm', 'run']; } }); this.addCommand('serve', 'Developing (https://webpack.js.org/)', exports.serveOptions .concat([ { flags: '-o, --open [browser]', description: 'open the named browser (default: chrome)' }, { flags: '--host <host>', description: 'dev server host' }, { flags: '-p, --port <port>', description: 'port' }, ]) .concat(exports.commonOptions), (options) => { const spawnArgs = ['cross-env']; if (options.mode) { spawnArgs.push(`NODE_ENV=${options.mode}`); } spawnArgs.push(`webpack`); spawnArgs.push(`serve`); spawnArgs.push(`--devtool=source-map`); if (options.analyze) { spawnArgs.push(`--analyze`); } if (options.hot) { spawnArgs.push(`--hot`); } if (options.open) { spawnArgs.push(`--open=${typeof options.open === 'string' && options.open.length > 0 ? options.open : 'chrome'}`); } if (options.host) { spawnArgs.push(`--host=${options.host}`); } if (options.port) { spawnArgs.push(`--port=${options.port}`); } return spawnArgs; }); this.addCommand('build', 'Building (https://webpack.js.org/)', exports.buildOptions.concat(exports.commonOptions), (options) => { const spawnArgs = ['cross-env']; if (options.mode) { spawnArgs.push(`NODE_ENV=${options.mode}`); } spawnArgs.push(`webpack`); if (options.analyze) { spawnArgs.push(`--analyze`); } return spawnArgs; }); this.addCommand('e2e', 'E2E-Testing (https://nightwatchjs.org/)', [ { flags: '-e, --env <environment>', description: 'test running environment' }, { flags: '-f, --filter <filter>', description: 'filter test files' }, { flags: '--headless', description: 'run tests in the headless mode', }, ].concat(exports.commonOptions), (options) => { const spawnArgs = ['nightwatch']; if (options.env) { spawnArgs.push(`--env=${options.env}`); } if (options.filter) { spawnArgs.push(`--filter=${options.filter}`); } if (options.headless) { spawnArgs.push('--headless'); } return spawnArgs; }); this.addCommand('format', 'Formatter (https://prettier.io/)', [{ flags: '-f, --fix', description: 'fix the code format' }].concat(exports.commonOptions), (options) => { const spawnArgs = ['prettier']; if (options.fix) { spawnArgs.push('--write'); } else { spawnArgs.push('--check'); } spawnArgs.push(`"{src,tests}/**"`); return spawnArgs; }); this.addCommand('lint', 'Linter (ESLint: https://eslint.org/)', [{ flags: '-f, --fix', description: 'fix the lint findings' }].concat(exports.commonOptions), (options) => { const spawnArgs = ['eslint']; if (options.fix) { spawnArgs.push('--fix'); } spawnArgs.push(`"{src,tests}/**/*.{html,js,json,jsx,ts,tsx,gql,graphql}"`); return spawnArgs; }); this.addCommand('test', 'Unit-Testing (https://mochajs.org/)', [{ flags: '-w, --watch', description: 'run tests in watch mode' }].concat(exports.commonOptions), (options) => { const spawnArgs = ['cross-env', 'NODE_ENV=test', 'mocha']; if (options.watch) { spawnArgs.push('--watch'); } return spawnArgs; }); this.addCommand('coverage', 'Unit-Test-Coverage (https://istanbul.js.org/)', [{ flags: '-c, --check-coverage', description: 'check coverage watermarks' }].concat(exports.commonOptions), (options) => { const spawnArgs = ['cross-env', 'NODE_ENV=test', 'nyc']; if (options.checkCoverage) { spawnArgs.push('--check-coverage'); } spawnArgs.push('mocha'); return spawnArgs; }); ['addons', 'cucumber', 'graphql', 'pwa', 'webhint'].forEach((plugin) => { try { require(`@leanup/cli-${plugin}/lib/cli`)(this); } catch (error) { } }); } } exports.CommonCLI = CommonCLI; }); //# sourceMappingURL=common-cli.js.map