@deot/dev-releaser 1.1.0 → 1.1.1

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,31 @@ class Release {
434
441
  cwd: packageDir
435
442
  });
436
443
  }
444
+ async clean() {
445
+ await this.cleanTagsAndKeepLastTag();
446
+ }
447
+ async cleanTagsAndKeepLastTag() {
448
+ const { commandOptions } = this;
449
+ if (!commandOptions.keepLastTag)
450
+ return;
451
+ let tags = await this.getTags();
452
+ tags = tags.slice(1).filter(i => !!i).reverse();
453
+ if (!tags.length)
454
+ return;
455
+ const { packageName } = this;
456
+ devShared.Logger.log(chalk.magenta(`CLEAN TAGS: `) + packageName);
457
+ if (commandOptions.dryRun) {
458
+ devShared.Logger.log(chalk.yellow(`Skipping Tags Clean`));
459
+ return;
460
+ }
461
+ await tags
462
+ .reduce((preProcess, tag) => {
463
+ preProcess = preProcess
464
+ .then(() => devShared.Shell.spawn('git', ['push', 'origin', '--delete', tag]))
465
+ .then(() => devShared.Shell.spawn('git', ['tag', '--delete', tag]));
466
+ return preProcess;
467
+ }, Promise.resolve());
468
+ }
437
469
  async process() {
438
470
  const { workspace } = devShared.Locals.impl();
439
471
  const { packageName, packageDir, packageFolderName } = this;
@@ -456,6 +488,7 @@ const run = (options) => devShared.Utils.autoCatch(async () => {
456
488
  publish: true,
457
489
  commit: true,
458
490
  push: true,
491
+ keepLastTag: false,
459
492
  ...options
460
493
  };
461
494
  const locals = devShared.Locals.impl();
@@ -511,7 +544,10 @@ const run = (options) => devShared.Utils.autoCatch(async () => {
511
544
  if (!isChanged) {
512
545
  devShared.Logger.log(chalk.magenta(`COMMIT: `) + 'Nothing Chanaged Found.');
513
546
  }
514
- else if (options.dryRun || !options.commit) {
547
+ else if (!options.commit) {
548
+ devShared.Logger.log(chalk.magenta(`COMMIT: `) + 'Disabled.');
549
+ }
550
+ else if (options.dryRun) {
515
551
  devShared.Logger.log(chalk.magenta(`COMMIT: `) + chalk.yellow(`Skipping Git Commit`) + `\n${message}`);
516
552
  }
517
553
  else {
@@ -521,21 +557,29 @@ const run = (options) => devShared.Utils.autoCatch(async () => {
521
557
  await devShared.Shell.spawn('git', ['add', process.cwd()]);
522
558
  await devShared.Shell.spawn('git', ['commit', '--m', `'${message}'`]);
523
559
  }
560
+ if ((options.keepLastTag || options.push) && !options.dryRun) {
561
+ devShared.Logger.log(chalk.yellow('Git Fetch...'));
562
+ await devShared.Shell.spawn('git', ['fetch', '--prune', '--prune-tags']);
563
+ }
524
564
  await inputs
525
565
  .reduce((preProcess, packageFolderName) => {
526
566
  const instance = instances[packageFolderName];
527
567
  preProcess = preProcess
528
568
  .then(() => instance.publish())
529
- .then(() => instance.tag());
569
+ .then(() => instance.tag())
570
+ .then(() => instance.clean());
530
571
  return preProcess;
531
572
  }, Promise.resolve());
532
573
  devShared.Logger.log(chalk.blue(`\n---------------------\n`));
533
- if (options.dryRun || !options.push) {
534
- devShared.Logger.log(chalk.magenta(`FINISH: `) + 'Skipping Git Push');
535
- }
536
- else if (!isChanged) {
574
+ if (!isChanged) {
537
575
  devShared.Logger.log(chalk.magenta(`FINISH: `) + 'Nothing Chanaged.');
538
576
  }
577
+ else if (!options.push) {
578
+ devShared.Logger.log(chalk.magenta(`FINISH: `) + 'Push Disabled.');
579
+ }
580
+ else if (options.dryRun) {
581
+ devShared.Logger.log(chalk.magenta(`FINISH: `) + 'Skipping Git Push');
582
+ }
539
583
  else {
540
584
  await devShared.Shell.spawn('git', ['push']);
541
585
  await devShared.Shell.spawn('git', ['push', '--tags']);
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,31 @@ class Release {
413
420
  cwd: packageDir
414
421
  });
415
422
  }
423
+ async clean() {
424
+ await this.cleanTagsAndKeepLastTag();
425
+ }
426
+ async cleanTagsAndKeepLastTag() {
427
+ const { commandOptions } = this;
428
+ if (!commandOptions.keepLastTag)
429
+ return;
430
+ let tags = await this.getTags();
431
+ tags = tags.slice(1).filter(i => !!i).reverse();
432
+ if (!tags.length)
433
+ return;
434
+ const { packageName } = this;
435
+ Logger.log(chalk.magenta(`CLEAN TAGS: `) + packageName);
436
+ if (commandOptions.dryRun) {
437
+ Logger.log(chalk.yellow(`Skipping Tags Clean`));
438
+ return;
439
+ }
440
+ await tags
441
+ .reduce((preProcess, tag) => {
442
+ preProcess = preProcess
443
+ .then(() => Shell.spawn('git', ['push', 'origin', '--delete', tag]))
444
+ .then(() => Shell.spawn('git', ['tag', '--delete', tag]));
445
+ return preProcess;
446
+ }, Promise.resolve());
447
+ }
416
448
  async process() {
417
449
  const { workspace } = Locals.impl();
418
450
  const { packageName, packageDir, packageFolderName } = this;
@@ -435,6 +467,7 @@ const run = (options) => Utils.autoCatch(async () => {
435
467
  publish: true,
436
468
  commit: true,
437
469
  push: true,
470
+ keepLastTag: false,
438
471
  ...options
439
472
  };
440
473
  const locals = Locals.impl();
@@ -490,7 +523,10 @@ const run = (options) => Utils.autoCatch(async () => {
490
523
  if (!isChanged) {
491
524
  Logger.log(chalk.magenta(`COMMIT: `) + 'Nothing Chanaged Found.');
492
525
  }
493
- else if (options.dryRun || !options.commit) {
526
+ else if (!options.commit) {
527
+ Logger.log(chalk.magenta(`COMMIT: `) + 'Disabled.');
528
+ }
529
+ else if (options.dryRun) {
494
530
  Logger.log(chalk.magenta(`COMMIT: `) + chalk.yellow(`Skipping Git Commit`) + `\n${message}`);
495
531
  }
496
532
  else {
@@ -500,21 +536,29 @@ const run = (options) => Utils.autoCatch(async () => {
500
536
  await Shell.spawn('git', ['add', process.cwd()]);
501
537
  await Shell.spawn('git', ['commit', '--m', `'${message}'`]);
502
538
  }
539
+ if ((options.keepLastTag || options.push) && !options.dryRun) {
540
+ Logger.log(chalk.yellow('Git Fetch...'));
541
+ await Shell.spawn('git', ['fetch', '--prune', '--prune-tags']);
542
+ }
503
543
  await inputs
504
544
  .reduce((preProcess, packageFolderName) => {
505
545
  const instance = instances[packageFolderName];
506
546
  preProcess = preProcess
507
547
  .then(() => instance.publish())
508
- .then(() => instance.tag());
548
+ .then(() => instance.tag())
549
+ .then(() => instance.clean());
509
550
  return preProcess;
510
551
  }, Promise.resolve());
511
552
  Logger.log(chalk.blue(`\n---------------------\n`));
512
- if (options.dryRun || !options.push) {
513
- Logger.log(chalk.magenta(`FINISH: `) + 'Skipping Git Push');
514
- }
515
- else if (!isChanged) {
553
+ if (!isChanged) {
516
554
  Logger.log(chalk.magenta(`FINISH: `) + 'Nothing Chanaged.');
517
555
  }
556
+ else if (!options.push) {
557
+ Logger.log(chalk.magenta(`FINISH: `) + 'Push Disabled.');
558
+ }
559
+ else if (options.dryRun) {
560
+ Logger.log(chalk.magenta(`FINISH: `) + 'Skipping Git Push');
561
+ }
518
562
  else {
519
563
  await Shell.spawn('git', ['push']);
520
564
  await Shell.spawn('git', ['push', '--tags']);
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.1",
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
  }