@deot/dev-cli 1.0.5 → 1.0.7
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 +54 -2
- package/config/commit-lint.js +3 -1
- package/config/jest.config.js +13 -4
- package/dist/index.js +96 -49
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,8 +9,60 @@
|
|
|
9
9
|
- `link`
|
|
10
10
|
- `test`
|
|
11
11
|
- `add`
|
|
12
|
-
- `release`: [与本仓库相同](
|
|
12
|
+
- `release`: [与本仓库相同](../../README.md)
|
|
13
13
|
|
|
14
14
|
## 其他
|
|
15
15
|
|
|
16
|
-
暂时不支持全局引入,一些配置项,如`tsconfig.json`, `api-extractor.json`, `jest.config.cjs` 这些依赖项目本身
|
|
16
|
+
暂时不支持全局引入,一些配置项,如`tsconfig.json`, `api-extractor.json`, `jest.config.cjs` 这些依赖项目本身
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## 默认的目录参考(配置后期再考虑)
|
|
20
|
+
|
|
21
|
+
#### Monorepo
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
Monorepo
|
|
25
|
+
├─ .husky
|
|
26
|
+
├─ packages
|
|
27
|
+
│ ├─ index
|
|
28
|
+
│ │ ├─ __tests__
|
|
29
|
+
│ │ ├─ src
|
|
30
|
+
│ │ ├─ api-extractor.json
|
|
31
|
+
│ │ └─ package.json
|
|
32
|
+
│ ├─ shared
|
|
33
|
+
│ │ ├─ __tests__
|
|
34
|
+
│ │ ├─ src
|
|
35
|
+
│ │ ├─ api-extractor.json
|
|
36
|
+
│ │ └─ package.json
|
|
37
|
+
│ └─ shims.d.ts
|
|
38
|
+
├─ .eslintignore
|
|
39
|
+
├─ .eslintrc.cjs
|
|
40
|
+
├─ .lintstagedrc.json
|
|
41
|
+
├─ .npmrc
|
|
42
|
+
├─ jest.config.js
|
|
43
|
+
├─ pnpm-lock.yaml
|
|
44
|
+
├─ pnpm-workspace.yaml
|
|
45
|
+
├─ tsconfig.json
|
|
46
|
+
└─ package.json
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
#### Single Repo
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
Single Repo
|
|
53
|
+
├─ .husky
|
|
54
|
+
├─ __tests__
|
|
55
|
+
├─ src
|
|
56
|
+
├─ .eslintignore
|
|
57
|
+
├─ .eslintrc.cjs
|
|
58
|
+
├─ .npmrc
|
|
59
|
+
├─ jest.config.js
|
|
60
|
+
├─ shims.d.ts
|
|
61
|
+
├─ api-extractor.json
|
|
62
|
+
├─ pnpm-lock.yaml
|
|
63
|
+
├─ pnpm-workspace.yaml
|
|
64
|
+
├─ tsconfig.json
|
|
65
|
+
├─ yarn.lock
|
|
66
|
+
└─ package.json
|
|
67
|
+
```
|
|
68
|
+
|
package/config/commit-lint.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// eslint-disable-next-line max-len
|
|
4
|
+
const commitRE = /^(revert: )?(void|fix|feat|docs|style|perf|test|types|build|chore|refactor|workflow|ci|wip|release|breaking change)(\(.+\))?: .{1,50}/;
|
|
4
5
|
const mergeRE = /Merge branch /;
|
|
5
6
|
|
|
6
7
|
const gitParams = process.env.HUSKY_GIT_PARAMS || process.argv.pop(); // 兼容husky@v4和husky@v8
|
|
@@ -30,6 +31,7 @@ if (!commitRE.test(commitMsg) && !mergeRE.test(commitMsg)) {
|
|
|
30
31
|
- build:影响构建系统或外部依赖项的更改
|
|
31
32
|
- ci: 持续集成相关
|
|
32
33
|
- breaking change:破坏性修改
|
|
34
|
+
- void:无类型,通常用于初始化
|
|
33
35
|
- Merge branch 'foo' into 'bar'
|
|
34
36
|
`
|
|
35
37
|
);
|
package/config/jest.config.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
const options = JSON.parse(decodeURIComponent(process.env.TEST_OPTIONS || '{}'));
|
|
2
|
-
const { packageFolderName } = options;
|
|
2
|
+
const { workspace, packageFolderName } = options;
|
|
3
|
+
const rootDir = process.cwd();
|
|
4
|
+
|
|
5
|
+
const testDirPrefix = workspace
|
|
6
|
+
? `<rootDir>/${workspace}/${packageFolderName || '*'}/__tests__`
|
|
7
|
+
: `<rootDir>/__tests__`;
|
|
8
|
+
|
|
9
|
+
const collectDirPrefix = workspace
|
|
10
|
+
? `<rootDir>/${workspace}/${packageFolderName || '*'}/src`
|
|
11
|
+
: `<rootDir>/src`;
|
|
3
12
|
|
|
4
13
|
export default {
|
|
5
14
|
preset: 'ts-jest',
|
|
@@ -22,19 +31,19 @@ export default {
|
|
|
22
31
|
// 匹配相关
|
|
23
32
|
moduleFileExtensions: ['ts', 'tsx', 'js', 'json'],
|
|
24
33
|
// 匹配规则很重要
|
|
25
|
-
rootDir
|
|
34
|
+
rootDir,
|
|
26
35
|
watchPathIgnorePatterns: ['/node_modules/', '/dist/', '/.git/'],
|
|
27
36
|
testPathIgnorePatterns: [
|
|
28
37
|
'/node_modules/'
|
|
29
38
|
],
|
|
30
39
|
testMatch: [
|
|
31
|
-
|
|
40
|
+
`${testDirPrefix}/**.(spec|test).[jt]s?(x)`
|
|
32
41
|
],
|
|
33
42
|
|
|
34
43
|
collectCoverage: true,
|
|
35
44
|
coverageDirectory: 'coverage',
|
|
36
45
|
collectCoverageFrom: [
|
|
37
|
-
|
|
46
|
+
`${collectDirPrefix}/**/*.ts`
|
|
38
47
|
],
|
|
39
48
|
coverageThreshold: {
|
|
40
49
|
global: {
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { program } from 'commander';
|
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import ora from 'ora';
|
|
5
|
-
import { Utils,
|
|
5
|
+
import { Utils, Logger, Shell } from '@deot/dev-shared';
|
|
6
6
|
import * as path from 'node:path';
|
|
7
7
|
import { resolve } from 'node:path';
|
|
8
8
|
import fs from 'fs-extra';
|
|
@@ -61,16 +61,20 @@ class Shared {
|
|
|
61
61
|
return result.reverse();
|
|
62
62
|
};
|
|
63
63
|
static getPackageName = (packageFolderName$) => {
|
|
64
|
-
const { packageFolderName, packageName } = Shared.impl();
|
|
65
|
-
if (!
|
|
66
|
-
|
|
64
|
+
const { workspace, packageFolderName, packageName } = Shared.impl();
|
|
65
|
+
if (!workspace
|
|
66
|
+
|| !packageFolderName$
|
|
67
|
+
|| packageFolderName$ === packageFolderName) {
|
|
68
|
+
return packageName;
|
|
67
69
|
}
|
|
68
70
|
else {
|
|
69
71
|
return `${packageName}-${packageFolderName$.replace(new RegExp(`${packageName}-?`), '')}`;
|
|
70
72
|
}
|
|
71
73
|
};
|
|
72
74
|
static getPackageFolderName = (packageName$) => {
|
|
73
|
-
const { packageFolderName, packageName } = Shared.impl();
|
|
75
|
+
const { workspace, packageFolderName, packageName } = Shared.impl();
|
|
76
|
+
if (!workspace)
|
|
77
|
+
return '';
|
|
74
78
|
if (packageName$ === packageName)
|
|
75
79
|
return packageFolderName;
|
|
76
80
|
return packageName$?.replace(new RegExp(`${packageName}-?`), '');
|
|
@@ -79,12 +83,15 @@ class Shared {
|
|
|
79
83
|
if (Shared.config)
|
|
80
84
|
return Shared.config;
|
|
81
85
|
const rootPackageOptions = require$$2(`${cwd}/package.json`);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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'));
|
|
85
92
|
const packageName = packageOptions.name;
|
|
86
93
|
const packageVersion = packageOptions.version;
|
|
87
|
-
const packageFolderNames = fs
|
|
94
|
+
const packageFolderNames = !isMonorepo ? [] : fs
|
|
88
95
|
.readdirSync(packageDir)
|
|
89
96
|
.reduce((pre, file) => {
|
|
90
97
|
const fullpath = path.resolve(packageDir, file);
|
|
@@ -95,12 +102,12 @@ class Shared {
|
|
|
95
102
|
}
|
|
96
103
|
return pre;
|
|
97
104
|
}, []);
|
|
98
|
-
const packageOptionsMap = packageFolderNames.reduce((pre,
|
|
99
|
-
pre[
|
|
105
|
+
const packageOptionsMap = packageFolderNames.reduce((pre, packageFolderName$) => {
|
|
106
|
+
pre[packageFolderName$] = require$$2(path.resolve(packageDir, packageFolderName$, 'package.json'));
|
|
100
107
|
return pre;
|
|
101
108
|
}, {});
|
|
102
|
-
const packageRelation = packageFolderNames.reduce((pre,
|
|
103
|
-
let packagesOptions = packageOptionsMap[
|
|
109
|
+
const packageRelation = packageFolderNames.reduce((pre, packageFolderName$) => {
|
|
110
|
+
let packagesOptions = packageOptionsMap[packageFolderName$];
|
|
104
111
|
let deps = {
|
|
105
112
|
...(packagesOptions.dependencies || {}),
|
|
106
113
|
...(packagesOptions.devDependencies || {}),
|
|
@@ -111,8 +118,10 @@ class Shared {
|
|
|
111
118
|
const normalizePackageNames = Shared.getNormalizePackage(packageRelation);
|
|
112
119
|
const normalizePackageFolderNames = normalizePackageNames
|
|
113
120
|
.map(i => i.replace(new RegExp(`${packageName}-?`), '') || packageFolderName);
|
|
121
|
+
const homepage = (rootPackageOptions.repository || packageOptions.repository || {}).url || '';
|
|
114
122
|
const config = {
|
|
115
|
-
|
|
123
|
+
workspace,
|
|
124
|
+
homepage: homepage.replace(/(.*)(https?:\/\/.*)(#|\.git)/, '$2'),
|
|
116
125
|
packageFolderName,
|
|
117
126
|
packageDir,
|
|
118
127
|
packageOptions,
|
|
@@ -130,13 +139,17 @@ class Shared {
|
|
|
130
139
|
}
|
|
131
140
|
|
|
132
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
|
+
}
|
|
133
147
|
if (typeof options.dryRun === 'undefined') {
|
|
134
148
|
options.dryRun = process.env.NODE_ENV === 'UNIT';
|
|
135
149
|
}
|
|
136
|
-
const command =
|
|
150
|
+
const command = `npx pnpm link ./${workspace}/`;
|
|
137
151
|
if (options.dryRun)
|
|
138
152
|
return Shell.spawn(`echo ${command}`);
|
|
139
|
-
const { packageFolderNames } = Shared.impl();
|
|
140
153
|
const spinner = ora(`Links ...\n`);
|
|
141
154
|
spinner.start();
|
|
142
155
|
await Promise.all(packageFolderNames.map(i => {
|
|
@@ -231,14 +244,18 @@ const getOptions$1 = async () => {
|
|
|
231
244
|
};
|
|
232
245
|
|
|
233
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
|
+
}
|
|
234
252
|
if (typeof options.dryRun === 'undefined') {
|
|
235
253
|
options.dryRun = process.env.NODE_ENV === 'UNIT';
|
|
236
254
|
}
|
|
237
255
|
const { mode, dependentName, args, packageFolderName, packageName } = await getOptions$1();
|
|
238
|
-
const { packageDir } = Shared.impl();
|
|
239
256
|
let command = mode === 'dependent'
|
|
240
257
|
? `npx pnpm add --filter ${packageName} ${dependentName} ${args.join(' ')}`
|
|
241
|
-
: `npx pnpm link
|
|
258
|
+
: `npx pnpm link ./${workspace}/${packageFolderName}`;
|
|
242
259
|
if (options.dryRun)
|
|
243
260
|
return Shell.spawn(`echo "${command}"`);
|
|
244
261
|
const spinner = ora(`${command}\n`).start();
|
|
@@ -266,7 +283,7 @@ const run$4 = (options) => Utils.autoCatch(async () => {
|
|
|
266
283
|
}, null, 2));
|
|
267
284
|
fs.outputFileSync(`${dir}/${packageFolderName}/api-extractor.json`, JSON.stringify({
|
|
268
285
|
extends: "../../api-extractor.json",
|
|
269
|
-
mainEntryPointFilePath: `./dist
|
|
286
|
+
mainEntryPointFilePath: `./dist/${workspace}/${packageFolderName}/src/index.d.ts`,
|
|
270
287
|
dtsRollup: {
|
|
271
288
|
publicTrimmedFilePath: "./dist/index.d.ts"
|
|
272
289
|
}
|
|
@@ -317,10 +334,11 @@ const getOptions = async () => {
|
|
|
317
334
|
};
|
|
318
335
|
|
|
319
336
|
const run$3 = (options) => Utils.autoCatch(async () => {
|
|
337
|
+
const locals = Shared.impl();
|
|
320
338
|
if (typeof options.dryRun === 'undefined') {
|
|
321
339
|
options.dryRun = process.env.NODE_ENV === 'UNIT';
|
|
322
340
|
}
|
|
323
|
-
if (!options.packageName) {
|
|
341
|
+
if (locals.workspace && !options.packageName) {
|
|
324
342
|
const promptOptions = await getOptions();
|
|
325
343
|
options = {
|
|
326
344
|
...options,
|
|
@@ -329,8 +347,11 @@ const run$3 = (options) => Utils.autoCatch(async () => {
|
|
|
329
347
|
}
|
|
330
348
|
const { packageName, watch, dryRun } = options;
|
|
331
349
|
options.packageFolderName = Shared.getPackageFolderName(options.packageName) || options.packageFolderName;
|
|
350
|
+
options.workspace = locals.workspace;
|
|
332
351
|
if (!options.packageFolderName)
|
|
333
352
|
delete options.packageFolderName;
|
|
353
|
+
if (!options.workspace)
|
|
354
|
+
delete options.workspace;
|
|
334
355
|
delete options.packageName;
|
|
335
356
|
const command = `cross-env NODE_ENV=${process.env.NODE_ENV || 'TEST'} TEST_OPTIONS=${encodeURIComponent(JSON.stringify(options))} jest `
|
|
336
357
|
+ ([
|
|
@@ -362,6 +383,7 @@ const run$2 = (options) => Utils.autoCatch(async () => {
|
|
|
362
383
|
if (options.dryRun)
|
|
363
384
|
return Shell.spawn(`echo development`);
|
|
364
385
|
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
|
386
|
+
options.watch = true;
|
|
365
387
|
await run$3(options);
|
|
366
388
|
});
|
|
367
389
|
|
|
@@ -372,13 +394,13 @@ class Builder {
|
|
|
372
394
|
packageOptions;
|
|
373
395
|
config;
|
|
374
396
|
constructor(config) {
|
|
375
|
-
const { packageDir, packageName } = Shared.impl();
|
|
397
|
+
const { workspace, packageDir, packageName } = Shared.impl();
|
|
376
398
|
if (typeof config === 'string') {
|
|
377
399
|
let packageFolderName = config;
|
|
378
400
|
let packageDir$ = path.resolve(packageDir, packageFolderName);
|
|
379
401
|
config = {
|
|
380
402
|
dir: packageDir$,
|
|
381
|
-
name: packageFolderName,
|
|
403
|
+
name: packageFolderName || 'index',
|
|
382
404
|
input: packageDir$ + '/src/index.ts',
|
|
383
405
|
output: {
|
|
384
406
|
file: packageDir$ + '/dist/index.js',
|
|
@@ -388,8 +410,10 @@ class Builder {
|
|
|
388
410
|
}
|
|
389
411
|
};
|
|
390
412
|
}
|
|
391
|
-
this.packageDir = path.resolve(packageDir, `./${config.name}`);
|
|
392
|
-
this.packageName = config.name === 'index'
|
|
413
|
+
this.packageDir = path.resolve(packageDir, workspace ? `./${config.name}` : '');
|
|
414
|
+
this.packageName = config.name === 'index'
|
|
415
|
+
? packageName
|
|
416
|
+
: `${packageName}-${config.name}`;
|
|
393
417
|
this.packageOptions = require$$1(`${this.packageDir}/package.json`);
|
|
394
418
|
this.config = config;
|
|
395
419
|
}
|
|
@@ -410,6 +434,7 @@ class Builder {
|
|
|
410
434
|
}
|
|
411
435
|
}
|
|
412
436
|
async buildSourceAsES() {
|
|
437
|
+
const { workspace } = Shared.impl();
|
|
413
438
|
const { name, input, output } = this.config;
|
|
414
439
|
const { packageOptions } = this;
|
|
415
440
|
const external = Object
|
|
@@ -418,6 +443,9 @@ class Builder {
|
|
|
418
443
|
...packageOptions.peerDependencies
|
|
419
444
|
})
|
|
420
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';
|
|
421
449
|
const builder = await rollup({
|
|
422
450
|
input,
|
|
423
451
|
external: [
|
|
@@ -427,18 +455,18 @@ class Builder {
|
|
|
427
455
|
],
|
|
428
456
|
plugins: [
|
|
429
457
|
typescript({
|
|
430
|
-
include: [
|
|
458
|
+
include: [source, shims],
|
|
431
459
|
exclude: ['dist'],
|
|
432
460
|
compilerOptions: {
|
|
433
461
|
rootDir: '.',
|
|
434
|
-
outDir
|
|
462
|
+
outDir,
|
|
435
463
|
declaration: true
|
|
436
464
|
}
|
|
437
465
|
}),
|
|
438
466
|
commonjs({ extensions: ['.js', '.ts'] }),
|
|
439
467
|
nodeResolve(),
|
|
440
468
|
replace({
|
|
441
|
-
'1.0.
|
|
469
|
+
'1.0.6': `'${packageOptions.version}'`,
|
|
442
470
|
false: 'false',
|
|
443
471
|
true: true
|
|
444
472
|
})
|
|
@@ -449,17 +477,20 @@ class Builder {
|
|
|
449
477
|
return stat;
|
|
450
478
|
}
|
|
451
479
|
async buildTypes() {
|
|
480
|
+
const { workspace } = Shared.impl();
|
|
452
481
|
const { packageDir } = this;
|
|
453
482
|
const config = path.resolve(packageDir, `api-extractor.json`);
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
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
|
+
}
|
|
461
492
|
}
|
|
462
|
-
await fs.remove(`${packageDir}/dist
|
|
493
|
+
await fs.remove(`${packageDir}/dist/${workspace || 'src'}`);
|
|
463
494
|
}
|
|
464
495
|
}
|
|
465
496
|
const builder = (options) => {
|
|
@@ -467,13 +498,14 @@ const builder = (options) => {
|
|
|
467
498
|
};
|
|
468
499
|
|
|
469
500
|
const run$1 = (options) => Utils.autoCatch(async () => {
|
|
501
|
+
const locals = Shared.impl();
|
|
470
502
|
if (typeof options.dryRun === 'undefined') {
|
|
471
503
|
options.dryRun = process.env.NODE_ENV === 'UNIT';
|
|
472
504
|
}
|
|
473
505
|
const { normalizePackageFolderNames } = Shared.impl();
|
|
474
506
|
let packageFolderName = Shared.getPackageFolderName(options.packageName || '**');
|
|
475
507
|
let inputs = [];
|
|
476
|
-
if (packageFolderName === '**') {
|
|
508
|
+
if (locals.workspace && packageFolderName === '**') {
|
|
477
509
|
inputs = normalizePackageFolderNames;
|
|
478
510
|
}
|
|
479
511
|
else {
|
|
@@ -531,7 +563,7 @@ class Releaser {
|
|
|
531
563
|
this.packageName = Shared.getPackageName(config.name);
|
|
532
564
|
this.packageFolderName = config.name;
|
|
533
565
|
this.packageOptions = require$(`${this.packageDir}/package.json`);
|
|
534
|
-
this.packageRelation = packageRelation[this.packageName];
|
|
566
|
+
this.packageRelation = packageRelation[this.packageName] || [];
|
|
535
567
|
this.config = config;
|
|
536
568
|
this.commits = [];
|
|
537
569
|
this.changeLog = '';
|
|
@@ -539,13 +571,13 @@ class Releaser {
|
|
|
539
571
|
this.commandOptions = commandOptions;
|
|
540
572
|
}
|
|
541
573
|
async parseCommits() {
|
|
574
|
+
const { workspace } = Shared.impl();
|
|
542
575
|
const { packageFolderName, packageName, commandOptions } = this;
|
|
543
576
|
let params = ['tag', '--list', `'${packageName}@*'`, '--sort', '-v:refname'];
|
|
544
577
|
const { stdout: tags } = await Shell.exec('git', params);
|
|
545
578
|
const [latestTag] = tags.split('\n');
|
|
546
579
|
Logger.log(chalk.yellow(`Last Release Tag`) + `: ${latestTag || '<none>'}`);
|
|
547
580
|
params = ['--no-pager', 'log', `${latestTag}..HEAD`, `--format=%B%n${HASH}%n%H${SUFFIX}`];
|
|
548
|
-
const rePlugin = new RegExp(`^[\\w\\!]+\\(([\\w,-]+)?${packageFolderName}([\\w,-]+)?\\)`, 'i');
|
|
549
581
|
let { stdout } = await Shell.exec('git', params);
|
|
550
582
|
let skipGetLog = false;
|
|
551
583
|
if (latestTag) {
|
|
@@ -564,8 +596,10 @@ class Releaser {
|
|
|
564
596
|
}
|
|
565
597
|
({ stdout } = await Shell.exec('git', params));
|
|
566
598
|
}
|
|
567
|
-
const
|
|
568
|
-
|
|
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
|
|
569
603
|
.filter((commit) => {
|
|
570
604
|
const chunk = commit.trim();
|
|
571
605
|
return chunk && rePlugin.test(chunk);
|
|
@@ -586,7 +620,11 @@ class Releaser {
|
|
|
586
620
|
Logger.log(chalk.red(`No Commits Found.`));
|
|
587
621
|
}
|
|
588
622
|
else {
|
|
589
|
-
Logger.log(chalk.yellow(`Found `)
|
|
623
|
+
Logger.log(chalk.yellow(`Found `)
|
|
624
|
+
+ chalk.bold(`${allCommits.length}`)
|
|
625
|
+
+ ` Commits, `
|
|
626
|
+
+ chalk.bold(`${commits.length}`)
|
|
627
|
+
+ ' Commits Valid');
|
|
590
628
|
}
|
|
591
629
|
const { skipUpdatePackage } = commandOptions;
|
|
592
630
|
if (commits.length && skipUpdatePackage) {
|
|
@@ -639,7 +677,7 @@ class Releaser {
|
|
|
639
677
|
this.commits = [
|
|
640
678
|
{
|
|
641
679
|
type: 'chore',
|
|
642
|
-
header: `chore(${this.packageFolderName}): force-publish ${versionChanged}`,
|
|
680
|
+
header: `chore(${this.packageFolderName || 'release'}): force-publish ${versionChanged}`,
|
|
643
681
|
hash: '',
|
|
644
682
|
effect: false,
|
|
645
683
|
breaking: false,
|
|
@@ -652,7 +690,7 @@ class Releaser {
|
|
|
652
690
|
}
|
|
653
691
|
rebuildChangeLog(commits) {
|
|
654
692
|
const { packageDir } = this;
|
|
655
|
-
const { homepage } = Shared.impl();
|
|
693
|
+
const { homepage, workspace } = Shared.impl();
|
|
656
694
|
const logPath = path.resolve(packageDir, './CHANGELOG.md');
|
|
657
695
|
const logFile = fs.existsSync(logPath) ? fs.readFileSync(logPath, 'utf-8') : '';
|
|
658
696
|
const notes = {
|
|
@@ -669,7 +707,7 @@ class Releaser {
|
|
|
669
707
|
? ''
|
|
670
708
|
: ` ([${hash?.substring(0, 7)}](${homepage}/commit/${hash}))`;
|
|
671
709
|
let message = header?.trim();
|
|
672
|
-
if (!effect) {
|
|
710
|
+
if (workspace && !effect) {
|
|
673
711
|
message = message.replace(/\(.+\)!?:/, ':');
|
|
674
712
|
}
|
|
675
713
|
message = message
|
|
@@ -898,11 +936,12 @@ class Releaser {
|
|
|
898
936
|
});
|
|
899
937
|
}
|
|
900
938
|
async process() {
|
|
939
|
+
const { workspace } = Shared.impl();
|
|
901
940
|
const { packageName, packageDir, packageFolderName } = this;
|
|
902
941
|
if (!packageDir || !fs.pathExists(packageDir)) {
|
|
903
942
|
throw new RangeError(`Could not find directory for package: ${packageFolderName}`);
|
|
904
943
|
}
|
|
905
|
-
Logger.log(chalk.cyan(`Releasing ${packageName}`) + ' from ' + chalk.grey(
|
|
944
|
+
Logger.log(chalk.cyan(`Releasing ${packageName}`) + ' from ' + chalk.grey(`${workspace}/${packageFolderName}`));
|
|
906
945
|
await this.parseCommits();
|
|
907
946
|
return this;
|
|
908
947
|
}
|
|
@@ -912,13 +951,20 @@ const releaser = (options, commandOptions) => {
|
|
|
912
951
|
};
|
|
913
952
|
|
|
914
953
|
const run = (options) => Utils.autoCatch(async () => {
|
|
954
|
+
const locals = Shared.impl();
|
|
915
955
|
if (options.dryRun) {
|
|
916
956
|
Logger.log(chalk.magenta(`DRY RUN: `)
|
|
917
957
|
+ 'No files will be modified.');
|
|
918
958
|
}
|
|
919
|
-
|
|
959
|
+
let inputs = [];
|
|
960
|
+
if (locals.workspace) {
|
|
961
|
+
inputs = locals.normalizePackageFolderNames;
|
|
962
|
+
}
|
|
963
|
+
else {
|
|
964
|
+
inputs = [''];
|
|
965
|
+
}
|
|
920
966
|
const instances = {};
|
|
921
|
-
await
|
|
967
|
+
await inputs
|
|
922
968
|
.reduce((preProcess, packageFolderName) => {
|
|
923
969
|
preProcess = preProcess
|
|
924
970
|
.then(() => releaser(packageFolderName, options).process())
|
|
@@ -930,7 +976,7 @@ const run = (options) => Utils.autoCatch(async () => {
|
|
|
930
976
|
Logger.log(chalk.blue(`---------------------\n`));
|
|
931
977
|
let message = `chore(release): publish\n\n`;
|
|
932
978
|
let relationVerisons = {};
|
|
933
|
-
await
|
|
979
|
+
await inputs.reduce((preProcess, packageFolderName) => {
|
|
934
980
|
const instance = instances[packageFolderName];
|
|
935
981
|
instance.packageRelation.forEach(i => {
|
|
936
982
|
let packageFolderName$ = Shared.getPackageFolderName(i);
|
|
@@ -968,7 +1014,7 @@ const run = (options) => Utils.autoCatch(async () => {
|
|
|
968
1014
|
await Shell.spawn('git', ['add', process.cwd()]);
|
|
969
1015
|
await Shell.spawn('git', ['commit', '--m', `'${message}'`]);
|
|
970
1016
|
}
|
|
971
|
-
await
|
|
1017
|
+
await inputs
|
|
972
1018
|
.reduce((preProcess, packageFolderName) => {
|
|
973
1019
|
const instance = instances[packageFolderName];
|
|
974
1020
|
preProcess = preProcess
|
|
@@ -1024,6 +1070,7 @@ program
|
|
|
1024
1070
|
.command('dev')
|
|
1025
1071
|
.alias('d')
|
|
1026
1072
|
.description('dev')
|
|
1073
|
+
.option('-p, --package-name <string>', 'Select PackageName')
|
|
1027
1074
|
.option('--dry-run [boolean]', 'Dry Run')
|
|
1028
1075
|
.action(run$2);
|
|
1029
1076
|
program
|