npm-update-package 0.2.0 → 0.5.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.
Files changed (32) hide show
  1. package/.github/FUNDING.yml +2 -0
  2. package/README.md +18 -0
  3. package/dist/app.js +1 -1
  4. package/dist/bin.js +3 -2
  5. package/dist/branch-name-creator/BranchNameCreator.js +22 -0
  6. package/dist/branch-name-creator/index.js +5 -0
  7. package/dist/commit-message-creator/CommitMessageCreator.js +22 -0
  8. package/dist/commit-message-creator/index.js +5 -0
  9. package/dist/main.js +7 -1
  10. package/dist/options/Options.js +2 -0
  11. package/dist/options/initOptions.js +13 -4
  12. package/dist/outdated-package-processor/OutdatedPackageProcessor.js +5 -5
  13. package/npm-update-package.code-workspace +8 -0
  14. package/package.json +3 -1
  15. package/src/app.ts +1 -1
  16. package/src/bin.ts +3 -2
  17. package/src/branch-name-creator/BranchNameCreator.test.ts +17 -0
  18. package/src/branch-name-creator/BranchNameCreator.ts +19 -0
  19. package/src/branch-name-creator/index.ts +1 -0
  20. package/src/commit-message-creator/CommitMessageCreator.test.ts +17 -0
  21. package/src/commit-message-creator/CommitMessageCreator.ts +19 -0
  22. package/src/commit-message-creator/index.ts +1 -0
  23. package/src/main.ts +7 -1
  24. package/src/options/Options.ts +2 -0
  25. package/src/options/initOptions.ts +16 -4
  26. package/src/outdated-package-processor/OutdatedPackageProcessor.ts +13 -5
  27. package/dist/outdated-package-processor/createBranchName.js +0 -9
  28. package/dist/outdated-package-processor/createCommitMessage.js +0 -10
  29. package/src/outdated-package-processor/createBranchName.test.ts +0 -14
  30. package/src/outdated-package-processor/createBranchName.ts +0 -7
  31. package/src/outdated-package-processor/createCommitMessage.test.ts +0 -43
  32. package/src/outdated-package-processor/createCommitMessage.ts +0 -8
@@ -0,0 +1,2 @@
1
+ github: munierujp
2
+ custom: ["https://www.paypal.me/munieru"]
package/README.md CHANGED
@@ -37,8 +37,26 @@ 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}}`|
41
+ |`--commit-message`|Commit message template|-|string|`chore(deps): {{updateType}} update {{{packageName}}} to v{{newVersion}}`|
40
42
  |`--git-user-email`|User email of commit|-|string|-|
41
43
  |`--git-user-name`|User name of commit|-|string|-|
42
44
  |`--github-token`|GitHub token|✓|string|-|
43
45
  |`--log-level`|Log level to show|-|`info`, `debug`|`info`|
44
46
  |`--package-manager`|Package manager of your project|-|`npm`, `yarn`|`npm`|
47
+
48
+ ### Templates
49
+
50
+ npm-update-package is using [mustache](https://www.npmjs.com/package/mustache) for generating string from templates.
51
+ These variables are available:
52
+
53
+ - `--branch-name`
54
+ - `packageName`
55
+ - `currentVersion`
56
+ - `newVersion`
57
+ - `updateType`
58
+ - `--commit-message`
59
+ - `packageName`
60
+ - `currentVersion`
61
+ - `newVersion`
62
+ - `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.1.0',
6
+ version: '0.5.0',
7
7
  web: 'https://github.com/npm-update-package/npm-update-package'
8
8
  };
package/dist/bin.js CHANGED
@@ -1,17 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ const app_1 = require("./app");
4
5
  const logger_1 = require("./logger");
5
6
  const main_1 = require("./main");
6
7
  const options_1 = require("./options");
7
8
  const options = (0, options_1.initOptions)();
8
9
  const logger = (0, logger_1.createLogger)(options.logLevel);
9
- logger.info('Start npm-update-package.');
10
+ logger.info(`Start ${app_1.app.name} v${app_1.app.version}`);
10
11
  (0, main_1.main)({
11
12
  options,
12
13
  logger
13
14
  })
14
- .then(() => logger.info('End npm-update-package'))
15
+ .then(() => logger.info(`End ${app_1.app.name} v${app_1.app.version}`))
15
16
  .catch((e) => {
16
17
  // TODO: improve error handling
17
18
  logger.fatal('Unexpected error has occurred.', e);
@@ -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; } });
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommitMessageCreator = void 0;
4
+ const mustache_1 = require("mustache");
5
+ class CommitMessageCreator {
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.CommitMessageCreator = CommitMessageCreator;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommitMessageCreator = void 0;
4
+ var CommitMessageCreator_1 = require("./CommitMessageCreator");
5
+ Object.defineProperty(exports, "CommitMessageCreator", { enumerable: true, get: function () { return CommitMessageCreator_1.CommitMessageCreator; } });
package/dist/main.js CHANGED
@@ -1,6 +1,8 @@
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");
5
+ const commit_message_creator_1 = require("./commit-message-creator");
4
6
  const git_1 = require("./git");
5
7
  const github_1 = require("./github");
6
8
  const ncu_1 = require("./ncu");
@@ -55,6 +57,8 @@ const main = async ({ options, logger }) => {
55
57
  githubRepo,
56
58
  logger
57
59
  });
60
+ const branchNameCreator = new branch_name_creator_1.BranchNameCreator(options.branchName);
61
+ const commitMessageCreator = new commit_message_creator_1.CommitMessageCreator(options.commitMessage);
58
62
  const outdatedPackageProcessor = new outdated_package_processor_1.OutdatedPackageProcessor({
59
63
  committer,
60
64
  git,
@@ -62,7 +66,9 @@ const main = async ({ options, logger }) => {
62
66
  packageManager,
63
67
  pullRequestCreator,
64
68
  remoteBranchExistenceChecker,
65
- logger
69
+ logger,
70
+ branchNameCreator,
71
+ commitMessageCreator
66
72
  });
67
73
  const outdatedPackagesProcessor = new outdated_packages_processor_1.OutdatedPackagesProcessor({
68
74
  outdatedPackageProcessor,
@@ -4,6 +4,8 @@ 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,
8
+ commitMessage: io_ts_1.string,
7
9
  githubToken: io_ts_1.string,
8
10
  logLevel: (0, io_ts_1.union)([(0, io_ts_1.literal)('info'), (0, io_ts_1.literal)('debug')]),
9
11
  packageManager: (0, io_ts_1.union)([(0, io_ts_1.literal)('npm'), (0, io_ts_1.literal)('yarn')])
@@ -3,20 +3,29 @@ 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}}')
13
+ .option('--commit-message <value>', 'Commit message template', 'chore(deps): {{updateType}} update {{{packageName}}} to v{{newVersion}}')
11
14
  .option('--git-user-email <value>', 'User email of commit')
12
15
  .option('--git-user-name <value>', 'User name of commit')
13
16
  .requiredOption('--github-token <value>', 'GitHub token')
14
17
  .addOption(new commander_1.Option('--log-level <value>', 'Log level to show')
15
- .choices(['info', 'debug'])
16
- .default('info'))
18
+ .choices([
19
+ enums_1.LogLevel.Info,
20
+ enums_1.LogLevel.Debug
21
+ ])
22
+ .default(enums_1.LogLevel.Info))
17
23
  .addOption(new commander_1.Option('--package-manager <value>', 'Package manager of your project')
18
- .choices(['npm', 'yarn'])
19
- .default('npm'));
24
+ .choices([
25
+ enums_1.PackageManagerName.Npm,
26
+ enums_1.PackageManagerName.Yarn
27
+ ])
28
+ .default(enums_1.PackageManagerName.Npm));
20
29
  commander_1.program.parse(process.argv);
21
30
  const options = commander_1.program.opts();
22
31
  if (!(0, Options_1.isOptions)(options)) {
@@ -1,11 +1,9 @@
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
- const createCommitMessage_1 = require("./createCommitMessage");
6
4
  // TODO: add test
7
5
  class OutdatedPackageProcessor {
8
- constructor({ committer, git, ncu, packageManager, pullRequestCreator, remoteBranchExistenceChecker, logger }) {
6
+ constructor({ committer, git, ncu, packageManager, pullRequestCreator, remoteBranchExistenceChecker, logger, branchNameCreator, commitMessageCreator }) {
9
7
  this.committer = committer;
10
8
  this.git = git;
11
9
  this.ncu = ncu;
@@ -13,12 +11,14 @@ class OutdatedPackageProcessor {
13
11
  this.pullRequestCreator = pullRequestCreator;
14
12
  this.remoteBranchExistenceChecker = remoteBranchExistenceChecker;
15
13
  this.logger = logger;
14
+ this.branchNameCreator = branchNameCreator;
15
+ this.commitMessageCreator = commitMessageCreator;
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.`);
@@ -36,7 +36,7 @@ class OutdatedPackageProcessor {
36
36
  await this.packageManager.install();
37
37
  this.logger.info(`${outdatedPackage.name} has updated from v${outdatedPackage.currentVersion.version} to v${outdatedPackage.newVersion.version}`);
38
38
  await this.git.add(...this.packageManager.packageFiles);
39
- const message = (0, createCommitMessage_1.createCommitMessage)(outdatedPackage);
39
+ const message = this.commitMessageCreator.create(outdatedPackage);
40
40
  this.logger.debug(`message=${message}`);
41
41
  await this.committer.commit(message);
42
42
  await this.git.push(branchName);
@@ -0,0 +1,8 @@
1
+ {
2
+ "folders": [
3
+ {
4
+ "path": "."
5
+ }
6
+ ],
7
+ "settings": {}
8
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npm-update-package",
3
- "version": "0.2.0",
3
+ "version": "0.5.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.1.0',
3
+ version: '0.5.0',
4
4
  web: 'https://github.com/npm-update-package/npm-update-package'
5
5
  } as const
package/src/bin.ts CHANGED
@@ -1,18 +1,19 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ import { app } from './app'
3
4
  import { createLogger } from './logger'
4
5
  import { main } from './main'
5
6
  import { initOptions } from './options'
6
7
 
7
8
  const options = initOptions()
8
9
  const logger = createLogger(options.logLevel)
9
- logger.info('Start npm-update-package.')
10
+ logger.info(`Start ${app.name} v${app.version}`)
10
11
 
11
12
  main({
12
13
  options,
13
14
  logger
14
15
  })
15
- .then(() => logger.info('End npm-update-package'))
16
+ .then(() => logger.info(`End ${app.name} v${app.version}`))
16
17
  .catch((e: unknown) => {
17
18
  // TODO: improve error handling
18
19
  logger.fatal('Unexpected error has occurred.', e)
@@ -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'
@@ -0,0 +1,17 @@
1
+ import { PackageVersion } from '../values'
2
+ import { CommitMessageCreator } from './CommitMessageCreator'
3
+
4
+ describe('CommitMessageCreator', () => {
5
+ describe('create', () => {
6
+ it('returns commit message', () => {
7
+ const commitMessageCreator = new CommitMessageCreator('chore(deps): {{updateType}} update {{{packageName}}} from {{currentVersion}} to v{{newVersion}}')
8
+ const actual = commitMessageCreator.create({
9
+ name: '@typescript-eslint/eslint-plugin',
10
+ currentVersion: PackageVersion.of('1.0.0'),
11
+ newVersion: PackageVersion.of('2.0.0'),
12
+ type: 'major'
13
+ })
14
+ expect(actual).toBe('chore(deps): major update @typescript-eslint/eslint-plugin from 1.0.0 to v2.0.0')
15
+ })
16
+ })
17
+ })
@@ -0,0 +1,19 @@
1
+ import { render } from 'mustache'
2
+ import type { OutdatedPackage } from '../types'
3
+
4
+ export class CommitMessageCreator {
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 { CommitMessageCreator } from './CommitMessageCreator'
package/src/main.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { BranchNameCreator } from './branch-name-creator'
2
+ import { CommitMessageCreator } from './commit-message-creator'
1
3
  import {
2
4
  Committer,
3
5
  Git
@@ -75,6 +77,8 @@ export const main = async ({
75
77
  githubRepo,
76
78
  logger
77
79
  })
80
+ const branchNameCreator = new BranchNameCreator(options.branchName)
81
+ const commitMessageCreator = new CommitMessageCreator(options.commitMessage)
78
82
  const outdatedPackageProcessor = new OutdatedPackageProcessor({
79
83
  committer,
80
84
  git,
@@ -82,7 +86,9 @@ export const main = async ({
82
86
  packageManager,
83
87
  pullRequestCreator,
84
88
  remoteBranchExistenceChecker,
85
- logger
89
+ logger,
90
+ branchNameCreator,
91
+ commitMessageCreator
86
92
  })
87
93
  const outdatedPackagesProcessor = new OutdatedPackagesProcessor({
88
94
  outdatedPackageProcessor,
@@ -10,6 +10,8 @@ import type { TypeOf } from 'io-ts'
10
10
 
11
11
  export const Options = intersection([
12
12
  type({
13
+ branchName: string,
14
+ commitMessage: string,
13
15
  githubToken: string,
14
16
  logLevel: union([literal('info'), literal('debug')]),
15
17
  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,26 @@ 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}}')
18
+ .option('--commit-message <value>', 'Commit message template', 'chore(deps): {{updateType}} update {{{packageName}}} to v{{newVersion}}')
13
19
  .option('--git-user-email <value>', 'User email of commit')
14
20
  .option('--git-user-name <value>', 'User name of commit')
15
21
  .requiredOption('--github-token <value>', 'GitHub token')
16
22
  .addOption(
17
23
  new Option('--log-level <value>', 'Log level to show')
18
- .choices(['info', 'debug'])
19
- .default('info')
24
+ .choices([
25
+ LogLevel.Info,
26
+ LogLevel.Debug
27
+ ])
28
+ .default(LogLevel.Info)
20
29
  )
21
30
  .addOption(
22
31
  new Option('--package-manager <value>', 'Package manager of your project')
23
- .choices(['npm', 'yarn'])
24
- .default('npm')
32
+ .choices([
33
+ PackageManagerName.Npm,
34
+ PackageManagerName.Yarn
35
+ ])
36
+ .default(PackageManagerName.Npm)
25
37
  )
26
38
  program.parse(process.argv)
27
39
  const options = program.opts()
@@ -1,3 +1,5 @@
1
+ import type { BranchNameCreator } from '../branch-name-creator'
2
+ import type { CommitMessageCreator } from '../commit-message-creator'
1
3
  import type {
2
4
  Committer,
3
5
  Git
@@ -13,8 +15,6 @@ import type {
13
15
  OutdatedPackage,
14
16
  Result
15
17
  } from '../types'
16
- import { createBranchName } from './createBranchName'
17
- import { createCommitMessage } from './createCommitMessage'
18
18
 
19
19
  // TODO: add test
20
20
  export class OutdatedPackageProcessor {
@@ -25,6 +25,8 @@ 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
29
+ private readonly commitMessageCreator: CommitMessageCreator
28
30
 
29
31
  constructor ({
30
32
  committer,
@@ -33,7 +35,9 @@ export class OutdatedPackageProcessor {
33
35
  packageManager,
34
36
  pullRequestCreator,
35
37
  remoteBranchExistenceChecker,
36
- logger
38
+ logger,
39
+ branchNameCreator,
40
+ commitMessageCreator
37
41
  }: {
38
42
  committer: Committer
39
43
  git: Git
@@ -42,6 +46,8 @@ export class OutdatedPackageProcessor {
42
46
  pullRequestCreator: PullRequestCreator
43
47
  remoteBranchExistenceChecker: RemoteBranchExistenceChecker
44
48
  logger: Logger
49
+ branchNameCreator: BranchNameCreator
50
+ commitMessageCreator: CommitMessageCreator
45
51
  }) {
46
52
  this.committer = committer
47
53
  this.git = git
@@ -50,13 +56,15 @@ export class OutdatedPackageProcessor {
50
56
  this.pullRequestCreator = pullRequestCreator
51
57
  this.remoteBranchExistenceChecker = remoteBranchExistenceChecker
52
58
  this.logger = logger
59
+ this.branchNameCreator = branchNameCreator
60
+ this.commitMessageCreator = commitMessageCreator
53
61
  }
54
62
 
55
63
  /**
56
64
  * Don't run in parallel because it includes file operations.
57
65
  */
58
66
  async process (outdatedPackage: OutdatedPackage): Promise<Result> {
59
- const branchName = createBranchName(outdatedPackage)
67
+ const branchName = this.branchNameCreator.create(outdatedPackage)
60
68
  this.logger.debug(`branchName=${branchName}`)
61
69
 
62
70
  if (this.remoteBranchExistenceChecker.check(branchName)) {
@@ -80,7 +88,7 @@ export class OutdatedPackageProcessor {
80
88
  this.logger.info(`${outdatedPackage.name} has updated from v${outdatedPackage.currentVersion.version} to v${outdatedPackage.newVersion.version}`)
81
89
 
82
90
  await this.git.add(...this.packageManager.packageFiles)
83
- const message = createCommitMessage(outdatedPackage)
91
+ const message = this.commitMessageCreator.create(outdatedPackage)
84
92
  this.logger.debug(`message=${message}`)
85
93
 
86
94
  await this.committer.commit(message)
@@ -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,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createCommitMessage = void 0;
4
- const createCommitMessage = (outdatedPackage) => {
5
- const packageName = outdatedPackage.name;
6
- const newVersion = outdatedPackage.newVersion.version;
7
- const updateType = outdatedPackage.type;
8
- return `chore(deps): ${updateType} update ${packageName} to v${newVersion}`;
9
- };
10
- exports.createCommitMessage = createCommitMessage;
@@ -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
- }
@@ -1,43 +0,0 @@
1
- import { UpdateType } from '../enums'
2
- import { PackageVersion } from '../values'
3
- import { createCommitMessage } from './createCommitMessage'
4
-
5
- describe('createCommitMessage', () => {
6
- const currentVersion = PackageVersion.of('1.0.0')
7
-
8
- describe('if update type is patch', () => {
9
- it('returns commit message', () => {
10
- const actual = createCommitMessage({
11
- name: '@typescript-eslint/eslint-plugin',
12
- currentVersion,
13
- newVersion: PackageVersion.of('1.0.1'),
14
- type: UpdateType.Patch
15
- })
16
- expect(actual).toBe('chore(deps): patch update @typescript-eslint/eslint-plugin to v1.0.1')
17
- })
18
- })
19
-
20
- describe('if update type is minor', () => {
21
- it('returns commit message', () => {
22
- const actual = createCommitMessage({
23
- name: '@typescript-eslint/eslint-plugin',
24
- currentVersion,
25
- newVersion: PackageVersion.of('1.1.0'),
26
- type: UpdateType.Minor
27
- })
28
- expect(actual).toBe('chore(deps): minor update @typescript-eslint/eslint-plugin to v1.1.0')
29
- })
30
- })
31
-
32
- describe('if update type is major', () => {
33
- it('returns commit message', () => {
34
- const actual = createCommitMessage({
35
- name: '@typescript-eslint/eslint-plugin',
36
- currentVersion,
37
- newVersion: PackageVersion.of('2.0.0'),
38
- type: UpdateType.Major
39
- })
40
- expect(actual).toBe('chore(deps): major update @typescript-eslint/eslint-plugin to v2.0.0')
41
- })
42
- })
43
- })
@@ -1,8 +0,0 @@
1
- import type { OutdatedPackage } from '../types'
2
-
3
- export const createCommitMessage = (outdatedPackage: OutdatedPackage): string => {
4
- const packageName = outdatedPackage.name
5
- const newVersion = outdatedPackage.newVersion.version
6
- const updateType = outdatedPackage.type
7
- return `chore(deps): ${updateType} update ${packageName} to v${newVersion}`
8
- }