npm-update-package 0.16.0 → 0.17.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 +7 -0
- package/dist/app.js +1 -1
- package/dist/git/index.js +3 -1
- package/dist/github/GitHub.js +4 -0
- package/dist/github/Label.js +2 -0
- package/dist/github/PullRequestCreator.js +14 -5
- package/dist/main.js +2 -1
- package/dist/ncu/NcuResultConverter.js +23 -12
- package/dist/options/CLIOption.js +2 -0
- package/dist/options/OptionType.js +10 -0
- package/dist/options/Options.js +14 -9
- package/dist/options/cliOptions.js +79 -0
- package/dist/options/initOptions.js +6 -30
- package/dist/options/toCommanderOption.js +32 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -129,6 +129,13 @@ This PR updates these packages:
|
|
|
129
129
|
This PR has been generated by [{{{appName}}}]({{{appWeb}}}) v{{appVersion}}
|
|
130
130
|
```
|
|
131
131
|
|
|
132
|
+
### `--pull-request-labels`
|
|
133
|
+
|
|
134
|
+
Pull request labels
|
|
135
|
+
|
|
136
|
+
- type: string array
|
|
137
|
+
- required: false
|
|
138
|
+
|
|
132
139
|
### `--pull-request-title`
|
|
133
140
|
|
|
134
141
|
Pull request title template
|
package/dist/app.js
CHANGED
package/dist/git/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Git = exports.CommitMessageCreator = exports.BranchNameCreator = void 0;
|
|
3
|
+
exports.GitRepository = exports.Git = exports.CommitMessageCreator = exports.BranchNameCreator = void 0;
|
|
4
4
|
var BranchNameCreator_1 = require("./BranchNameCreator");
|
|
5
5
|
Object.defineProperty(exports, "BranchNameCreator", { enumerable: true, get: function () { return BranchNameCreator_1.BranchNameCreator; } });
|
|
6
6
|
var CommitMessageCreator_1 = require("./CommitMessageCreator");
|
|
7
7
|
Object.defineProperty(exports, "CommitMessageCreator", { enumerable: true, get: function () { return CommitMessageCreator_1.CommitMessageCreator; } });
|
|
8
8
|
var Git_1 = require("./Git");
|
|
9
9
|
Object.defineProperty(exports, "Git", { enumerable: true, get: function () { return Git_1.Git; } });
|
|
10
|
+
var GitRepository_1 = require("./GitRepository");
|
|
11
|
+
Object.defineProperty(exports, "GitRepository", { enumerable: true, get: function () { return GitRepository_1.GitRepository; } });
|
package/dist/github/GitHub.js
CHANGED
|
@@ -6,6 +6,10 @@ class GitHub {
|
|
|
6
6
|
constructor(octokit) {
|
|
7
7
|
this.octokit = octokit;
|
|
8
8
|
}
|
|
9
|
+
async addLabels(params) {
|
|
10
|
+
const { data } = await this.octokit.issues.addLabels(params);
|
|
11
|
+
return data;
|
|
12
|
+
}
|
|
9
13
|
async createPullRequest(params) {
|
|
10
14
|
const { data } = await this.octokit.pulls.create(params);
|
|
11
15
|
return data;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PullRequestCreator = void 0;
|
|
4
|
-
// TODO: add test
|
|
5
4
|
class PullRequestCreator {
|
|
6
|
-
constructor({ github, gitRepo, githubRepo, pullRequestTitleCreator, pullRequestBodyCreator, logger }) {
|
|
5
|
+
constructor({ github, gitRepo, githubRepo, pullRequestTitleCreator, pullRequestBodyCreator, logger, labels }) {
|
|
7
6
|
this.github = github;
|
|
8
7
|
this.gitRepo = gitRepo;
|
|
9
8
|
this.githubRepo = githubRepo;
|
|
10
9
|
this.pullRequestTitleCreator = pullRequestTitleCreator;
|
|
11
10
|
this.pullRequestBodyCreator = pullRequestBodyCreator;
|
|
12
11
|
this.logger = logger;
|
|
12
|
+
this.labels = labels;
|
|
13
13
|
}
|
|
14
14
|
async create({ outdatedPackage, branchName }) {
|
|
15
15
|
const title = this.pullRequestTitleCreator.create(outdatedPackage);
|
|
16
16
|
this.logger.debug(`title=${title}`);
|
|
17
17
|
const body = this.pullRequestBodyCreator.create(outdatedPackage);
|
|
18
18
|
this.logger.debug(`body=${body}`);
|
|
19
|
-
const
|
|
19
|
+
const pullRequest = await this.github.createPullRequest({
|
|
20
20
|
owner: this.gitRepo.owner,
|
|
21
21
|
repo: this.gitRepo.name,
|
|
22
22
|
base: this.githubRepo.default_branch,
|
|
@@ -24,8 +24,17 @@ class PullRequestCreator {
|
|
|
24
24
|
title,
|
|
25
25
|
body
|
|
26
26
|
});
|
|
27
|
-
this.logger.debug(`
|
|
28
|
-
this.
|
|
27
|
+
this.logger.debug(`pullRequest=${JSON.stringify(pullRequest)}`);
|
|
28
|
+
if (this.labels !== undefined) {
|
|
29
|
+
const labels = await this.github.addLabels({
|
|
30
|
+
owner: this.gitRepo.owner,
|
|
31
|
+
repo: this.gitRepo.name,
|
|
32
|
+
issue_number: pullRequest.number,
|
|
33
|
+
labels: this.labels
|
|
34
|
+
});
|
|
35
|
+
this.logger.debug(`labels=${JSON.stringify(labels)}`);
|
|
36
|
+
}
|
|
37
|
+
this.logger.info(`Pull request for ${outdatedPackage.name} has created. ${pullRequest.html_url}`);
|
|
29
38
|
}
|
|
30
39
|
}
|
|
31
40
|
exports.PullRequestCreator = PullRequestCreator;
|
package/dist/main.js
CHANGED
|
@@ -59,7 +59,8 @@ const main = async ({ options, logger }) => {
|
|
|
59
59
|
githubRepo,
|
|
60
60
|
pullRequestTitleCreator,
|
|
61
61
|
pullRequestBodyCreator,
|
|
62
|
-
logger
|
|
62
|
+
logger,
|
|
63
|
+
labels: options.pullRequestLabels
|
|
63
64
|
});
|
|
64
65
|
const branchNameCreator = new git_1.BranchNameCreator(options.branchName);
|
|
65
66
|
const commitMessageCreator = new git_1.CommitMessageCreator(options.commitMessage);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NcuResultConverter = void 0;
|
|
4
|
+
const type_guards_1 = require("type-guards");
|
|
4
5
|
const PackageVersion_1 = require("./PackageVersion");
|
|
5
6
|
const toUpdateType_1 = require("./toUpdateType");
|
|
6
7
|
// TODO: add test
|
|
@@ -9,18 +10,28 @@ class NcuResultConverter {
|
|
|
9
10
|
this.currentDependencies = currentDependencies;
|
|
10
11
|
}
|
|
11
12
|
toOutdatedPackages(result) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
name,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
newVersion
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
const resultEntries = Object.entries(result);
|
|
14
|
+
const outdatedPackages = resultEntries
|
|
15
|
+
.map(([name, newVersionString]) => {
|
|
16
|
+
const currentVersionString = this.currentDependencies[name];
|
|
17
|
+
if (currentVersionString === undefined) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
const currentVersion = PackageVersion_1.PackageVersion.of(currentVersionString);
|
|
21
|
+
const newVersion = PackageVersion_1.PackageVersion.of(newVersionString);
|
|
22
|
+
const type = (0, toUpdateType_1.toUpdateType)(currentVersion, newVersion);
|
|
23
|
+
return {
|
|
24
|
+
name,
|
|
25
|
+
currentVersion,
|
|
26
|
+
newVersion,
|
|
27
|
+
type
|
|
28
|
+
};
|
|
29
|
+
})
|
|
30
|
+
.filter(type_guards_1.isNotUndefined);
|
|
31
|
+
if (resultEntries.length !== outdatedPackages.length) {
|
|
32
|
+
throw new Error('Failed to convert to outdatedPackages from NcuResult.');
|
|
33
|
+
}
|
|
34
|
+
return outdatedPackages;
|
|
24
35
|
}
|
|
25
36
|
}
|
|
26
37
|
exports.NcuResultConverter = NcuResultConverter;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isOptionType = exports.OptionType = void 0;
|
|
4
|
+
exports.OptionType = {
|
|
5
|
+
String: 'string',
|
|
6
|
+
StringArray: 'string[]'
|
|
7
|
+
};
|
|
8
|
+
const optionTypes = Object.values(exports.OptionType);
|
|
9
|
+
const isOptionType = (value) => optionTypes.includes(value);
|
|
10
|
+
exports.isOptionType = isOptionType;
|
package/dist/options/Options.js
CHANGED
|
@@ -4,13 +4,18 @@ exports.isOptions = void 0;
|
|
|
4
4
|
const io_ts_1 = require("io-ts");
|
|
5
5
|
const logger_1 = require("../logger");
|
|
6
6
|
const package_manager_1 = require("../package-manager");
|
|
7
|
-
const Options = (0, io_ts_1.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
const Options = (0, io_ts_1.intersection)([
|
|
8
|
+
(0, io_ts_1.type)({
|
|
9
|
+
branchName: io_ts_1.string,
|
|
10
|
+
commitMessage: io_ts_1.string,
|
|
11
|
+
githubToken: io_ts_1.string,
|
|
12
|
+
logLevel: (0, io_ts_1.union)([(0, io_ts_1.literal)(logger_1.LogLevel.Off), (0, io_ts_1.literal)(logger_1.LogLevel.Error), (0, io_ts_1.literal)(logger_1.LogLevel.Info), (0, io_ts_1.literal)(logger_1.LogLevel.Debug)]),
|
|
13
|
+
packageManager: (0, io_ts_1.union)([(0, io_ts_1.literal)(package_manager_1.PackageManagerName.Npm), (0, io_ts_1.literal)(package_manager_1.PackageManagerName.Yarn)]),
|
|
14
|
+
pullRequestBody: io_ts_1.string,
|
|
15
|
+
pullRequestTitle: io_ts_1.string
|
|
16
|
+
}),
|
|
17
|
+
(0, io_ts_1.partial)({
|
|
18
|
+
pullRequestLabels: (0, io_ts_1.array)(io_ts_1.string)
|
|
19
|
+
})
|
|
20
|
+
]);
|
|
16
21
|
exports.isOptions = Options.is;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cliOptions = void 0;
|
|
4
|
+
const logger_1 = require("../logger");
|
|
5
|
+
const package_manager_1 = require("../package-manager");
|
|
6
|
+
const OptionType_1 = require("./OptionType");
|
|
7
|
+
exports.cliOptions = [
|
|
8
|
+
{
|
|
9
|
+
name: 'branch-name',
|
|
10
|
+
description: 'Branch name template',
|
|
11
|
+
type: OptionType_1.OptionType.String,
|
|
12
|
+
required: false,
|
|
13
|
+
default: 'npm-update-package/{{{packageName}}}/v{{newVersion}}'
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: 'commit-message',
|
|
17
|
+
description: 'Commit message template',
|
|
18
|
+
type: OptionType_1.OptionType.String,
|
|
19
|
+
required: false,
|
|
20
|
+
default: 'chore(deps): {{updateType}} update {{{packageName}}} to v{{newVersion}}'
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'github-token',
|
|
24
|
+
description: 'GitHub token',
|
|
25
|
+
type: OptionType_1.OptionType.String,
|
|
26
|
+
required: true
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: 'log-level',
|
|
30
|
+
description: 'Log level to show',
|
|
31
|
+
type: OptionType_1.OptionType.String,
|
|
32
|
+
required: false,
|
|
33
|
+
choices: [
|
|
34
|
+
logger_1.LogLevel.Off,
|
|
35
|
+
logger_1.LogLevel.Error,
|
|
36
|
+
logger_1.LogLevel.Info,
|
|
37
|
+
logger_1.LogLevel.Debug
|
|
38
|
+
],
|
|
39
|
+
default: logger_1.LogLevel.Info
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: 'package-manager',
|
|
43
|
+
description: 'Package manager of your project',
|
|
44
|
+
type: OptionType_1.OptionType.String,
|
|
45
|
+
required: false,
|
|
46
|
+
choices: [
|
|
47
|
+
package_manager_1.PackageManagerName.Npm,
|
|
48
|
+
package_manager_1.PackageManagerName.Yarn
|
|
49
|
+
],
|
|
50
|
+
default: package_manager_1.PackageManagerName.Npm
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'pull-request-body',
|
|
54
|
+
description: 'Pull request body template',
|
|
55
|
+
type: OptionType_1.OptionType.String,
|
|
56
|
+
required: false,
|
|
57
|
+
default: `This PR updates these packages:
|
|
58
|
+
|
|
59
|
+
|package|type|current version|new version|
|
|
60
|
+
|---|---|---|---|
|
|
61
|
+
|[{{{packageName}}}](https://www.npmjs.com/package/{{{packageName}}})|{{updateType}}|\`{{currentVersion}}\`|\`{{newVersion}}\`|
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
This PR has been generated by [{{{appName}}}]({{{appWeb}}}) v{{appVersion}}`
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'pull-request-labels',
|
|
68
|
+
description: 'Pull request labels',
|
|
69
|
+
type: OptionType_1.OptionType.StringArray,
|
|
70
|
+
required: false
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: 'pull-request-title',
|
|
74
|
+
description: 'Pull request title template',
|
|
75
|
+
type: OptionType_1.OptionType.String,
|
|
76
|
+
required: false,
|
|
77
|
+
default: 'chore(deps): {{updateType}} update {{{packageName}}} to v{{newVersion}}'
|
|
78
|
+
}
|
|
79
|
+
];
|
|
@@ -3,39 +3,15 @@ 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
|
|
7
|
-
const package_manager_1 = require("../package-manager");
|
|
6
|
+
const cliOptions_1 = require("./cliOptions");
|
|
8
7
|
const Options_1 = require("./Options");
|
|
8
|
+
const toCommanderOption_1 = require("./toCommanderOption");
|
|
9
9
|
// TODO: add test
|
|
10
10
|
const initOptions = () => {
|
|
11
|
-
commander_1.program
|
|
12
|
-
|
|
13
|
-
.
|
|
14
|
-
.option
|
|
15
|
-
.requiredOption('--github-token <value>', 'GitHub token')
|
|
16
|
-
.addOption(new commander_1.Option('--log-level <value>', 'Log level to show')
|
|
17
|
-
.choices([
|
|
18
|
-
logger_1.LogLevel.Off,
|
|
19
|
-
logger_1.LogLevel.Error,
|
|
20
|
-
logger_1.LogLevel.Info,
|
|
21
|
-
logger_1.LogLevel.Debug
|
|
22
|
-
])
|
|
23
|
-
.default(logger_1.LogLevel.Info))
|
|
24
|
-
.addOption(new commander_1.Option('--package-manager <value>', 'Package manager of your project')
|
|
25
|
-
.choices([
|
|
26
|
-
package_manager_1.PackageManagerName.Npm,
|
|
27
|
-
package_manager_1.PackageManagerName.Yarn
|
|
28
|
-
])
|
|
29
|
-
.default(package_manager_1.PackageManagerName.Npm))
|
|
30
|
-
.option('--pull-request-body <value>', 'Pull request body template', `This PR updates these packages:
|
|
31
|
-
|
|
32
|
-
|package|type|current version|new version|
|
|
33
|
-
|---|---|---|---|
|
|
34
|
-
|[{{{packageName}}}](https://www.npmjs.com/package/{{{packageName}}})|{{updateType}}|\`{{currentVersion}}\`|\`{{newVersion}}\`|
|
|
35
|
-
|
|
36
|
-
---
|
|
37
|
-
This PR has been generated by [{{{appName}}}]({{{appWeb}}}) v{{appVersion}}`)
|
|
38
|
-
.option('--pull-request-title <value>', 'Pull request title template', 'chore(deps): {{updateType}} update {{{packageName}}} to v{{newVersion}}');
|
|
11
|
+
commander_1.program.version(app_1.app.version);
|
|
12
|
+
cliOptions_1.cliOptions
|
|
13
|
+
.map(toCommanderOption_1.toCommanderOption)
|
|
14
|
+
.forEach(option => commander_1.program.addOption(option));
|
|
39
15
|
commander_1.program.parse(process.argv);
|
|
40
16
|
const options = commander_1.program.opts();
|
|
41
17
|
if (!(0, Options_1.isOptions)(options)) {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toCommanderOption = void 0;
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const OptionType_1 = require("./OptionType");
|
|
6
|
+
// TODO: add test
|
|
7
|
+
const toCommanderOption = (cliOption) => {
|
|
8
|
+
const argument = createArgumentString(cliOption);
|
|
9
|
+
const option = new commander_1.Option(`--${cliOption.name} ${argument}`, cliOption.description);
|
|
10
|
+
if (cliOption.choices !== undefined) {
|
|
11
|
+
option.choices(cliOption.choices);
|
|
12
|
+
}
|
|
13
|
+
if (!cliOption.required && cliOption.default !== undefined) {
|
|
14
|
+
option.default(cliOption.default);
|
|
15
|
+
}
|
|
16
|
+
return option;
|
|
17
|
+
};
|
|
18
|
+
exports.toCommanderOption = toCommanderOption;
|
|
19
|
+
const createArgumentString = (cliOption) => {
|
|
20
|
+
const prefix = cliOption.required ? '<' : '[';
|
|
21
|
+
const suffix = cliOption.required ? '>' : ']';
|
|
22
|
+
const name = createArgumentNameString(cliOption.type);
|
|
23
|
+
return `${prefix}${name}${suffix}`;
|
|
24
|
+
};
|
|
25
|
+
const createArgumentNameString = (optionType) => {
|
|
26
|
+
switch (optionType) {
|
|
27
|
+
case OptionType_1.OptionType.String:
|
|
28
|
+
return 'value';
|
|
29
|
+
case OptionType_1.OptionType.StringArray:
|
|
30
|
+
return 'values...';
|
|
31
|
+
}
|
|
32
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-update-package",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.1",
|
|
4
4
|
"description": "CLI tool for creating pull request to update npm packages",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc --project tsconfig.build.json",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"mustache": "4.1.0",
|
|
27
27
|
"npm-check-updates": "12.0.5",
|
|
28
28
|
"parse-github-url": "1.0.2",
|
|
29
|
-
"semver": "7.3.5"
|
|
29
|
+
"semver": "7.3.5",
|
|
30
|
+
"type-guards": "0.15.0"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@jest/types": "27.0.6",
|