UNPKG

7.86 kBJavaScriptView Raw
1(function (factory) {
2 if (typeof module === "object" && typeof module.exports === "object") {
3 var v = factory(require, exports);
4 if (v !== undefined) module.exports = v;
5 }
6 else if (typeof define === "function" && define.amd) {
7 define(["require", "exports", "./abstract-cli"], factory);
8 }
9})(function (require, exports) {
10 "use strict";
11 Object.defineProperty(exports, "__esModule", { value: true });
12 exports.CommonCLI = exports.serveOptions = exports.buildOptions = exports.webpackOptions = exports.commonOptions = void 0;
13 const abstract_cli_1 = require("./abstract-cli");
14 exports.commonOptions = [
15 {
16 flags: '-s, --silent',
17 description: 'minimal consoles spending',
18 },
19 ];
20 exports.webpackOptions = [
21 { flags: '-a, --analyze', description: 'Visualize size of webpack output files' },
22 { flags: '-e, --environment <environment>', description: '[DEPRECATED] technical environment (CMS)' },
23 { flags: '-t, --template <template>', description: '[DEPRECATED] corporate design (Style)' },
24 { flags: '-i, --include <include>', description: '[DEPRECATED] add node_modules to webpack loader' },
25 ];
26 exports.buildOptions = exports.webpackOptions.concat([
27 { flags: '-m, --mode [development|production]', description: 'webpack transformation mode', default: 'production' },
28 ]);
29 exports.serveOptions = exports.webpackOptions.concat([
30 { flags: '-h, --hot', description: 'Enables Hot Module Replacement' },
31 { flags: '-m, --mode [development|production]', description: 'webpack transformation mode', default: 'development' },
32 ]);
33 class CommonCLI extends abstract_cli_1.AbstractCLI {
34 constructor(name, version) {
35 super(name, version);
36 this.addCommand('create', 'Create a new project.', [
37 { flags: '-n, --namespace <namespace>', description: 'individual npm namespace (@.../)' },
38 { flags: '-o, --overwrite', description: 'do overwrite existing files' },
39 { flags: '--no-install', description: 'do not install dependencies after creation' },
40 { flags: '--only-config', description: 'copy or update only config files' },
41 ].concat(exports.commonOptions), (options) => {
42 this.consoleLog(`Project name: ${(0, abstract_cli_1.getProjectName)(options.namespace)}`, options.silent);
43 if (options.install) {
44 return ['npm', 'install', '--loglevel=error', '--prefer-offline', '--no-audit'];
45 }
46 else {
47 return ['npm', 'run'];
48 }
49 });
50 this.addCommand('serve', 'Developing (https://webpack.js.org/)', exports.serveOptions
51 .concat([
52 { flags: '-o, --open [browser]', description: 'open the named browser (default: chrome)' },
53 { flags: '--host <host>', description: 'dev server host' },
54 { flags: '-p, --port <port>', description: 'port' },
55 ])
56 .concat(exports.commonOptions), (options) => {
57 const spawnArgs = ['cross-env'];
58 if (options.mode) {
59 spawnArgs.push(`NODE_ENV=${options.mode}`);
60 }
61 spawnArgs.push(`webpack`);
62 spawnArgs.push(`serve`);
63 spawnArgs.push(`--devtool=source-map`);
64 if (options.analyze) {
65 spawnArgs.push(`--analyze`);
66 }
67 if (options.hot) {
68 spawnArgs.push(`--hot`);
69 }
70 if (options.open) {
71 spawnArgs.push(`--open=${typeof options.open === 'string' && options.open.length > 0 ? options.open : 'chrome'}`);
72 }
73 if (options.host) {
74 spawnArgs.push(`--host=${options.host}`);
75 }
76 if (options.port) {
77 spawnArgs.push(`--port=${options.port}`);
78 }
79 return spawnArgs;
80 });
81 this.addCommand('build', 'Building (https://webpack.js.org/)', exports.buildOptions.concat(exports.commonOptions), (options) => {
82 const spawnArgs = ['cross-env'];
83 if (options.mode) {
84 spawnArgs.push(`NODE_ENV=${options.mode}`);
85 }
86 spawnArgs.push(`webpack`);
87 if (options.analyze) {
88 spawnArgs.push(`--analyze`);
89 }
90 return spawnArgs;
91 });
92 this.addCommand('e2e', 'E2E-Testing (https://nightwatchjs.org/)', [
93 { flags: '-e, --env <environment>', description: 'test running environment' },
94 { flags: '-f, --filter <filter>', description: 'filter test files' },
95 {
96 flags: '--headless',
97 description: 'run tests in the headless mode',
98 },
99 ].concat(exports.commonOptions), (options) => {
100 const spawnArgs = ['nightwatch'];
101 if (options.env) {
102 spawnArgs.push(`--env=${options.env}`);
103 }
104 if (options.filter) {
105 spawnArgs.push(`--filter=${options.filter}`);
106 }
107 if (options.headless) {
108 spawnArgs.push('--headless');
109 }
110 return spawnArgs;
111 });
112 this.addCommand('format', 'Formatter (https://prettier.io/)', [{ flags: '-f, --fix', description: 'fix the code format' }].concat(exports.commonOptions), (options) => {
113 const spawnArgs = ['prettier'];
114 if (options.fix) {
115 spawnArgs.push('--write');
116 }
117 else {
118 spawnArgs.push('--check');
119 }
120 spawnArgs.push(`"{src,tests}/**"`);
121 spawnArgs.push('--ignore-unknown');
122 return spawnArgs;
123 });
124 this.addCommand('lint', 'Linter (ESLint: https://eslint.org/)', [{ flags: '-f, --fix', description: 'fix the lint findings' }].concat(exports.commonOptions), (options) => {
125 const spawnArgs = ['eslint'];
126 if (options.fix) {
127 spawnArgs.push('--fix');
128 }
129 spawnArgs.push(`"{src,tests}/**/*.{html,js,json,jsx,ts,tsx,gql,graphql}"`);
130 return spawnArgs;
131 });
132 this.addCommand('test', 'Unit-Testing (https://mochajs.org/)', [{ flags: '-w, --watch', description: 'run tests in watch mode' }].concat(exports.commonOptions), (options) => {
133 const spawnArgs = ['cross-env', 'NODE_ENV=test', 'mocha'];
134 if (options.watch) {
135 spawnArgs.push('--watch');
136 }
137 return spawnArgs;
138 });
139 this.addCommand('coverage', 'Unit-Test-Coverage (https://istanbul.js.org/)', [{ flags: '-c, --check-coverage', description: 'check coverage watermarks' }].concat(exports.commonOptions), (options) => {
140 const spawnArgs = ['cross-env', 'NODE_ENV=test', 'nyc'];
141 if (options.checkCoverage) {
142 spawnArgs.push('--check-coverage');
143 }
144 spawnArgs.push('mocha');
145 return spawnArgs;
146 });
147 ['addons', 'cucumber', 'graphql', 'pwa', 'webhint'].forEach((plugin) => {
148 try {
149 require(`@leanup/cli-${plugin}/lib/cli`)(this);
150 }
151 catch (error) { }
152 });
153 }
154 }
155 exports.CommonCLI = CommonCLI;
156});
157//# sourceMappingURL=common-cli.js.map
\No newline at end of file