npm-update-package 0.19.2 → 0.22.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 +7 -50
- package/dist/app.js +1 -1
- package/dist/git/BranchNameCreator.js +2 -2
- package/dist/github/CreatedPullRequest.js +2 -0
- package/dist/github/GitHub.js +19 -1
- package/dist/github/PullRequestBodyCreator.js +33 -2
- package/dist/github/PullRequestCloser.js +17 -0
- package/dist/github/PullRequestCreator.js +8 -12
- package/dist/github/PullRequestFinder.js +26 -0
- package/dist/github/PullRequestMetadata.js +15 -0
- package/dist/github/extractPullRequestMetadata.js +17 -0
- package/dist/github/index.js +5 -1
- package/dist/github/isPullRequestByNpmUpdatePackage.js +7 -0
- package/dist/main.js +22 -6
- package/dist/ncu/Ncu.js +12 -12
- package/dist/options/Options.js +7 -14
- package/dist/options/cliOptions.js +0 -27
- package/dist/package-json/PackageJsonReader.js +20 -0
- package/dist/package-json/index.js +3 -1
- package/dist/package-manager/createPackageManager.js +3 -3
- package/dist/processors/OutdatedPackageProcessor.js +11 -2
- package/package.json +13 -13
- package/dist/file/index.js +0 -5
- package/dist/file/readFile.js +0 -10
package/README.md
CHANGED
|
@@ -14,20 +14,7 @@ npx npm-update-package --github-token $GITHUB_TOKEN
|
|
|
14
14
|
## Options
|
|
15
15
|
|
|
16
16
|
You can customize behavior via command-line options.
|
|
17
|
-
Template strings such as `--
|
|
18
|
-
|
|
19
|
-
### `--branch-name`
|
|
20
|
-
|
|
21
|
-
Branch name template
|
|
22
|
-
|
|
23
|
-
- type: string
|
|
24
|
-
- variables:
|
|
25
|
-
- `currentVersion`
|
|
26
|
-
- `newVersion`
|
|
27
|
-
- `packageName`
|
|
28
|
-
- `updateType`
|
|
29
|
-
- required: false
|
|
30
|
-
- default: `npm-update-package/{{{packageName}}}/v{{newVersion}}`
|
|
17
|
+
Template strings such as `--commit-message` can embed variables like `{{packageName}}`(HTML-escaped) or `{{{packageName}}}`(not HTML-escaped).
|
|
31
18
|
|
|
32
19
|
### `--commit-message`
|
|
33
20
|
|
|
@@ -73,40 +60,6 @@ Package manager of your project
|
|
|
73
60
|
- required: false
|
|
74
61
|
- default: `npm`
|
|
75
62
|
|
|
76
|
-
### `--pull-request-body`
|
|
77
|
-
|
|
78
|
-
Pull request body template
|
|
79
|
-
|
|
80
|
-
- type: string
|
|
81
|
-
- variables:
|
|
82
|
-
- `appName`
|
|
83
|
-
- `appVersion`
|
|
84
|
-
- `appWeb`
|
|
85
|
-
- `currentVersion`
|
|
86
|
-
- `newVersion`
|
|
87
|
-
- `packageName`
|
|
88
|
-
- `updateType`
|
|
89
|
-
- required: false
|
|
90
|
-
- default:
|
|
91
|
-
|
|
92
|
-
```
|
|
93
|
-
This PR updates these packages:
|
|
94
|
-
|
|
95
|
-
|package|type|current version|new version|
|
|
96
|
-
|---|---|---|---|
|
|
97
|
-
|[{{{packageName}}}](https://www.npmjs.com/package/{{{packageName}}})|{{updateType}}|\`{{currentVersion}}\`|\`{{newVersion}}\`|
|
|
98
|
-
|
|
99
|
-
---
|
|
100
|
-
This PR has been generated by [{{{appName}}}]({{{appWeb}}}) v{{appVersion}}
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
### `--pull-request-labels`
|
|
104
|
-
|
|
105
|
-
Pull request labels
|
|
106
|
-
|
|
107
|
-
- type: string array
|
|
108
|
-
- required: false
|
|
109
|
-
|
|
110
63
|
### `--pull-request-title`
|
|
111
64
|
|
|
112
65
|
Pull request title template
|
|
@@ -153,8 +106,6 @@ Actual working examples can be seen in these repositories.
|
|
|
153
106
|
|
|
154
107
|
The following shows the process flow of npm-update-package:
|
|
155
108
|
|
|
156
|
-
[](http://www.plantuml.com/plantuml/uml/RKyxKiCm5EpVARPqYbmWRi9Gq4666GuWx4tiGPQ4z0JXzaIn70D38wsUzkrddzH4pPELAv1Jz3bWCgEJtGCLFcjlb3s2wTxCYQaL6OzexgozZM0YaSDM_RPmDz213iqNqqO0kbve4z4ulv7BQpnAjNcgueSgT8Y-Oqe-IcIWKG7-9Quye8HvvkILU8t6TGDu7fEcFodM102mkuyqjursdhs4uh6qQdyHGxOMaU-PIUjFCVtuAN6jDjzpxDe2dyDeYUQHPrtKbv2oabTOaEmlHvxiDm00)
|
|
157
|
-
|
|
158
109
|
<!--
|
|
159
110
|
```plantuml
|
|
160
111
|
@startuml
|
|
@@ -167,6 +118,9 @@ if (All packages are up-to-date) then (yes)
|
|
|
167
118
|
else (no)
|
|
168
119
|
endif
|
|
169
120
|
|
|
121
|
+
:Get remote branches;
|
|
122
|
+
:Get pull requests;
|
|
123
|
+
|
|
170
124
|
group OutdatedPackagesProcessor
|
|
171
125
|
repeat
|
|
172
126
|
group OutdatedPackageProcessor
|
|
@@ -175,6 +129,7 @@ repeat
|
|
|
175
129
|
:Create branch;
|
|
176
130
|
:Update package;
|
|
177
131
|
:Create pull request;
|
|
132
|
+
:Close old pull requests;
|
|
178
133
|
:Remove branch;
|
|
179
134
|
endif
|
|
180
135
|
end group
|
|
@@ -187,6 +142,8 @@ end
|
|
|
187
142
|
```
|
|
188
143
|
-->
|
|
189
144
|
|
|
145
|
+
[](http://www.plantuml.com/plantuml/uml/RL0nKiCm4Epl5LlQHJuGDs4ew23330yGzYRs85j2Ea7uFNPanoP38vtsLhUxTuXgWgRUohMGSt39epVT8FidAbpInYWRU5D_c3DZ9TATK3nOUuDW0f7yJjrkufRGbWEA7yPI00wDq4QY65mfuwixIPuTs3ibteCPwdQSd56Vh4NWPsBK4PiTlSm-ZhFcCRYQCReWWPv61VYNkFA0oVVhLXEyTAF8dU7LB03i7mFDxKULiJS_QImBgBR4F_wNZdMHSBQv2vUxawMlhS1rH_dEeUQC-6uxInJFlEYYlKIGbRoMKoM7yKYz_GK0)
|
|
146
|
+
|
|
190
147
|
## FAQ
|
|
191
148
|
|
|
192
149
|
### What is the purpose of npm-update-package?
|
package/dist/app.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BranchNameCreator = void 0;
|
|
4
4
|
const mustache_1 = require("mustache");
|
|
5
5
|
class BranchNameCreator {
|
|
6
|
-
constructor(
|
|
7
|
-
this.template =
|
|
6
|
+
constructor() {
|
|
7
|
+
this.template = 'npm-update-package/{{{packageName}}}/v{{newVersion}}';
|
|
8
8
|
}
|
|
9
9
|
create(outdatedPackage) {
|
|
10
10
|
const packageName = outdatedPackage.name;
|
package/dist/github/GitHub.js
CHANGED
|
@@ -10,12 +10,30 @@ class GitHub {
|
|
|
10
10
|
const { data } = await this.octokit.issues.addLabels(params);
|
|
11
11
|
return data;
|
|
12
12
|
}
|
|
13
|
+
async closePullRequest(params) {
|
|
14
|
+
await this.octokit.pulls.update({
|
|
15
|
+
...params,
|
|
16
|
+
state: 'closed'
|
|
17
|
+
});
|
|
18
|
+
}
|
|
13
19
|
async createPullRequest(params) {
|
|
14
20
|
const { data } = await this.octokit.pulls.create(params);
|
|
15
21
|
return data;
|
|
16
22
|
}
|
|
23
|
+
// TODO: fetch all branches with page option
|
|
17
24
|
async fetchBranches(params) {
|
|
18
|
-
const { data } = await this.octokit.repos.listBranches(
|
|
25
|
+
const { data } = await this.octokit.repos.listBranches({
|
|
26
|
+
...params,
|
|
27
|
+
per_page: 100
|
|
28
|
+
});
|
|
29
|
+
return data;
|
|
30
|
+
}
|
|
31
|
+
// TODO: fetch all pull requests with page option
|
|
32
|
+
async fetchPullRequests(params) {
|
|
33
|
+
const { data } = await this.octokit.pulls.list({
|
|
34
|
+
...params,
|
|
35
|
+
per_page: 100
|
|
36
|
+
});
|
|
19
37
|
return data;
|
|
20
38
|
}
|
|
21
39
|
async fetchRepository(params) {
|
|
@@ -4,8 +4,39 @@ exports.PullRequestBodyCreator = void 0;
|
|
|
4
4
|
const mustache_1 = require("mustache");
|
|
5
5
|
const app_1 = require("../app");
|
|
6
6
|
class PullRequestBodyCreator {
|
|
7
|
-
constructor(
|
|
8
|
-
this.template =
|
|
7
|
+
constructor() {
|
|
8
|
+
this.template = `This PR updates these packages:
|
|
9
|
+
|
|
10
|
+
|package|type|current version|new version|
|
|
11
|
+
|---|---|---|---|
|
|
12
|
+
|[{{{packageName}}}](https://www.npmjs.com/package/{{{packageName}}})|{{updateType}}|\`{{currentVersion}}\`|\`{{newVersion}}\`|
|
|
13
|
+
|
|
14
|
+
<details>
|
|
15
|
+
<summary>Metadata</summary>
|
|
16
|
+
|
|
17
|
+
**Don't remove or edit this section because it will be used by npm-update-package.**
|
|
18
|
+
|
|
19
|
+
<div id="npm-update-package-metadata">
|
|
20
|
+
|
|
21
|
+
\`\`\`json
|
|
22
|
+
{
|
|
23
|
+
"version": "{{appVersion}}",
|
|
24
|
+
"packages": [
|
|
25
|
+
{
|
|
26
|
+
"name": "{{{packageName}}}",
|
|
27
|
+
"type": "{{updateType}}",
|
|
28
|
+
"currentVersion": "{{currentVersion}}",
|
|
29
|
+
"newVersion": "{{newVersion}}"
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
\`\`\`
|
|
34
|
+
|
|
35
|
+
</div>
|
|
36
|
+
</details>
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
This PR has been generated by [{{{appName}}}]({{{appWeb}}}) v{{appVersion}}`;
|
|
9
40
|
}
|
|
10
41
|
create(outdatedPackage) {
|
|
11
42
|
const appName = app_1.app.name;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PullRequestCloser = void 0;
|
|
4
|
+
// TODO: Add test
|
|
5
|
+
class PullRequestCloser {
|
|
6
|
+
constructor(github) {
|
|
7
|
+
this.github = github;
|
|
8
|
+
}
|
|
9
|
+
async close(pullRequest) {
|
|
10
|
+
await this.github.closePullRequest({
|
|
11
|
+
owner: pullRequest.base.repo.owner.login,
|
|
12
|
+
repo: pullRequest.base.repo.name,
|
|
13
|
+
pull_number: pullRequest.number
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.PullRequestCloser = PullRequestCloser;
|
|
@@ -2,14 +2,13 @@
|
|
|
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 }) {
|
|
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;
|
|
13
12
|
}
|
|
14
13
|
async create({ outdatedPackage, branchName }) {
|
|
15
14
|
const title = this.pullRequestTitleCreator.create(outdatedPackage);
|
|
@@ -25,16 +24,13 @@ class PullRequestCreator {
|
|
|
25
24
|
body
|
|
26
25
|
});
|
|
27
26
|
this.logger.debug(`pullRequest=${JSON.stringify(pullRequest)}`);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
this.logger.debug(`labels=${JSON.stringify(labels)}`);
|
|
36
|
-
}
|
|
37
|
-
this.logger.info(`Pull request for ${outdatedPackage.name} has created. ${pullRequest.html_url}`);
|
|
27
|
+
await this.github.addLabels({
|
|
28
|
+
owner: this.gitRepo.owner,
|
|
29
|
+
repo: this.gitRepo.name,
|
|
30
|
+
issue_number: pullRequest.number,
|
|
31
|
+
labels: ['npm-update-package']
|
|
32
|
+
});
|
|
33
|
+
return pullRequest;
|
|
38
34
|
}
|
|
39
35
|
}
|
|
40
36
|
exports.PullRequestCreator = PullRequestCreator;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PullRequestFinder = void 0;
|
|
4
|
+
const extractPullRequestMetadata_1 = require("./extractPullRequestMetadata");
|
|
5
|
+
const isPullRequestByNpmUpdatePackage_1 = require("./isPullRequestByNpmUpdatePackage");
|
|
6
|
+
// TODO: Add test
|
|
7
|
+
class PullRequestFinder {
|
|
8
|
+
constructor(pullRequests) {
|
|
9
|
+
this.pullRequests = pullRequests;
|
|
10
|
+
}
|
|
11
|
+
findByPackageName(packageName) {
|
|
12
|
+
return this.pullRequests
|
|
13
|
+
.filter(isPullRequestByNpmUpdatePackage_1.isPullRequestByNpmUpdatePackage)
|
|
14
|
+
.filter(({ body }) => {
|
|
15
|
+
if (body === null) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
const metadata = (0, extractPullRequestMetadata_1.extractPullRequestMetadata)(body);
|
|
19
|
+
if (metadata === undefined) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return metadata.packages.some(({ name }) => name === packageName);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.PullRequestFinder = PullRequestFinder;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPullRequestMetadata = void 0;
|
|
4
|
+
const io_ts_1 = require("io-ts");
|
|
5
|
+
const ncu_1 = require("../ncu");
|
|
6
|
+
const PullRequestMetadata = (0, io_ts_1.type)({
|
|
7
|
+
version: io_ts_1.string,
|
|
8
|
+
packages: (0, io_ts_1.array)((0, io_ts_1.type)({
|
|
9
|
+
name: io_ts_1.string,
|
|
10
|
+
currentVersion: io_ts_1.string,
|
|
11
|
+
newVersion: io_ts_1.string,
|
|
12
|
+
type: (0, io_ts_1.union)([(0, io_ts_1.literal)(ncu_1.UpdateType.Major), (0, io_ts_1.literal)(ncu_1.UpdateType.Minor), (0, io_ts_1.literal)(ncu_1.UpdateType.Patch)])
|
|
13
|
+
}))
|
|
14
|
+
});
|
|
15
|
+
exports.isPullRequestMetadata = PullRequestMetadata.is;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractPullRequestMetadata = void 0;
|
|
4
|
+
const PullRequestMetadata_1 = require("./PullRequestMetadata");
|
|
5
|
+
const extractPullRequestMetadata = (pullRequestBody) => {
|
|
6
|
+
const matched = pullRequestBody.match(/<div id="npm-update-package-metadata">\s*```json\s*([\s\S]+?)\s*```\s*<\/div>/);
|
|
7
|
+
const json = matched === null || matched === void 0 ? void 0 : matched[1];
|
|
8
|
+
if (json === undefined) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
const metadata = JSON.parse(json);
|
|
12
|
+
if (!(0, PullRequestMetadata_1.isPullRequestMetadata)(metadata)) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
return metadata;
|
|
16
|
+
};
|
|
17
|
+
exports.extractPullRequestMetadata = extractPullRequestMetadata;
|
package/dist/github/index.js
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RemoteBranchExistenceChecker = exports.PullRequestTitleCreator = exports.PullRequestCreator = exports.PullRequestBodyCreator = exports.GitHub = exports.createGitHub = void 0;
|
|
3
|
+
exports.RemoteBranchExistenceChecker = exports.PullRequestTitleCreator = exports.PullRequestFinder = exports.PullRequestCreator = exports.PullRequestBodyCreator = exports.PullRequestCloser = exports.GitHub = exports.createGitHub = void 0;
|
|
4
4
|
var createGitHub_1 = require("./createGitHub");
|
|
5
5
|
Object.defineProperty(exports, "createGitHub", { enumerable: true, get: function () { return createGitHub_1.createGitHub; } });
|
|
6
6
|
var GitHub_1 = require("./GitHub");
|
|
7
7
|
Object.defineProperty(exports, "GitHub", { enumerable: true, get: function () { return GitHub_1.GitHub; } });
|
|
8
|
+
var PullRequestCloser_1 = require("./PullRequestCloser");
|
|
9
|
+
Object.defineProperty(exports, "PullRequestCloser", { enumerable: true, get: function () { return PullRequestCloser_1.PullRequestCloser; } });
|
|
8
10
|
var PullRequestBodyCreator_1 = require("./PullRequestBodyCreator");
|
|
9
11
|
Object.defineProperty(exports, "PullRequestBodyCreator", { enumerable: true, get: function () { return PullRequestBodyCreator_1.PullRequestBodyCreator; } });
|
|
10
12
|
var PullRequestCreator_1 = require("./PullRequestCreator");
|
|
11
13
|
Object.defineProperty(exports, "PullRequestCreator", { enumerable: true, get: function () { return PullRequestCreator_1.PullRequestCreator; } });
|
|
14
|
+
var PullRequestFinder_1 = require("./PullRequestFinder");
|
|
15
|
+
Object.defineProperty(exports, "PullRequestFinder", { enumerable: true, get: function () { return PullRequestFinder_1.PullRequestFinder; } });
|
|
12
16
|
var PullRequestTitleCreator_1 = require("./PullRequestTitleCreator");
|
|
13
17
|
Object.defineProperty(exports, "PullRequestTitleCreator", { enumerable: true, get: function () { return PullRequestTitleCreator_1.PullRequestTitleCreator; } });
|
|
14
18
|
var RemoteBranchExistenceChecker_1 = require("./RemoteBranchExistenceChecker");
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPullRequestByNpmUpdatePackage = void 0;
|
|
4
|
+
const isPullRequestByNpmUpdatePackage = (pullRequest) => {
|
|
5
|
+
return pullRequest.labels.some(({ name }) => name === 'npm-update-package');
|
|
6
|
+
};
|
|
7
|
+
exports.isPullRequestByNpmUpdatePackage = isPullRequestByNpmUpdatePackage;
|
package/dist/main.js
CHANGED
|
@@ -6,6 +6,7 @@ const git_1 = require("./git");
|
|
|
6
6
|
const github_1 = require("./github");
|
|
7
7
|
const ncu_1 = require("./ncu");
|
|
8
8
|
const package_json_1 = require("./package-json");
|
|
9
|
+
const PackageJsonReader_1 = require("./package-json/PackageJsonReader");
|
|
9
10
|
const package_manager_1 = require("./package-manager");
|
|
10
11
|
const processors_1 = require("./processors");
|
|
11
12
|
const terminal_1 = require("./terminal");
|
|
@@ -16,7 +17,14 @@ const main = async ({ options, logger }) => {
|
|
|
16
17
|
githubToken: options.githubToken !== '' ? '***' : ''
|
|
17
18
|
})}`);
|
|
18
19
|
const packageJsonParser = new package_json_1.PackageJsonParser(logger);
|
|
19
|
-
const
|
|
20
|
+
const packageJsonReader = new PackageJsonReader_1.PackageJsonReader({
|
|
21
|
+
packageJsonParser,
|
|
22
|
+
logger
|
|
23
|
+
});
|
|
24
|
+
const ncu = new ncu_1.Ncu({
|
|
25
|
+
packageJsonReader,
|
|
26
|
+
logger
|
|
27
|
+
});
|
|
20
28
|
const outdatedPackages = await ncu.check();
|
|
21
29
|
logger.debug(`outdatedPackages=${JSON.stringify(outdatedPackages)}`);
|
|
22
30
|
if (outdatedPackages.length === 0) {
|
|
@@ -42,24 +50,30 @@ const main = async ({ options, logger }) => {
|
|
|
42
50
|
repo: gitRepo.name
|
|
43
51
|
});
|
|
44
52
|
logger.debug(`remoteBranches=${JSON.stringify(remoteBranches)}`);
|
|
53
|
+
const pullRequests = await github.fetchPullRequests({
|
|
54
|
+
owner: gitRepo.owner,
|
|
55
|
+
repo: gitRepo.name
|
|
56
|
+
});
|
|
57
|
+
logger.debug(`pullRequests=${JSON.stringify(pullRequests)}`);
|
|
45
58
|
const remoteBranchExistenceChecker = github_1.RemoteBranchExistenceChecker.of(remoteBranches);
|
|
46
59
|
const packageManager = (0, package_manager_1.createPackageManager)({
|
|
47
60
|
terminal,
|
|
48
61
|
packageManager: options.packageManager
|
|
49
62
|
});
|
|
50
63
|
const pullRequestTitleCreator = new github_1.PullRequestTitleCreator(options.pullRequestTitle);
|
|
51
|
-
const pullRequestBodyCreator = new github_1.PullRequestBodyCreator(
|
|
64
|
+
const pullRequestBodyCreator = new github_1.PullRequestBodyCreator();
|
|
52
65
|
const pullRequestCreator = new github_1.PullRequestCreator({
|
|
53
66
|
github,
|
|
54
67
|
gitRepo,
|
|
55
68
|
githubRepo,
|
|
56
69
|
pullRequestTitleCreator,
|
|
57
70
|
pullRequestBodyCreator,
|
|
58
|
-
logger
|
|
59
|
-
labels: options.pullRequestLabels
|
|
71
|
+
logger
|
|
60
72
|
});
|
|
61
|
-
const branchNameCreator = new git_1.BranchNameCreator(
|
|
73
|
+
const branchNameCreator = new git_1.BranchNameCreator();
|
|
62
74
|
const commitMessageCreator = new git_1.CommitMessageCreator(options.commitMessage);
|
|
75
|
+
const pullRequestFinder = new github_1.PullRequestFinder(pullRequests);
|
|
76
|
+
const pullRequestCloser = new github_1.PullRequestCloser(github);
|
|
63
77
|
const outdatedPackageProcessor = new processors_1.OutdatedPackageProcessor({
|
|
64
78
|
git,
|
|
65
79
|
ncu,
|
|
@@ -68,7 +82,9 @@ const main = async ({ options, logger }) => {
|
|
|
68
82
|
remoteBranchExistenceChecker,
|
|
69
83
|
logger,
|
|
70
84
|
branchNameCreator,
|
|
71
|
-
commitMessageCreator
|
|
85
|
+
commitMessageCreator,
|
|
86
|
+
pullRequestFinder,
|
|
87
|
+
pullRequestCloser
|
|
72
88
|
});
|
|
73
89
|
const outdatedPackagesProcessor = new processors_1.OutdatedPackagesProcessor({
|
|
74
90
|
outdatedPackageProcessor,
|
package/dist/ncu/Ncu.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Ncu = void 0;
|
|
4
4
|
const npm_check_updates_1 = require("npm-check-updates");
|
|
5
|
-
const file_1 = require("../file");
|
|
6
5
|
const NcuResult_1 = require("./NcuResult");
|
|
7
6
|
const NcuResultConverter_1 = require("./NcuResultConverter");
|
|
8
7
|
// TODO: add test
|
|
9
8
|
class Ncu {
|
|
10
|
-
constructor(
|
|
11
|
-
this.
|
|
9
|
+
constructor({ packageJsonReader, logger }) {
|
|
10
|
+
this.packageJsonReader = packageJsonReader;
|
|
11
|
+
this.logger = logger;
|
|
12
12
|
}
|
|
13
13
|
async check() {
|
|
14
14
|
return await this.run({
|
|
@@ -23,19 +23,19 @@ class Ncu {
|
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
async run(options) {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
const currentDependencies = {
|
|
29
|
-
...pkg.dependencies,
|
|
30
|
-
...pkg.devDependencies,
|
|
31
|
-
...pkg.peerDependencies,
|
|
32
|
-
...pkg.optionalDependencies
|
|
33
|
-
};
|
|
26
|
+
const pkg = await this.packageJsonReader.read();
|
|
27
|
+
this.logger.debug(`pkg=${JSON.stringify(pkg)}`);
|
|
34
28
|
const result = await (0, npm_check_updates_1.run)(options);
|
|
29
|
+
this.logger.debug(`result=${JSON.stringify(result)}`);
|
|
35
30
|
if (!(0, NcuResult_1.isNcuResult)(result)) {
|
|
36
31
|
throw new Error('result is not NcuResult');
|
|
37
32
|
}
|
|
38
|
-
const ncuResultConverter = new NcuResultConverter_1.NcuResultConverter(
|
|
33
|
+
const ncuResultConverter = new NcuResultConverter_1.NcuResultConverter({
|
|
34
|
+
...pkg.dependencies,
|
|
35
|
+
...pkg.devDependencies,
|
|
36
|
+
...pkg.peerDependencies,
|
|
37
|
+
...pkg.optionalDependencies
|
|
38
|
+
});
|
|
39
39
|
return ncuResultConverter.toOutdatedPackages(result);
|
|
40
40
|
}
|
|
41
41
|
}
|
package/dist/options/Options.js
CHANGED
|
@@ -4,18 +4,11 @@ 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
|
-
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
|
-
]);
|
|
7
|
+
const Options = (0, io_ts_1.type)({
|
|
8
|
+
commitMessage: io_ts_1.string,
|
|
9
|
+
githubToken: io_ts_1.string,
|
|
10
|
+
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)]),
|
|
11
|
+
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)]),
|
|
12
|
+
pullRequestTitle: io_ts_1.string
|
|
13
|
+
});
|
|
21
14
|
exports.isOptions = Options.is;
|
|
@@ -5,13 +5,6 @@ const logger_1 = require("../logger");
|
|
|
5
5
|
const package_manager_1 = require("../package-manager");
|
|
6
6
|
const OptionType_1 = require("./OptionType");
|
|
7
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
8
|
{
|
|
16
9
|
name: 'commit-message',
|
|
17
10
|
description: 'Commit message template',
|
|
@@ -49,26 +42,6 @@ exports.cliOptions = [
|
|
|
49
42
|
],
|
|
50
43
|
default: package_manager_1.PackageManagerName.Npm
|
|
51
44
|
},
|
|
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
45
|
{
|
|
73
46
|
name: 'pull-request-title',
|
|
74
47
|
description: 'Pull request title template',
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PackageJsonReader = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
// TODO: add test
|
|
9
|
+
class PackageJsonReader {
|
|
10
|
+
constructor({ packageJsonParser, logger }) {
|
|
11
|
+
this.packageJsonParser = packageJsonParser;
|
|
12
|
+
this.logger = logger;
|
|
13
|
+
}
|
|
14
|
+
async read() {
|
|
15
|
+
const json = await fs_1.default.promises.readFile('./package.json', 'utf8');
|
|
16
|
+
this.logger.debug(`json=${json}`);
|
|
17
|
+
return this.packageJsonParser.parse(json);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.PackageJsonReader = PackageJsonReader;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PackageJsonParser = void 0;
|
|
3
|
+
exports.PackageJsonReader = exports.PackageJsonParser = void 0;
|
|
4
4
|
var PackageJsonParser_1 = require("./PackageJsonParser");
|
|
5
5
|
Object.defineProperty(exports, "PackageJsonParser", { enumerable: true, get: function () { return PackageJsonParser_1.PackageJsonParser; } });
|
|
6
|
+
var PackageJsonReader_1 = require("./PackageJsonReader");
|
|
7
|
+
Object.defineProperty(exports, "PackageJsonReader", { enumerable: true, get: function () { return PackageJsonReader_1.PackageJsonReader; } });
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createPackageManager = void 0;
|
|
4
4
|
const Npm_1 = require("./Npm");
|
|
5
|
+
const PackageManagerName_1 = require("./PackageManagerName");
|
|
5
6
|
const Yarn_1 = require("./Yarn");
|
|
6
|
-
// TODO: add test
|
|
7
7
|
const createPackageManager = ({ terminal, packageManager }) => {
|
|
8
8
|
switch (packageManager) {
|
|
9
|
-
case
|
|
9
|
+
case PackageManagerName_1.PackageManagerName.Npm:
|
|
10
10
|
return new Npm_1.Npm(terminal);
|
|
11
|
-
case
|
|
11
|
+
case PackageManagerName_1.PackageManagerName.Yarn:
|
|
12
12
|
return new Yarn_1.Yarn(terminal);
|
|
13
13
|
}
|
|
14
14
|
};
|
|
@@ -4,7 +4,7 @@ exports.OutdatedPackageProcessor = void 0;
|
|
|
4
4
|
const Either_1 = require("fp-ts/lib/Either");
|
|
5
5
|
// TODO: add test
|
|
6
6
|
class OutdatedPackageProcessor {
|
|
7
|
-
constructor({ git, ncu, packageManager, pullRequestCreator, remoteBranchExistenceChecker, logger, branchNameCreator, commitMessageCreator }) {
|
|
7
|
+
constructor({ git, ncu, packageManager, pullRequestCreator, remoteBranchExistenceChecker, logger, branchNameCreator, commitMessageCreator, pullRequestFinder, pullRequestCloser }) {
|
|
8
8
|
this.git = git;
|
|
9
9
|
this.ncu = ncu;
|
|
10
10
|
this.packageManager = packageManager;
|
|
@@ -13,6 +13,8 @@ class OutdatedPackageProcessor {
|
|
|
13
13
|
this.logger = logger;
|
|
14
14
|
this.branchNameCreator = branchNameCreator;
|
|
15
15
|
this.commitMessageCreator = commitMessageCreator;
|
|
16
|
+
this.pullRequestFinder = pullRequestFinder;
|
|
17
|
+
this.pullRequestCloser = pullRequestCloser;
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
18
20
|
* Don't run in parallel because it includes file operations.
|
|
@@ -50,10 +52,17 @@ class OutdatedPackageProcessor {
|
|
|
50
52
|
this.logger.debug(`message=${message}`);
|
|
51
53
|
await this.git.commit(message);
|
|
52
54
|
await this.git.push(branchName);
|
|
53
|
-
await this.pullRequestCreator.create({
|
|
55
|
+
const pullRequest = await this.pullRequestCreator.create({
|
|
54
56
|
outdatedPackage,
|
|
55
57
|
branchName
|
|
56
58
|
});
|
|
59
|
+
this.logger.info(`Pull request for ${outdatedPackage.name} has created. ${pullRequest.html_url}`);
|
|
60
|
+
const pullRequests = this.pullRequestFinder.findByPackageName(outdatedPackage.name);
|
|
61
|
+
this.logger.debug(`pullRequests=${JSON.stringify(pullRequests)}`);
|
|
62
|
+
await Promise.all(pullRequests.map(async (pullRequest) => {
|
|
63
|
+
await this.pullRequestCloser.close(pullRequest);
|
|
64
|
+
this.logger.info(`Pull request for ${outdatedPackage.name} has closed. ${pullRequest.html_url}`);
|
|
65
|
+
}));
|
|
57
66
|
return (0, Either_1.right)({
|
|
58
67
|
outdatedPackage,
|
|
59
68
|
updated: true
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-update-package",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.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",
|
|
@@ -20,34 +20,34 @@
|
|
|
20
20
|
"@octokit/rest": "18.12.0",
|
|
21
21
|
"commander": "8.3.0",
|
|
22
22
|
"execa": "5.1.1",
|
|
23
|
-
"fp-ts": "2.11.
|
|
23
|
+
"fp-ts": "2.11.6",
|
|
24
24
|
"io-ts": "2.2.16",
|
|
25
25
|
"log4js": "6.3.0",
|
|
26
26
|
"mustache": "4.1.0",
|
|
27
|
-
"npm-check-updates": "12.0
|
|
27
|
+
"npm-check-updates": "12.1.0",
|
|
28
28
|
"parse-github-url": "1.0.2",
|
|
29
29
|
"semver": "7.3.5",
|
|
30
30
|
"type-guards": "0.15.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@jest/types": "27.
|
|
34
|
-
"@tsconfig/
|
|
35
|
-
"@types/jest": "27.0
|
|
33
|
+
"@jest/types": "27.4.2",
|
|
34
|
+
"@tsconfig/node12": "1.0.9",
|
|
35
|
+
"@types/jest": "27.4.0",
|
|
36
36
|
"@types/mustache": "4.1.2",
|
|
37
|
-
"@types/node": "
|
|
37
|
+
"@types/node": "12.20.40",
|
|
38
38
|
"@types/parse-github-url": "1.0.0",
|
|
39
39
|
"@types/semver": "7.3.9",
|
|
40
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
41
|
-
"eslint": "8.
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "5.9.0",
|
|
41
|
+
"eslint": "8.6.0",
|
|
42
42
|
"eslint-config-standard-with-typescript": "21.0.1",
|
|
43
|
-
"eslint-plugin-import": "2.25.
|
|
44
|
-
"eslint-plugin-jest": "25.3.
|
|
43
|
+
"eslint-plugin-import": "2.25.4",
|
|
44
|
+
"eslint-plugin-jest": "25.3.4",
|
|
45
45
|
"eslint-plugin-node": "11.1.0",
|
|
46
46
|
"eslint-plugin-promise": "6.0.0",
|
|
47
47
|
"eslint-plugin-tsdoc": "0.2.14",
|
|
48
48
|
"husky": "7.0.4",
|
|
49
|
-
"jest": "27.
|
|
50
|
-
"lint-staged": "12.1.
|
|
49
|
+
"jest": "27.4.7",
|
|
50
|
+
"lint-staged": "12.1.7",
|
|
51
51
|
"npm-run-all": "4.1.5",
|
|
52
52
|
"rimraf": "3.0.2",
|
|
53
53
|
"ts-jest": "27.1.2",
|
package/dist/file/index.js
DELETED
package/dist/file/readFile.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readFile = void 0;
|
|
4
|
-
const promises_1 = require("fs/promises");
|
|
5
|
-
// TODO: add test
|
|
6
|
-
const readFile = async (path) => {
|
|
7
|
-
const data = await (0, promises_1.readFile)(path, 'utf8');
|
|
8
|
-
return data;
|
|
9
|
-
};
|
|
10
|
-
exports.readFile = readFile;
|