npm-update-package 0.1.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/.eslintignore +3 -0
- package/.eslintrc.js +23 -0
- package/.github/renovate.json +15 -0
- package/.github/workflows/eslint.yml +14 -0
- package/.github/workflows/test.yml +19 -0
- package/.husky/pre-commit +4 -0
- package/.nvmrc +1 -0
- package/LICENSE +22 -0
- package/README.md +43 -0
- package/dist/app.js +8 -0
- package/dist/bin.js +18 -0
- package/dist/enums/LogLevel.js +10 -0
- package/dist/enums/PackageManagerName.js +10 -0
- package/dist/enums/UpdateType.js +11 -0
- package/dist/enums/index.js +12 -0
- package/dist/git/Committer.js +31 -0
- package/dist/git/Git.js +48 -0
- package/dist/git/GitRepository.js +41 -0
- package/dist/git/index.js +7 -0
- package/dist/github/Branch.js +2 -0
- package/dist/github/GitHub.js +22 -0
- package/dist/github/PullRequest.js +2 -0
- package/dist/github/PullRequestCreator.js +31 -0
- package/dist/github/RemoteBranchExistenceChecker.js +17 -0
- package/dist/github/Repository.js +2 -0
- package/dist/github/createGitHub.js +14 -0
- package/dist/github/createOctokit.js +24 -0
- package/dist/github/createPullRequestBody.js +19 -0
- package/dist/github/createPullRequestTitle.js +10 -0
- package/dist/github/index.js +11 -0
- package/dist/logger/Logger.js +2 -0
- package/dist/logger/createLogger.js +11 -0
- package/dist/logger/index.js +5 -0
- package/dist/main.js +83 -0
- package/dist/ncu/Ncu.js +38 -0
- package/dist/ncu/NcuOutdatedPackages.js +2 -0
- package/dist/ncu/NcuOutdatedPackagesConverter.js +26 -0
- package/dist/ncu/index.js +5 -0
- package/dist/ncu/isNcuOutdatedPackages.js +8 -0
- package/dist/ncu/toUpdateType.js +17 -0
- package/dist/options/Options.js +16 -0
- package/dist/options/index.js +5 -0
- package/dist/options/initOptions.js +27 -0
- package/dist/outdated-package-processor/OutdatedPackageProcessor.js +56 -0
- package/dist/outdated-package-processor/createBranchName.js +9 -0
- package/dist/outdated-package-processor/createCommitMessage.js +10 -0
- package/dist/outdated-package-processor/index.js +5 -0
- package/dist/outdated-packages-processor/OutdatedPackagesProcessor.js +19 -0
- package/dist/outdated-packages-processor/index.js +5 -0
- package/dist/package-manager/Npm.js +20 -0
- package/dist/package-manager/PackageManager.js +2 -0
- package/dist/package-manager/Yarn.js +20 -0
- package/dist/package-manager/createPackageManager.js +15 -0
- package/dist/package-manager/index.js +9 -0
- package/dist/read-package-json/Package.js +18 -0
- package/dist/read-package-json/PackageDependencies.js +6 -0
- package/dist/read-package-json/index.js +5 -0
- package/dist/read-package-json/parsePackageJson.js +15 -0
- package/dist/read-package-json/readFile.js +12 -0
- package/dist/read-package-json/readPackageJson.js +11 -0
- package/dist/terminal/Terminal.js +29 -0
- package/dist/terminal/index.js +5 -0
- package/dist/terminal/isExecaReturnValue.js +24 -0
- package/dist/types/OutdatedPackage.js +2 -0
- package/dist/types/Result.js +2 -0
- package/dist/types/index.js +2 -0
- package/dist/values/PackageVersion.js +25 -0
- package/dist/values/index.js +5 -0
- package/jest.config.ts +11 -0
- package/lint-staged.config.js +4 -0
- package/package.json +59 -0
- package/src/app.ts +5 -0
- package/src/bin.ts +19 -0
- package/src/enums/LogLevel.ts +8 -0
- package/src/enums/PackageManagerName.ts +8 -0
- package/src/enums/UpdateType.ts +9 -0
- package/src/enums/index.ts +12 -0
- package/src/git/Committer.ts +49 -0
- package/src/git/Git.ts +55 -0
- package/src/git/GitRepository.test.ts +61 -0
- package/src/git/GitRepository.ts +57 -0
- package/src/git/index.ts +3 -0
- package/src/github/Branch.ts +4 -0
- package/src/github/GitHub.ts +27 -0
- package/src/github/PullRequest.ts +3 -0
- package/src/github/PullRequestCreator.ts +57 -0
- package/src/github/RemoteBranchExistenceChecker.ts +15 -0
- package/src/github/Repository.ts +3 -0
- package/src/github/createGitHub.ts +18 -0
- package/src/github/createOctokit.ts +28 -0
- package/src/github/createPullRequestBody.test.ts +62 -0
- package/src/github/createPullRequestBody.ts +17 -0
- package/src/github/createPullRequestTitle.test.ts +43 -0
- package/src/github/createPullRequestTitle.ts +8 -0
- package/src/github/index.ts +7 -0
- package/src/logger/Logger.ts +1 -0
- package/src/logger/createLogger.ts +10 -0
- package/src/logger/index.ts +2 -0
- package/src/main.ts +105 -0
- package/src/ncu/Ncu.ts +41 -0
- package/src/ncu/NcuOutdatedPackages.ts +6 -0
- package/src/ncu/NcuOutdatedPackagesConverter.ts +25 -0
- package/src/ncu/index.ts +1 -0
- package/src/ncu/isNcuOutdatedPackages.ts +6 -0
- package/src/ncu/toUpdateType.test.ts +21 -0
- package/src/ncu/toUpdateType.ts +18 -0
- package/src/options/Options.ts +24 -0
- package/src/options/index.ts +2 -0
- package/src/options/initOptions.ts +34 -0
- package/src/outdated-package-processor/OutdatedPackageProcessor.ts +101 -0
- package/src/outdated-package-processor/createBranchName.test.ts +14 -0
- package/src/outdated-package-processor/createBranchName.ts +7 -0
- package/src/outdated-package-processor/createCommitMessage.test.ts +43 -0
- package/src/outdated-package-processor/createCommitMessage.ts +8 -0
- package/src/outdated-package-processor/index.ts +1 -0
- package/src/outdated-packages-processor/OutdatedPackagesProcessor.ts +34 -0
- package/src/outdated-packages-processor/index.ts +1 -0
- package/src/package-manager/Npm.ts +19 -0
- package/src/package-manager/PackageManager.ts +4 -0
- package/src/package-manager/Yarn.ts +19 -0
- package/src/package-manager/createPackageManager.ts +21 -0
- package/src/package-manager/index.ts +4 -0
- package/src/read-package-json/Package.ts +24 -0
- package/src/read-package-json/PackageDependencies.ts +10 -0
- package/src/read-package-json/index.ts +2 -0
- package/src/read-package-json/parsePackageJson.ts +13 -0
- package/src/read-package-json/readFile.ts +6 -0
- package/src/read-package-json/readPackageJson.ts +9 -0
- package/src/terminal/Terminal.ts +30 -0
- package/src/terminal/index.ts +1 -0
- package/src/terminal/isExecaReturnValue.ts +30 -0
- package/src/types/OutdatedPackage.ts +9 -0
- package/src/types/Result.ts +7 -0
- package/src/types/index.ts +2 -0
- package/src/values/PackageVersion.test.ts +25 -0
- package/src/values/PackageVersion.ts +40 -0
- package/src/values/index.ts +1 -0
- package/tsconfig.base.json +3 -0
- package/tsconfig.build.json +13 -0
- package/tsconfig.json +9 -0
package/dist/ncu/Ncu.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Ncu = void 0;
|
|
4
|
+
const npm_check_updates_1 = require("npm-check-updates");
|
|
5
|
+
const read_package_json_1 = require("../read-package-json");
|
|
6
|
+
const isNcuOutdatedPackages_1 = require("./isNcuOutdatedPackages");
|
|
7
|
+
const NcuOutdatedPackagesConverter_1 = require("./NcuOutdatedPackagesConverter");
|
|
8
|
+
// TODO: add test
|
|
9
|
+
class Ncu {
|
|
10
|
+
async check() {
|
|
11
|
+
return await this.run({
|
|
12
|
+
jsonUpgraded: true
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
async update(outdatedPackage) {
|
|
16
|
+
return await this.run({
|
|
17
|
+
jsonUpgraded: true,
|
|
18
|
+
filter: outdatedPackage.name,
|
|
19
|
+
upgrade: true
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
async run(options) {
|
|
23
|
+
const pkg = await (0, read_package_json_1.readPackageJson)('./package.json');
|
|
24
|
+
const currentDependencies = {
|
|
25
|
+
...pkg.dependencies,
|
|
26
|
+
...pkg.devDependencies,
|
|
27
|
+
...pkg.peerDependencies,
|
|
28
|
+
...pkg.optionalDependencies
|
|
29
|
+
};
|
|
30
|
+
const result = await (0, npm_check_updates_1.run)(options);
|
|
31
|
+
if (!(0, isNcuOutdatedPackages_1.isNcuOutdatedPackages)(result)) {
|
|
32
|
+
throw new Error('result is not NcuOutdatedPackages');
|
|
33
|
+
}
|
|
34
|
+
const ncuOutdatedPackagesConverter = new NcuOutdatedPackagesConverter_1.NcuOutdatedPackagesConverter(currentDependencies);
|
|
35
|
+
return ncuOutdatedPackagesConverter.toOutdatedPackages(result);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.Ncu = Ncu;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NcuOutdatedPackagesConverter = void 0;
|
|
4
|
+
const values_1 = require("../values");
|
|
5
|
+
const toUpdateType_1 = require("./toUpdateType");
|
|
6
|
+
// TODO: add test
|
|
7
|
+
class NcuOutdatedPackagesConverter {
|
|
8
|
+
constructor(currentDependencies) {
|
|
9
|
+
this.currentDependencies = currentDependencies;
|
|
10
|
+
}
|
|
11
|
+
toOutdatedPackages(outdatedPackages) {
|
|
12
|
+
return Object.entries(outdatedPackages)
|
|
13
|
+
.map(([name, newVersion]) => ({
|
|
14
|
+
name,
|
|
15
|
+
currentVersion: values_1.PackageVersion.of(this.currentDependencies[name]),
|
|
16
|
+
newVersion: values_1.PackageVersion.of(newVersion)
|
|
17
|
+
}))
|
|
18
|
+
.map(({ name, currentVersion, newVersion }) => ({
|
|
19
|
+
name,
|
|
20
|
+
currentVersion,
|
|
21
|
+
newVersion,
|
|
22
|
+
type: (0, toUpdateType_1.toUpdateType)(currentVersion, newVersion)
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.NcuOutdatedPackagesConverter = NcuOutdatedPackagesConverter;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isNcuOutdatedPackages = void 0;
|
|
4
|
+
// TODO: add test
|
|
5
|
+
const isNcuOutdatedPackages = (value) => {
|
|
6
|
+
return typeof value === 'object' && value !== null && Object.values(value).every(value => typeof value === 'string');
|
|
7
|
+
};
|
|
8
|
+
exports.isNcuOutdatedPackages = isNcuOutdatedPackages;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toUpdateType = void 0;
|
|
4
|
+
const enums_1 = require("../enums");
|
|
5
|
+
const toUpdateType = (currentVersion, newVersion) => {
|
|
6
|
+
if (currentVersion.major !== newVersion.major) {
|
|
7
|
+
return enums_1.UpdateType.Major;
|
|
8
|
+
}
|
|
9
|
+
if (currentVersion.minor !== newVersion.minor) {
|
|
10
|
+
return enums_1.UpdateType.Minor;
|
|
11
|
+
}
|
|
12
|
+
if (currentVersion.patch !== newVersion.patch) {
|
|
13
|
+
return enums_1.UpdateType.Patch;
|
|
14
|
+
}
|
|
15
|
+
throw new Error('Both versions are same.');
|
|
16
|
+
};
|
|
17
|
+
exports.toUpdateType = toUpdateType;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isOptions = exports.Options = void 0;
|
|
4
|
+
const io_ts_1 = require("io-ts");
|
|
5
|
+
exports.Options = (0, io_ts_1.intersection)([
|
|
6
|
+
(0, io_ts_1.type)({
|
|
7
|
+
githubToken: io_ts_1.string,
|
|
8
|
+
logLevel: (0, io_ts_1.union)([(0, io_ts_1.literal)('info'), (0, io_ts_1.literal)('debug')]),
|
|
9
|
+
packageManager: (0, io_ts_1.union)([(0, io_ts_1.literal)('npm'), (0, io_ts_1.literal)('yarn')])
|
|
10
|
+
}),
|
|
11
|
+
(0, io_ts_1.partial)({
|
|
12
|
+
gitUserEmail: io_ts_1.string,
|
|
13
|
+
gitUserName: io_ts_1.string
|
|
14
|
+
})
|
|
15
|
+
]);
|
|
16
|
+
exports.isOptions = exports.Options.is;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initOptions = void 0;
|
|
4
|
+
var initOptions_1 = require("./initOptions");
|
|
5
|
+
Object.defineProperty(exports, "initOptions", { enumerable: true, get: function () { return initOptions_1.initOptions; } });
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initOptions = void 0;
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const app_1 = require("../app");
|
|
6
|
+
const Options_1 = require("./Options");
|
|
7
|
+
// TODO: add test
|
|
8
|
+
const initOptions = () => {
|
|
9
|
+
commander_1.program
|
|
10
|
+
.version(app_1.app.version)
|
|
11
|
+
.option('--git-user-email <value>', 'User email of commit')
|
|
12
|
+
.option('--git-user-name <value>', 'User name of commit')
|
|
13
|
+
.requiredOption('--github-token <value>', 'GitHub token')
|
|
14
|
+
.addOption(new commander_1.Option('--log-level <value>', 'Log level to show')
|
|
15
|
+
.choices(['info', 'debug'])
|
|
16
|
+
.default('info'))
|
|
17
|
+
.addOption(new commander_1.Option('--package-manager <value>', 'Package manager of your project')
|
|
18
|
+
.choices(['npm', 'yarn'])
|
|
19
|
+
.default('npm'));
|
|
20
|
+
commander_1.program.parse(process.argv);
|
|
21
|
+
const options = commander_1.program.opts();
|
|
22
|
+
if (!(0, Options_1.isOptions)(options)) {
|
|
23
|
+
throw new Error(`Failed to parse command-line options. options=${JSON.stringify(options)}`);
|
|
24
|
+
}
|
|
25
|
+
return options;
|
|
26
|
+
};
|
|
27
|
+
exports.initOptions = initOptions;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OutdatedPackageProcessor = void 0;
|
|
4
|
+
const createBranchName_1 = require("./createBranchName");
|
|
5
|
+
const createCommitMessage_1 = require("./createCommitMessage");
|
|
6
|
+
// TODO: add test
|
|
7
|
+
class OutdatedPackageProcessor {
|
|
8
|
+
constructor({ committer, git, ncu, packageManager, pullRequestCreator, remoteBranchExistenceChecker, logger }) {
|
|
9
|
+
this.committer = committer;
|
|
10
|
+
this.git = git;
|
|
11
|
+
this.ncu = ncu;
|
|
12
|
+
this.packageManager = packageManager;
|
|
13
|
+
this.pullRequestCreator = pullRequestCreator;
|
|
14
|
+
this.remoteBranchExistenceChecker = remoteBranchExistenceChecker;
|
|
15
|
+
this.logger = logger;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Don't run in parallel because it includes file operations.
|
|
19
|
+
*/
|
|
20
|
+
async process(outdatedPackage) {
|
|
21
|
+
const branchName = (0, createBranchName_1.createBranchName)(outdatedPackage);
|
|
22
|
+
this.logger.debug(`branchName=${branchName}`);
|
|
23
|
+
if (this.remoteBranchExistenceChecker.check(branchName)) {
|
|
24
|
+
this.logger.info(`Skip ${outdatedPackage.name} because ${branchName} branch already exists on remote.`);
|
|
25
|
+
return {
|
|
26
|
+
outdatedPackage,
|
|
27
|
+
skipped: true
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
await this.git.createBranch(branchName);
|
|
31
|
+
this.logger.info(`${branchName} branch has created.`);
|
|
32
|
+
const updatedPackages = await this.ncu.update(outdatedPackage);
|
|
33
|
+
if (updatedPackages.length !== 1) {
|
|
34
|
+
throw new Error(`Failed to update ${outdatedPackage.name}.`);
|
|
35
|
+
}
|
|
36
|
+
await this.packageManager.install();
|
|
37
|
+
this.logger.info(`${outdatedPackage.name} has updated from v${outdatedPackage.currentVersion.version} to v${outdatedPackage.newVersion.version}`);
|
|
38
|
+
await this.git.add(...this.packageManager.packageFiles);
|
|
39
|
+
const message = (0, createCommitMessage_1.createCommitMessage)(outdatedPackage);
|
|
40
|
+
this.logger.debug(`message=${message}`);
|
|
41
|
+
await this.committer.commit(message);
|
|
42
|
+
await this.git.push(branchName);
|
|
43
|
+
await this.pullRequestCreator.create({
|
|
44
|
+
outdatedPackage,
|
|
45
|
+
branchName
|
|
46
|
+
});
|
|
47
|
+
await this.git.checkout('-');
|
|
48
|
+
await this.git.removeBranch(branchName);
|
|
49
|
+
this.logger.info(`${branchName} branch has removed.`);
|
|
50
|
+
return {
|
|
51
|
+
outdatedPackage,
|
|
52
|
+
updated: true
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.OutdatedPackageProcessor = OutdatedPackageProcessor;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createBranchName = void 0;
|
|
4
|
+
const createBranchName = (outdatedPackage) => {
|
|
5
|
+
const packageName = outdatedPackage.name;
|
|
6
|
+
const newVersion = outdatedPackage.newVersion.version;
|
|
7
|
+
return `npm-update-package/${packageName}/v${newVersion}`;
|
|
8
|
+
};
|
|
9
|
+
exports.createBranchName = createBranchName;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCommitMessage = void 0;
|
|
4
|
+
const createCommitMessage = (outdatedPackage) => {
|
|
5
|
+
const packageName = outdatedPackage.name;
|
|
6
|
+
const newVersion = outdatedPackage.newVersion.version;
|
|
7
|
+
const updateType = outdatedPackage.type;
|
|
8
|
+
return `chore(deps): ${updateType} update ${packageName} to v${newVersion}`;
|
|
9
|
+
};
|
|
10
|
+
exports.createCommitMessage = createCommitMessage;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OutdatedPackageProcessor = void 0;
|
|
4
|
+
var OutdatedPackageProcessor_1 = require("./OutdatedPackageProcessor");
|
|
5
|
+
Object.defineProperty(exports, "OutdatedPackageProcessor", { enumerable: true, get: function () { return OutdatedPackageProcessor_1.OutdatedPackageProcessor; } });
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OutdatedPackagesProcessor = void 0;
|
|
4
|
+
class OutdatedPackagesProcessor {
|
|
5
|
+
constructor({ outdatedPackageProcessor, logger }) {
|
|
6
|
+
this.outdatedPackageProcessor = outdatedPackageProcessor;
|
|
7
|
+
this.logger = logger;
|
|
8
|
+
}
|
|
9
|
+
async process(outdatedPackages) {
|
|
10
|
+
const results = [];
|
|
11
|
+
for (const outdatedPackage of outdatedPackages) {
|
|
12
|
+
this.logger.debug(`outdatedPackage=${JSON.stringify(outdatedPackage)}`);
|
|
13
|
+
const result = await this.outdatedPackageProcessor.process(outdatedPackage);
|
|
14
|
+
results.push(result);
|
|
15
|
+
}
|
|
16
|
+
return results;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.OutdatedPackagesProcessor = OutdatedPackagesProcessor;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OutdatedPackagesProcessor = void 0;
|
|
4
|
+
var OutdatedPackagesProcessor_1 = require("./OutdatedPackagesProcessor");
|
|
5
|
+
Object.defineProperty(exports, "OutdatedPackagesProcessor", { enumerable: true, get: function () { return OutdatedPackagesProcessor_1.OutdatedPackagesProcessor; } });
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Npm = void 0;
|
|
4
|
+
// TODO: add test
|
|
5
|
+
class Npm {
|
|
6
|
+
constructor(terminal) {
|
|
7
|
+
this.terminal = terminal;
|
|
8
|
+
this.packageFiles = [
|
|
9
|
+
'package.json',
|
|
10
|
+
'package-lock.json'
|
|
11
|
+
];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @see https://docs.npmjs.com/cli/v8/commands/npm-install
|
|
15
|
+
*/
|
|
16
|
+
async install() {
|
|
17
|
+
await this.terminal.run('npm', 'install');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.Npm = Npm;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Yarn = void 0;
|
|
4
|
+
// TODO: add test
|
|
5
|
+
class Yarn {
|
|
6
|
+
constructor(terminal) {
|
|
7
|
+
this.terminal = terminal;
|
|
8
|
+
this.packageFiles = [
|
|
9
|
+
'package.json',
|
|
10
|
+
'yarn.lock'
|
|
11
|
+
];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @see https://classic.yarnpkg.com/en/docs/cli/install
|
|
15
|
+
*/
|
|
16
|
+
async install() {
|
|
17
|
+
await this.terminal.run('yarn', 'install');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.Yarn = Yarn;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPackageManager = void 0;
|
|
4
|
+
const Npm_1 = require("./Npm");
|
|
5
|
+
const Yarn_1 = require("./Yarn");
|
|
6
|
+
// TODO: add test
|
|
7
|
+
const createPackageManager = ({ terminal, packageManager }) => {
|
|
8
|
+
switch (packageManager) {
|
|
9
|
+
case 'npm':
|
|
10
|
+
return new Npm_1.Npm(terminal);
|
|
11
|
+
case 'yarn':
|
|
12
|
+
return new Yarn_1.Yarn(terminal);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
exports.createPackageManager = createPackageManager;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Yarn = exports.Npm = exports.createPackageManager = void 0;
|
|
4
|
+
var createPackageManager_1 = require("./createPackageManager");
|
|
5
|
+
Object.defineProperty(exports, "createPackageManager", { enumerable: true, get: function () { return createPackageManager_1.createPackageManager; } });
|
|
6
|
+
var Npm_1 = require("./Npm");
|
|
7
|
+
Object.defineProperty(exports, "Npm", { enumerable: true, get: function () { return Npm_1.Npm; } });
|
|
8
|
+
var Yarn_1 = require("./Yarn");
|
|
9
|
+
Object.defineProperty(exports, "Yarn", { enumerable: true, get: function () { return Yarn_1.Yarn; } });
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPackage = exports.Package = void 0;
|
|
4
|
+
const io_ts_1 = require("io-ts");
|
|
5
|
+
const PackageDependencies_1 = require("./PackageDependencies");
|
|
6
|
+
exports.Package = (0, io_ts_1.intersection)([
|
|
7
|
+
(0, io_ts_1.type)({
|
|
8
|
+
name: io_ts_1.string,
|
|
9
|
+
version: io_ts_1.string
|
|
10
|
+
}),
|
|
11
|
+
(0, io_ts_1.partial)({
|
|
12
|
+
dependencies: PackageDependencies_1.PackageDependencies,
|
|
13
|
+
devDependencies: PackageDependencies_1.PackageDependencies,
|
|
14
|
+
peerDependencies: PackageDependencies_1.PackageDependencies,
|
|
15
|
+
optionalDependencies: PackageDependencies_1.PackageDependencies
|
|
16
|
+
})
|
|
17
|
+
]);
|
|
18
|
+
exports.isPackage = exports.Package.is;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPackageDependencies = exports.PackageDependencies = void 0;
|
|
4
|
+
const io_ts_1 = require("io-ts");
|
|
5
|
+
exports.PackageDependencies = (0, io_ts_1.record)(io_ts_1.string, io_ts_1.string);
|
|
6
|
+
exports.isPackageDependencies = exports.PackageDependencies.is;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readPackageJson = void 0;
|
|
4
|
+
var readPackageJson_1 = require("./readPackageJson");
|
|
5
|
+
Object.defineProperty(exports, "readPackageJson", { enumerable: true, get: function () { return readPackageJson_1.readPackageJson; } });
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parsePackageJson = void 0;
|
|
4
|
+
const Package_1 = require("./Package");
|
|
5
|
+
// TODO: add test
|
|
6
|
+
const parsePackageJson = (json) => {
|
|
7
|
+
const parsed = JSON.parse(json);
|
|
8
|
+
if ((0, Package_1.isPackage)(parsed)) {
|
|
9
|
+
return parsed;
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
throw new Error(`Failed to parse package.json. json=${json}`);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
exports.parsePackageJson = parsePackageJson;
|
|
@@ -0,0 +1,12 @@
|
|
|
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.readFile = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
// TODO: add test
|
|
9
|
+
const readFile = async (filePath) => {
|
|
10
|
+
return await fs_1.default.promises.readFile(filePath, 'utf8');
|
|
11
|
+
};
|
|
12
|
+
exports.readFile = readFile;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readPackageJson = void 0;
|
|
4
|
+
const parsePackageJson_1 = require("./parsePackageJson");
|
|
5
|
+
const readFile_1 = require("./readFile");
|
|
6
|
+
// TODO: add test
|
|
7
|
+
const readPackageJson = async (filePath) => {
|
|
8
|
+
const json = await (0, readFile_1.readFile)(filePath);
|
|
9
|
+
return (0, parsePackageJson_1.parsePackageJson)(json);
|
|
10
|
+
};
|
|
11
|
+
exports.readPackageJson = readPackageJson;
|
|
@@ -0,0 +1,29 @@
|
|
|
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.Terminal = void 0;
|
|
7
|
+
const execa_1 = __importDefault(require("execa"));
|
|
8
|
+
const isExecaReturnValue_1 = require("./isExecaReturnValue");
|
|
9
|
+
// TODO: add test
|
|
10
|
+
class Terminal {
|
|
11
|
+
async run(command, ...args) {
|
|
12
|
+
return await (0, execa_1.default)(command, args);
|
|
13
|
+
}
|
|
14
|
+
async runWithErrorHandling(command, ...args) {
|
|
15
|
+
try {
|
|
16
|
+
return await this.run(command, ...args);
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
const value = e instanceof Error ? JSON.parse(JSON.stringify(e)) : e;
|
|
20
|
+
if ((0, isExecaReturnValue_1.isExecaReturnValue)(value)) {
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
throw e;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.Terminal = Terminal;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isExecaReturnValue = void 0;
|
|
4
|
+
const io_ts_1 = require("io-ts");
|
|
5
|
+
const ExecaReturnValueType = (0, io_ts_1.intersection)([
|
|
6
|
+
(0, io_ts_1.type)({
|
|
7
|
+
command: io_ts_1.string,
|
|
8
|
+
escapedCommand: io_ts_1.string,
|
|
9
|
+
exitCode: io_ts_1.number,
|
|
10
|
+
failed: io_ts_1.boolean,
|
|
11
|
+
timedOut: io_ts_1.boolean,
|
|
12
|
+
killed: io_ts_1.boolean,
|
|
13
|
+
isCanceled: io_ts_1.boolean
|
|
14
|
+
}),
|
|
15
|
+
(0, io_ts_1.partial)({
|
|
16
|
+
signal: io_ts_1.string,
|
|
17
|
+
signalDescription: io_ts_1.string
|
|
18
|
+
})
|
|
19
|
+
]);
|
|
20
|
+
// TODO: add test
|
|
21
|
+
const isExecaReturnValue = (value) => {
|
|
22
|
+
return ExecaReturnValueType.is(value);
|
|
23
|
+
};
|
|
24
|
+
exports.isExecaReturnValue = isExecaReturnValue;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PackageVersion = void 0;
|
|
4
|
+
const semver_1 = require("semver");
|
|
5
|
+
class PackageVersion {
|
|
6
|
+
constructor({ version, major, minor, patch }) {
|
|
7
|
+
this.version = version;
|
|
8
|
+
this.major = major;
|
|
9
|
+
this.minor = minor;
|
|
10
|
+
this.patch = patch;
|
|
11
|
+
}
|
|
12
|
+
static of(version) {
|
|
13
|
+
const semver = (0, semver_1.coerce)(version);
|
|
14
|
+
if (semver === null) {
|
|
15
|
+
throw new Error(`Failed to parse package version. version=${version}`);
|
|
16
|
+
}
|
|
17
|
+
return new PackageVersion({
|
|
18
|
+
version: semver.version,
|
|
19
|
+
major: semver.major,
|
|
20
|
+
minor: semver.minor,
|
|
21
|
+
patch: semver.patch
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.PackageVersion = PackageVersion;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PackageVersion = void 0;
|
|
4
|
+
var PackageVersion_1 = require("./PackageVersion");
|
|
5
|
+
Object.defineProperty(exports, "PackageVersion", { enumerable: true, get: function () { return PackageVersion_1.PackageVersion; } });
|
package/jest.config.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "npm-update-package",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI tool for creating pull request to update npm packages",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "tsc --project tsconfig.build.json",
|
|
7
|
+
"clean": "rimraf dist",
|
|
8
|
+
"lint": "eslint '**/*.{js,ts}'",
|
|
9
|
+
"prepare": "husky install",
|
|
10
|
+
"prepublish": "npm-run-all clean lint test build",
|
|
11
|
+
"start": "ts-node src/start.ts",
|
|
12
|
+
"test": "jest --passWithNoTests"
|
|
13
|
+
},
|
|
14
|
+
"bin": "dist/bin.js",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@octokit/rest": "18.12.0",
|
|
17
|
+
"commander": "8.3.0",
|
|
18
|
+
"execa": "5.1.1",
|
|
19
|
+
"fp-ts": "2.11.5",
|
|
20
|
+
"io-ts": "2.2.16",
|
|
21
|
+
"log4js": "6.3.0",
|
|
22
|
+
"npm-check-updates": "12.0.2",
|
|
23
|
+
"parse-github-url": "1.0.2",
|
|
24
|
+
"semver": "7.3.5"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@jest/types": "27.0.6",
|
|
28
|
+
"@tsconfig/node12": "1.0.9",
|
|
29
|
+
"@types/jest": "27.0.3",
|
|
30
|
+
"@types/node": "12.20.15",
|
|
31
|
+
"@types/parse-github-url": "1.0.0",
|
|
32
|
+
"@types/semver": "7.3.9",
|
|
33
|
+
"@typescript-eslint/eslint-plugin": "5.4.0",
|
|
34
|
+
"eslint": "8.3.0",
|
|
35
|
+
"eslint-config-standard-with-typescript": "21.0.1",
|
|
36
|
+
"eslint-plugin-import": "2.25.3",
|
|
37
|
+
"eslint-plugin-jest": "25.3.0",
|
|
38
|
+
"eslint-plugin-node": "11.1.0",
|
|
39
|
+
"eslint-plugin-promise": "5.1.1",
|
|
40
|
+
"eslint-plugin-tsdoc": "0.2.14",
|
|
41
|
+
"husky": "7.0.4",
|
|
42
|
+
"jest": "27.0.6",
|
|
43
|
+
"lint-staged": "12.1.2",
|
|
44
|
+
"npm-run-all": "4.1.5",
|
|
45
|
+
"rimraf": "3.0.2",
|
|
46
|
+
"ts-jest": "27.0.7",
|
|
47
|
+
"ts-node": "10.4.0",
|
|
48
|
+
"typescript": "4.4.4",
|
|
49
|
+
"utility-types": "3.10.0"
|
|
50
|
+
},
|
|
51
|
+
"homepage": "https://github.com/munierujp/npm-update-package",
|
|
52
|
+
"bugs": {
|
|
53
|
+
"url": "https://github.com/munierujp/npm-update-package/issues"
|
|
54
|
+
},
|
|
55
|
+
"repository": {
|
|
56
|
+
"type": "git",
|
|
57
|
+
"url": "https://github.com/munierujp/npm-update-package.git"
|
|
58
|
+
}
|
|
59
|
+
}
|
package/src/app.ts
ADDED
package/src/bin.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { createLogger } from './logger'
|
|
4
|
+
import { main } from './main'
|
|
5
|
+
import { initOptions } from './options'
|
|
6
|
+
|
|
7
|
+
const options = initOptions()
|
|
8
|
+
const logger = createLogger(options.logLevel)
|
|
9
|
+
logger.info('Start npm-update-package.')
|
|
10
|
+
|
|
11
|
+
main({
|
|
12
|
+
options,
|
|
13
|
+
logger
|
|
14
|
+
})
|
|
15
|
+
.then(() => logger.info('End npm-update-package'))
|
|
16
|
+
.catch((e: unknown) => {
|
|
17
|
+
// TODO: improve error handling
|
|
18
|
+
logger.fatal('Unexpected error has occurred.', e)
|
|
19
|
+
})
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const LogLevel = {
|
|
2
|
+
Info: 'info',
|
|
3
|
+
Debug: 'debug'
|
|
4
|
+
} as const
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
6
|
+
export type LogLevel = typeof LogLevel[keyof typeof LogLevel]
|
|
7
|
+
const logLevels = Object.values(LogLevel)
|
|
8
|
+
export const isLogLevel = (value: any): value is LogLevel => logLevels.includes(value)
|