npm-update-package 0.3.0 → 0.4.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 CHANGED
@@ -37,8 +37,20 @@ You can customize behavior via command-line options.
37
37
 
38
38
  |Option|Description|Required|Value|Default|
39
39
  |---|---|---|---|---|
40
+ |`--branch-name`|Branch name template|-|string|`npm-update-package/{{{packageName}}}/v{{newVersion}}`|
40
41
  |`--git-user-email`|User email of commit|-|string|-|
41
42
  |`--git-user-name`|User name of commit|-|string|-|
42
43
  |`--github-token`|GitHub token|✓|string|-|
43
44
  |`--log-level`|Log level to show|-|`info`, `debug`|`info`|
44
45
  |`--package-manager`|Package manager of your project|-|`npm`, `yarn`|`npm`|
46
+
47
+ ### Templates
48
+
49
+ npm-update-package is using [mustache](https://www.npmjs.com/package/mustache) for generating string from templates.
50
+ These variables are available:
51
+
52
+ - `--branch-name`
53
+ - `packageName`
54
+ - `currentVersion`
55
+ - `newVersion`
56
+ - `updateType`
package/dist/app.js CHANGED
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.app = void 0;
4
4
  exports.app = {
5
5
  name: 'npm-update-package',
6
- version: '0.3.0',
6
+ version: '0.4.0',
7
7
  web: 'https://github.com/npm-update-package/npm-update-package'
8
8
  };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BranchNameCreator = void 0;
4
+ const mustache_1 = require("mustache");
5
+ class BranchNameCreator {
6
+ constructor(template) {
7
+ this.template = template;
8
+ }
9
+ create(outdatedPackage) {
10
+ const packageName = outdatedPackage.name;
11
+ const currentVersion = outdatedPackage.currentVersion.version;
12
+ const newVersion = outdatedPackage.newVersion.version;
13
+ const updateType = outdatedPackage.type;
14
+ return (0, mustache_1.render)(this.template, {
15
+ packageName,
16
+ currentVersion,
17
+ newVersion,
18
+ updateType
19
+ });
20
+ }
21
+ }
22
+ exports.BranchNameCreator = BranchNameCreator;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BranchNameCreator = void 0;
4
+ var BranchNameCreator_1 = require("./BranchNameCreator");
5
+ Object.defineProperty(exports, "BranchNameCreator", { enumerable: true, get: function () { return BranchNameCreator_1.BranchNameCreator; } });
package/dist/main.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.main = void 0;
4
+ const branch_name_creator_1 = require("./branch-name-creator");
4
5
  const git_1 = require("./git");
5
6
  const github_1 = require("./github");
6
7
  const ncu_1 = require("./ncu");
@@ -55,6 +56,7 @@ const main = async ({ options, logger }) => {
55
56
  githubRepo,
56
57
  logger
57
58
  });
59
+ const branchNameCreator = new branch_name_creator_1.BranchNameCreator(options.branchName);
58
60
  const outdatedPackageProcessor = new outdated_package_processor_1.OutdatedPackageProcessor({
59
61
  committer,
60
62
  git,
@@ -62,7 +64,8 @@ const main = async ({ options, logger }) => {
62
64
  packageManager,
63
65
  pullRequestCreator,
64
66
  remoteBranchExistenceChecker,
65
- logger
67
+ logger,
68
+ branchNameCreator
66
69
  });
67
70
  const outdatedPackagesProcessor = new outdated_packages_processor_1.OutdatedPackagesProcessor({
68
71
  outdatedPackageProcessor,
@@ -4,6 +4,7 @@ exports.isOptions = exports.Options = void 0;
4
4
  const io_ts_1 = require("io-ts");
5
5
  exports.Options = (0, io_ts_1.intersection)([
6
6
  (0, io_ts_1.type)({
7
+ branchName: io_ts_1.string,
7
8
  githubToken: io_ts_1.string,
8
9
  logLevel: (0, io_ts_1.union)([(0, io_ts_1.literal)('info'), (0, io_ts_1.literal)('debug')]),
9
10
  packageManager: (0, io_ts_1.union)([(0, io_ts_1.literal)('npm'), (0, io_ts_1.literal)('yarn')])
@@ -3,20 +3,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.initOptions = void 0;
4
4
  const commander_1 = require("commander");
5
5
  const app_1 = require("../app");
6
+ const enums_1 = require("../enums");
6
7
  const Options_1 = require("./Options");
7
8
  // TODO: add test
8
9
  const initOptions = () => {
9
10
  commander_1.program
10
11
  .version(app_1.app.version)
12
+ .option('--branch-name <value>', 'Branch name template', 'npm-update-package/{{{packageName}}}/v{{newVersion}}')
11
13
  .option('--git-user-email <value>', 'User email of commit')
12
14
  .option('--git-user-name <value>', 'User name of commit')
13
15
  .requiredOption('--github-token <value>', 'GitHub token')
14
16
  .addOption(new commander_1.Option('--log-level <value>', 'Log level to show')
15
- .choices(['info', 'debug'])
16
- .default('info'))
17
+ .choices([
18
+ enums_1.LogLevel.Info,
19
+ enums_1.LogLevel.Debug
20
+ ])
21
+ .default(enums_1.LogLevel.Info))
17
22
  .addOption(new commander_1.Option('--package-manager <value>', 'Package manager of your project')
18
- .choices(['npm', 'yarn'])
19
- .default('npm'));
23
+ .choices([
24
+ enums_1.PackageManagerName.Npm,
25
+ enums_1.PackageManagerName.Yarn
26
+ ])
27
+ .default(enums_1.PackageManagerName.Npm));
20
28
  commander_1.program.parse(process.argv);
21
29
  const options = commander_1.program.opts();
22
30
  if (!(0, Options_1.isOptions)(options)) {
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OutdatedPackageProcessor = void 0;
4
- const createBranchName_1 = require("./createBranchName");
5
4
  const createCommitMessage_1 = require("./createCommitMessage");
6
5
  // TODO: add test
7
6
  class OutdatedPackageProcessor {
8
- constructor({ committer, git, ncu, packageManager, pullRequestCreator, remoteBranchExistenceChecker, logger }) {
7
+ constructor({ committer, git, ncu, packageManager, pullRequestCreator, remoteBranchExistenceChecker, logger, branchNameCreator }) {
9
8
  this.committer = committer;
10
9
  this.git = git;
11
10
  this.ncu = ncu;
@@ -13,12 +12,13 @@ class OutdatedPackageProcessor {
13
12
  this.pullRequestCreator = pullRequestCreator;
14
13
  this.remoteBranchExistenceChecker = remoteBranchExistenceChecker;
15
14
  this.logger = logger;
15
+ this.branchNameCreator = branchNameCreator;
16
16
  }
17
17
  /**
18
18
  * Don't run in parallel because it includes file operations.
19
19
  */
20
20
  async process(outdatedPackage) {
21
- const branchName = (0, createBranchName_1.createBranchName)(outdatedPackage);
21
+ const branchName = this.branchNameCreator.create(outdatedPackage);
22
22
  this.logger.debug(`branchName=${branchName}`);
23
23
  if (this.remoteBranchExistenceChecker.check(branchName)) {
24
24
  this.logger.info(`Skip ${outdatedPackage.name} because ${branchName} branch already exists on remote.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-update-package",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "CLI tool for creating pull request to update npm packages",
5
5
  "scripts": {
6
6
  "build": "tsc --project tsconfig.build.json",
@@ -19,6 +19,7 @@
19
19
  "fp-ts": "2.11.5",
20
20
  "io-ts": "2.2.16",
21
21
  "log4js": "6.3.0",
22
+ "mustache": "4.1.0",
22
23
  "npm-check-updates": "12.0.2",
23
24
  "parse-github-url": "1.0.2",
24
25
  "semver": "7.3.5"
@@ -27,6 +28,7 @@
27
28
  "@jest/types": "27.0.6",
28
29
  "@tsconfig/node12": "1.0.9",
29
30
  "@types/jest": "27.0.3",
31
+ "@types/mustache": "4.1.2",
30
32
  "@types/node": "12.20.15",
31
33
  "@types/parse-github-url": "1.0.0",
32
34
  "@types/semver": "7.3.9",
package/src/app.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export const app = {
2
2
  name: 'npm-update-package',
3
- version: '0.3.0',
3
+ version: '0.4.0',
4
4
  web: 'https://github.com/npm-update-package/npm-update-package'
5
5
  } as const
@@ -0,0 +1,17 @@
1
+ import { PackageVersion } from '../values'
2
+ import { BranchNameCreator } from './BranchNameCreator'
3
+
4
+ describe('BranchNameCreator', () => {
5
+ describe('create', () => {
6
+ it('returns branch name', () => {
7
+ const branchNameCreator = new BranchNameCreator('npm-update-package/{{{packageName}}}/{{updateType}}/{{currentVersion}}/{{newVersion}}')
8
+ const actual = branchNameCreator.create({
9
+ name: '@typescript-eslint/eslint-plugin',
10
+ currentVersion: PackageVersion.of('1.0.0'),
11
+ newVersion: PackageVersion.of('1.2.3'),
12
+ type: 'major'
13
+ })
14
+ expect(actual).toBe('npm-update-package/@typescript-eslint/eslint-plugin/major/1.0.0/1.2.3')
15
+ })
16
+ })
17
+ })
@@ -0,0 +1,19 @@
1
+ import { render } from 'mustache'
2
+ import type { OutdatedPackage } from '../types'
3
+
4
+ export class BranchNameCreator {
5
+ constructor (private readonly template: string) {}
6
+
7
+ create (outdatedPackage: OutdatedPackage): string {
8
+ const packageName = outdatedPackage.name
9
+ const currentVersion = outdatedPackage.currentVersion.version
10
+ const newVersion = outdatedPackage.newVersion.version
11
+ const updateType = outdatedPackage.type
12
+ return render(this.template, {
13
+ packageName,
14
+ currentVersion,
15
+ newVersion,
16
+ updateType
17
+ })
18
+ }
19
+ }
@@ -0,0 +1 @@
1
+ export { BranchNameCreator } from './BranchNameCreator'
package/src/main.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { BranchNameCreator } from './branch-name-creator'
1
2
  import {
2
3
  Committer,
3
4
  Git
@@ -75,6 +76,7 @@ export const main = async ({
75
76
  githubRepo,
76
77
  logger
77
78
  })
79
+ const branchNameCreator = new BranchNameCreator(options.branchName)
78
80
  const outdatedPackageProcessor = new OutdatedPackageProcessor({
79
81
  committer,
80
82
  git,
@@ -82,7 +84,8 @@ export const main = async ({
82
84
  packageManager,
83
85
  pullRequestCreator,
84
86
  remoteBranchExistenceChecker,
85
- logger
87
+ logger,
88
+ branchNameCreator
86
89
  })
87
90
  const outdatedPackagesProcessor = new OutdatedPackagesProcessor({
88
91
  outdatedPackageProcessor,
@@ -10,6 +10,7 @@ import type { TypeOf } from 'io-ts'
10
10
 
11
11
  export const Options = intersection([
12
12
  type({
13
+ branchName: string,
13
14
  githubToken: string,
14
15
  logLevel: union([literal('info'), literal('debug')]),
15
16
  packageManager: union([literal('npm'), literal('yarn')])
@@ -3,6 +3,10 @@ import {
3
3
  program
4
4
  } from 'commander'
5
5
  import { app } from '../app'
6
+ import {
7
+ LogLevel,
8
+ PackageManagerName
9
+ } from '../enums'
6
10
  import { isOptions } from './Options'
7
11
  import type { Options } from './Options'
8
12
 
@@ -10,18 +14,25 @@ import type { Options } from './Options'
10
14
  export const initOptions = (): Options => {
11
15
  program
12
16
  .version(app.version)
17
+ .option('--branch-name <value>', 'Branch name template', 'npm-update-package/{{{packageName}}}/v{{newVersion}}')
13
18
  .option('--git-user-email <value>', 'User email of commit')
14
19
  .option('--git-user-name <value>', 'User name of commit')
15
20
  .requiredOption('--github-token <value>', 'GitHub token')
16
21
  .addOption(
17
22
  new Option('--log-level <value>', 'Log level to show')
18
- .choices(['info', 'debug'])
19
- .default('info')
23
+ .choices([
24
+ LogLevel.Info,
25
+ LogLevel.Debug
26
+ ])
27
+ .default(LogLevel.Info)
20
28
  )
21
29
  .addOption(
22
30
  new Option('--package-manager <value>', 'Package manager of your project')
23
- .choices(['npm', 'yarn'])
24
- .default('npm')
31
+ .choices([
32
+ PackageManagerName.Npm,
33
+ PackageManagerName.Yarn
34
+ ])
35
+ .default(PackageManagerName.Npm)
25
36
  )
26
37
  program.parse(process.argv)
27
38
  const options = program.opts()
@@ -1,3 +1,4 @@
1
+ import type { BranchNameCreator } from '../branch-name-creator'
1
2
  import type {
2
3
  Committer,
3
4
  Git
@@ -13,7 +14,6 @@ import type {
13
14
  OutdatedPackage,
14
15
  Result
15
16
  } from '../types'
16
- import { createBranchName } from './createBranchName'
17
17
  import { createCommitMessage } from './createCommitMessage'
18
18
 
19
19
  // TODO: add test
@@ -25,6 +25,7 @@ export class OutdatedPackageProcessor {
25
25
  private readonly pullRequestCreator: PullRequestCreator
26
26
  private readonly remoteBranchExistenceChecker: RemoteBranchExistenceChecker
27
27
  private readonly logger: Logger
28
+ private readonly branchNameCreator: BranchNameCreator
28
29
 
29
30
  constructor ({
30
31
  committer,
@@ -33,7 +34,8 @@ export class OutdatedPackageProcessor {
33
34
  packageManager,
34
35
  pullRequestCreator,
35
36
  remoteBranchExistenceChecker,
36
- logger
37
+ logger,
38
+ branchNameCreator
37
39
  }: {
38
40
  committer: Committer
39
41
  git: Git
@@ -42,6 +44,7 @@ export class OutdatedPackageProcessor {
42
44
  pullRequestCreator: PullRequestCreator
43
45
  remoteBranchExistenceChecker: RemoteBranchExistenceChecker
44
46
  logger: Logger
47
+ branchNameCreator: BranchNameCreator
45
48
  }) {
46
49
  this.committer = committer
47
50
  this.git = git
@@ -50,13 +53,14 @@ export class OutdatedPackageProcessor {
50
53
  this.pullRequestCreator = pullRequestCreator
51
54
  this.remoteBranchExistenceChecker = remoteBranchExistenceChecker
52
55
  this.logger = logger
56
+ this.branchNameCreator = branchNameCreator
53
57
  }
54
58
 
55
59
  /**
56
60
  * Don't run in parallel because it includes file operations.
57
61
  */
58
62
  async process (outdatedPackage: OutdatedPackage): Promise<Result> {
59
- const branchName = createBranchName(outdatedPackage)
63
+ const branchName = this.branchNameCreator.create(outdatedPackage)
60
64
  this.logger.debug(`branchName=${branchName}`)
61
65
 
62
66
  if (this.remoteBranchExistenceChecker.check(branchName)) {
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createBranchName = void 0;
4
- const createBranchName = (outdatedPackage) => {
5
- const packageName = outdatedPackage.name;
6
- const newVersion = outdatedPackage.newVersion.version;
7
- return `npm-update-package/${packageName}/v${newVersion}`;
8
- };
9
- exports.createBranchName = createBranchName;
@@ -1,14 +0,0 @@
1
- import { PackageVersion } from '../values'
2
- import { createBranchName } from './createBranchName'
3
-
4
- describe('createBranchName', () => {
5
- it('returns branch name', () => {
6
- const actual = createBranchName({
7
- name: '@typescript-eslint/eslint-plugin',
8
- currentVersion: PackageVersion.of('1.0.0'),
9
- newVersion: PackageVersion.of('1.2.3'),
10
- type: 'major'
11
- })
12
- expect(actual).toBe('npm-update-package/@typescript-eslint/eslint-plugin/v1.2.3')
13
- })
14
- })
@@ -1,7 +0,0 @@
1
- import type { OutdatedPackage } from '../types'
2
-
3
- export const createBranchName = (outdatedPackage: OutdatedPackage): string => {
4
- const packageName = outdatedPackage.name
5
- const newVersion = outdatedPackage.newVersion.version
6
- return `npm-update-package/${packageName}/v${newVersion}`
7
- }