npm-update-package 0.10.0 → 0.11.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 +9 -4
- package/dist/app.js +1 -1
- package/dist/bin.js +6 -4
- package/dist/git/Git.js +7 -4
- package/dist/logger/LogLevel.js +3 -2
- package/dist/main.js +14 -3
- package/dist/options/Options.js +1 -1
- package/dist/options/initOptions.js +1 -0
- package/dist/processors/{Result.js → FailedResult.js} +0 -0
- package/dist/processors/OutdatedPackageProcessor.js +38 -23
- package/dist/processors/SucceededResult.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,6 +9,10 @@ CLI tool for creating pull request to update npm packages
|
|
|
9
9
|
|
|
10
10
|
This package is currently under development, so the major version is 0 yet.
|
|
11
11
|
|
|
12
|
+
## Requirements
|
|
13
|
+
|
|
14
|
+
- Git v2.23.0 or higher
|
|
15
|
+
|
|
12
16
|
## Installation
|
|
13
17
|
|
|
14
18
|
If you are using npm:
|
|
@@ -45,7 +49,7 @@ Template strings such as `--branch-name` can embed variables like `{{packageName
|
|
|
45
49
|
Branch name template
|
|
46
50
|
|
|
47
51
|
- value: template string
|
|
48
|
-
-
|
|
52
|
+
- variables:
|
|
49
53
|
- `currentVersion`
|
|
50
54
|
- `newVersion`
|
|
51
55
|
- `packageName`
|
|
@@ -58,7 +62,7 @@ Branch name template
|
|
|
58
62
|
Commit message template
|
|
59
63
|
|
|
60
64
|
- value: template string
|
|
61
|
-
-
|
|
65
|
+
- variables:
|
|
62
66
|
- `currentVersion`
|
|
63
67
|
- `newVersion`
|
|
64
68
|
- `packageName`
|
|
@@ -78,6 +82,7 @@ GitHub token
|
|
|
78
82
|
Log level to show
|
|
79
83
|
|
|
80
84
|
- value: string
|
|
85
|
+
- `error`
|
|
81
86
|
- `info`
|
|
82
87
|
- `debug`
|
|
83
88
|
- required: false
|
|
@@ -98,7 +103,7 @@ Package manager of your project
|
|
|
98
103
|
Pull request body template
|
|
99
104
|
|
|
100
105
|
- value: template string
|
|
101
|
-
-
|
|
106
|
+
- variables:
|
|
102
107
|
- `appName`
|
|
103
108
|
- `appVersion`
|
|
104
109
|
- `appWeb`
|
|
@@ -125,7 +130,7 @@ This PR has been generated by [{{{appName}}}]({{{appWeb}}}) v{{appVersion}}
|
|
|
125
130
|
Pull request title template
|
|
126
131
|
|
|
127
132
|
- value: template string
|
|
128
|
-
-
|
|
133
|
+
- variables:
|
|
129
134
|
- `currentVersion`
|
|
130
135
|
- `newVersion`
|
|
131
136
|
- `packageName`
|
package/dist/app.js
CHANGED
package/dist/bin.js
CHANGED
|
@@ -12,8 +12,10 @@ logger.info(`Start ${app_1.app.name} v${app_1.app.version}`);
|
|
|
12
12
|
options,
|
|
13
13
|
logger
|
|
14
14
|
})
|
|
15
|
-
.then(() =>
|
|
16
|
-
.
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
.then(() => {
|
|
16
|
+
logger.info(`End ${app_1.app.name} v${app_1.app.version}`);
|
|
17
|
+
})
|
|
18
|
+
.catch((error) => {
|
|
19
|
+
logger.fatal(error);
|
|
20
|
+
throw error;
|
|
19
21
|
});
|
package/dist/git/Git.js
CHANGED
|
@@ -10,14 +10,11 @@ class Git {
|
|
|
10
10
|
async add(...files) {
|
|
11
11
|
await this.terminal.run('git', 'add', ...files);
|
|
12
12
|
}
|
|
13
|
-
async checkout(branchName) {
|
|
14
|
-
await this.terminal.run('git', 'checkout', branchName);
|
|
15
|
-
}
|
|
16
13
|
async commit(message) {
|
|
17
14
|
await this.terminal.run('git', 'commit', '--message', message);
|
|
18
15
|
}
|
|
19
16
|
async createBranch(branchName) {
|
|
20
|
-
await this.terminal.run('git', '
|
|
17
|
+
await this.terminal.run('git', 'switch', '-c', branchName);
|
|
21
18
|
}
|
|
22
19
|
async getConfig(key) {
|
|
23
20
|
const { stdout } = await this.terminal.run('git', 'config', key);
|
|
@@ -41,8 +38,14 @@ class Git {
|
|
|
41
38
|
async removeBranch(branchName) {
|
|
42
39
|
await this.terminal.run('git', 'branch', '-D', branchName);
|
|
43
40
|
}
|
|
41
|
+
async restore(...files) {
|
|
42
|
+
await this.terminal.run('git', 'restore', '--worktree', '--staged', ...files);
|
|
43
|
+
}
|
|
44
44
|
async setConfig(key, value) {
|
|
45
45
|
await this.terminal.run('git', 'config', key, value);
|
|
46
46
|
}
|
|
47
|
+
async switch(branchName) {
|
|
48
|
+
await this.terminal.run('git', 'switch', branchName);
|
|
49
|
+
}
|
|
47
50
|
}
|
|
48
51
|
exports.Git = Git;
|
package/dist/logger/LogLevel.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isLogLevel = exports.LogLevel = void 0;
|
|
4
4
|
exports.LogLevel = {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
Debug: 'debug',
|
|
6
|
+
Error: 'error',
|
|
7
|
+
Info: 'info'
|
|
7
8
|
};
|
|
8
9
|
const logLevels = Object.values(exports.LogLevel);
|
|
9
10
|
const isLogLevel = (value) => logLevels.includes(value);
|
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 Either_1 = require("fp-ts/lib/Either");
|
|
4
5
|
const git_1 = require("./git");
|
|
5
6
|
const github_1 = require("./github");
|
|
6
7
|
const ncu_1 = require("./ncu");
|
|
@@ -75,14 +76,24 @@ const main = async ({ options, logger }) => {
|
|
|
75
76
|
});
|
|
76
77
|
const results = await outdatedPackagesProcessor.process(outdatedPackages);
|
|
77
78
|
logger.debug(`results=${JSON.stringify(results)}`);
|
|
78
|
-
const
|
|
79
|
+
const succeededResults = results.filter(Either_1.isRight).map(({ right }) => right);
|
|
80
|
+
logger.debug(`succeededResults=${JSON.stringify(succeededResults)}`);
|
|
81
|
+
const updatedPackages = succeededResults
|
|
79
82
|
.filter(({ updated }) => updated)
|
|
80
83
|
.map(({ outdatedPackage }) => outdatedPackage);
|
|
81
84
|
logger.debug(`updatedPackages=${JSON.stringify(updatedPackages)}`);
|
|
82
|
-
const skippedPackages =
|
|
85
|
+
const skippedPackages = succeededResults
|
|
83
86
|
.filter(({ skipped }) => skipped)
|
|
84
87
|
.map(({ outdatedPackage }) => outdatedPackage);
|
|
85
88
|
logger.debug(`skippedPackages=${JSON.stringify(skippedPackages)}`);
|
|
86
|
-
|
|
89
|
+
const failedResults = results.filter(Either_1.isLeft).map(({ left }) => left);
|
|
90
|
+
logger.debug(`failedResults=${JSON.stringify(failedResults)}`);
|
|
91
|
+
const failedPackages = failedResults.map(({ outdatedPackage }) => outdatedPackage);
|
|
92
|
+
logger.debug(`failedPackages=${JSON.stringify(failedPackages)}`);
|
|
93
|
+
// TODO: show as table
|
|
94
|
+
logger.info(`Processed ${succeededResults.length + failedPackages.length} packages:
|
|
95
|
+
- ${updatedPackages.length} packages has updated: ${updatedPackages.map(({ name }) => name).join(',')}
|
|
96
|
+
- ${skippedPackages.length} packages has skipped: ${skippedPackages.map(({ name }) => name).join(',')}
|
|
97
|
+
- ${failedPackages.length} packages has failed: ${failedPackages.map(({ name }) => name).join(',')}`);
|
|
87
98
|
};
|
|
88
99
|
exports.main = main;
|
package/dist/options/Options.js
CHANGED
|
@@ -8,7 +8,7 @@ const Options = (0, io_ts_1.type)({
|
|
|
8
8
|
branchName: io_ts_1.string,
|
|
9
9
|
commitMessage: io_ts_1.string,
|
|
10
10
|
githubToken: io_ts_1.string,
|
|
11
|
-
logLevel: (0, io_ts_1.union)([(0, io_ts_1.literal)(logger_1.LogLevel.Info), (0, io_ts_1.literal)(logger_1.LogLevel.Debug)]),
|
|
11
|
+
logLevel: (0, io_ts_1.union)([(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)]),
|
|
12
12
|
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)]),
|
|
13
13
|
pullRequestBody: io_ts_1.string,
|
|
14
14
|
pullRequestTitle: io_ts_1.string
|
|
@@ -15,6 +15,7 @@ const initOptions = () => {
|
|
|
15
15
|
.requiredOption('--github-token <value>', 'GitHub token')
|
|
16
16
|
.addOption(new commander_1.Option('--log-level <value>', 'Log level to show')
|
|
17
17
|
.choices([
|
|
18
|
+
logger_1.LogLevel.Error,
|
|
18
19
|
logger_1.LogLevel.Info,
|
|
19
20
|
logger_1.LogLevel.Debug
|
|
20
21
|
])
|
|
File without changes
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OutdatedPackageProcessor = void 0;
|
|
4
|
+
const Either_1 = require("fp-ts/lib/Either");
|
|
4
5
|
// TODO: add test
|
|
5
6
|
class OutdatedPackageProcessor {
|
|
6
7
|
constructor({ git, ncu, packageManager, pullRequestCreator, remoteBranchExistenceChecker, logger, branchNameCreator, commitMessageCreator }) {
|
|
@@ -21,35 +22,49 @@ class OutdatedPackageProcessor {
|
|
|
21
22
|
this.logger.debug(`branchName=${branchName}`);
|
|
22
23
|
if (this.remoteBranchExistenceChecker.check(branchName)) {
|
|
23
24
|
this.logger.info(`Skip ${outdatedPackage.name} because ${branchName} branch already exists on remote.`);
|
|
24
|
-
return {
|
|
25
|
+
return (0, Either_1.right)({
|
|
25
26
|
outdatedPackage,
|
|
26
27
|
skipped: true
|
|
27
|
-
};
|
|
28
|
+
});
|
|
28
29
|
}
|
|
29
30
|
await this.git.createBranch(branchName);
|
|
30
31
|
this.logger.info(`${branchName} branch has created.`);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
try {
|
|
33
|
+
try {
|
|
34
|
+
const updatedPackages = await this.ncu.update(outdatedPackage);
|
|
35
|
+
if (updatedPackages.length !== 1) {
|
|
36
|
+
throw new Error(`Failed to update ${outdatedPackage.name}.`);
|
|
37
|
+
}
|
|
38
|
+
await this.packageManager.install();
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
this.logger.error(error);
|
|
42
|
+
return (0, Either_1.left)({
|
|
43
|
+
outdatedPackage,
|
|
44
|
+
error
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
this.logger.info(`${outdatedPackage.name} has updated from v${outdatedPackage.currentVersion.version} to v${outdatedPackage.newVersion.version}`);
|
|
48
|
+
await this.git.add(...this.packageManager.packageFiles);
|
|
49
|
+
const message = this.commitMessageCreator.create(outdatedPackage);
|
|
50
|
+
this.logger.debug(`message=${message}`);
|
|
51
|
+
await this.git.commit(message);
|
|
52
|
+
await this.git.push(branchName);
|
|
53
|
+
await this.pullRequestCreator.create({
|
|
54
|
+
outdatedPackage,
|
|
55
|
+
branchName
|
|
56
|
+
});
|
|
57
|
+
return (0, Either_1.right)({
|
|
58
|
+
outdatedPackage,
|
|
59
|
+
updated: true
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
await this.git.restore(...this.packageManager.packageFiles);
|
|
64
|
+
await this.git.switch('-');
|
|
65
|
+
await this.git.removeBranch(branchName);
|
|
66
|
+
this.logger.info(`${branchName} branch has removed.`);
|
|
34
67
|
}
|
|
35
|
-
await this.packageManager.install();
|
|
36
|
-
this.logger.info(`${outdatedPackage.name} has updated from v${outdatedPackage.currentVersion.version} to v${outdatedPackage.newVersion.version}`);
|
|
37
|
-
await this.git.add(...this.packageManager.packageFiles);
|
|
38
|
-
const message = this.commitMessageCreator.create(outdatedPackage);
|
|
39
|
-
this.logger.debug(`message=${message}`);
|
|
40
|
-
await this.git.commit(message);
|
|
41
|
-
await this.git.push(branchName);
|
|
42
|
-
await this.pullRequestCreator.create({
|
|
43
|
-
outdatedPackage,
|
|
44
|
-
branchName
|
|
45
|
-
});
|
|
46
|
-
await this.git.checkout('-');
|
|
47
|
-
await this.git.removeBranch(branchName);
|
|
48
|
-
this.logger.info(`${branchName} branch has removed.`);
|
|
49
|
-
return {
|
|
50
|
-
outdatedPackage,
|
|
51
|
-
updated: true
|
|
52
|
-
};
|
|
53
68
|
}
|
|
54
69
|
}
|
|
55
70
|
exports.OutdatedPackageProcessor = OutdatedPackageProcessor;
|