npm-update-package 0.16.1 → 0.17.2
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/github/GitHub.js +4 -0
- package/dist/github/Label.js +2 -0
- package/dist/github/PullRequestCreator.js +11 -1
- package/dist/main.js +2 -1
- package/dist/ncu/NcuResultConverter.js +23 -12
- package/dist/options/OptionType.js +10 -0
- package/dist/options/Options.js +14 -9
- package/dist/options/cliOptions.js +14 -0
- package/dist/options/toCommanderOption.js +18 -3
- package/package.json +5 -4
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/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;
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PullRequestCreator = void 0;
|
|
4
4
|
class PullRequestCreator {
|
|
5
|
-
constructor({ github, gitRepo, githubRepo, pullRequestTitleCreator, pullRequestBodyCreator, logger }) {
|
|
5
|
+
constructor({ github, gitRepo, githubRepo, pullRequestTitleCreator, pullRequestBodyCreator, logger, labels }) {
|
|
6
6
|
this.github = github;
|
|
7
7
|
this.gitRepo = gitRepo;
|
|
8
8
|
this.githubRepo = githubRepo;
|
|
9
9
|
this.pullRequestTitleCreator = pullRequestTitleCreator;
|
|
10
10
|
this.pullRequestBodyCreator = pullRequestBodyCreator;
|
|
11
11
|
this.logger = logger;
|
|
12
|
+
this.labels = labels;
|
|
12
13
|
}
|
|
13
14
|
async create({ outdatedPackage, branchName }) {
|
|
14
15
|
const title = this.pullRequestTitleCreator.create(outdatedPackage);
|
|
@@ -24,6 +25,15 @@ class PullRequestCreator {
|
|
|
24
25
|
body
|
|
25
26
|
});
|
|
26
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
|
+
}
|
|
27
37
|
this.logger.info(`Pull request for ${outdatedPackage.name} has created. ${pullRequest.html_url}`);
|
|
28
38
|
}
|
|
29
39
|
}
|
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;
|
|
@@ -3,27 +3,32 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.cliOptions = void 0;
|
|
4
4
|
const logger_1 = require("../logger");
|
|
5
5
|
const package_manager_1 = require("../package-manager");
|
|
6
|
+
const OptionType_1 = require("./OptionType");
|
|
6
7
|
exports.cliOptions = [
|
|
7
8
|
{
|
|
8
9
|
name: 'branch-name',
|
|
9
10
|
description: 'Branch name template',
|
|
11
|
+
type: OptionType_1.OptionType.String,
|
|
10
12
|
required: false,
|
|
11
13
|
default: 'npm-update-package/{{{packageName}}}/v{{newVersion}}'
|
|
12
14
|
},
|
|
13
15
|
{
|
|
14
16
|
name: 'commit-message',
|
|
15
17
|
description: 'Commit message template',
|
|
18
|
+
type: OptionType_1.OptionType.String,
|
|
16
19
|
required: false,
|
|
17
20
|
default: 'chore(deps): {{updateType}} update {{{packageName}}} to v{{newVersion}}'
|
|
18
21
|
},
|
|
19
22
|
{
|
|
20
23
|
name: 'github-token',
|
|
21
24
|
description: 'GitHub token',
|
|
25
|
+
type: OptionType_1.OptionType.String,
|
|
22
26
|
required: true
|
|
23
27
|
},
|
|
24
28
|
{
|
|
25
29
|
name: 'log-level',
|
|
26
30
|
description: 'Log level to show',
|
|
31
|
+
type: OptionType_1.OptionType.String,
|
|
27
32
|
required: false,
|
|
28
33
|
choices: [
|
|
29
34
|
logger_1.LogLevel.Off,
|
|
@@ -36,6 +41,7 @@ exports.cliOptions = [
|
|
|
36
41
|
{
|
|
37
42
|
name: 'package-manager',
|
|
38
43
|
description: 'Package manager of your project',
|
|
44
|
+
type: OptionType_1.OptionType.String,
|
|
39
45
|
required: false,
|
|
40
46
|
choices: [
|
|
41
47
|
package_manager_1.PackageManagerName.Npm,
|
|
@@ -46,6 +52,7 @@ exports.cliOptions = [
|
|
|
46
52
|
{
|
|
47
53
|
name: 'pull-request-body',
|
|
48
54
|
description: 'Pull request body template',
|
|
55
|
+
type: OptionType_1.OptionType.String,
|
|
49
56
|
required: false,
|
|
50
57
|
default: `This PR updates these packages:
|
|
51
58
|
|
|
@@ -56,9 +63,16 @@ exports.cliOptions = [
|
|
|
56
63
|
---
|
|
57
64
|
This PR has been generated by [{{{appName}}}]({{{appWeb}}}) v{{appVersion}}`
|
|
58
65
|
},
|
|
66
|
+
{
|
|
67
|
+
name: 'pull-request-labels',
|
|
68
|
+
description: 'Pull request labels',
|
|
69
|
+
type: OptionType_1.OptionType.StringArray,
|
|
70
|
+
required: false
|
|
71
|
+
},
|
|
59
72
|
{
|
|
60
73
|
name: 'pull-request-title',
|
|
61
74
|
description: 'Pull request title template',
|
|
75
|
+
type: OptionType_1.OptionType.String,
|
|
62
76
|
required: false,
|
|
63
77
|
default: 'chore(deps): {{updateType}} update {{{packageName}}} to v{{newVersion}}'
|
|
64
78
|
}
|
|
@@ -2,16 +2,31 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toCommanderOption = void 0;
|
|
4
4
|
const commander_1 = require("commander");
|
|
5
|
+
const OptionType_1 = require("./OptionType");
|
|
5
6
|
// TODO: add test
|
|
6
7
|
const toCommanderOption = (cliOption) => {
|
|
7
|
-
const
|
|
8
|
-
option.
|
|
8
|
+
const argument = createArgumentString(cliOption);
|
|
9
|
+
const option = new commander_1.Option(`--${cliOption.name} ${argument}`, cliOption.description);
|
|
9
10
|
if (cliOption.choices !== undefined) {
|
|
10
11
|
option.choices(cliOption.choices);
|
|
11
12
|
}
|
|
12
|
-
if (!cliOption.required) {
|
|
13
|
+
if (!cliOption.required && cliOption.default !== undefined) {
|
|
13
14
|
option.default(cliOption.default);
|
|
14
15
|
}
|
|
15
16
|
return option;
|
|
16
17
|
};
|
|
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.2",
|
|
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",
|
|
@@ -36,11 +37,11 @@
|
|
|
36
37
|
"@types/node": "12.20.15",
|
|
37
38
|
"@types/parse-github-url": "1.0.0",
|
|
38
39
|
"@types/semver": "7.3.9",
|
|
39
|
-
"@typescript-eslint/eslint-plugin": "5.8.
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "5.8.1",
|
|
40
41
|
"eslint": "8.5.0",
|
|
41
42
|
"eslint-config-standard-with-typescript": "21.0.1",
|
|
42
43
|
"eslint-plugin-import": "2.25.3",
|
|
43
|
-
"eslint-plugin-jest": "25.3.
|
|
44
|
+
"eslint-plugin-jest": "25.3.2",
|
|
44
45
|
"eslint-plugin-node": "11.1.0",
|
|
45
46
|
"eslint-plugin-promise": "6.0.0",
|
|
46
47
|
"eslint-plugin-tsdoc": "0.2.14",
|