npm-update-package 0.15.0 → 0.17.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 +13 -9
- 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/logger/LogLevel.js +2 -1
- package/dist/main.js +2 -1
- 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 -29
- package/dist/options/toCommanderOption.js +32 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,10 +5,6 @@
|
|
|
5
5
|
|
|
6
6
|
CLI tool for creating pull request to update npm packages
|
|
7
7
|
|
|
8
|
-
## Caution
|
|
9
|
-
|
|
10
|
-
This package is currently under development, so the major version is 0 yet.
|
|
11
|
-
|
|
12
8
|
## Usage
|
|
13
9
|
|
|
14
10
|
```sh
|
|
@@ -88,9 +84,10 @@ Log level to show
|
|
|
88
84
|
|
|
89
85
|
- type: string
|
|
90
86
|
- allowed values:
|
|
91
|
-
- `
|
|
92
|
-
- `
|
|
93
|
-
- `
|
|
87
|
+
- `off`: Do not output any logs.
|
|
88
|
+
- `error`: Output error logs.
|
|
89
|
+
- `info`: Output error/info logs.
|
|
90
|
+
- `debug`: Output error/info/debug logs.
|
|
94
91
|
- required: false
|
|
95
92
|
- default: `info`
|
|
96
93
|
|
|
@@ -132,6 +129,13 @@ This PR updates these packages:
|
|
|
132
129
|
This PR has been generated by [{{{appName}}}]({{{appWeb}}}) v{{appVersion}}
|
|
133
130
|
```
|
|
134
131
|
|
|
132
|
+
### `--pull-request-labels`
|
|
133
|
+
|
|
134
|
+
Pull request labels
|
|
135
|
+
|
|
136
|
+
- type: string array
|
|
137
|
+
- required: false
|
|
138
|
+
|
|
135
139
|
### `--pull-request-title`
|
|
136
140
|
|
|
137
141
|
Pull request title template
|
|
@@ -147,6 +151,6 @@ Pull request title template
|
|
|
147
151
|
|
|
148
152
|
## FAQ
|
|
149
153
|
|
|
150
|
-
### Conflicts
|
|
154
|
+
### Conflicts have occurred in PR. What should I do?
|
|
151
155
|
|
|
152
|
-
If conflicts
|
|
156
|
+
If conflicts have occurred in PR, close it and run npm-update-package again.
|
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/logger/LogLevel.js
CHANGED
|
@@ -4,7 +4,8 @@ exports.isLogLevel = exports.LogLevel = void 0;
|
|
|
4
4
|
exports.LogLevel = {
|
|
5
5
|
Debug: 'debug',
|
|
6
6
|
Error: 'error',
|
|
7
|
-
Info: 'info'
|
|
7
|
+
Info: 'info',
|
|
8
|
+
Off: 'off'
|
|
8
9
|
};
|
|
9
10
|
const logLevels = Object.values(exports.LogLevel);
|
|
10
11
|
const isLogLevel = (value) => logLevels.includes(value);
|
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);
|
|
@@ -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,38 +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.Error,
|
|
19
|
-
logger_1.LogLevel.Info,
|
|
20
|
-
logger_1.LogLevel.Debug
|
|
21
|
-
])
|
|
22
|
-
.default(logger_1.LogLevel.Info))
|
|
23
|
-
.addOption(new commander_1.Option('--package-manager <value>', 'Package manager of your project')
|
|
24
|
-
.choices([
|
|
25
|
-
package_manager_1.PackageManagerName.Npm,
|
|
26
|
-
package_manager_1.PackageManagerName.Yarn
|
|
27
|
-
])
|
|
28
|
-
.default(package_manager_1.PackageManagerName.Npm))
|
|
29
|
-
.option('--pull-request-body <value>', 'Pull request body template', `This PR updates these packages:
|
|
30
|
-
|
|
31
|
-
|package|type|current version|new version|
|
|
32
|
-
|---|---|---|---|
|
|
33
|
-
|[{{{packageName}}}](https://www.npmjs.com/package/{{{packageName}}})|{{updateType}}|\`{{currentVersion}}\`|\`{{newVersion}}\`|
|
|
34
|
-
|
|
35
|
-
---
|
|
36
|
-
This PR has been generated by [{{{appName}}}]({{{appWeb}}}) v{{appVersion}}`)
|
|
37
|
-
.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));
|
|
38
15
|
commander_1.program.parse(process.argv);
|
|
39
16
|
const options = commander_1.program.opts();
|
|
40
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
|
+
};
|