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/.eslintignore
ADDED
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
extends: [
|
|
3
|
+
'standard-with-typescript',
|
|
4
|
+
'plugin:jest/recommended'
|
|
5
|
+
],
|
|
6
|
+
plugins: [
|
|
7
|
+
'eslint-plugin-tsdoc'
|
|
8
|
+
],
|
|
9
|
+
parserOptions: {
|
|
10
|
+
project: './tsconfig.json'
|
|
11
|
+
},
|
|
12
|
+
rules: {
|
|
13
|
+
'import/order': ['error', {
|
|
14
|
+
alphabetize: {
|
|
15
|
+
order: 'asc',
|
|
16
|
+
caseInsensitive: true
|
|
17
|
+
}
|
|
18
|
+
}],
|
|
19
|
+
'no-console': 'error',
|
|
20
|
+
'sort-imports': 'off',
|
|
21
|
+
'tsdoc/syntax': 'warn'
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
name: eslint
|
|
2
|
+
on:
|
|
3
|
+
pull_request:
|
|
4
|
+
branches: [ master ]
|
|
5
|
+
jobs:
|
|
6
|
+
eslint:
|
|
7
|
+
name: runner / eslint
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
steps:
|
|
10
|
+
- uses: actions/checkout@v2
|
|
11
|
+
- name: eslint
|
|
12
|
+
uses: reviewdog/action-eslint@v1
|
|
13
|
+
with:
|
|
14
|
+
reporter: github-pr-check
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
name: test
|
|
2
|
+
on:
|
|
3
|
+
pull_request:
|
|
4
|
+
branches: [ master ]
|
|
5
|
+
jobs:
|
|
6
|
+
test:
|
|
7
|
+
runs-on: ubuntu-latest
|
|
8
|
+
strategy:
|
|
9
|
+
matrix:
|
|
10
|
+
node-version: [14.17.1]
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v2
|
|
13
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
14
|
+
uses: actions/setup-node@v2
|
|
15
|
+
with:
|
|
16
|
+
node-version: ${{ matrix.node-version }}
|
|
17
|
+
- run: npm ci
|
|
18
|
+
- run: npm run build --if-present
|
|
19
|
+
- run: npm test
|
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
12.20.2
|
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 TS Examples
|
|
4
|
+
Copyright (c) 2021 Munieru
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[](https://standardjs.com)
|
|
2
|
+
|
|
3
|
+
# npm-update-package
|
|
4
|
+
|
|
5
|
+
CLI tool for creating pull request to update npm packages
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
If you are using npm:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm i -g npm-update-package
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
If you are using Yarn:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
yarn global add npm-update-package
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Or, you can use [npx](https://docs.npmjs.com/cli/v8/commands/npx).
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
npx npm-update-package
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
npm-update-package --github-token $GITHUB_TOKEN
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Options
|
|
34
|
+
|
|
35
|
+
You can customize behavior via command-line options.
|
|
36
|
+
|
|
37
|
+
|Option|Description|Required|Value|Default|
|
|
38
|
+
|---|---|---|---|---|
|
|
39
|
+
|`--git-user-email`|User email of commit|-|string|-|
|
|
40
|
+
|`--git-user-name`|User name of commit|-|string|-|
|
|
41
|
+
|`--github-token`|GitHub token|✓|string|-|
|
|
42
|
+
|`--log-level`|Log level to show|-|`info`, `debug`|`info`|
|
|
43
|
+
|`--package-manager`|Package manager of your project|-|`npm`, `yarn`|`npm`|
|
package/dist/app.js
ADDED
package/dist/bin.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const logger_1 = require("./logger");
|
|
5
|
+
const main_1 = require("./main");
|
|
6
|
+
const options_1 = require("./options");
|
|
7
|
+
const options = (0, options_1.initOptions)();
|
|
8
|
+
const logger = (0, logger_1.createLogger)(options.logLevel);
|
|
9
|
+
logger.info('Start npm-update-package.');
|
|
10
|
+
(0, main_1.main)({
|
|
11
|
+
options,
|
|
12
|
+
logger
|
|
13
|
+
})
|
|
14
|
+
.then(() => logger.info('End npm-update-package'))
|
|
15
|
+
.catch((e) => {
|
|
16
|
+
// TODO: improve error handling
|
|
17
|
+
logger.fatal('Unexpected error has occurred.', e);
|
|
18
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isLogLevel = exports.LogLevel = void 0;
|
|
4
|
+
exports.LogLevel = {
|
|
5
|
+
Info: 'info',
|
|
6
|
+
Debug: 'debug'
|
|
7
|
+
};
|
|
8
|
+
const logLevels = Object.values(exports.LogLevel);
|
|
9
|
+
const isLogLevel = (value) => logLevels.includes(value);
|
|
10
|
+
exports.isLogLevel = isLogLevel;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPackageManagerName = exports.PackageManagerName = void 0;
|
|
4
|
+
exports.PackageManagerName = {
|
|
5
|
+
Npm: 'npm',
|
|
6
|
+
Yarn: 'yarn'
|
|
7
|
+
};
|
|
8
|
+
const packageManagerNames = Object.values(exports.PackageManagerName);
|
|
9
|
+
const isPackageManagerName = (value) => packageManagerNames.includes(value);
|
|
10
|
+
exports.isPackageManagerName = isPackageManagerName;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isUpdateType = exports.UpdateType = void 0;
|
|
4
|
+
exports.UpdateType = {
|
|
5
|
+
Major: 'major',
|
|
6
|
+
Minor: 'minor',
|
|
7
|
+
Patch: 'patch'
|
|
8
|
+
};
|
|
9
|
+
const updateTypes = Object.values(exports.UpdateType);
|
|
10
|
+
const isUpdateType = (value) => updateTypes.includes(value);
|
|
11
|
+
exports.isUpdateType = isUpdateType;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UpdateType = exports.isUpdateType = exports.PackageManagerName = exports.isPackageManagerName = exports.LogLevel = exports.isLogLevel = void 0;
|
|
4
|
+
var LogLevel_1 = require("./LogLevel");
|
|
5
|
+
Object.defineProperty(exports, "isLogLevel", { enumerable: true, get: function () { return LogLevel_1.isLogLevel; } });
|
|
6
|
+
Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return LogLevel_1.LogLevel; } });
|
|
7
|
+
var PackageManagerName_1 = require("./PackageManagerName");
|
|
8
|
+
Object.defineProperty(exports, "isPackageManagerName", { enumerable: true, get: function () { return PackageManagerName_1.isPackageManagerName; } });
|
|
9
|
+
Object.defineProperty(exports, "PackageManagerName", { enumerable: true, get: function () { return PackageManagerName_1.PackageManagerName; } });
|
|
10
|
+
var UpdateType_1 = require("./UpdateType");
|
|
11
|
+
Object.defineProperty(exports, "isUpdateType", { enumerable: true, get: function () { return UpdateType_1.isUpdateType; } });
|
|
12
|
+
Object.defineProperty(exports, "UpdateType", { enumerable: true, get: function () { return UpdateType_1.UpdateType; } });
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Committer = void 0;
|
|
4
|
+
// TODO: add test
|
|
5
|
+
class Committer {
|
|
6
|
+
constructor({ git, user }) {
|
|
7
|
+
this.git = git;
|
|
8
|
+
this.user = user;
|
|
9
|
+
}
|
|
10
|
+
async commit(message) {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
let name;
|
|
13
|
+
if (((_a = this.user) === null || _a === void 0 ? void 0 : _a.name) !== undefined) {
|
|
14
|
+
name = await this.git.getConfig('user.name');
|
|
15
|
+
await this.git.setConfig('user.name', this.user.name);
|
|
16
|
+
}
|
|
17
|
+
let email;
|
|
18
|
+
if (((_b = this.user) === null || _b === void 0 ? void 0 : _b.email) !== undefined) {
|
|
19
|
+
email = await this.git.getConfig('user.email');
|
|
20
|
+
await this.git.setConfig('user.email', this.user.email);
|
|
21
|
+
}
|
|
22
|
+
await this.git.commit(message);
|
|
23
|
+
if (name !== undefined) {
|
|
24
|
+
await this.git.setConfig('user.name', name);
|
|
25
|
+
}
|
|
26
|
+
if (email !== undefined) {
|
|
27
|
+
await this.git.setConfig('user.email', email);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.Committer = Committer;
|
package/dist/git/Git.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Git = void 0;
|
|
4
|
+
const GitRepository_1 = require("./GitRepository");
|
|
5
|
+
// TODO: add test
|
|
6
|
+
class Git {
|
|
7
|
+
constructor(terminal) {
|
|
8
|
+
this.terminal = terminal;
|
|
9
|
+
}
|
|
10
|
+
async add(...files) {
|
|
11
|
+
await this.terminal.run('git', 'add', ...files);
|
|
12
|
+
}
|
|
13
|
+
async checkout(branchName) {
|
|
14
|
+
await this.terminal.run('git', 'checkout', branchName);
|
|
15
|
+
}
|
|
16
|
+
async commit(message) {
|
|
17
|
+
await this.terminal.run('git', 'commit', '--message', message);
|
|
18
|
+
}
|
|
19
|
+
async createBranch(branchName) {
|
|
20
|
+
await this.terminal.run('git', 'checkout', '-b', branchName);
|
|
21
|
+
}
|
|
22
|
+
async getConfig(key) {
|
|
23
|
+
const { stdout } = await this.terminal.run('git', 'config', key);
|
|
24
|
+
return stdout.trim();
|
|
25
|
+
}
|
|
26
|
+
async getCurrentBranch() {
|
|
27
|
+
const { stdout } = await this.terminal.run('git', 'rev-parse', '--abbrev-ref', 'HEAD');
|
|
28
|
+
return stdout.trim();
|
|
29
|
+
}
|
|
30
|
+
async getRemoteUrl() {
|
|
31
|
+
const { stdout } = await this.terminal.run('git', 'remote', 'get-url', '--push', 'origin');
|
|
32
|
+
return stdout.trim();
|
|
33
|
+
}
|
|
34
|
+
async getRepository() {
|
|
35
|
+
const url = await this.getRemoteUrl();
|
|
36
|
+
return GitRepository_1.GitRepository.of(url);
|
|
37
|
+
}
|
|
38
|
+
async push(branchName) {
|
|
39
|
+
await this.terminal.run('git', 'push', 'origin', branchName);
|
|
40
|
+
}
|
|
41
|
+
async removeBranch(branchName) {
|
|
42
|
+
await this.terminal.run('git', 'branch', '-D', branchName);
|
|
43
|
+
}
|
|
44
|
+
async setConfig(key, value) {
|
|
45
|
+
await this.terminal.run('git', 'config', key, value);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.Git = Git;
|
|
@@ -0,0 +1,41 @@
|
|
|
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.GitRepository = void 0;
|
|
7
|
+
const parse_github_url_1 = __importDefault(require("parse-github-url"));
|
|
8
|
+
class GitRepository {
|
|
9
|
+
constructor({ host, owner, name }) {
|
|
10
|
+
this.host = host;
|
|
11
|
+
this.owner = owner;
|
|
12
|
+
this.name = name;
|
|
13
|
+
}
|
|
14
|
+
static of(url) {
|
|
15
|
+
const parsed = (0, parse_github_url_1.default)(url);
|
|
16
|
+
if (parsed === null) {
|
|
17
|
+
throw new Error(`Failed to parse url. url=${url}`);
|
|
18
|
+
}
|
|
19
|
+
const { host, owner, name } = parsed;
|
|
20
|
+
if (host === null || owner === null || name === null) {
|
|
21
|
+
throw new Error(`Failed to parse url. url=${url}`);
|
|
22
|
+
}
|
|
23
|
+
return new GitRepository({
|
|
24
|
+
host,
|
|
25
|
+
owner,
|
|
26
|
+
name
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
get apiEndPoint() {
|
|
30
|
+
if (this.isGitHubDotCom) {
|
|
31
|
+
return 'https://api.github.com';
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return `https://${this.host}/api/v3`;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
get isGitHubDotCom() {
|
|
38
|
+
return this.host === 'github.com';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.GitRepository = GitRepository;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Git = exports.Committer = void 0;
|
|
4
|
+
var Committer_1 = require("./Committer");
|
|
5
|
+
Object.defineProperty(exports, "Committer", { enumerable: true, get: function () { return Committer_1.Committer; } });
|
|
6
|
+
var Git_1 = require("./Git");
|
|
7
|
+
Object.defineProperty(exports, "Git", { enumerable: true, get: function () { return Git_1.Git; } });
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GitHub = void 0;
|
|
4
|
+
// TODO: add test
|
|
5
|
+
class GitHub {
|
|
6
|
+
constructor(octokit) {
|
|
7
|
+
this.octokit = octokit;
|
|
8
|
+
}
|
|
9
|
+
async createPullRequest(params) {
|
|
10
|
+
const { data } = await this.octokit.pulls.create(params);
|
|
11
|
+
return data;
|
|
12
|
+
}
|
|
13
|
+
async fetchBranches(params) {
|
|
14
|
+
const { data } = await this.octokit.repos.listBranches(params);
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
async fetchRepository(params) {
|
|
18
|
+
const { data } = await this.octokit.repos.get(params);
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.GitHub = GitHub;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PullRequestCreator = void 0;
|
|
4
|
+
const createPullRequestBody_1 = require("./createPullRequestBody");
|
|
5
|
+
const createPullRequestTitle_1 = require("./createPullRequestTitle");
|
|
6
|
+
// TODO: add test
|
|
7
|
+
class PullRequestCreator {
|
|
8
|
+
constructor({ github, gitRepo, githubRepo, logger }) {
|
|
9
|
+
this.github = github;
|
|
10
|
+
this.gitRepo = gitRepo;
|
|
11
|
+
this.githubRepo = githubRepo;
|
|
12
|
+
this.logger = logger;
|
|
13
|
+
}
|
|
14
|
+
async create({ outdatedPackage, branchName }) {
|
|
15
|
+
const title = (0, createPullRequestTitle_1.createPullRequestTitle)(outdatedPackage);
|
|
16
|
+
this.logger.debug(`title=${title}`);
|
|
17
|
+
const body = (0, createPullRequestBody_1.createPullRequestBody)(outdatedPackage);
|
|
18
|
+
this.logger.debug(`body=${body}`);
|
|
19
|
+
const createdPullRequest = await this.github.createPullRequest({
|
|
20
|
+
owner: this.gitRepo.owner,
|
|
21
|
+
repo: this.gitRepo.name,
|
|
22
|
+
base: this.githubRepo.default_branch,
|
|
23
|
+
head: branchName,
|
|
24
|
+
title,
|
|
25
|
+
body
|
|
26
|
+
});
|
|
27
|
+
this.logger.debug(`createdPullRequest=${JSON.stringify(createdPullRequest)}`);
|
|
28
|
+
this.logger.info(`Pull request for ${outdatedPackage.name} has created. ${createdPullRequest.html_url}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.PullRequestCreator = PullRequestCreator;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RemoteBranchExistenceChecker = void 0;
|
|
4
|
+
// TODO: add test
|
|
5
|
+
class RemoteBranchExistenceChecker {
|
|
6
|
+
constructor(remoteBranchNames) {
|
|
7
|
+
this.remoteBranchNames = remoteBranchNames;
|
|
8
|
+
}
|
|
9
|
+
static of(remoteBranches) {
|
|
10
|
+
const remoteBranchNames = remoteBranches.map(({ name }) => name);
|
|
11
|
+
return new RemoteBranchExistenceChecker(remoteBranchNames);
|
|
12
|
+
}
|
|
13
|
+
check(branchName) {
|
|
14
|
+
return this.remoteBranchNames.includes(branchName);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.RemoteBranchExistenceChecker = RemoteBranchExistenceChecker;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createGitHub = void 0;
|
|
4
|
+
const createOctokit_1 = require("./createOctokit");
|
|
5
|
+
const GitHub_1 = require("./GitHub");
|
|
6
|
+
// TODO: add test
|
|
7
|
+
const createGitHub = ({ repository, token }) => {
|
|
8
|
+
const octokit = (0, createOctokit_1.createOctokit)({
|
|
9
|
+
repository,
|
|
10
|
+
token
|
|
11
|
+
});
|
|
12
|
+
return new GitHub_1.GitHub(octokit);
|
|
13
|
+
};
|
|
14
|
+
exports.createGitHub = createGitHub;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createOctokit = void 0;
|
|
4
|
+
const rest_1 = require("@octokit/rest");
|
|
5
|
+
const app_1 = require("../app");
|
|
6
|
+
// TODO: add test
|
|
7
|
+
const createOctokit = ({ repository, token }) => {
|
|
8
|
+
const auth = `token ${token}`;
|
|
9
|
+
const userAgent = `${app_1.app.name}/${app_1.app.version}`;
|
|
10
|
+
if (repository.isGitHubDotCom) {
|
|
11
|
+
return new rest_1.Octokit({
|
|
12
|
+
auth,
|
|
13
|
+
userAgent
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return new rest_1.Octokit({
|
|
18
|
+
auth,
|
|
19
|
+
userAgent,
|
|
20
|
+
baseUrl: repository.apiEndPoint
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
exports.createOctokit = createOctokit;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPullRequestBody = void 0;
|
|
4
|
+
const app_1 = require("../app");
|
|
5
|
+
const createPullRequestBody = (outdatedPackage) => {
|
|
6
|
+
const packageName = outdatedPackage.name;
|
|
7
|
+
const currentVersion = outdatedPackage.currentVersion.version;
|
|
8
|
+
const newVersion = outdatedPackage.newVersion.version;
|
|
9
|
+
const updateType = outdatedPackage.type;
|
|
10
|
+
return `This PR updates these packages:
|
|
11
|
+
|
|
12
|
+
|package|type|current version|new version|
|
|
13
|
+
|---|---|---|---|
|
|
14
|
+
|[${packageName}](https://www.npmjs.com/package/${packageName})|${updateType}|\`${currentVersion}\`|\`${newVersion}\`|
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
This PR has been generated by [${app_1.app.name}](${app_1.app.web})`;
|
|
18
|
+
};
|
|
19
|
+
exports.createPullRequestBody = createPullRequestBody;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPullRequestTitle = void 0;
|
|
4
|
+
const createPullRequestTitle = (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.createPullRequestTitle = createPullRequestTitle;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RemoteBranchExistenceChecker = exports.PullRequestCreator = exports.GitHub = exports.createGitHub = void 0;
|
|
4
|
+
var createGitHub_1 = require("./createGitHub");
|
|
5
|
+
Object.defineProperty(exports, "createGitHub", { enumerable: true, get: function () { return createGitHub_1.createGitHub; } });
|
|
6
|
+
var GitHub_1 = require("./GitHub");
|
|
7
|
+
Object.defineProperty(exports, "GitHub", { enumerable: true, get: function () { return GitHub_1.GitHub; } });
|
|
8
|
+
var PullRequestCreator_1 = require("./PullRequestCreator");
|
|
9
|
+
Object.defineProperty(exports, "PullRequestCreator", { enumerable: true, get: function () { return PullRequestCreator_1.PullRequestCreator; } });
|
|
10
|
+
var RemoteBranchExistenceChecker_1 = require("./RemoteBranchExistenceChecker");
|
|
11
|
+
Object.defineProperty(exports, "RemoteBranchExistenceChecker", { enumerable: true, get: function () { return RemoteBranchExistenceChecker_1.RemoteBranchExistenceChecker; } });
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLogger = void 0;
|
|
4
|
+
const log4js_1 = require("log4js");
|
|
5
|
+
// TODO: add test
|
|
6
|
+
const createLogger = (logLevel) => {
|
|
7
|
+
const logger = (0, log4js_1.getLogger)();
|
|
8
|
+
logger.level = logLevel;
|
|
9
|
+
return logger;
|
|
10
|
+
};
|
|
11
|
+
exports.createLogger = createLogger;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createLogger = void 0;
|
|
4
|
+
var createLogger_1 = require("./createLogger");
|
|
5
|
+
Object.defineProperty(exports, "createLogger", { enumerable: true, get: function () { return createLogger_1.createLogger; } });
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.main = void 0;
|
|
4
|
+
const git_1 = require("./git");
|
|
5
|
+
const github_1 = require("./github");
|
|
6
|
+
const ncu_1 = require("./ncu");
|
|
7
|
+
const outdated_package_processor_1 = require("./outdated-package-processor");
|
|
8
|
+
const outdated_packages_processor_1 = require("./outdated-packages-processor");
|
|
9
|
+
const package_manager_1 = require("./package-manager");
|
|
10
|
+
const terminal_1 = require("./terminal");
|
|
11
|
+
// TODO: add test
|
|
12
|
+
const main = async ({ options, logger }) => {
|
|
13
|
+
logger.debug(`options=${JSON.stringify(options)}`);
|
|
14
|
+
const ncu = new ncu_1.Ncu();
|
|
15
|
+
const outdatedPackages = await ncu.check();
|
|
16
|
+
logger.debug(`outdatedPackages=${JSON.stringify(outdatedPackages)}`);
|
|
17
|
+
if (outdatedPackages.length === 0) {
|
|
18
|
+
logger.info('All packages are up-to-date.');
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
logger.info(`There are ${outdatedPackages.length} outdated packages.`);
|
|
22
|
+
const terminal = new terminal_1.Terminal();
|
|
23
|
+
const git = new git_1.Git(terminal);
|
|
24
|
+
const gitRepo = await git.getRepository();
|
|
25
|
+
logger.debug(`gitRepo=${JSON.stringify(gitRepo)}`);
|
|
26
|
+
const github = (0, github_1.createGitHub)({
|
|
27
|
+
repository: gitRepo,
|
|
28
|
+
token: options.githubToken
|
|
29
|
+
});
|
|
30
|
+
const githubRepo = await github.fetchRepository({
|
|
31
|
+
owner: gitRepo.owner,
|
|
32
|
+
repo: gitRepo.name
|
|
33
|
+
});
|
|
34
|
+
logger.debug(`githubRepo=${JSON.stringify(githubRepo)}`);
|
|
35
|
+
const remoteBranches = await github.fetchBranches({
|
|
36
|
+
owner: gitRepo.owner,
|
|
37
|
+
repo: gitRepo.name
|
|
38
|
+
});
|
|
39
|
+
logger.debug(`remoteBranches=${JSON.stringify(remoteBranches)}`);
|
|
40
|
+
const remoteBranchExistenceChecker = github_1.RemoteBranchExistenceChecker.of(remoteBranches);
|
|
41
|
+
const committer = new git_1.Committer({
|
|
42
|
+
git,
|
|
43
|
+
user: {
|
|
44
|
+
name: options.gitUserName,
|
|
45
|
+
email: options.gitUserEmail
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
const packageManager = (0, package_manager_1.createPackageManager)({
|
|
49
|
+
terminal,
|
|
50
|
+
packageManager: options.packageManager
|
|
51
|
+
});
|
|
52
|
+
const pullRequestCreator = new github_1.PullRequestCreator({
|
|
53
|
+
github,
|
|
54
|
+
gitRepo,
|
|
55
|
+
githubRepo,
|
|
56
|
+
logger
|
|
57
|
+
});
|
|
58
|
+
const outdatedPackageProcessor = new outdated_package_processor_1.OutdatedPackageProcessor({
|
|
59
|
+
committer,
|
|
60
|
+
git,
|
|
61
|
+
ncu,
|
|
62
|
+
packageManager,
|
|
63
|
+
pullRequestCreator,
|
|
64
|
+
remoteBranchExistenceChecker,
|
|
65
|
+
logger
|
|
66
|
+
});
|
|
67
|
+
const outdatedPackagesProcessor = new outdated_packages_processor_1.OutdatedPackagesProcessor({
|
|
68
|
+
outdatedPackageProcessor,
|
|
69
|
+
logger
|
|
70
|
+
});
|
|
71
|
+
const results = await outdatedPackagesProcessor.process(outdatedPackages);
|
|
72
|
+
logger.debug(`results=${JSON.stringify(results)}`);
|
|
73
|
+
const updatedPackages = results
|
|
74
|
+
.filter(({ updated }) => updated)
|
|
75
|
+
.map(({ outdatedPackage }) => outdatedPackage);
|
|
76
|
+
logger.debug(`updatedPackages=${JSON.stringify(updatedPackages)}`);
|
|
77
|
+
const skippedPackages = results
|
|
78
|
+
.filter(({ skipped }) => skipped)
|
|
79
|
+
.map(({ outdatedPackage }) => outdatedPackage);
|
|
80
|
+
logger.debug(`skippedPackages=${JSON.stringify(skippedPackages)}`);
|
|
81
|
+
logger.info(`${updatedPackages.length} packages has updated. ${skippedPackages.length} packages has skipped.`);
|
|
82
|
+
};
|
|
83
|
+
exports.main = main;
|