npm-update-package 0.1.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/.github/workflows/test.yml +1 -1
- package/FUNDING.yml +2 -0
- package/README.md +13 -0
- package/dist/app.js +2 -2
- package/dist/bin.js +3 -2
- package/dist/branch-name-creator/BranchNameCreator.js +22 -0
- package/dist/branch-name-creator/index.js +5 -0
- package/dist/main.js +4 -1
- package/dist/options/Options.js +1 -0
- package/dist/options/initOptions.js +12 -4
- package/dist/outdated-package-processor/OutdatedPackageProcessor.js +3 -3
- package/npm-update-package.code-workspace +8 -0
- package/package.json +6 -4
- package/src/app.ts +2 -2
- package/src/bin.ts +3 -2
- package/src/branch-name-creator/BranchNameCreator.test.ts +17 -0
- package/src/branch-name-creator/BranchNameCreator.ts +19 -0
- package/src/branch-name-creator/index.ts +1 -0
- package/src/git/GitRepository.test.ts +8 -8
- package/src/github/createPullRequestBody.test.ts +3 -3
- package/src/main.ts +4 -1
- package/src/options/Options.ts +1 -0
- package/src/options/initOptions.ts +15 -4
- package/src/outdated-package-processor/OutdatedPackageProcessor.ts +7 -3
- package/dist/outdated-package-processor/createBranchName.js +0 -9
- package/src/outdated-package-processor/createBranchName.test.ts +0 -14
- package/src/outdated-package-processor/createBranchName.ts +0 -7
package/FUNDING.yml
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
[](https://badge.fury.io/js/npm-update-package)
|
|
1
2
|
[](https://standardjs.com)
|
|
2
3
|
|
|
3
4
|
# npm-update-package
|
|
@@ -36,8 +37,20 @@ You can customize behavior via command-line options.
|
|
|
36
37
|
|
|
37
38
|
|Option|Description|Required|Value|Default|
|
|
38
39
|
|---|---|---|---|---|
|
|
40
|
+
|`--branch-name`|Branch name template|-|string|`npm-update-package/{{{packageName}}}/v{{newVersion}}`|
|
|
39
41
|
|`--git-user-email`|User email of commit|-|string|-|
|
|
40
42
|
|`--git-user-name`|User name of commit|-|string|-|
|
|
41
43
|
|`--github-token`|GitHub token|✓|string|-|
|
|
42
44
|
|`--log-level`|Log level to show|-|`info`, `debug`|`info`|
|
|
43
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.
|
|
7
|
-
web: 'https://github.com/
|
|
6
|
+
version: '0.4.0',
|
|
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(
|
|
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(
|
|
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; } });
|
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,
|
package/dist/options/Options.js
CHANGED
|
@@ -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([
|
|
16
|
-
.
|
|
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([
|
|
19
|
-
.
|
|
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 =
|
|
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
|
+
"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",
|
|
@@ -48,12 +50,12 @@
|
|
|
48
50
|
"typescript": "4.4.4",
|
|
49
51
|
"utility-types": "3.10.0"
|
|
50
52
|
},
|
|
51
|
-
"homepage": "https://github.com/
|
|
53
|
+
"homepage": "https://github.com/npm-update-package/npm-update-package",
|
|
52
54
|
"bugs": {
|
|
53
|
-
"url": "https://github.com/
|
|
55
|
+
"url": "https://github.com/npm-update-package/npm-update-package/issues"
|
|
54
56
|
},
|
|
55
57
|
"repository": {
|
|
56
58
|
"type": "git",
|
|
57
|
-
"url": "https://github.com/
|
|
59
|
+
"url": "https://github.com/npm-update-package/npm-update-package.git"
|
|
58
60
|
}
|
|
59
61
|
}
|
package/src/app.ts
CHANGED
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(
|
|
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(
|
|
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'
|
|
@@ -4,12 +4,12 @@ describe('GitRepository', () => {
|
|
|
4
4
|
describe('of', () => {
|
|
5
5
|
describe('if URL is HTTPS', () => {
|
|
6
6
|
describe('if URL is github.com', () => {
|
|
7
|
-
const url = 'https://github.com/
|
|
7
|
+
const url = 'https://github.com/npm-update-package/npm-update-package.git'
|
|
8
8
|
|
|
9
9
|
it('returns new GitRepository instance', () => {
|
|
10
10
|
const repo = GitRepository.of(url)
|
|
11
11
|
expect(repo.host).toBe('github.com')
|
|
12
|
-
expect(repo.owner).toBe('
|
|
12
|
+
expect(repo.owner).toBe('npm-update-package')
|
|
13
13
|
expect(repo.name).toBe('npm-update-package')
|
|
14
14
|
expect(repo.apiEndPoint).toBe('https://api.github.com')
|
|
15
15
|
expect(repo.isGitHubDotCom).toBe(true)
|
|
@@ -17,12 +17,12 @@ describe('GitRepository', () => {
|
|
|
17
17
|
})
|
|
18
18
|
|
|
19
19
|
describe('if URL is not github.com', () => {
|
|
20
|
-
const url = 'https://git.example.com/
|
|
20
|
+
const url = 'https://git.example.com/npm-update-package/npm-update-package.git'
|
|
21
21
|
|
|
22
22
|
it('returns new GitRepository instance', () => {
|
|
23
23
|
const repo = GitRepository.of(url)
|
|
24
24
|
expect(repo.host).toBe('git.example.com')
|
|
25
|
-
expect(repo.owner).toBe('
|
|
25
|
+
expect(repo.owner).toBe('npm-update-package')
|
|
26
26
|
expect(repo.name).toBe('npm-update-package')
|
|
27
27
|
expect(repo.apiEndPoint).toBe('https://git.example.com/api/v3')
|
|
28
28
|
expect(repo.isGitHubDotCom).toBe(false)
|
|
@@ -32,12 +32,12 @@ describe('GitRepository', () => {
|
|
|
32
32
|
|
|
33
33
|
describe('if URL is SSH', () => {
|
|
34
34
|
describe('if URL is github.com', () => {
|
|
35
|
-
const url = 'git@github.com:
|
|
35
|
+
const url = 'git@github.com:npm-update-package/npm-update-package.git'
|
|
36
36
|
|
|
37
37
|
it('returns new GitRepository instance', () => {
|
|
38
38
|
const repo = GitRepository.of(url)
|
|
39
39
|
expect(repo.host).toBe('github.com')
|
|
40
|
-
expect(repo.owner).toBe('
|
|
40
|
+
expect(repo.owner).toBe('npm-update-package')
|
|
41
41
|
expect(repo.name).toBe('npm-update-package')
|
|
42
42
|
expect(repo.apiEndPoint).toBe('https://api.github.com')
|
|
43
43
|
expect(repo.isGitHubDotCom).toBe(true)
|
|
@@ -45,12 +45,12 @@ describe('GitRepository', () => {
|
|
|
45
45
|
})
|
|
46
46
|
|
|
47
47
|
describe('if URL is not github.com', () => {
|
|
48
|
-
const url = 'git@git.example.com:
|
|
48
|
+
const url = 'git@git.example.com:npm-update-package/npm-update-package.git'
|
|
49
49
|
|
|
50
50
|
it('returns new GitRepository instance', () => {
|
|
51
51
|
const repo = GitRepository.of(url)
|
|
52
52
|
expect(repo.host).toBe('git.example.com')
|
|
53
|
-
expect(repo.owner).toBe('
|
|
53
|
+
expect(repo.owner).toBe('npm-update-package')
|
|
54
54
|
expect(repo.name).toBe('npm-update-package')
|
|
55
55
|
expect(repo.apiEndPoint).toBe('https://git.example.com/api/v3')
|
|
56
56
|
expect(repo.isGitHubDotCom).toBe(false)
|
|
@@ -18,7 +18,7 @@ describe('createPullRequestBody', () => {
|
|
|
18
18
|
|[@typescript-eslint/eslint-plugin](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin)|patch|\`1.0.0\`|\`1.0.1\`|
|
|
19
19
|
|
|
20
20
|
---
|
|
21
|
-
This PR has been generated by [npm-update-package](https://github.com/
|
|
21
|
+
This PR has been generated by [npm-update-package](https://github.com/npm-update-package/npm-update-package)`)
|
|
22
22
|
})
|
|
23
23
|
})
|
|
24
24
|
|
|
@@ -37,7 +37,7 @@ This PR has been generated by [npm-update-package](https://github.com/munierujp/
|
|
|
37
37
|
|[@typescript-eslint/eslint-plugin](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin)|minor|\`1.0.0\`|\`1.1.0\`|
|
|
38
38
|
|
|
39
39
|
---
|
|
40
|
-
This PR has been generated by [npm-update-package](https://github.com/
|
|
40
|
+
This PR has been generated by [npm-update-package](https://github.com/npm-update-package/npm-update-package)`)
|
|
41
41
|
})
|
|
42
42
|
})
|
|
43
43
|
|
|
@@ -56,7 +56,7 @@ This PR has been generated by [npm-update-package](https://github.com/munierujp/
|
|
|
56
56
|
|[@typescript-eslint/eslint-plugin](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin)|major|\`1.0.0\`|\`2.0.0\`|
|
|
57
57
|
|
|
58
58
|
---
|
|
59
|
-
This PR has been generated by [npm-update-package](https://github.com/
|
|
59
|
+
This PR has been generated by [npm-update-package](https://github.com/npm-update-package/npm-update-package)`)
|
|
60
60
|
})
|
|
61
61
|
})
|
|
62
62
|
})
|
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,
|
package/src/options/Options.ts
CHANGED
|
@@ -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([
|
|
19
|
-
|
|
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([
|
|
24
|
-
|
|
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 =
|
|
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
|
-
}
|