@deot/dev-releaser 1.1.0 → 1.1.2

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 CHANGED
@@ -2,5 +2,8 @@
2
2
 
3
3
  用于发包流程, 自动生成changelog, tags....
4
4
 
5
- - 默认`dryRun`
6
- - 使用`dependencies`,非`peerDependencies`。主要考虑仅安装`@deot/dev-releaser`即可
5
+ - 默认`dryRun`, `Skipping`表示会修改的内容,但是跳过了
6
+ - 使用`dependencies`,非`peerDependencies`。主要考虑仅安装`@deot/dev-releaser`即可
7
+
8
+
9
+ [API参考](../cli/src/index.ts)
package/dist/index.cjs.js CHANGED
@@ -71,12 +71,10 @@ class Release {
71
71
  }
72
72
  async parseCommits() {
73
73
  const { workspace } = devShared.Locals.impl();
74
- const { packageFolderName, packageName, commandOptions } = this;
75
- let params = ['tag', '--list', `'${packageName}@*'`, '--sort', '-v:refname'];
76
- const { stdout: tags } = await devShared.Shell.exec('git', params);
77
- const [latestTag] = tags.split('\n');
74
+ const { packageFolderName, commandOptions } = this;
75
+ const [latestTag] = await this.getTags();
78
76
  devShared.Logger.log(chalk.yellow(`Last Release Tag`) + `: ${latestTag || '<none>'}`);
79
- params = ['--no-pager', 'log', `${latestTag}..HEAD`, `--format=%B%n${HASH}%n%H${SUFFIX}`];
77
+ let params = ['--no-pager', 'log', `${latestTag}..HEAD`, `--format=%B%n${HASH}%n%H${SUFFIX}`];
80
78
  let { stdout } = await devShared.Shell.exec('git', params);
81
79
  let skipGetLog = false;
82
80
  if (latestTag) {
@@ -140,7 +138,7 @@ class Release {
140
138
  skip = result.skip;
141
139
  }
142
140
  else if (typeof skipUpdatePackage === 'string'
143
- && (skipUpdatePackage === '**'
141
+ && (skipUpdatePackage === '*'
144
142
  || skipUpdatePackage.split(',').includes(this.packageName))) {
145
143
  skip = true;
146
144
  }
@@ -166,7 +164,7 @@ class Release {
166
164
  force = result.force;
167
165
  }
168
166
  else if (typeof forceUpdatePackage === 'string'
169
- && (forceUpdatePackage === '**'
167
+ && (forceUpdatePackage === '*'
170
168
  || forceUpdatePackage.split(',').includes(this.packageName))) {
171
169
  force = true;
172
170
  }
@@ -187,6 +185,12 @@ class Release {
187
185
  }
188
186
  }
189
187
  }
188
+ async getTags() {
189
+ const { packageName } = this;
190
+ const params = ['tag', '--list', `'${packageName}@*'`, '--sort', '-v:refname'];
191
+ const { stdout } = await devShared.Shell.exec('git', params);
192
+ return stdout.split('\n');
193
+ }
190
194
  rebuildChangeLog(commits) {
191
195
  const { packageDir } = this;
192
196
  const { homepage, workspace } = devShared.Locals.impl();
@@ -297,10 +301,10 @@ class Release {
297
301
  if (!commits.length)
298
302
  return;
299
303
  const { packageName } = this;
300
- const olds = this.commits.map(i => JSON.stringify(i));
304
+ const olds = this.commits.map(i => JSON.stringify({ ...i, effect: false }));
301
305
  const newCommits = commits
302
306
  .filter(i => {
303
- return !olds.includes(JSON.stringify(i));
307
+ return !olds.includes(JSON.stringify({ ...i, effect: false }));
304
308
  })
305
309
  .map(j => {
306
310
  return {
@@ -407,10 +411,12 @@ class Release {
407
411
  await devShared.Shell.exec(`npm run build -- --package-name ${this.packageName}`);
408
412
  }
409
413
  async publish() {
410
- if (!this.isChanged())
414
+ const { commandOptions } = this;
415
+ if (!this.isChanged() || !commandOptions.publish)
411
416
  return;
412
- const { commandOptions, packageDir } = this;
413
- if (commandOptions.dryRun || !commandOptions.publish) {
417
+ const { packageDir, packageName } = this;
418
+ devShared.Logger.log(chalk.magenta(`PUBLISH: `) + packageName);
419
+ if (commandOptions.dryRun) {
414
420
  devShared.Logger.log(chalk.yellow(`Skipping Publish`));
415
421
  return;
416
422
  }
@@ -420,11 +426,12 @@ class Release {
420
426
  });
421
427
  }
422
428
  async tag() {
423
- if (!this.isChanged())
429
+ const { commandOptions } = this;
430
+ if (!this.isChanged() || !commandOptions.tag)
424
431
  return;
425
- const { commandOptions, packageDir } = this;
426
- const { packageName, packageOptions } = this;
427
- if (commandOptions.dryRun || !commandOptions.tag) {
432
+ const { packageDir, packageName, packageOptions } = this;
433
+ devShared.Logger.log(chalk.magenta(`TAG: `) + packageName);
434
+ if (commandOptions.dryRun) {
428
435
  devShared.Logger.log(chalk.yellow(`Skipping Git Tag`));
429
436
  return;
430
437
  }
@@ -434,6 +441,28 @@ class Release {
434
441
  cwd: packageDir
435
442
  });
436
443
  }
444
+ async cleanTagsAndKeepLastTag() {
445
+ const { commandOptions } = this;
446
+ if (!commandOptions.keepLastTag)
447
+ return;
448
+ let tags = await this.getTags();
449
+ tags = tags.slice(1).filter(i => !!i).reverse();
450
+ if (!tags.length)
451
+ return;
452
+ const { packageName } = this;
453
+ devShared.Logger.log(chalk.magenta(`CLEAN TAGS: `) + packageName);
454
+ if (commandOptions.dryRun) {
455
+ devShared.Logger.log(chalk.yellow(`Skipping Tags Clean`));
456
+ return;
457
+ }
458
+ await tags
459
+ .reduce((preProcess, tag) => {
460
+ preProcess = preProcess
461
+ .then(() => devShared.Shell.spawn('git', ['push', 'origin', '--delete', tag]))
462
+ .then(() => devShared.Shell.spawn('git', ['tag', '--delete', tag]));
463
+ return preProcess;
464
+ }, Promise.resolve());
465
+ }
437
466
  async process() {
438
467
  const { workspace } = devShared.Locals.impl();
439
468
  const { packageName, packageDir, packageFolderName } = this;
@@ -456,6 +485,7 @@ const run = (options) => devShared.Utils.autoCatch(async () => {
456
485
  publish: true,
457
486
  commit: true,
458
487
  push: true,
488
+ keepLastTag: false,
459
489
  ...options
460
490
  };
461
491
  const locals = devShared.Locals.impl();
@@ -511,7 +541,10 @@ const run = (options) => devShared.Utils.autoCatch(async () => {
511
541
  if (!isChanged) {
512
542
  devShared.Logger.log(chalk.magenta(`COMMIT: `) + 'Nothing Chanaged Found.');
513
543
  }
514
- else if (options.dryRun || !options.commit) {
544
+ else if (!options.commit) {
545
+ devShared.Logger.log(chalk.magenta(`COMMIT: `) + 'Disabled.');
546
+ }
547
+ else if (options.dryRun) {
515
548
  devShared.Logger.log(chalk.magenta(`COMMIT: `) + chalk.yellow(`Skipping Git Commit`) + `\n${message}`);
516
549
  }
517
550
  else {
@@ -521,6 +554,11 @@ const run = (options) => devShared.Utils.autoCatch(async () => {
521
554
  await devShared.Shell.spawn('git', ['add', process.cwd()]);
522
555
  await devShared.Shell.spawn('git', ['commit', '--m', `'${message}'`]);
523
556
  }
557
+ if ((options.keepLastTag || options.push) && !options.dryRun) {
558
+ devShared.Logger.log(chalk.yellow('Git Fetch...'));
559
+ await devShared.Shell.spawn('git', ['fetch', '--prune', '--prune-tags']);
560
+ }
561
+ devShared.Logger.log(chalk.blue(`\n---------------------\n`));
524
562
  await inputs
525
563
  .reduce((preProcess, packageFolderName) => {
526
564
  const instance = instances[packageFolderName];
@@ -530,16 +568,30 @@ const run = (options) => devShared.Utils.autoCatch(async () => {
530
568
  return preProcess;
531
569
  }, Promise.resolve());
532
570
  devShared.Logger.log(chalk.blue(`\n---------------------\n`));
533
- if (options.dryRun || !options.push) {
534
- devShared.Logger.log(chalk.magenta(`FINISH: `) + 'Skipping Git Push');
571
+ if (!isChanged) {
572
+ devShared.Logger.log(chalk.magenta(`PUSH: `) + 'Nothing Chanaged.');
573
+ }
574
+ else if (!options.push) {
575
+ devShared.Logger.log(chalk.magenta(`PUSH: `) + 'Push Disabled.');
535
576
  }
536
- else if (!isChanged) {
537
- devShared.Logger.log(chalk.magenta(`FINISH: `) + 'Nothing Chanaged.');
577
+ else if (options.dryRun) {
578
+ devShared.Logger.log(chalk.magenta(`PUSH: `) + 'Skipping Git Push');
538
579
  }
539
580
  else {
581
+ devShared.Logger.log(chalk.yellow('Git Pull/Push...'));
582
+ await devShared.Shell.spawn('git', ['pull', '--rebase']);
540
583
  await devShared.Shell.spawn('git', ['push']);
541
584
  await devShared.Shell.spawn('git', ['push', '--tags']);
542
585
  }
586
+ devShared.Logger.log(chalk.blue(`\n---------------------\n`));
587
+ await inputs
588
+ .reduce((preProcess, packageFolderName) => {
589
+ const instance = instances[packageFolderName];
590
+ preProcess = preProcess
591
+ .then(() => instance.cleanTagsAndKeepLastTag());
592
+ return preProcess;
593
+ }, Promise.resolve());
594
+ devShared.Logger.log(chalk.magenta(`FINISH: `) + chalk.green(`Release Successed.`));
543
595
  if (options.dryRun) {
544
596
  devShared.Logger.log(chalk.green('NO DRY RUN WAY: ')
545
597
  + chalk.grey(`npm run release -- --no-dry-run\n`));
@@ -552,6 +604,7 @@ const run = (options) => devShared.Utils.autoCatch(async () => {
552
604
  else {
553
605
  devShared.Logger.error(e);
554
606
  }
607
+ devShared.Logger.log(chalk.magenta(`FINISH: `) + chalk.red(`Release Failed.`));
555
608
  process.exit(1);
556
609
  }
557
610
  });
package/dist/index.es.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import chalk from 'chalk';
2
- import { Locals, Shell, Logger, Utils } from '@deot/dev-shared';
2
+ import { Locals, Logger, Shell, Utils } from '@deot/dev-shared';
3
3
  import * as path from 'node:path';
4
4
  import fs from 'fs-extra';
5
5
  import { createRequire } from 'node:module';
@@ -50,12 +50,10 @@ class Release {
50
50
  }
51
51
  async parseCommits() {
52
52
  const { workspace } = Locals.impl();
53
- const { packageFolderName, packageName, commandOptions } = this;
54
- let params = ['tag', '--list', `'${packageName}@*'`, '--sort', '-v:refname'];
55
- const { stdout: tags } = await Shell.exec('git', params);
56
- const [latestTag] = tags.split('\n');
53
+ const { packageFolderName, commandOptions } = this;
54
+ const [latestTag] = await this.getTags();
57
55
  Logger.log(chalk.yellow(`Last Release Tag`) + `: ${latestTag || '<none>'}`);
58
- params = ['--no-pager', 'log', `${latestTag}..HEAD`, `--format=%B%n${HASH}%n%H${SUFFIX}`];
56
+ let params = ['--no-pager', 'log', `${latestTag}..HEAD`, `--format=%B%n${HASH}%n%H${SUFFIX}`];
59
57
  let { stdout } = await Shell.exec('git', params);
60
58
  let skipGetLog = false;
61
59
  if (latestTag) {
@@ -119,7 +117,7 @@ class Release {
119
117
  skip = result.skip;
120
118
  }
121
119
  else if (typeof skipUpdatePackage === 'string'
122
- && (skipUpdatePackage === '**'
120
+ && (skipUpdatePackage === '*'
123
121
  || skipUpdatePackage.split(',').includes(this.packageName))) {
124
122
  skip = true;
125
123
  }
@@ -145,7 +143,7 @@ class Release {
145
143
  force = result.force;
146
144
  }
147
145
  else if (typeof forceUpdatePackage === 'string'
148
- && (forceUpdatePackage === '**'
146
+ && (forceUpdatePackage === '*'
149
147
  || forceUpdatePackage.split(',').includes(this.packageName))) {
150
148
  force = true;
151
149
  }
@@ -166,6 +164,12 @@ class Release {
166
164
  }
167
165
  }
168
166
  }
167
+ async getTags() {
168
+ const { packageName } = this;
169
+ const params = ['tag', '--list', `'${packageName}@*'`, '--sort', '-v:refname'];
170
+ const { stdout } = await Shell.exec('git', params);
171
+ return stdout.split('\n');
172
+ }
169
173
  rebuildChangeLog(commits) {
170
174
  const { packageDir } = this;
171
175
  const { homepage, workspace } = Locals.impl();
@@ -276,10 +280,10 @@ class Release {
276
280
  if (!commits.length)
277
281
  return;
278
282
  const { packageName } = this;
279
- const olds = this.commits.map(i => JSON.stringify(i));
283
+ const olds = this.commits.map(i => JSON.stringify({ ...i, effect: false }));
280
284
  const newCommits = commits
281
285
  .filter(i => {
282
- return !olds.includes(JSON.stringify(i));
286
+ return !olds.includes(JSON.stringify({ ...i, effect: false }));
283
287
  })
284
288
  .map(j => {
285
289
  return {
@@ -386,10 +390,12 @@ class Release {
386
390
  await Shell.exec(`npm run build -- --package-name ${this.packageName}`);
387
391
  }
388
392
  async publish() {
389
- if (!this.isChanged())
393
+ const { commandOptions } = this;
394
+ if (!this.isChanged() || !commandOptions.publish)
390
395
  return;
391
- const { commandOptions, packageDir } = this;
392
- if (commandOptions.dryRun || !commandOptions.publish) {
396
+ const { packageDir, packageName } = this;
397
+ Logger.log(chalk.magenta(`PUBLISH: `) + packageName);
398
+ if (commandOptions.dryRun) {
393
399
  Logger.log(chalk.yellow(`Skipping Publish`));
394
400
  return;
395
401
  }
@@ -399,11 +405,12 @@ class Release {
399
405
  });
400
406
  }
401
407
  async tag() {
402
- if (!this.isChanged())
408
+ const { commandOptions } = this;
409
+ if (!this.isChanged() || !commandOptions.tag)
403
410
  return;
404
- const { commandOptions, packageDir } = this;
405
- const { packageName, packageOptions } = this;
406
- if (commandOptions.dryRun || !commandOptions.tag) {
411
+ const { packageDir, packageName, packageOptions } = this;
412
+ Logger.log(chalk.magenta(`TAG: `) + packageName);
413
+ if (commandOptions.dryRun) {
407
414
  Logger.log(chalk.yellow(`Skipping Git Tag`));
408
415
  return;
409
416
  }
@@ -413,6 +420,28 @@ class Release {
413
420
  cwd: packageDir
414
421
  });
415
422
  }
423
+ async cleanTagsAndKeepLastTag() {
424
+ const { commandOptions } = this;
425
+ if (!commandOptions.keepLastTag)
426
+ return;
427
+ let tags = await this.getTags();
428
+ tags = tags.slice(1).filter(i => !!i).reverse();
429
+ if (!tags.length)
430
+ return;
431
+ const { packageName } = this;
432
+ Logger.log(chalk.magenta(`CLEAN TAGS: `) + packageName);
433
+ if (commandOptions.dryRun) {
434
+ Logger.log(chalk.yellow(`Skipping Tags Clean`));
435
+ return;
436
+ }
437
+ await tags
438
+ .reduce((preProcess, tag) => {
439
+ preProcess = preProcess
440
+ .then(() => Shell.spawn('git', ['push', 'origin', '--delete', tag]))
441
+ .then(() => Shell.spawn('git', ['tag', '--delete', tag]));
442
+ return preProcess;
443
+ }, Promise.resolve());
444
+ }
416
445
  async process() {
417
446
  const { workspace } = Locals.impl();
418
447
  const { packageName, packageDir, packageFolderName } = this;
@@ -435,6 +464,7 @@ const run = (options) => Utils.autoCatch(async () => {
435
464
  publish: true,
436
465
  commit: true,
437
466
  push: true,
467
+ keepLastTag: false,
438
468
  ...options
439
469
  };
440
470
  const locals = Locals.impl();
@@ -490,7 +520,10 @@ const run = (options) => Utils.autoCatch(async () => {
490
520
  if (!isChanged) {
491
521
  Logger.log(chalk.magenta(`COMMIT: `) + 'Nothing Chanaged Found.');
492
522
  }
493
- else if (options.dryRun || !options.commit) {
523
+ else if (!options.commit) {
524
+ Logger.log(chalk.magenta(`COMMIT: `) + 'Disabled.');
525
+ }
526
+ else if (options.dryRun) {
494
527
  Logger.log(chalk.magenta(`COMMIT: `) + chalk.yellow(`Skipping Git Commit`) + `\n${message}`);
495
528
  }
496
529
  else {
@@ -500,6 +533,11 @@ const run = (options) => Utils.autoCatch(async () => {
500
533
  await Shell.spawn('git', ['add', process.cwd()]);
501
534
  await Shell.spawn('git', ['commit', '--m', `'${message}'`]);
502
535
  }
536
+ if ((options.keepLastTag || options.push) && !options.dryRun) {
537
+ Logger.log(chalk.yellow('Git Fetch...'));
538
+ await Shell.spawn('git', ['fetch', '--prune', '--prune-tags']);
539
+ }
540
+ Logger.log(chalk.blue(`\n---------------------\n`));
503
541
  await inputs
504
542
  .reduce((preProcess, packageFolderName) => {
505
543
  const instance = instances[packageFolderName];
@@ -509,16 +547,30 @@ const run = (options) => Utils.autoCatch(async () => {
509
547
  return preProcess;
510
548
  }, Promise.resolve());
511
549
  Logger.log(chalk.blue(`\n---------------------\n`));
512
- if (options.dryRun || !options.push) {
513
- Logger.log(chalk.magenta(`FINISH: `) + 'Skipping Git Push');
550
+ if (!isChanged) {
551
+ Logger.log(chalk.magenta(`PUSH: `) + 'Nothing Chanaged.');
552
+ }
553
+ else if (!options.push) {
554
+ Logger.log(chalk.magenta(`PUSH: `) + 'Push Disabled.');
514
555
  }
515
- else if (!isChanged) {
516
- Logger.log(chalk.magenta(`FINISH: `) + 'Nothing Chanaged.');
556
+ else if (options.dryRun) {
557
+ Logger.log(chalk.magenta(`PUSH: `) + 'Skipping Git Push');
517
558
  }
518
559
  else {
560
+ Logger.log(chalk.yellow('Git Pull/Push...'));
561
+ await Shell.spawn('git', ['pull', '--rebase']);
519
562
  await Shell.spawn('git', ['push']);
520
563
  await Shell.spawn('git', ['push', '--tags']);
521
564
  }
565
+ Logger.log(chalk.blue(`\n---------------------\n`));
566
+ await inputs
567
+ .reduce((preProcess, packageFolderName) => {
568
+ const instance = instances[packageFolderName];
569
+ preProcess = preProcess
570
+ .then(() => instance.cleanTagsAndKeepLastTag());
571
+ return preProcess;
572
+ }, Promise.resolve());
573
+ Logger.log(chalk.magenta(`FINISH: `) + chalk.green(`Release Successed.`));
522
574
  if (options.dryRun) {
523
575
  Logger.log(chalk.green('NO DRY RUN WAY: ')
524
576
  + chalk.grey(`npm run release -- --no-dry-run\n`));
@@ -531,6 +583,7 @@ const run = (options) => Utils.autoCatch(async () => {
531
583
  else {
532
584
  Logger.error(e);
533
585
  }
586
+ Logger.log(chalk.magenta(`FINISH: `) + chalk.red(`Release Failed.`));
534
587
  process.exit(1);
535
588
  }
536
589
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deot/dev-releaser",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "main": "dist/index.es.js",
5
5
  "module": "dist/index.es.js",
6
6
  "types": "dist/index.d.ts",
@@ -13,9 +13,15 @@
13
13
  "access": "public"
14
14
  },
15
15
  "dependencies": {
16
- "@deot/dev-extract": "^1.1.0",
17
- "@deot/dev-shared": "^1.1.0",
16
+ "@deot/dev-shared": "^1.1.1",
18
17
  "conventional-commits-parser": "^3.2.4",
18
+ "chalk": "^5.2.0",
19
+ "fs-extra": "^11.1.1",
20
+ "inquirer": "^9.1.5",
21
+ "inquirer-autocomplete-prompt": "^3.0.0",
19
22
  "semver": "^7.3.8"
23
+ },
24
+ "devDependencies": {
25
+ "cross-env": "^7.0.3"
20
26
  }
21
27
  }