@deot/dev-cli 1.0.7 → 1.1.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/README.md +2 -2
- package/bin/cli.js +1 -1
- package/dist/index.cjs.js +95 -0
- package/dist/index.es.js +69 -0
- package/package.json +12 -39
- package/config/.eslintrc.cjs +0 -233
- package/config/api-extractor.json +0 -76
- package/config/commit-lint.js +0 -39
- package/config/jest.config.js +0 -60
- package/config/tsconfig.json +0 -18
- package/dist/index.js +0 -1110
package/dist/index.js
DELETED
|
@@ -1,1110 +0,0 @@
|
|
|
1
|
-
import { program } from 'commander';
|
|
2
|
-
import { createRequire } from 'node:module';
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
import ora from 'ora';
|
|
5
|
-
import { Utils, Logger, Shell } from '@deot/dev-shared';
|
|
6
|
-
import * as path from 'node:path';
|
|
7
|
-
import { resolve } from 'node:path';
|
|
8
|
-
import fs from 'fs-extra';
|
|
9
|
-
import inquirer from 'inquirer';
|
|
10
|
-
import autocomplete from 'inquirer-autocomplete-prompt';
|
|
11
|
-
import typescript from '@rollup/plugin-typescript';
|
|
12
|
-
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
13
|
-
import commonjs from '@rollup/plugin-commonjs';
|
|
14
|
-
import replace from '@rollup/plugin-replace';
|
|
15
|
-
import { rollup } from 'rollup';
|
|
16
|
-
import { Extractor, ExtractorConfig } from '@microsoft/api-extractor';
|
|
17
|
-
import parser from 'conventional-commits-parser';
|
|
18
|
-
import semver from 'semver';
|
|
19
|
-
|
|
20
|
-
const cwd = process.cwd();
|
|
21
|
-
const require$$2 = createRequire(cwd);
|
|
22
|
-
class Shared {
|
|
23
|
-
static config;
|
|
24
|
-
static getNormalizePackage = (dataMap) => {
|
|
25
|
-
Object.keys(dataMap).forEach(packageName => {
|
|
26
|
-
const relations = dataMap[packageName];
|
|
27
|
-
relations.forEach((packageName$) => {
|
|
28
|
-
if (dataMap[packageName$].includes(packageName)) {
|
|
29
|
-
throw new Error(`${packageName} ${packageName$} deps loop`);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
const needUseMap = Object.keys(dataMap).reduce((pre, key) => (pre[key] = 0, pre), {});
|
|
34
|
-
const queue = [];
|
|
35
|
-
for (let key in dataMap) {
|
|
36
|
-
const dependencies = dataMap[key];
|
|
37
|
-
dependencies.forEach((dependency) => {
|
|
38
|
-
needUseMap[dependency] += 1;
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
for (let key in needUseMap) {
|
|
42
|
-
if (needUseMap[key] === 0) {
|
|
43
|
-
queue.push(key);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
const result = [];
|
|
47
|
-
while (queue.length > 0) {
|
|
48
|
-
const node = queue.shift();
|
|
49
|
-
if (!node)
|
|
50
|
-
return [];
|
|
51
|
-
result.push(node);
|
|
52
|
-
const dependencies = dataMap[node];
|
|
53
|
-
for (let i = 0; i < dependencies.length; i++) {
|
|
54
|
-
const dependency = dependencies[i];
|
|
55
|
-
needUseMap[dependency] -= 1;
|
|
56
|
-
if (needUseMap[dependency] === 0) {
|
|
57
|
-
queue.push(dependency);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return result.reverse();
|
|
62
|
-
};
|
|
63
|
-
static getPackageName = (packageFolderName$) => {
|
|
64
|
-
const { workspace, packageFolderName, packageName } = Shared.impl();
|
|
65
|
-
if (!workspace
|
|
66
|
-
|| !packageFolderName$
|
|
67
|
-
|| packageFolderName$ === packageFolderName) {
|
|
68
|
-
return packageName;
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
return `${packageName}-${packageFolderName$.replace(new RegExp(`${packageName}-?`), '')}`;
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
static getPackageFolderName = (packageName$) => {
|
|
75
|
-
const { workspace, packageFolderName, packageName } = Shared.impl();
|
|
76
|
-
if (!workspace)
|
|
77
|
-
return '';
|
|
78
|
-
if (packageName$ === packageName)
|
|
79
|
-
return packageFolderName;
|
|
80
|
-
return packageName$?.replace(new RegExp(`${packageName}-?`), '');
|
|
81
|
-
};
|
|
82
|
-
static impl() {
|
|
83
|
-
if (Shared.config)
|
|
84
|
-
return Shared.config;
|
|
85
|
-
const rootPackageOptions = require$$2(`${cwd}/package.json`);
|
|
86
|
-
let workspace = 'packages';
|
|
87
|
-
let isMonorepo = fs.existsSync(path.resolve(cwd, workspace));
|
|
88
|
-
workspace = isMonorepo ? workspace : '';
|
|
89
|
-
const packageFolderName = isMonorepo ? 'index' : '';
|
|
90
|
-
const packageDir = path.resolve(cwd, workspace);
|
|
91
|
-
const packageOptions = require$$2(path.resolve(packageDir, packageFolderName, 'package.json'));
|
|
92
|
-
const packageName = packageOptions.name;
|
|
93
|
-
const packageVersion = packageOptions.version;
|
|
94
|
-
const packageFolderNames = !isMonorepo ? [] : fs
|
|
95
|
-
.readdirSync(packageDir)
|
|
96
|
-
.reduce((pre, file) => {
|
|
97
|
-
const fullpath = path.resolve(packageDir, file);
|
|
98
|
-
const stat = fs.statSync(fullpath);
|
|
99
|
-
if (!(/(^_|tpl)/.test(file))
|
|
100
|
-
&& stat.isDirectory()) {
|
|
101
|
-
pre.push(file);
|
|
102
|
-
}
|
|
103
|
-
return pre;
|
|
104
|
-
}, []);
|
|
105
|
-
const packageOptionsMap = packageFolderNames.reduce((pre, packageFolderName$) => {
|
|
106
|
-
pre[packageFolderName$] = require$$2(path.resolve(packageDir, packageFolderName$, 'package.json'));
|
|
107
|
-
return pre;
|
|
108
|
-
}, {});
|
|
109
|
-
const packageRelation = packageFolderNames.reduce((pre, packageFolderName$) => {
|
|
110
|
-
let packagesOptions = packageOptionsMap[packageFolderName$];
|
|
111
|
-
let deps = {
|
|
112
|
-
...(packagesOptions.dependencies || {}),
|
|
113
|
-
...(packagesOptions.devDependencies || {}),
|
|
114
|
-
};
|
|
115
|
-
pre[packagesOptions.name] = Object.keys(deps).filter(i => new RegExp(`${packageName}`).test(i));
|
|
116
|
-
return pre;
|
|
117
|
-
}, {});
|
|
118
|
-
const normalizePackageNames = Shared.getNormalizePackage(packageRelation);
|
|
119
|
-
const normalizePackageFolderNames = normalizePackageNames
|
|
120
|
-
.map(i => i.replace(new RegExp(`${packageName}-?`), '') || packageFolderName);
|
|
121
|
-
const homepage = (rootPackageOptions.repository || packageOptions.repository || {}).url || '';
|
|
122
|
-
const config = {
|
|
123
|
-
workspace,
|
|
124
|
-
homepage: homepage.replace(/(.*)(https?:\/\/.*)(#|\.git)/, '$2'),
|
|
125
|
-
packageFolderName,
|
|
126
|
-
packageDir,
|
|
127
|
-
packageOptions,
|
|
128
|
-
packageName,
|
|
129
|
-
packageVersion,
|
|
130
|
-
packageFolderNames,
|
|
131
|
-
packageOptionsMap,
|
|
132
|
-
packageRelation,
|
|
133
|
-
normalizePackageNames,
|
|
134
|
-
normalizePackageFolderNames
|
|
135
|
-
};
|
|
136
|
-
Shared.config = config;
|
|
137
|
-
return config;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const run$5 = (options) => Utils.autoCatch(async () => {
|
|
142
|
-
const locals = Shared.impl();
|
|
143
|
-
const { workspace, packageFolderNames } = locals;
|
|
144
|
-
if (!workspace) {
|
|
145
|
-
return Logger.log(`<link> Monorepo Supported Only.`);
|
|
146
|
-
}
|
|
147
|
-
if (typeof options.dryRun === 'undefined') {
|
|
148
|
-
options.dryRun = process.env.NODE_ENV === 'UNIT';
|
|
149
|
-
}
|
|
150
|
-
const command = `npx pnpm link ./${workspace}/`;
|
|
151
|
-
if (options.dryRun)
|
|
152
|
-
return Shell.spawn(`echo ${command}`);
|
|
153
|
-
const spinner = ora(`Links ...\n`);
|
|
154
|
-
spinner.start();
|
|
155
|
-
await Promise.all(packageFolderNames.map(i => {
|
|
156
|
-
return Shell.spawn(`${command}${i}`);
|
|
157
|
-
}));
|
|
158
|
-
spinner.stop();
|
|
159
|
-
Logger.log(`${chalk.green('Links Success')}`);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
const { prompt: prompt$2, registerPrompt: registerPrompt$1, Separator } = inquirer;
|
|
163
|
-
const getOptions$1 = async () => {
|
|
164
|
-
const { packageFolderNames } = Shared.impl();
|
|
165
|
-
const question = [
|
|
166
|
-
{
|
|
167
|
-
type: 'list',
|
|
168
|
-
name: 'mode',
|
|
169
|
-
message: 'Select Mode:',
|
|
170
|
-
choices: [
|
|
171
|
-
new Separator('选择添加的类型:'),
|
|
172
|
-
'dependent',
|
|
173
|
-
'package'
|
|
174
|
-
],
|
|
175
|
-
default: 'package'
|
|
176
|
-
},
|
|
177
|
-
{
|
|
178
|
-
type: 'autocomplete',
|
|
179
|
-
message: 'Select Package To Install:',
|
|
180
|
-
when: (answers) => answers.mode === 'dependent',
|
|
181
|
-
name: 'packageFolderName',
|
|
182
|
-
default: 'index',
|
|
183
|
-
source: (_, input) => {
|
|
184
|
-
input = input || '';
|
|
185
|
-
return new Promise(($resolve => {
|
|
186
|
-
let filter = input
|
|
187
|
-
? packageFolderNames.filter(item => item.includes(input))
|
|
188
|
-
: packageFolderNames;
|
|
189
|
-
$resolve(filter);
|
|
190
|
-
}));
|
|
191
|
-
}
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
type: 'input',
|
|
195
|
-
name: 'dependentName',
|
|
196
|
-
message: 'Input Dependent Name',
|
|
197
|
-
default: '',
|
|
198
|
-
when: (answers) => answers.mode === 'dependent',
|
|
199
|
-
validate: (answer) => {
|
|
200
|
-
if (!answer) {
|
|
201
|
-
return '请输入需要添加的模块名';
|
|
202
|
-
}
|
|
203
|
-
return true;
|
|
204
|
-
}
|
|
205
|
-
},
|
|
206
|
-
{
|
|
207
|
-
type: 'list',
|
|
208
|
-
name: 'args',
|
|
209
|
-
when: (answers) => answers.mode === 'dependent',
|
|
210
|
-
message: 'Select Install Mode:',
|
|
211
|
-
choices: [
|
|
212
|
-
'-S',
|
|
213
|
-
'-D',
|
|
214
|
-
'-O'
|
|
215
|
-
]
|
|
216
|
-
},
|
|
217
|
-
{
|
|
218
|
-
type: 'input',
|
|
219
|
-
name: 'packageFolderName',
|
|
220
|
-
message: 'Input Package Name',
|
|
221
|
-
default: '',
|
|
222
|
-
when: (answers) => answers.mode === 'package',
|
|
223
|
-
validate: (answer) => {
|
|
224
|
-
if (!answer) {
|
|
225
|
-
return '请输入需要添加的包名';
|
|
226
|
-
}
|
|
227
|
-
if (packageFolderNames.includes(answer) || answer === 'dev') {
|
|
228
|
-
return '包名已存在';
|
|
229
|
-
}
|
|
230
|
-
return true;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
];
|
|
234
|
-
registerPrompt$1('autocomplete', autocomplete);
|
|
235
|
-
let result = await prompt$2(question);
|
|
236
|
-
if (result.mode == 'dependent') {
|
|
237
|
-
result.packageName = Shared.getPackageName(result.packageFolderName);
|
|
238
|
-
}
|
|
239
|
-
if (result.mode == 'package') {
|
|
240
|
-
result.packageName = Shared.getPackageName(result.packageFolderName);
|
|
241
|
-
}
|
|
242
|
-
result.args = [result.args];
|
|
243
|
-
return result;
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
const run$4 = (options) => Utils.autoCatch(async () => {
|
|
247
|
-
const locals = Shared.impl();
|
|
248
|
-
const { workspace, packageDir } = locals;
|
|
249
|
-
if (!workspace) {
|
|
250
|
-
return Logger.log(`<add> Monorepo Supported Only.`);
|
|
251
|
-
}
|
|
252
|
-
if (typeof options.dryRun === 'undefined') {
|
|
253
|
-
options.dryRun = process.env.NODE_ENV === 'UNIT';
|
|
254
|
-
}
|
|
255
|
-
const { mode, dependentName, args, packageFolderName, packageName } = await getOptions$1();
|
|
256
|
-
let command = mode === 'dependent'
|
|
257
|
-
? `npx pnpm add --filter ${packageName} ${dependentName} ${args.join(' ')}`
|
|
258
|
-
: `npx pnpm link ./${workspace}/${packageFolderName}`;
|
|
259
|
-
if (options.dryRun)
|
|
260
|
-
return Shell.spawn(`echo "${command}"`);
|
|
261
|
-
const spinner = ora(`${command}\n`).start();
|
|
262
|
-
await Shell.spawn(command);
|
|
263
|
-
spinner.stop();
|
|
264
|
-
if (mode === 'package') {
|
|
265
|
-
let dir = resolve(packageDir);
|
|
266
|
-
fs.outputFileSync(`${dir}/${packageFolderName}/README.md`, '// TODO');
|
|
267
|
-
fs.outputFileSync(`${dir}/${packageFolderName}/src/index.ts`, '// TODO');
|
|
268
|
-
fs.outputFileSync(`${dir}/${packageFolderName}/__tests__/index.spec.ts`, '// TODO');
|
|
269
|
-
fs.outputFileSync(`${dir}/${packageFolderName}/package.json`, JSON.stringify({
|
|
270
|
-
name: packageName,
|
|
271
|
-
version: '1.0.0',
|
|
272
|
-
main: 'dist/index.js',
|
|
273
|
-
types: "dist/index.d.ts",
|
|
274
|
-
type: "module",
|
|
275
|
-
files: [
|
|
276
|
-
"dist"
|
|
277
|
-
],
|
|
278
|
-
license: 'MIT',
|
|
279
|
-
publishConfig: {
|
|
280
|
-
access: 'public'
|
|
281
|
-
},
|
|
282
|
-
dependencies: {}
|
|
283
|
-
}, null, 2));
|
|
284
|
-
fs.outputFileSync(`${dir}/${packageFolderName}/api-extractor.json`, JSON.stringify({
|
|
285
|
-
extends: "../../api-extractor.json",
|
|
286
|
-
mainEntryPointFilePath: `./dist/${workspace}/${packageFolderName}/src/index.d.ts`,
|
|
287
|
-
dtsRollup: {
|
|
288
|
-
publicTrimmedFilePath: "./dist/index.d.ts"
|
|
289
|
-
}
|
|
290
|
-
}, null, 2));
|
|
291
|
-
}
|
|
292
|
-
await Shell.spawn(command);
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
const ALL_PACKAGE = 'All Packages';
|
|
296
|
-
const { prompt: prompt$1, registerPrompt } = inquirer;
|
|
297
|
-
const getOptions = async () => {
|
|
298
|
-
const isDev = process.env.NODE_ENV === 'development';
|
|
299
|
-
const { packageFolderNames } = Shared.impl();
|
|
300
|
-
const packages$ = [ALL_PACKAGE, ...packageFolderNames];
|
|
301
|
-
const question = [
|
|
302
|
-
{
|
|
303
|
-
type: 'autocomplete',
|
|
304
|
-
message: `Select Package To ${isDev ? 'Develop' : 'Test'}:`,
|
|
305
|
-
name: 'packageFolderName',
|
|
306
|
-
default: 'cli',
|
|
307
|
-
source: (_, input) => {
|
|
308
|
-
input = input || '';
|
|
309
|
-
return new Promise(($resolve => {
|
|
310
|
-
let filter = input
|
|
311
|
-
? packages$.filter(item => item.includes(input))
|
|
312
|
-
: packages$;
|
|
313
|
-
$resolve(filter);
|
|
314
|
-
}));
|
|
315
|
-
}
|
|
316
|
-
},
|
|
317
|
-
{
|
|
318
|
-
type: 'confirm',
|
|
319
|
-
message: 'Watch Mode?',
|
|
320
|
-
name: 'watch',
|
|
321
|
-
when: () => !isDev,
|
|
322
|
-
default: (answers) => {
|
|
323
|
-
return answers.packageFolderName !== ALL_PACKAGE;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
];
|
|
327
|
-
registerPrompt('autocomplete', autocomplete);
|
|
328
|
-
let result = await prompt$1(question);
|
|
329
|
-
result.packageFolderName = result.packageFolderName == ALL_PACKAGE
|
|
330
|
-
? undefined
|
|
331
|
-
: result.packageFolderName;
|
|
332
|
-
result.watch = result.watch || isDev;
|
|
333
|
-
return result;
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
const run$3 = (options) => Utils.autoCatch(async () => {
|
|
337
|
-
const locals = Shared.impl();
|
|
338
|
-
if (typeof options.dryRun === 'undefined') {
|
|
339
|
-
options.dryRun = process.env.NODE_ENV === 'UNIT';
|
|
340
|
-
}
|
|
341
|
-
if (locals.workspace && !options.packageName) {
|
|
342
|
-
const promptOptions = await getOptions();
|
|
343
|
-
options = {
|
|
344
|
-
...options,
|
|
345
|
-
...promptOptions
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
const { packageName, watch, dryRun } = options;
|
|
349
|
-
options.packageFolderName = Shared.getPackageFolderName(options.packageName) || options.packageFolderName;
|
|
350
|
-
options.workspace = locals.workspace;
|
|
351
|
-
if (!options.packageFolderName)
|
|
352
|
-
delete options.packageFolderName;
|
|
353
|
-
if (!options.workspace)
|
|
354
|
-
delete options.workspace;
|
|
355
|
-
delete options.packageName;
|
|
356
|
-
const command = `cross-env NODE_ENV=${process.env.NODE_ENV || 'TEST'} TEST_OPTIONS=${encodeURIComponent(JSON.stringify(options))} jest `
|
|
357
|
-
+ ([
|
|
358
|
-
'--passWithNoTests',
|
|
359
|
-
`${watch ? '--watchAll' : ''}`
|
|
360
|
-
].join(' '));
|
|
361
|
-
if (dryRun)
|
|
362
|
-
return Shell.spawn(`echo ${command}`);
|
|
363
|
-
await Shell.spawn(command);
|
|
364
|
-
if (!watch)
|
|
365
|
-
return;
|
|
366
|
-
Logger.log(packageName || '', '测试已通过');
|
|
367
|
-
}, {
|
|
368
|
-
onError: (e) => {
|
|
369
|
-
if (typeof e === 'number' && e === 1) {
|
|
370
|
-
Logger.error('测试未通过');
|
|
371
|
-
}
|
|
372
|
-
else {
|
|
373
|
-
Logger.error(e);
|
|
374
|
-
}
|
|
375
|
-
process.exit(1);
|
|
376
|
-
}
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
const run$2 = (options) => Utils.autoCatch(async () => {
|
|
380
|
-
if (typeof options.dryRun === 'undefined') {
|
|
381
|
-
options.dryRun = process.env.NODE_ENV === 'UNIT';
|
|
382
|
-
}
|
|
383
|
-
if (options.dryRun)
|
|
384
|
-
return Shell.spawn(`echo development`);
|
|
385
|
-
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
|
386
|
-
options.watch = true;
|
|
387
|
-
await run$3(options);
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
const require$$1 = createRequire(import.meta.url);
|
|
391
|
-
class Builder {
|
|
392
|
-
packageDir;
|
|
393
|
-
packageName;
|
|
394
|
-
packageOptions;
|
|
395
|
-
config;
|
|
396
|
-
constructor(config) {
|
|
397
|
-
const { workspace, packageDir, packageName } = Shared.impl();
|
|
398
|
-
if (typeof config === 'string') {
|
|
399
|
-
let packageFolderName = config;
|
|
400
|
-
let packageDir$ = path.resolve(packageDir, packageFolderName);
|
|
401
|
-
config = {
|
|
402
|
-
dir: packageDir$,
|
|
403
|
-
name: packageFolderName || 'index',
|
|
404
|
-
input: packageDir$ + '/src/index.ts',
|
|
405
|
-
output: {
|
|
406
|
-
file: packageDir$ + '/dist/index.js',
|
|
407
|
-
format: 'es',
|
|
408
|
-
exports: 'named',
|
|
409
|
-
sourcemap: false
|
|
410
|
-
}
|
|
411
|
-
};
|
|
412
|
-
}
|
|
413
|
-
this.packageDir = path.resolve(packageDir, workspace ? `./${config.name}` : '');
|
|
414
|
-
this.packageName = config.name === 'index'
|
|
415
|
-
? packageName
|
|
416
|
-
: `${packageName}-${config.name}`;
|
|
417
|
-
this.packageOptions = require$$1(`${this.packageDir}/package.json`);
|
|
418
|
-
this.config = config;
|
|
419
|
-
}
|
|
420
|
-
async process() {
|
|
421
|
-
const { packageName, packageDir } = this;
|
|
422
|
-
const spinner = ora(`${packageName} Build ...`);
|
|
423
|
-
try {
|
|
424
|
-
spinner.start();
|
|
425
|
-
await fs.emptyDir(`${packageDir}/dist`);
|
|
426
|
-
const stat = await this.buildSourceAsES();
|
|
427
|
-
await this.buildTypes();
|
|
428
|
-
spinner.stop();
|
|
429
|
-
Logger.log(`${chalk.cyan(`${packageName}`)} ${chalk.green('Success')} ES: ${Utils.formatBytes(stat.size)}`);
|
|
430
|
-
}
|
|
431
|
-
catch (e) {
|
|
432
|
-
Logger.log('Error!', e);
|
|
433
|
-
throw e;
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
async buildSourceAsES() {
|
|
437
|
-
const { workspace } = Shared.impl();
|
|
438
|
-
const { name, input, output } = this.config;
|
|
439
|
-
const { packageOptions } = this;
|
|
440
|
-
const external = Object
|
|
441
|
-
.keys({
|
|
442
|
-
...packageOptions.dependencies,
|
|
443
|
-
...packageOptions.peerDependencies
|
|
444
|
-
})
|
|
445
|
-
.map(i => new RegExp(`^${i}$`));
|
|
446
|
-
const source = workspace ? `${workspace}/${name}/**/*` : 'src/**/*';
|
|
447
|
-
const shims = workspace ? `${workspace}/shims.d.ts` : 'shims.d.ts';
|
|
448
|
-
const outDir = workspace ? `${workspace}/${name}/dist` : 'dist';
|
|
449
|
-
const builder = await rollup({
|
|
450
|
-
input,
|
|
451
|
-
external: [
|
|
452
|
-
/^node:/,
|
|
453
|
-
/^[a-zA-Z@]/,
|
|
454
|
-
...external
|
|
455
|
-
],
|
|
456
|
-
plugins: [
|
|
457
|
-
typescript({
|
|
458
|
-
include: [source, shims],
|
|
459
|
-
exclude: ['dist'],
|
|
460
|
-
compilerOptions: {
|
|
461
|
-
rootDir: '.',
|
|
462
|
-
outDir,
|
|
463
|
-
declaration: true
|
|
464
|
-
}
|
|
465
|
-
}),
|
|
466
|
-
commonjs({ extensions: ['.js', '.ts'] }),
|
|
467
|
-
nodeResolve(),
|
|
468
|
-
replace({
|
|
469
|
-
'1.0.6': `'${packageOptions.version}'`,
|
|
470
|
-
false: 'false',
|
|
471
|
-
true: true
|
|
472
|
-
})
|
|
473
|
-
]
|
|
474
|
-
});
|
|
475
|
-
await builder.write(output);
|
|
476
|
-
const stat = await fs.stat(output.file);
|
|
477
|
-
return stat;
|
|
478
|
-
}
|
|
479
|
-
async buildTypes() {
|
|
480
|
-
const { workspace } = Shared.impl();
|
|
481
|
-
const { packageDir } = this;
|
|
482
|
-
const config = path.resolve(packageDir, `api-extractor.json`);
|
|
483
|
-
if (fs.existsSync(config)) {
|
|
484
|
-
const result = Extractor.invoke(ExtractorConfig.loadFileAndPrepare(config), {
|
|
485
|
-
localBuild: true,
|
|
486
|
-
showVerboseMessages: false
|
|
487
|
-
});
|
|
488
|
-
if (!result.succeeded) {
|
|
489
|
-
Logger.error(`API Extractor completed with ${result.errorCount} errors and ${result.warningCount} warnings`);
|
|
490
|
-
process.exitCode = 1;
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
await fs.remove(`${packageDir}/dist/${workspace || 'src'}`);
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
const builder = (options) => {
|
|
497
|
-
return new Builder(options);
|
|
498
|
-
};
|
|
499
|
-
|
|
500
|
-
const run$1 = (options) => Utils.autoCatch(async () => {
|
|
501
|
-
const locals = Shared.impl();
|
|
502
|
-
if (typeof options.dryRun === 'undefined') {
|
|
503
|
-
options.dryRun = process.env.NODE_ENV === 'UNIT';
|
|
504
|
-
}
|
|
505
|
-
const { normalizePackageFolderNames } = Shared.impl();
|
|
506
|
-
let packageFolderName = Shared.getPackageFolderName(options.packageName || '**');
|
|
507
|
-
let inputs = [];
|
|
508
|
-
if (locals.workspace && packageFolderName === '**') {
|
|
509
|
-
inputs = normalizePackageFolderNames;
|
|
510
|
-
}
|
|
511
|
-
else {
|
|
512
|
-
inputs = [packageFolderName];
|
|
513
|
-
}
|
|
514
|
-
if (options.dryRun)
|
|
515
|
-
return Shell.spawn(`echo ${inputs.join(' ')}`);
|
|
516
|
-
await inputs
|
|
517
|
-
.reduce((preProcess, packageFolderName$) => {
|
|
518
|
-
preProcess = preProcess.then(() => builder(packageFolderName$).process());
|
|
519
|
-
return preProcess;
|
|
520
|
-
}, Promise.resolve());
|
|
521
|
-
}, {
|
|
522
|
-
onError: (e) => {
|
|
523
|
-
if (typeof e === 'number' && e === 1) {
|
|
524
|
-
Logger.error('编译未通过');
|
|
525
|
-
}
|
|
526
|
-
else {
|
|
527
|
-
Logger.error(e);
|
|
528
|
-
}
|
|
529
|
-
process.exit(1);
|
|
530
|
-
}
|
|
531
|
-
});
|
|
532
|
-
|
|
533
|
-
const require$ = createRequire(import.meta.url);
|
|
534
|
-
const { prompt } = inquirer;
|
|
535
|
-
const HASH = '-hash-';
|
|
536
|
-
const SUFFIX = '🐒💨🙊';
|
|
537
|
-
const parserOptions = {
|
|
538
|
-
noteKeywords: ['BREAKING CHANGE', 'Breaking Change']
|
|
539
|
-
};
|
|
540
|
-
const reBreaking = new RegExp(`(${parserOptions.noteKeywords.join(')|(')})`);
|
|
541
|
-
class Releaser {
|
|
542
|
-
packageDir;
|
|
543
|
-
packageName;
|
|
544
|
-
packageFolderName;
|
|
545
|
-
packageOptions;
|
|
546
|
-
packageRelation;
|
|
547
|
-
config;
|
|
548
|
-
changeLog;
|
|
549
|
-
version;
|
|
550
|
-
commits;
|
|
551
|
-
commandOptions;
|
|
552
|
-
constructor(config, commandOptions) {
|
|
553
|
-
const { packageDir, packageRelation } = Shared.impl();
|
|
554
|
-
if (typeof config === 'string') {
|
|
555
|
-
let packageFolderName = config;
|
|
556
|
-
let packageDir$ = path.resolve(packageDir, packageFolderName);
|
|
557
|
-
config = {
|
|
558
|
-
dir: packageDir$,
|
|
559
|
-
name: packageFolderName
|
|
560
|
-
};
|
|
561
|
-
}
|
|
562
|
-
this.packageDir = config.dir;
|
|
563
|
-
this.packageName = Shared.getPackageName(config.name);
|
|
564
|
-
this.packageFolderName = config.name;
|
|
565
|
-
this.packageOptions = require$(`${this.packageDir}/package.json`);
|
|
566
|
-
this.packageRelation = packageRelation[this.packageName] || [];
|
|
567
|
-
this.config = config;
|
|
568
|
-
this.commits = [];
|
|
569
|
-
this.changeLog = '';
|
|
570
|
-
this.version = '';
|
|
571
|
-
this.commandOptions = commandOptions;
|
|
572
|
-
}
|
|
573
|
-
async parseCommits() {
|
|
574
|
-
const { workspace } = Shared.impl();
|
|
575
|
-
const { packageFolderName, packageName, commandOptions } = this;
|
|
576
|
-
let params = ['tag', '--list', `'${packageName}@*'`, '--sort', '-v:refname'];
|
|
577
|
-
const { stdout: tags } = await Shell.exec('git', params);
|
|
578
|
-
const [latestTag] = tags.split('\n');
|
|
579
|
-
Logger.log(chalk.yellow(`Last Release Tag`) + `: ${latestTag || '<none>'}`);
|
|
580
|
-
params = ['--no-pager', 'log', `${latestTag}..HEAD`, `--format=%B%n${HASH}%n%H${SUFFIX}`];
|
|
581
|
-
let { stdout } = await Shell.exec('git', params);
|
|
582
|
-
let skipGetLog = false;
|
|
583
|
-
if (latestTag) {
|
|
584
|
-
const log1 = await Shell.exec('git', ['rev-parse', latestTag]);
|
|
585
|
-
const log2 = await Shell.exec('git', ['--no-pager', 'log', '-1', '--format=%H']);
|
|
586
|
-
if (log1.stdout === log2.stdout) {
|
|
587
|
-
skipGetLog = true;
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
if (!skipGetLog && !stdout) {
|
|
591
|
-
if (latestTag) {
|
|
592
|
-
params.splice(2, 1, `${latestTag}`);
|
|
593
|
-
}
|
|
594
|
-
else {
|
|
595
|
-
params.splice(2, 1, 'HEAD');
|
|
596
|
-
}
|
|
597
|
-
({ stdout } = await Shell.exec('git', params));
|
|
598
|
-
}
|
|
599
|
-
const allowTypes = ['feat', `fix`, `break change`, `style`, `perf`, `types`, `refactor`, `chore`];
|
|
600
|
-
const rePlugin = new RegExp(`^(${allowTypes.join('|')})${workspace ? `\\(${packageFolderName}\\)` : '(\\(.+\\))?'}: .*`, 'i');
|
|
601
|
-
const allCommits = stdout.split(SUFFIX);
|
|
602
|
-
const commits = allCommits
|
|
603
|
-
.filter((commit) => {
|
|
604
|
-
const chunk = commit.trim();
|
|
605
|
-
return chunk && rePlugin.test(chunk);
|
|
606
|
-
})
|
|
607
|
-
.map((commit) => {
|
|
608
|
-
const node = parser.sync(commit);
|
|
609
|
-
const body = (node.body || node.footer);
|
|
610
|
-
if (!node.type)
|
|
611
|
-
node.type = parser.sync(node.header?.replace(/\(.+\)!?:/, ':') || '').type;
|
|
612
|
-
if (!node.hash)
|
|
613
|
-
node.hash = commit.split(HASH).pop()?.trim();
|
|
614
|
-
node.breaking = reBreaking.test(body) || /!:/.test(node.header);
|
|
615
|
-
node.effect = false;
|
|
616
|
-
node.custom = false;
|
|
617
|
-
return node;
|
|
618
|
-
});
|
|
619
|
-
if (!commits.length) {
|
|
620
|
-
Logger.log(chalk.red(`No Commits Found.`));
|
|
621
|
-
}
|
|
622
|
-
else {
|
|
623
|
-
Logger.log(chalk.yellow(`Found `)
|
|
624
|
-
+ chalk.bold(`${allCommits.length}`)
|
|
625
|
-
+ ` Commits, `
|
|
626
|
-
+ chalk.bold(`${commits.length}`)
|
|
627
|
-
+ ' Commits Valid');
|
|
628
|
-
}
|
|
629
|
-
const { skipUpdatePackage } = commandOptions;
|
|
630
|
-
if (commits.length && skipUpdatePackage) {
|
|
631
|
-
let skip = false;
|
|
632
|
-
if (typeof skipUpdatePackage === 'boolean' && skipUpdatePackage) {
|
|
633
|
-
let result = await prompt([
|
|
634
|
-
{
|
|
635
|
-
type: 'confirm',
|
|
636
|
-
name: 'skip',
|
|
637
|
-
message: `Skip Update(${this.packageName}@${this.packageOptions.version}):`,
|
|
638
|
-
default: true
|
|
639
|
-
}
|
|
640
|
-
]);
|
|
641
|
-
skip = result.skip;
|
|
642
|
-
}
|
|
643
|
-
else if (typeof skipUpdatePackage === 'string'
|
|
644
|
-
&& (skipUpdatePackage === '**'
|
|
645
|
-
|| skipUpdatePackage.split(',').includes(this.packageName))) {
|
|
646
|
-
skip = true;
|
|
647
|
-
}
|
|
648
|
-
if (skip) {
|
|
649
|
-
Logger.log(chalk.red(`Skipping Update\n`));
|
|
650
|
-
return;
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
await this.updateVersion();
|
|
654
|
-
await this.updateCommits(commits);
|
|
655
|
-
const { forceUpdatePackage } = commandOptions;
|
|
656
|
-
if (!commits.length && forceUpdatePackage) {
|
|
657
|
-
let force = false;
|
|
658
|
-
if (typeof forceUpdatePackage === 'boolean' && forceUpdatePackage) {
|
|
659
|
-
let result = await prompt([
|
|
660
|
-
{
|
|
661
|
-
type: 'confirm',
|
|
662
|
-
name: 'force',
|
|
663
|
-
message: `Force Update(${this.packageName}@${this.packageOptions.version}):`,
|
|
664
|
-
default: true
|
|
665
|
-
}
|
|
666
|
-
]);
|
|
667
|
-
force = result.force;
|
|
668
|
-
}
|
|
669
|
-
else if (typeof forceUpdatePackage === 'string'
|
|
670
|
-
&& (forceUpdatePackage === '**'
|
|
671
|
-
|| forceUpdatePackage.split(',').includes(this.packageName))) {
|
|
672
|
-
force = true;
|
|
673
|
-
}
|
|
674
|
-
if (force) {
|
|
675
|
-
const oldVersion = this.packageOptions.version;
|
|
676
|
-
const versionChanged = `\`${oldVersion}\` -> \`${this.version}\``;
|
|
677
|
-
this.commits = [
|
|
678
|
-
{
|
|
679
|
-
type: 'chore',
|
|
680
|
-
header: `chore(${this.packageFolderName || 'release'}): force-publish ${versionChanged}`,
|
|
681
|
-
hash: '',
|
|
682
|
-
effect: false,
|
|
683
|
-
breaking: false,
|
|
684
|
-
custom: true
|
|
685
|
-
}
|
|
686
|
-
];
|
|
687
|
-
this.changeLog = `### Force Update Package\n\n- ${versionChanged}`.trim();
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
rebuildChangeLog(commits) {
|
|
692
|
-
const { packageDir } = this;
|
|
693
|
-
const { homepage, workspace } = Shared.impl();
|
|
694
|
-
const logPath = path.resolve(packageDir, './CHANGELOG.md');
|
|
695
|
-
const logFile = fs.existsSync(logPath) ? fs.readFileSync(logPath, 'utf-8') : '';
|
|
696
|
-
const notes = {
|
|
697
|
-
breaking: [],
|
|
698
|
-
features: [],
|
|
699
|
-
fixes: [],
|
|
700
|
-
updates: []
|
|
701
|
-
};
|
|
702
|
-
const closeRegxp = /\(?(closes? )\(?#((\d+))\)/ig;
|
|
703
|
-
const pullRegxp = /(?<!closes? )\((#(\d+))\)/ig;
|
|
704
|
-
for (const commit of commits) {
|
|
705
|
-
const { effect, breaking, hash, header, type } = commit;
|
|
706
|
-
const ref = !hash || pullRegxp.test(header)
|
|
707
|
-
? ''
|
|
708
|
-
: ` ([${hash?.substring(0, 7)}](${homepage}/commit/${hash}))`;
|
|
709
|
-
let message = header?.trim();
|
|
710
|
-
if (workspace && !effect) {
|
|
711
|
-
message = message.replace(/\(.+\)!?:/, ':');
|
|
712
|
-
}
|
|
713
|
-
message = message
|
|
714
|
-
.replace(pullRegxp, `[$1](${homepage}/pull/$2)`)
|
|
715
|
-
.replace(closeRegxp, `[$1$2](${homepage}/issues/$2)`) + ref;
|
|
716
|
-
if (breaking) {
|
|
717
|
-
notes.breaking.push(message);
|
|
718
|
-
}
|
|
719
|
-
else if (type === 'fix') {
|
|
720
|
-
notes.fixes.push(message);
|
|
721
|
-
}
|
|
722
|
-
else if (type === 'feat') {
|
|
723
|
-
notes.features.push(message);
|
|
724
|
-
}
|
|
725
|
-
else {
|
|
726
|
-
notes.updates.push(message);
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
Object.keys(notes).forEach(i => {
|
|
730
|
-
notes[i] = notes[i].filter((j) => {
|
|
731
|
-
return !logFile.includes(j);
|
|
732
|
-
});
|
|
733
|
-
});
|
|
734
|
-
const parts = [
|
|
735
|
-
notes.breaking.length ? `### Breaking Changes\n\n- ${notes.breaking.join('\n- ')}`.trim() : '',
|
|
736
|
-
notes.fixes.length ? `### Bugfixes\n\n- ${notes.fixes.join('\n- ')}`.trim() : '',
|
|
737
|
-
notes.features.length ? `### Features\n\n- ${notes.features.join('\n- ')}`.trim() : '',
|
|
738
|
-
notes.updates.length ? `### Updates\n\n- ${notes.updates.join('\n- ')}`.trim() : ''
|
|
739
|
-
].filter(Boolean);
|
|
740
|
-
const newLog = parts.join('\n\n');
|
|
741
|
-
return !parts.length || logFile.includes(newLog)
|
|
742
|
-
? ''
|
|
743
|
-
: newLog;
|
|
744
|
-
}
|
|
745
|
-
async updateVersion() {
|
|
746
|
-
const { packageOptions, commits, commandOptions } = this;
|
|
747
|
-
const { version } = packageOptions;
|
|
748
|
-
let newVersion = '';
|
|
749
|
-
if (commandOptions.customVersion) {
|
|
750
|
-
newVersion = commandOptions.customVersion;
|
|
751
|
-
if (!(/\d+.\d+.\d+/.test(newVersion)) || version === newVersion) {
|
|
752
|
-
let result = await prompt([
|
|
753
|
-
{
|
|
754
|
-
type: 'input',
|
|
755
|
-
name: 'version',
|
|
756
|
-
message: `Custom Update Version(${this.packageName}@${version}):`,
|
|
757
|
-
default: '',
|
|
758
|
-
validate: (answer) => {
|
|
759
|
-
if (!(/\d+.\d+.\d+/.test(answer))) {
|
|
760
|
-
return 'Version Should Be Like x.x.x';
|
|
761
|
-
}
|
|
762
|
-
if (answer === version) {
|
|
763
|
-
return 'Version Should Be Diff Than Before';
|
|
764
|
-
}
|
|
765
|
-
return true;
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
]);
|
|
769
|
-
newVersion = result.version;
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
else {
|
|
773
|
-
const intersection = [
|
|
774
|
-
commandOptions.major && 'major',
|
|
775
|
-
commandOptions.minor && 'minor',
|
|
776
|
-
commandOptions.patch && 'patch'
|
|
777
|
-
].filter(i => !!i);
|
|
778
|
-
if (intersection.length) {
|
|
779
|
-
newVersion = semver.inc(version, intersection[0]) || '';
|
|
780
|
-
}
|
|
781
|
-
else {
|
|
782
|
-
const types = new Set(commits.map(({ type }) => type));
|
|
783
|
-
const breaking = commits.some((commit) => !!commit.breaking);
|
|
784
|
-
const level = breaking
|
|
785
|
-
? 'major'
|
|
786
|
-
: types.has('feat')
|
|
787
|
-
? 'minor'
|
|
788
|
-
: 'patch';
|
|
789
|
-
newVersion = semver.inc(version, level) || '';
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
this.version = newVersion;
|
|
793
|
-
}
|
|
794
|
-
isChanged() {
|
|
795
|
-
return !!this.commits.length;
|
|
796
|
-
}
|
|
797
|
-
async updateCommits(commits, source) {
|
|
798
|
-
if (!commits.length)
|
|
799
|
-
return;
|
|
800
|
-
const { packageName } = this;
|
|
801
|
-
const olds = this.commits.map(i => JSON.stringify(i));
|
|
802
|
-
const newCommits = commits
|
|
803
|
-
.filter(i => {
|
|
804
|
-
return !olds.includes(JSON.stringify(i));
|
|
805
|
-
})
|
|
806
|
-
.map(j => {
|
|
807
|
-
return {
|
|
808
|
-
...j,
|
|
809
|
-
effect: !!source
|
|
810
|
-
};
|
|
811
|
-
});
|
|
812
|
-
if (newCommits.length && this.commits.length) {
|
|
813
|
-
this.commits = this.commits.filter(i => !i.custom);
|
|
814
|
-
}
|
|
815
|
-
const commits$ = this.commits.concat(newCommits);
|
|
816
|
-
if (source) {
|
|
817
|
-
Logger.log(chalk.magenta(`MERGE COMMITS: `)
|
|
818
|
-
+ chalk.bold(`${commits.length}`) + ` Commits. `
|
|
819
|
-
+ 'merge ' + chalk.yellow(source) + ' into ' + chalk.green(packageName));
|
|
820
|
-
}
|
|
821
|
-
else {
|
|
822
|
-
Logger.log(``);
|
|
823
|
-
}
|
|
824
|
-
const changeLog = this.rebuildChangeLog(commits$);
|
|
825
|
-
if (changeLog) {
|
|
826
|
-
this.commits = commits$;
|
|
827
|
-
this.changeLog = changeLog;
|
|
828
|
-
}
|
|
829
|
-
else if (commits.length) {
|
|
830
|
-
Logger.log(chalk.red(`${commits.length} Commits Already Exists.`));
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
async updatePackageOptions(relationVerisons = {}) {
|
|
834
|
-
if (!this.isChanged())
|
|
835
|
-
return;
|
|
836
|
-
const { packageDir, packageOptions, commandOptions } = this;
|
|
837
|
-
const { dependencies, devDependencies } = packageOptions;
|
|
838
|
-
const newVersion = this.version;
|
|
839
|
-
Logger.log(chalk.yellow(`New Version: `) + `${newVersion}`);
|
|
840
|
-
packageOptions.version = newVersion;
|
|
841
|
-
if (Object.keys(this.packageRelation).length) {
|
|
842
|
-
for (let packageName$ in relationVerisons) {
|
|
843
|
-
let newVersion$ = relationVerisons[packageName$];
|
|
844
|
-
if (dependencies?.[packageName$]) {
|
|
845
|
-
dependencies[packageName$] = newVersion$;
|
|
846
|
-
}
|
|
847
|
-
if (devDependencies?.[packageName$]) {
|
|
848
|
-
devDependencies[packageName$] = newVersion$;
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
if (commandOptions.dryRun) {
|
|
853
|
-
Logger.log(chalk.yellow(`Skipping package.json Update`));
|
|
854
|
-
return;
|
|
855
|
-
}
|
|
856
|
-
Logger.log(chalk.yellow(`Updating `) + 'package.json');
|
|
857
|
-
fs.outputFileSync(`${packageDir}/package.json`, JSON.stringify(packageOptions, null, 2));
|
|
858
|
-
}
|
|
859
|
-
async updateChangelog() {
|
|
860
|
-
if (!this.isChanged())
|
|
861
|
-
return;
|
|
862
|
-
const { packageName, packageDir, packageOptions, commandOptions } = this;
|
|
863
|
-
const title = `# ${packageName} ChangeLog`;
|
|
864
|
-
const [date] = new Date().toISOString().split('T');
|
|
865
|
-
const logPath = path.resolve(packageDir, './CHANGELOG.md');
|
|
866
|
-
const logFile = fs.existsSync(logPath) ? fs.readFileSync(logPath, 'utf-8') : '';
|
|
867
|
-
const oldNotes = logFile.startsWith(title) ? logFile.slice(title.length).trim() : logFile;
|
|
868
|
-
const parts = [
|
|
869
|
-
`## v${packageOptions.version}`,
|
|
870
|
-
`_${date}_`,
|
|
871
|
-
this.changeLog
|
|
872
|
-
].filter(Boolean);
|
|
873
|
-
const newLog = parts.join('\n\n');
|
|
874
|
-
if (commandOptions.dryRun) {
|
|
875
|
-
Logger.log(chalk.yellow(`New ChangeLog:`) + `\n${newLog}`);
|
|
876
|
-
return;
|
|
877
|
-
}
|
|
878
|
-
Logger.log(chalk.yellow(`Updating `) + `CHANGELOG.md`);
|
|
879
|
-
let content = [title, newLog, oldNotes].filter(Boolean).join('\n\n');
|
|
880
|
-
if (!content.endsWith('\n'))
|
|
881
|
-
content += '\n';
|
|
882
|
-
fs.writeFileSync(logPath, content, 'utf-8');
|
|
883
|
-
}
|
|
884
|
-
async test() {
|
|
885
|
-
if (!this.isChanged())
|
|
886
|
-
return;
|
|
887
|
-
const { commandOptions } = this;
|
|
888
|
-
if (commandOptions.dryRun) {
|
|
889
|
-
Logger.log(chalk.yellow('Skipping Test'));
|
|
890
|
-
return;
|
|
891
|
-
}
|
|
892
|
-
else {
|
|
893
|
-
Logger.log(chalk.yellow('Test...'));
|
|
894
|
-
}
|
|
895
|
-
await Shell.exec(`npm run test -- --package-name ${this.packageName}`);
|
|
896
|
-
}
|
|
897
|
-
async build() {
|
|
898
|
-
if (!this.isChanged())
|
|
899
|
-
return;
|
|
900
|
-
const { commandOptions } = this;
|
|
901
|
-
if (commandOptions.dryRun) {
|
|
902
|
-
Logger.log(chalk.yellow('Skipping Build'));
|
|
903
|
-
return;
|
|
904
|
-
}
|
|
905
|
-
else {
|
|
906
|
-
Logger.log(chalk.yellow('Build...'));
|
|
907
|
-
}
|
|
908
|
-
await Shell.exec(`npm run build -- --package-name ${this.packageName}`);
|
|
909
|
-
}
|
|
910
|
-
async publish() {
|
|
911
|
-
if (!this.isChanged())
|
|
912
|
-
return;
|
|
913
|
-
const { commandOptions, packageDir } = this;
|
|
914
|
-
if (commandOptions.dryRun || !commandOptions.publish) {
|
|
915
|
-
Logger.log(chalk.yellow(`Skipping Publish`));
|
|
916
|
-
return;
|
|
917
|
-
}
|
|
918
|
-
Logger.log(chalk.cyan(`\n Publishing to NPM`));
|
|
919
|
-
await Shell.spawn('npm', ['publish', '--no-git-checks', '--access', 'public'], {
|
|
920
|
-
cwd: packageDir
|
|
921
|
-
});
|
|
922
|
-
}
|
|
923
|
-
async tag() {
|
|
924
|
-
if (!this.isChanged())
|
|
925
|
-
return;
|
|
926
|
-
const { commandOptions, packageDir } = this;
|
|
927
|
-
const { packageName, packageOptions } = this;
|
|
928
|
-
if (commandOptions.dryRun || !commandOptions.tag) {
|
|
929
|
-
Logger.log(chalk.yellow(`Skipping Git Tag`));
|
|
930
|
-
return;
|
|
931
|
-
}
|
|
932
|
-
const tagName = `${packageName}@${packageOptions.version}`;
|
|
933
|
-
Logger.log(chalk.blue(`\n Tagging`) + chalk.grey(`${tagName}`));
|
|
934
|
-
await Shell.spawn('git', ['tag', tagName], {
|
|
935
|
-
cwd: packageDir
|
|
936
|
-
});
|
|
937
|
-
}
|
|
938
|
-
async process() {
|
|
939
|
-
const { workspace } = Shared.impl();
|
|
940
|
-
const { packageName, packageDir, packageFolderName } = this;
|
|
941
|
-
if (!packageDir || !fs.pathExists(packageDir)) {
|
|
942
|
-
throw new RangeError(`Could not find directory for package: ${packageFolderName}`);
|
|
943
|
-
}
|
|
944
|
-
Logger.log(chalk.cyan(`Releasing ${packageName}`) + ' from ' + chalk.grey(`${workspace}/${packageFolderName}`));
|
|
945
|
-
await this.parseCommits();
|
|
946
|
-
return this;
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
const releaser = (options, commandOptions) => {
|
|
950
|
-
return new Releaser(options, commandOptions);
|
|
951
|
-
};
|
|
952
|
-
|
|
953
|
-
const run = (options) => Utils.autoCatch(async () => {
|
|
954
|
-
const locals = Shared.impl();
|
|
955
|
-
if (options.dryRun) {
|
|
956
|
-
Logger.log(chalk.magenta(`DRY RUN: `)
|
|
957
|
-
+ 'No files will be modified.');
|
|
958
|
-
}
|
|
959
|
-
let inputs = [];
|
|
960
|
-
if (locals.workspace) {
|
|
961
|
-
inputs = locals.normalizePackageFolderNames;
|
|
962
|
-
}
|
|
963
|
-
else {
|
|
964
|
-
inputs = [''];
|
|
965
|
-
}
|
|
966
|
-
const instances = {};
|
|
967
|
-
await inputs
|
|
968
|
-
.reduce((preProcess, packageFolderName) => {
|
|
969
|
-
preProcess = preProcess
|
|
970
|
-
.then(() => releaser(packageFolderName, options).process())
|
|
971
|
-
.then((instance) => {
|
|
972
|
-
instances[packageFolderName] = instance;
|
|
973
|
-
});
|
|
974
|
-
return preProcess;
|
|
975
|
-
}, Promise.resolve());
|
|
976
|
-
Logger.log(chalk.blue(`---------------------\n`));
|
|
977
|
-
let message = `chore(release): publish\n\n`;
|
|
978
|
-
let relationVerisons = {};
|
|
979
|
-
await inputs.reduce((preProcess, packageFolderName) => {
|
|
980
|
-
const instance = instances[packageFolderName];
|
|
981
|
-
instance.packageRelation.forEach(i => {
|
|
982
|
-
let packageFolderName$ = Shared.getPackageFolderName(i);
|
|
983
|
-
let instance$ = instances[packageFolderName$];
|
|
984
|
-
if (instance$.commits.length > 0) {
|
|
985
|
-
instance.updateCommits(instance$.commits, instance$.packageName);
|
|
986
|
-
}
|
|
987
|
-
});
|
|
988
|
-
if (instance.commits.length) {
|
|
989
|
-
preProcess = preProcess
|
|
990
|
-
.then(() => Logger.log(chalk.magenta(`CHANGED: `) + instance.packageName))
|
|
991
|
-
.then(() => instance.test())
|
|
992
|
-
.then(() => instance.build())
|
|
993
|
-
.then(() => instance.updatePackageOptions(relationVerisons))
|
|
994
|
-
.then(() => instance.updateChangelog())
|
|
995
|
-
.then(() => {
|
|
996
|
-
message += `- ${instance.packageName}@${instance.packageOptions.version}\n`;
|
|
997
|
-
relationVerisons[instance.packageName] = `^${instance.packageOptions.version}`;
|
|
998
|
-
});
|
|
999
|
-
}
|
|
1000
|
-
return preProcess;
|
|
1001
|
-
}, Promise.resolve());
|
|
1002
|
-
Logger.log(chalk.blue(`\n---------------------\n`));
|
|
1003
|
-
const isChanged = Object.keys(relationVerisons).length;
|
|
1004
|
-
if (!isChanged) {
|
|
1005
|
-
Logger.log(chalk.magenta(`COMMIT: `) + 'Nothing Chanaged Found.');
|
|
1006
|
-
}
|
|
1007
|
-
else if (options.dryRun || !options.commit) {
|
|
1008
|
-
Logger.log(chalk.magenta(`COMMIT: `) + chalk.yellow(`Skipping Git Commit`) + `\n${message}`);
|
|
1009
|
-
}
|
|
1010
|
-
else {
|
|
1011
|
-
Logger.log(chalk.magenta(`CHANGED: `) + `pnpm-lock.yaml`);
|
|
1012
|
-
await Shell.spawn('npx', ['pnpm', 'install', '--lockfile-only']);
|
|
1013
|
-
Logger.log(chalk.magenta(`COMMIT: `) + `CHANGELOG.md, package.json, pnpm-lock.yaml`);
|
|
1014
|
-
await Shell.spawn('git', ['add', process.cwd()]);
|
|
1015
|
-
await Shell.spawn('git', ['commit', '--m', `'${message}'`]);
|
|
1016
|
-
}
|
|
1017
|
-
await inputs
|
|
1018
|
-
.reduce((preProcess, packageFolderName) => {
|
|
1019
|
-
const instance = instances[packageFolderName];
|
|
1020
|
-
preProcess = preProcess
|
|
1021
|
-
.then(() => instance.publish())
|
|
1022
|
-
.then(() => instance.tag());
|
|
1023
|
-
return preProcess;
|
|
1024
|
-
}, Promise.resolve());
|
|
1025
|
-
Logger.log(chalk.blue(`\n---------------------\n`));
|
|
1026
|
-
if (options.dryRun || !options.push) {
|
|
1027
|
-
Logger.log(chalk.magenta(`FINISH: `) + 'Skipping Git Push');
|
|
1028
|
-
}
|
|
1029
|
-
else if (!isChanged) {
|
|
1030
|
-
Logger.log(chalk.magenta(`FINISH: `) + 'Nothing Chanaged.');
|
|
1031
|
-
}
|
|
1032
|
-
else {
|
|
1033
|
-
await Shell.spawn('git', ['push']);
|
|
1034
|
-
await Shell.spawn('git', ['push', '--tags']);
|
|
1035
|
-
}
|
|
1036
|
-
if (options.dryRun) {
|
|
1037
|
-
Logger.log(chalk.green('NO DRY RUN WAY: ')
|
|
1038
|
-
+ chalk.grey(`npm run release -- --no-dry-run\n`));
|
|
1039
|
-
}
|
|
1040
|
-
}, {
|
|
1041
|
-
onError: (e) => {
|
|
1042
|
-
if (typeof e === 'number' && e === 1) {
|
|
1043
|
-
Logger.error('发布失败');
|
|
1044
|
-
}
|
|
1045
|
-
else {
|
|
1046
|
-
Logger.error(e);
|
|
1047
|
-
}
|
|
1048
|
-
process.exit(1);
|
|
1049
|
-
}
|
|
1050
|
-
});
|
|
1051
|
-
|
|
1052
|
-
const require = createRequire(import.meta.url);
|
|
1053
|
-
program
|
|
1054
|
-
.version(require('../package.json').version);
|
|
1055
|
-
program
|
|
1056
|
-
.usage('<cmd>');
|
|
1057
|
-
program
|
|
1058
|
-
.command('link')
|
|
1059
|
-
.alias('d')
|
|
1060
|
-
.description('pnpm link')
|
|
1061
|
-
.option('--dry-run [boolean]', 'Dry Run')
|
|
1062
|
-
.action(run$5);
|
|
1063
|
-
program
|
|
1064
|
-
.command('add')
|
|
1065
|
-
.alias('a')
|
|
1066
|
-
.description('add dep or create package')
|
|
1067
|
-
.option('--dry-run [boolean]', 'Dry Run')
|
|
1068
|
-
.action(run$4);
|
|
1069
|
-
program
|
|
1070
|
-
.command('dev')
|
|
1071
|
-
.alias('d')
|
|
1072
|
-
.description('dev')
|
|
1073
|
-
.option('-p, --package-name <string>', 'Select PackageName')
|
|
1074
|
-
.option('--dry-run [boolean]', 'Dry Run')
|
|
1075
|
-
.action(run$2);
|
|
1076
|
-
program
|
|
1077
|
-
.command('build')
|
|
1078
|
-
.alias('b')
|
|
1079
|
-
.description('build')
|
|
1080
|
-
.option('-p, --package-name <string>', 'select packageName')
|
|
1081
|
-
.option('--dry-run [boolean]', 'Dry Run')
|
|
1082
|
-
.action(run$1);
|
|
1083
|
-
program
|
|
1084
|
-
.command('release')
|
|
1085
|
-
.alias('r')
|
|
1086
|
-
.description('release')
|
|
1087
|
-
.option('--no-dry-run [boolean]', 'No Dry Run')
|
|
1088
|
-
.option('--no-tag [boolean]', 'No Tag')
|
|
1089
|
-
.option('--no-publish [boolean]', 'No Publish')
|
|
1090
|
-
.option('--no-commit [boolean]', 'No Commit')
|
|
1091
|
-
.option('--no-push [boolean]', 'No Push')
|
|
1092
|
-
.option('--force-update-package [string]', 'Force Update Package')
|
|
1093
|
-
.option('--skip-update-package [string]', 'Skip Update Package')
|
|
1094
|
-
.option('--custom-version [string]', 'Dry Run')
|
|
1095
|
-
.option('--patch [boolean]', 'Patch')
|
|
1096
|
-
.option('--major [boolean]', 'Major')
|
|
1097
|
-
.option('--minor [boolean]', 'Minor')
|
|
1098
|
-
.action(run);
|
|
1099
|
-
program
|
|
1100
|
-
.command('test')
|
|
1101
|
-
.alias('t')
|
|
1102
|
-
.description('unit-test')
|
|
1103
|
-
.option('-p, --package-name <string>', 'Select PackageName')
|
|
1104
|
-
.option('-w, --watch [boolean]', 'Watch Test')
|
|
1105
|
-
.option('--dry-run [boolean]', 'Dry Run')
|
|
1106
|
-
.action(run$3);
|
|
1107
|
-
program.parse(process.argv);
|
|
1108
|
-
if (!program.args.length) {
|
|
1109
|
-
program.help();
|
|
1110
|
-
}
|