@deot/dev-cli 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 deot
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # @deot/dev-cli
2
+
3
+ 包管理命令行
4
+
5
+ ## `ddc <cmd>`
6
+
7
+ - `dev`
8
+ - `build`
9
+ - `link`
10
+ - `test`
11
+ - `add`
12
+
13
+ ## 其他
14
+
15
+ 暂时不支持全局引入,一些配置项,如`tsconfig.json`, `api-extractor.json`, `jest.config.cjs` 这些依赖项目本身
package/bin/cli.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ import '../dist/index.js';
@@ -0,0 +1,233 @@
1
+ module.exports = {
2
+ "root": true,
3
+ "parser": "@typescript-eslint/parser",
4
+ "parserOptions": {
5
+ "requireConfigFile": false,
6
+ "ecmaVersion": 2020,
7
+ "sourceType": "module",
8
+ "ecmaFeatures": {
9
+ "jsx": true,
10
+ "tsx": true
11
+ }
12
+ },
13
+ "env":
14
+ {
15
+ "browser": true,
16
+ "node": true,
17
+ "es6": true,
18
+ "mocha": true
19
+ },
20
+ // 四个级别: base/essential/strongly-recommended/recommended, 使用最高约束
21
+ "extends": [
22
+ "eslint:recommended",
23
+ "plugin:@typescript-eslint/recommended",
24
+ "plugin:jsdoc/recommended",
25
+ "plugin:markdown/recommended",
26
+ "airbnb-base"
27
+ ],
28
+ "plugins": [
29
+ "@typescript-eslint",
30
+ "markdown",
31
+ "jsdoc",
32
+ "babel"
33
+ ],
34
+ "settings": {
35
+ "import/resolver": {
36
+ "node": {
37
+ "extensions": [
38
+ ".js"
39
+ ]
40
+ }
41
+ }
42
+ },
43
+ "globals": {
44
+ "_global": "readonly"
45
+ },
46
+
47
+ // 避免全局类型出错
48
+ "overrides": [
49
+ {
50
+ // .md有效
51
+ "files": ["**/*.md"],
52
+ "processor": "markdown/markdown"
53
+ },
54
+ {
55
+ // 在md文件中标识:```js
56
+ "files": ["**/*.md/*.js"],
57
+ "rules": {
58
+ "no-console": 0,
59
+ "import/no-unresolved": 0,
60
+ "no-undef": 0
61
+ }
62
+ },
63
+
64
+ {
65
+ "files": ["*.ts"],
66
+ "rules": {
67
+ "no-undef": 0
68
+ }
69
+ }
70
+ ],
71
+
72
+ "rules":
73
+ {
74
+ "import/no-import-module-exports": 0,
75
+
76
+ // ts
77
+ "@typescript-eslint/ban-ts-ignore": 0,
78
+ "@typescript-eslint/explicit-function-return-type": 0,
79
+ "@typescript-eslint/no-explicit-any": 0,
80
+ "@typescript-eslint/no-var-requires": 0,
81
+ "@typescript-eslint/no-empty-function": 0,
82
+ "@typescript-eslint/no-use-before-define": 0,
83
+ "@typescript-eslint/ban-ts-comment": 0,
84
+ "@typescript-eslint/ban-types": 0,
85
+ "@typescript-eslint/no-non-null-assertion": 0,
86
+ "@typescript-eslint/explicit-module-boundary-types": 0,
87
+ "@typescript-eslint/no-unused-vars": 1,
88
+ "@typescript-eslint/no-inferrable-types": 0,
89
+ // https://github.com/typescript-eslint/typescript-eslint/issues/2483
90
+ "@typescript-eslint/no-shadow": "error",
91
+ "@typescript-eslint/member-delimiter-style": 'warn',
92
+ "no-shadow": "off",
93
+
94
+ // "@typescript-eslint/no-unused-vars": [
95
+ // "warn",
96
+ // {
97
+ // argsIgnorePattern: "^_",
98
+ // varsIgnorePattern: "^_",
99
+ // }
100
+ // ],
101
+
102
+ // airbnb
103
+ "comma-dangle": ["warn", {
104
+ "arrays": "never",
105
+ "objects": "ignore",
106
+ "imports": "never",
107
+ "exports": "never",
108
+ "functions": "ignore"
109
+ }],
110
+ "camelcase": 0,
111
+ "dot-notation": 0,
112
+ "new-parens": ["warn"],
113
+ "no-mixed-spaces-and-tabs": ["warn", "smart-tabs"],
114
+ "object-curly-newline": 0, // { a, b, c } 允许不换行
115
+ "arrow-body-style": 0, // a => 1
116
+ "arrow-parens": 0, // a => 1
117
+ "quote-props": 0, // "a-1": 2
118
+ "guard-for-in": 0, // xx.hasOwnProperty(key)
119
+ "no-restricted-syntax": 0,
120
+ "global-require": 0,
121
+ "eqeqeq": 0,
122
+ "no-plusplus": 0,
123
+ "no-unused-expressions": 0,
124
+ "no-undef": ["warn"],
125
+ "no-unused-vars": 0,
126
+ "import/no-extraneous-dependencies": 0,
127
+ "import/prefer-default-export": 0,
128
+ "import/newline-after-import": ["warn"],
129
+ "import/first": 0,
130
+ "import/no-unresolved": 0,
131
+ "import/extensions": 0,
132
+ "no-multiple-empty-lines": 0,
133
+ "no-restricted-globals": 0,
134
+ "no-param-reassign": 0,
135
+ "no-use-before-define": 0,
136
+ "consistent-return": 0,
137
+ "no-useless-return": 0,
138
+ "prefer-const": 0,
139
+ "no-else-return": 0,
140
+ "no-useless-escape": 0,
141
+ "func-names": 0,
142
+ "prefer-arrow-callback": 0,
143
+ "no-bitwise": 0,
144
+ "padded-blocks": 0, // {} 允许空行
145
+ "no-return-assign": 0,
146
+ "max-len": ["warn", { "code": 150, "ignoreComments": true }],
147
+ "prefer-destructuring": 0,
148
+ "prefer-template": 0,
149
+ "no-nested-ternary": 0,
150
+ "prefer-rest-params": 0,
151
+ "class-methods-use-this": 0,
152
+ // tab缩进
153
+ "indent": ["warn", "tab", { "SwitchCase": 1 }],
154
+ "no-tabs": 0,
155
+ "quotes": 0,
156
+ "no-console": 0,
157
+ "no-debugger": 1,
158
+ "no-var": 1,
159
+ "import/named": 0,
160
+ "semi": [
161
+ 1,
162
+ "always"
163
+ ],
164
+ "no-trailing-spaces": 0,
165
+ "eol-last": 0,
166
+ "no-underscore-dangle": 0,
167
+ "no-alert": 0,
168
+ "no-lone-blocks": 0,
169
+ // 关键字周围强制使用空格
170
+ "keyword-spacing": [
171
+ "error",
172
+ {
173
+ "before": true,
174
+ "after": true
175
+ }
176
+ ],
177
+ // 大括号中强制使用空格
178
+ "object-curly-spacing": [
179
+ "warn",
180
+ "always"
181
+ ],
182
+ // 单行代码块前后要加空格
183
+ "block-spacing": [
184
+ "warn",
185
+ "always"
186
+ ],
187
+ // 逗号后面加空格
188
+ "comma-spacing": [
189
+ "warn",
190
+ {
191
+ "before": false,
192
+ "after": true
193
+ }
194
+ ],
195
+ // 分号后面加空格
196
+ "semi-spacing": [
197
+ "warn",
198
+ {
199
+ "before": false,
200
+ "after": true
201
+ }
202
+ ],
203
+ // 在注释前有空白
204
+ "spaced-comment": [
205
+ "warn",
206
+ "always"
207
+ ],
208
+ // 箭头函数前后要有空格
209
+ "arrow-spacing": [
210
+ "warn",
211
+ {
212
+ "before": true,
213
+ "after": true
214
+ }
215
+ ],
216
+ // 对象字面量的属性中键和值之间使用一致的间距
217
+ "key-spacing": [
218
+ "warn",
219
+ {
220
+ "beforeColon": false,
221
+ "afterColon": true
222
+ }
223
+ ],
224
+ // 要求操作符周围有空格
225
+ "space-infix-ops": [
226
+ "warn",
227
+ {
228
+ "int32Hint": false
229
+ }
230
+ ],
231
+ "jsx-quotes": 1,
232
+ }
233
+ };
@@ -0,0 +1,75 @@
1
+ // this the shared base config for all packages.
2
+ {
3
+ "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
4
+ "compiler": {
5
+ "overrideTsconfig": {
6
+ "compilerOptions": {
7
+ "paths": null
8
+ }
9
+ }
10
+ },
11
+ "apiReport": {
12
+ "enabled": true,
13
+ "reportFolder": "<projectFolder>/temp/"
14
+ },
15
+
16
+ "docModel": {
17
+ "enabled": true
18
+ },
19
+
20
+ "dtsRollup": {
21
+ "enabled": true
22
+ },
23
+
24
+ "tsdocMetadata": {
25
+ "enabled": false
26
+ },
27
+
28
+ "messages": {
29
+ "compilerMessageReporting": {
30
+ "default": {
31
+ "logLevel": "warning"
32
+ }
33
+ },
34
+
35
+ "extractorMessageReporting": {
36
+ "default": {
37
+ "logLevel": "warning",
38
+ "addToApiReportFile": true
39
+ },
40
+
41
+ "ae-missing-release-tag": {
42
+ "logLevel": "none"
43
+ },
44
+ "ae-wrong-input-file-type": {
45
+ "logLevel": "none"
46
+ }
47
+ },
48
+
49
+ "tsdocMessageReporting": {
50
+ "default": {
51
+ "logLevel": "warning"
52
+ },
53
+
54
+ "tsdoc-undefined-tag": {
55
+ "logLevel": "none"
56
+ },
57
+
58
+ "tsdoc-escape-greater-than": {
59
+ "logLevel": "none"
60
+ },
61
+
62
+ "tsdoc-malformed-inline-tag": {
63
+ "logLevel": "none"
64
+ },
65
+
66
+ "tsdoc-escape-right-brace": {
67
+ "logLevel": "none"
68
+ },
69
+
70
+ "tsdoc-unnecessary-backslash": {
71
+ "logLevel": "none"
72
+ }
73
+ }
74
+ }
75
+ }
@@ -0,0 +1,37 @@
1
+ import fs from 'fs';
2
+
3
+ const commitRE = /^(revert: )?(fix|feat|docs|style|perf|test|types|build|chore|refactor|workflow|ci|wip|release|breaking change)(\(.+\))?: .{1,50}/;
4
+ const mergeRE = /Merge branch /;
5
+
6
+ const gitParams = process.env.HUSKY_GIT_PARAMS;
7
+ const commitMsg = fs.readFileSync(gitParams, 'utf-8').trim();
8
+
9
+ if (!commitRE.test(commitMsg) && !mergeRE.test(commitMsg)) {
10
+ console.error(
11
+ `invalid commit message: "${commitMsg}".
12
+
13
+ Examples:
14
+
15
+ - fix(Button): incorrect style
16
+ - feat(Button): incorrect style
17
+ - docs(Button): fix typo
18
+
19
+ Allowed Types:
20
+
21
+ - fix:修补bug
22
+ - feat:新功能(feature)
23
+ - docs:文档(documentation)
24
+ - style:不影响代码含义的更改,可能与代码格式有关,例如空格、缺少分号等
25
+ - test:包括新的或更正以前的测试
26
+ - chore:构建过程或辅助工具的变动
27
+ - refactor:重构(即不是新增功能,也不是修改bug的代码变动)
28
+ - perf:性能改进(performance improvements)
29
+ - types:类型
30
+ - build:影响构建系统或外部依赖项的更改
31
+ - ci: 持续集成相关
32
+ - breaking change:破坏性修改
33
+ - Merge branch 'foo' into 'bar'
34
+ `
35
+ );
36
+ process.exit(1);
37
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "esnext",
4
+ "module": "esnext",
5
+ "moduleResolution": "node",
6
+ "lib": ["esnext", "dom"],
7
+ "types": ["node", "jest"],
8
+ "jsx": "preserve",
9
+ "strict": true,
10
+ "sourceMap": false,
11
+ "declaration": false,
12
+ "resolveJsonModule": true,
13
+ "esModuleInterop": true,
14
+ "noImplicitAny": false,
15
+ "removeComments": true,
16
+ "allowSyntheticDefaultImports": true
17
+ }
18
+ }
@@ -0,0 +1 @@
1
+ export { }
package/dist/index.js ADDED
@@ -0,0 +1,412 @@
1
+ import { program } from 'commander';
2
+ import { createRequire } from 'node:module';
3
+ import { Utils, Shell, Logger } from '@deot/dev-shared';
4
+ import path, { resolve } from 'node:path';
5
+ import ora from 'ora';
6
+ import fs from 'fs-extra';
7
+ import inquirer from 'inquirer';
8
+ import autocomplete from 'inquirer-autocomplete-prompt';
9
+ import typescript from '@rollup/plugin-typescript';
10
+ import { nodeResolve } from '@rollup/plugin-node-resolve';
11
+ import commonjs from '@rollup/plugin-commonjs';
12
+ import replace from '@rollup/plugin-replace';
13
+ import { rollup } from 'rollup';
14
+ import { Extractor, ExtractorConfig } from '@microsoft/api-extractor';
15
+ import chalk from 'chalk';
16
+
17
+ const run$4 = () => Utils.autoCatch(async () => {
18
+ const command = 'lerna link --force-local';
19
+ if (process.env.NODE_ENV === 'UNIT')
20
+ return Shell.spawn(`echo ${command}`);
21
+ await Shell.spawn(command);
22
+ });
23
+
24
+ const require$$1 = createRequire(import.meta.url);
25
+ const cwd = process.cwd();
26
+ class Shared {
27
+ static impl() {
28
+ return {
29
+ packageName: require$$1(`${cwd}/packages/index/package.json`).name,
30
+ directory: path.resolve(cwd, './packages')
31
+ };
32
+ }
33
+ }
34
+
35
+ const { prompt: prompt$1, registerPrompt: registerPrompt$1, Separator } = inquirer;
36
+ const getOptions$1 = async () => {
37
+ const { directory, packageName } = Shared.impl();
38
+ const packages$ = [];
39
+ fs.readdirSync(directory).forEach((file) => {
40
+ const fullpath = resolve(directory, file);
41
+ const stat = fs.statSync(fullpath);
42
+ if (!(/(^_|tpl)/.test(file))
43
+ && stat.isDirectory()) {
44
+ packages$.push(file);
45
+ }
46
+ });
47
+ const question = [
48
+ {
49
+ type: 'list',
50
+ name: 'mode',
51
+ message: 'Select Mode:',
52
+ choices: [
53
+ new Separator('选择添加的类型:'),
54
+ 'dependent',
55
+ 'package'
56
+ ],
57
+ default: 'package'
58
+ },
59
+ {
60
+ type: 'autocomplete',
61
+ message: 'Select Package To Install:',
62
+ when: (answers) => answers.mode === 'dependent',
63
+ name: 'packageName',
64
+ default: 'index',
65
+ source: (_, input) => {
66
+ input = input || '';
67
+ return new Promise(($resolve => {
68
+ let filter = input
69
+ ? packages$.filter(item => item.includes(input))
70
+ : packages$;
71
+ $resolve(filter);
72
+ }));
73
+ }
74
+ },
75
+ {
76
+ type: 'input',
77
+ name: 'dependentName',
78
+ message: 'Input Dependent Name',
79
+ default: '',
80
+ when: (answers) => answers.mode === 'dependent',
81
+ validate: (answer) => {
82
+ if (!answer) {
83
+ return '请输入需要添加的模块名';
84
+ }
85
+ return true;
86
+ }
87
+ },
88
+ {
89
+ type: 'checkbox',
90
+ name: 'args',
91
+ when: (answers) => answers.mode === 'dependent',
92
+ message: 'Select modules:',
93
+ choices: [
94
+ '--dev',
95
+ '--peer',
96
+ '--exact',
97
+ '--no-bootstrap'
98
+ ],
99
+ validate(answer) {
100
+ if (answer.length < 1) {
101
+ return '至少选择一个模块, 使用Space键选中';
102
+ }
103
+ return true;
104
+ }
105
+ },
106
+ {
107
+ type: 'input',
108
+ name: 'packageName',
109
+ message: 'Input Package Name',
110
+ default: '',
111
+ when: (answers) => answers.mode === 'package',
112
+ validate: (answer) => {
113
+ if (!answer) {
114
+ return '请输入需要添加的包名';
115
+ }
116
+ if (packages$.includes(answer) || answer === 'dev') {
117
+ return '包名已存在';
118
+ }
119
+ return true;
120
+ }
121
+ }
122
+ ];
123
+ registerPrompt$1('autocomplete', autocomplete);
124
+ let result = await prompt$1(question);
125
+ if (result.mode == 'dependent') {
126
+ if (result.packageName === 'index') {
127
+ result.$packageName = `${packageName}`;
128
+ }
129
+ else {
130
+ result.$packageName = `${packageName}-${result.packageName}`;
131
+ }
132
+ }
133
+ if (result.mode == 'package') {
134
+ result.$packageName = `${packageName}-${result.packageName}`;
135
+ }
136
+ return result;
137
+ };
138
+
139
+ const run$3 = () => Utils.autoCatch(async () => {
140
+ const { mode, dependentName, args, packageName, $packageName } = await getOptions$1();
141
+ const { directory } = Shared.impl();
142
+ let command = mode === 'dependent'
143
+ ? `lerna add ${dependentName} ${args.join(' ')} --scope=${$packageName}`
144
+ : `lerna create ${$packageName} --yes`;
145
+ if (process.env.NODE_ENV === 'UNIT')
146
+ return Shell.spawn(`echo "${command}"`);
147
+ const spinner = ora(command).start();
148
+ await Shell.spawn(command);
149
+ spinner.stop();
150
+ if (mode === 'package') {
151
+ let dir = resolve(directory);
152
+ fs.renameSync(`${dir}/${$packageName.split('/')[1]}`, `${dir}/${packageName}`);
153
+ fs.removeSync(`${dir}/${packageName}/__tests__`);
154
+ fs.removeSync(`${dir}/${packageName}/lib`);
155
+ fs.outputFileSync(`${dir}/${packageName}/README.md`, '// TODO');
156
+ fs.outputFileSync(`${dir}/${packageName}/src/index.ts`, '// TODO');
157
+ fs.outputFileSync(`${dir}/${packageName}/package.json`, JSON.stringify({
158
+ name: $packageName,
159
+ version: '1.0.0',
160
+ main: 'dist/index.js',
161
+ types: "dist/index.d.ts",
162
+ type: "module",
163
+ files: [
164
+ "dist"
165
+ ],
166
+ license: 'MIT',
167
+ publishConfig: {
168
+ access: 'public'
169
+ },
170
+ dependencies: {}
171
+ }, null, '\t'));
172
+ fs.outputFileSync(`${dir}/${packageName}/api-extractor.json`, JSON.stringify({
173
+ extends: "../../api-extractor.json",
174
+ mainEntryPointFilePath: `./dist/packages/${packageName}/src/index.d.ts`,
175
+ dtsRollup: {
176
+ publicTrimmedFilePath: "./dist/index.d.ts"
177
+ }
178
+ }, null, '\t'));
179
+ }
180
+ });
181
+
182
+ const ALL_PACKAGE = 'All Packages';
183
+ const { prompt, registerPrompt } = inquirer;
184
+ const getOptions = async () => {
185
+ const isDev = process.env.NODE_ENV === 'development';
186
+ const { directory } = Shared.impl();
187
+ const packages$ = [ALL_PACKAGE];
188
+ fs.readdirSync(directory).forEach((file) => {
189
+ const fullpath = resolve(directory, file);
190
+ const stat = fs.statSync(fullpath);
191
+ if (!(/(^_|tpl)/.test(file))
192
+ && stat.isDirectory()) {
193
+ packages$.push(file);
194
+ }
195
+ });
196
+ const question = [
197
+ {
198
+ type: 'autocomplete',
199
+ message: `Select Package To ${isDev ? 'Develop' : 'Test'}:`,
200
+ name: 'packageName',
201
+ default: 'cli',
202
+ source: (_, input) => {
203
+ input = input || '';
204
+ return new Promise(($resolve => {
205
+ let filter = input
206
+ ? packages$.filter(item => item.includes(input))
207
+ : packages$;
208
+ $resolve(filter);
209
+ }));
210
+ }
211
+ },
212
+ {
213
+ type: 'confirm',
214
+ message: 'Watch Mode?',
215
+ name: 'watch',
216
+ when: () => !isDev,
217
+ default: (answers) => {
218
+ return answers.packageName !== ALL_PACKAGE;
219
+ }
220
+ }
221
+ ];
222
+ registerPrompt('autocomplete', autocomplete);
223
+ let result = await prompt(question);
224
+ result.packageName = result.packageName == ALL_PACKAGE
225
+ ? undefined
226
+ : result.packageName;
227
+ result.watch = result.watch || isDev;
228
+ return result;
229
+ };
230
+
231
+ const run$2 = (options) => Utils.autoCatch(async () => {
232
+ if (!options || !options.packageName) {
233
+ options = await getOptions();
234
+ }
235
+ const { packageName, watch } = options;
236
+ const command = `cross-env NODE_ENV=${process.env.NODE_ENV || 'TEST'} TEST_OPTIONS=${encodeURIComponent(JSON.stringify(options))} jest `
237
+ + ([
238
+ '--passWithNoTests',
239
+ `${watch ? '--watchAll' : ''}`
240
+ ].join(' '));
241
+ if (process.env.NODE_ENV === 'UNIT')
242
+ return Shell.spawn(`echo ${command}`);
243
+ await Shell.spawn(command);
244
+ if (!watch)
245
+ return;
246
+ Logger.log(packageName || '', '测试已通过');
247
+ }, {
248
+ onError: (e) => {
249
+ if (typeof e === 'number' && e === 1) {
250
+ Logger.error('测试未通过');
251
+ }
252
+ else {
253
+ Logger.error(e);
254
+ }
255
+ }
256
+ });
257
+
258
+ const run$1 = () => Utils.autoCatch(async () => {
259
+ if (process.env.NODE_ENV === 'UNIT')
260
+ return Shell.spawn(`echo development`);
261
+ process.env.NODE_ENV = process.env.NODE_ENV || 'development';
262
+ await run$2({});
263
+ });
264
+
265
+ const require$ = createRequire(import.meta.url);
266
+ class Builder {
267
+ packageDir;
268
+ packageName;
269
+ packageOptions;
270
+ config;
271
+ constructor(config) {
272
+ const { directory, packageName } = Shared.impl();
273
+ this.packageDir = path.resolve(directory, `./${config.name}`);
274
+ this.packageName = config.name === 'index' ? packageName : `${packageName}-${config.name}`;
275
+ this.packageOptions = require$(`${this.packageDir}/package.json`);
276
+ this.config = config;
277
+ }
278
+ async process() {
279
+ const { packageName, packageDir } = this;
280
+ const spinner = ora(`${packageName} Build ...`);
281
+ try {
282
+ spinner.start();
283
+ await fs.emptyDir(`${packageDir}/dist`);
284
+ const stat = await this.buildSourceAsES();
285
+ await this.buildTypes();
286
+ spinner.stop();
287
+ Logger.log(`${chalk.cyan(`${packageName}`)} ${chalk.green('Success')} ES: ${Utils.formatBytes(stat.size)}`);
288
+ }
289
+ catch (e) {
290
+ Logger.log('Error!', e);
291
+ throw e;
292
+ }
293
+ }
294
+ async buildSourceAsES() {
295
+ const { name, input, output } = this.config;
296
+ const { packageOptions } = this;
297
+ const external = Object
298
+ .keys({
299
+ ...packageOptions.dependencies,
300
+ ...packageOptions.peerDependencies
301
+ })
302
+ .map(i => new RegExp(`^${i}$`));
303
+ const builder = await rollup({
304
+ input,
305
+ external: [
306
+ /^node:/,
307
+ /^[a-zA-Z@]/,
308
+ ...external
309
+ ],
310
+ plugins: [
311
+ typescript({
312
+ include: [`packages/${name}/**/*`, 'packages/shims.d.ts'],
313
+ exclude: ['dist'],
314
+ compilerOptions: {
315
+ rootDir: '.',
316
+ outDir: `packages/${name}/dist`,
317
+ declaration: true
318
+ }
319
+ }),
320
+ commonjs({ extensions: ['.js', '.ts'] }),
321
+ nodeResolve(),
322
+ replace({
323
+ '1.0.0': `'${packageOptions.version}'`,
324
+ false: 'false',
325
+ true: true
326
+ })
327
+ ]
328
+ });
329
+ await builder.write(output);
330
+ const stat = await fs.stat(output.file);
331
+ return stat;
332
+ }
333
+ async buildTypes() {
334
+ const { packageDir } = this;
335
+ const config = path.resolve(packageDir, `api-extractor.json`);
336
+ const result = Extractor.invoke(ExtractorConfig.loadFileAndPrepare(config), {
337
+ localBuild: true,
338
+ showVerboseMessages: false
339
+ });
340
+ if (!result.succeeded) {
341
+ Logger.error(`API Extractor completed with ${result.errorCount} errors and ${result.warningCount} warnings`);
342
+ process.exitCode = 1;
343
+ }
344
+ await fs.remove(`${packageDir}/dist/packages`);
345
+ }
346
+ }
347
+ const run = () => Utils.autoCatch(async () => {
348
+ const { directory } = Shared.impl();
349
+ const files = ['shared', ...fs.readdirSync(directory)]
350
+ .filter((i, index, source) => !['index'].includes(i) && source.indexOf(i) === index);
351
+ if (process.env.NODE_ENV === 'UNIT')
352
+ return Shell.spawn(`echo ${[...files, 'index'].join(' ')}`);
353
+ await [...files, 'index'].reduce((preProcess, file) => {
354
+ const fullpath = path.resolve(directory, file);
355
+ const stat = fs.statSync(fullpath);
356
+ if (!(/(^_)/.test(file)) && stat.isDirectory()) {
357
+ return preProcess.then(() => {
358
+ const builder = new Builder({
359
+ fullpath,
360
+ name: file,
361
+ input: fullpath + '/src/index.ts',
362
+ output: {
363
+ file: fullpath + '/dist/index.js',
364
+ format: 'es',
365
+ exports: 'named',
366
+ sourcemap: false
367
+ }
368
+ });
369
+ return builder.process();
370
+ });
371
+ }
372
+ else {
373
+ return preProcess;
374
+ }
375
+ }, Promise.resolve());
376
+ });
377
+
378
+ const require = createRequire(import.meta.url);
379
+ program
380
+ .version(require('../package.json').version);
381
+ program
382
+ .usage('<cmd>');
383
+ program
384
+ .command('link')
385
+ .alias('d')
386
+ .description('lerna link')
387
+ .action(run$4);
388
+ program
389
+ .command('add')
390
+ .alias('a')
391
+ .description('lerna add or lerna create')
392
+ .action(run$3);
393
+ program
394
+ .command('dev')
395
+ .alias('d')
396
+ .description('dev')
397
+ .action(run$1);
398
+ program
399
+ .command('build')
400
+ .alias('b')
401
+ .description('build')
402
+ .action(run);
403
+ program
404
+ .command('test')
405
+ .alias('t')
406
+ .description('unit-test')
407
+ .option('-p, --packageName <packageName>', 'select packageName')
408
+ .action(run$2);
409
+ program.parse(process.argv);
410
+ if (!program.args.length) {
411
+ program.help();
412
+ }
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@deot/dev-cli",
3
+ "version": "1.0.0",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "type": "module",
7
+ "files": [
8
+ "dist",
9
+ "config"
10
+ ],
11
+ "license": "MIT",
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "dependencies": {
16
+ "@babel/core": "^7.21.3",
17
+ "@babel/preset-env": "^7.20.2",
18
+ "@deot/dev-shared": "^1.0.0",
19
+ "@microsoft/api-extractor": "^7.34.4",
20
+ "@rollup/plugin-commonjs": "^24.0.1",
21
+ "@rollup/plugin-node-resolve": "^15.0.1",
22
+ "@rollup/plugin-replace": "^5.0.2",
23
+ "@rollup/plugin-typescript": "11.0.0",
24
+ "@types/jest": "^29.4.0",
25
+ "@types/node": "^18.11.9",
26
+ "@typescript-eslint/eslint-plugin": "^5.44.0",
27
+ "@typescript-eslint/parser": "^5.44.0",
28
+ "commander": "^10.0.0",
29
+ "cross-env": "^7.0.3",
30
+ "eslint": "^8.35.0",
31
+ "eslint-config-airbnb-base": "^15.0.0",
32
+ "eslint-plugin-babel": "^5.3.1",
33
+ "eslint-plugin-import": "^2.27.5",
34
+ "eslint-plugin-jsdoc": "^40.0.1",
35
+ "eslint-plugin-markdown": "^3.0.0",
36
+ "eslint-watch": "^8.0.0",
37
+ "fs-extra": "^10.0.0",
38
+ "husky": "^4.3.8",
39
+ "inquirer": "^9.1.5",
40
+ "inquirer-autocomplete-prompt": "^3.0.0",
41
+ "jest": "^29.5.0",
42
+ "jest-environment-jsdom": "^29.5.0",
43
+ "lerna": "*",
44
+ "lint-staged": "^11.1.2",
45
+ "ora": "^6.1.2",
46
+ "rollup": "^3.18.0",
47
+ "ts-jest": "^29.0.5",
48
+ "typescript": "^4.9.5",
49
+ "upath": "^2.0.1"
50
+ },
51
+ "devDependencies": {
52
+ "@deot/dev-test": "^1.0.0"
53
+ },
54
+ "bin": {
55
+ "ddc": "bin/cli.js"
56
+ },
57
+ "gitHead": "f960c31945e60a492e50e835cbf0c987a9fc3d5c"
58
+ }