npm-update-package 0.31.3 → 0.33.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 +1 -1
- package/dist/package.json +7 -7
- package/dist/src/options/cliOptions.js +1 -1
- package/package.json +7 -7
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -23
- package/.github/renovate.json +0 -15
- package/.github/workflows/eslint.yml +0 -14
- package/.github/workflows/test.yml +0 -20
- package/.husky/pre-commit +0 -4
- package/.nvmrc +0 -1
- package/jest.config.ts +0 -12
- package/lint-staged.config.js +0 -4
- package/npm-update-package.code-workspace +0 -10
- package/src/bin.ts +0 -22
- package/src/core/FailedResult.ts +0 -6
- package/src/core/OutdatedPackage.ts +0 -11
- package/src/core/OutdatedPackageProcessor.ts +0 -136
- package/src/core/OutdatedPackagesProcessor.ts +0 -35
- package/src/core/SucceededResult.ts +0 -7
- package/src/core/index.ts +0 -5
- package/src/file/index.ts +0 -1
- package/src/file/readFile.ts +0 -6
- package/src/git/CommitMessageCreator.test.ts +0 -17
- package/src/git/CommitMessageCreator.ts +0 -19
- package/src/git/Git.ts +0 -59
- package/src/git/GitRepository.test.ts +0 -82
- package/src/git/GitRepository.ts +0 -57
- package/src/git/createBranchName.test.ts +0 -14
- package/src/git/createBranchName.ts +0 -7
- package/src/git/index.ts +0 -4
- package/src/github/GitHub.ts +0 -198
- package/src/github/branch/finder/BranchFinder.test.ts +0 -21
- package/src/github/branch/finder/BranchFinder.ts +0 -9
- package/src/github/branch/finder/index.ts +0 -1
- package/src/github/branch/index.ts +0 -1
- package/src/github/createGitHub.test.ts +0 -16
- package/src/github/createGitHub.ts +0 -17
- package/src/github/createOctokit.test.ts +0 -27
- package/src/github/createOctokit.ts +0 -27
- package/src/github/errors/NotFoundError.ts +0 -11
- package/src/github/errors/index.ts +0 -1
- package/src/github/index.ts +0 -5
- package/src/github/label/creator/LabelCreator.ts +0 -71
- package/src/github/label/creator/index.ts +0 -1
- package/src/github/label/index.ts +0 -1
- package/src/github/pull-request/closer/PullRequestCloser.test.ts +0 -53
- package/src/github/pull-request/closer/PullRequestCloser.ts +0 -21
- package/src/github/pull-request/closer/index.ts +0 -1
- package/src/github/pull-request/creator/PullRequestCreator.test.ts +0 -98
- package/src/github/pull-request/creator/PullRequestCreator.ts +0 -84
- package/src/github/pull-request/creator/PullRequestTitleCreator.test.ts +0 -17
- package/src/github/pull-request/creator/PullRequestTitleCreator.ts +0 -19
- package/src/github/pull-request/creator/createPullRequestBody.test.ts +0 -47
- package/src/github/pull-request/creator/createPullRequestBody.ts +0 -35
- package/src/github/pull-request/creator/index.ts +0 -2
- package/src/github/pull-request/finder/PullRequestFinder.ts +0 -27
- package/src/github/pull-request/finder/index.ts +0 -1
- package/src/github/pull-request/finder/isPullRequestByNpmUpdatePackage.test.ts +0 -24
- package/src/github/pull-request/finder/isPullRequestByNpmUpdatePackage.ts +0 -5
- package/src/github/pull-request/index.ts +0 -3
- package/src/github/pull-request/metadata/PullRequestMetadata.ts +0 -22
- package/src/github/pull-request/metadata/createPullRequestMetadata.test.ts +0 -31
- package/src/github/pull-request/metadata/createPullRequestMetadata.ts +0 -21
- package/src/github/pull-request/metadata/extractPullRequestMetadata.test.ts +0 -53
- package/src/github/pull-request/metadata/extractPullRequestMetadata.ts +0 -21
- package/src/github/pull-request/metadata/index.ts +0 -3
- package/src/json/index.ts +0 -1
- package/src/json/toJSON.test.ts +0 -65
- package/src/json/toJSON.ts +0 -13
- package/src/logger/LogLevel.ts +0 -13
- package/src/logger/Logger.ts +0 -1
- package/src/logger/createLogger.ts +0 -10
- package/src/logger/index.ts +0 -3
- package/src/main.ts +0 -149
- package/src/ncu/Ncu.ts +0 -84
- package/src/ncu/NcuResult.ts +0 -10
- package/src/ncu/index.ts +0 -1
- package/src/options/CLIOption.ts +0 -19
- package/src/options/OptionType.ts +0 -8
- package/src/options/Options.ts +0 -40
- package/src/options/cliOptions.ts +0 -60
- package/src/options/index.ts +0 -2
- package/src/options/initOptions.ts +0 -24
- package/src/options/toCommanderOption.ts +0 -35
- package/src/package-json/PackageMetadata.ts +0 -24
- package/src/package-json/PackageMetadataDependencies.ts +0 -10
- package/src/package-json/index.ts +0 -2
- package/src/package-json/parsePackageJson.ts +0 -15
- package/src/package-manager/Npm.ts +0 -17
- package/src/package-manager/PackageManager.ts +0 -5
- package/src/package-manager/PackageManagerName.ts +0 -8
- package/src/package-manager/Yarn.ts +0 -17
- package/src/package-manager/createPackageManager.test.ts +0 -27
- package/src/package-manager/createPackageManager.ts +0 -20
- package/src/package-manager/index.ts +0 -5
- package/src/semver/SemVer.test.ts +0 -17
- package/src/semver/SemVer.ts +0 -40
- package/src/semver/SemVerLevel.ts +0 -9
- package/src/semver/compareSemVers.test.ts +0 -21
- package/src/semver/compareSemVers.ts +0 -16
- package/src/semver/index.ts +0 -3
- package/src/terminal/Terminal.ts +0 -12
- package/src/terminal/index.ts +0 -1
- package/tsconfig.base.json +0 -7
- package/tsconfig.build.json +0 -12
- package/tsconfig.json +0 -9
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ Commit message template
|
|
|
27
27
|
- `newVersion`: new package version
|
|
28
28
|
- `packageName`: package name
|
|
29
29
|
- `level`: semver level (major/minor/patch)
|
|
30
|
-
- default: `chore(deps): {{level}} update {{{packageName}}} to v{{newVersion}}`
|
|
30
|
+
- default: `chore(deps): {{{level}}} update {{{packageName}}} to v{{{newVersion}}}`
|
|
31
31
|
|
|
32
32
|
### `--github-token`
|
|
33
33
|
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-update-package",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.0",
|
|
4
4
|
"description": "CLI tool for creating pull requests to update npm packages",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc --project tsconfig.build.json",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"io-ts": "2.2.16",
|
|
23
23
|
"log4js": "6.4.1",
|
|
24
24
|
"mustache": "4.1.0",
|
|
25
|
-
"npm-check-updates": "12.
|
|
25
|
+
"npm-check-updates": "12.4.0",
|
|
26
26
|
"parse-github-url": "1.0.2",
|
|
27
27
|
"semver": "7.3.5",
|
|
28
28
|
"type-guards": "0.15.0"
|
|
@@ -35,21 +35,21 @@
|
|
|
35
35
|
"@types/node": "12.20.40",
|
|
36
36
|
"@types/parse-github-url": "1.0.0",
|
|
37
37
|
"@types/semver": "7.3.9",
|
|
38
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
39
|
-
"eslint": "8.
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "5.12.0",
|
|
39
|
+
"eslint": "8.9.0",
|
|
40
40
|
"eslint-config-standard-with-typescript": "21.0.1",
|
|
41
41
|
"eslint-plugin-import": "2.25.4",
|
|
42
|
-
"eslint-plugin-jest": "26.
|
|
42
|
+
"eslint-plugin-jest": "26.1.1",
|
|
43
43
|
"eslint-plugin-node": "11.1.0",
|
|
44
44
|
"eslint-plugin-promise": "6.0.0",
|
|
45
45
|
"eslint-plugin-tsdoc": "0.2.14",
|
|
46
46
|
"husky": "7.0.4",
|
|
47
47
|
"jest": "27.4.7",
|
|
48
|
-
"lint-staged": "12.3.
|
|
48
|
+
"lint-staged": "12.3.4",
|
|
49
49
|
"npm-run-all": "4.1.5",
|
|
50
50
|
"rimraf": "3.0.2",
|
|
51
51
|
"ts-jest": "27.1.3",
|
|
52
|
-
"ts-node": "10.
|
|
52
|
+
"ts-node": "10.5.0",
|
|
53
53
|
"typescript": "4.5.5",
|
|
54
54
|
"utility-types": "3.10.0"
|
|
55
55
|
},
|
|
@@ -10,7 +10,7 @@ exports.cliOptions = [
|
|
|
10
10
|
description: 'Commit message template',
|
|
11
11
|
type: OptionType_1.OptionType.String,
|
|
12
12
|
required: false,
|
|
13
|
-
default: 'chore(deps): {{level}} update {{{packageName}}} to v{{newVersion}}'
|
|
13
|
+
default: 'chore(deps): {{{level}}} update {{{packageName}}} to v{{{newVersion}}}'
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
16
|
name: 'github-token',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-update-package",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.0",
|
|
4
4
|
"description": "CLI tool for creating pull requests to update npm packages",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc --project tsconfig.build.json",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"io-ts": "2.2.16",
|
|
23
23
|
"log4js": "6.4.1",
|
|
24
24
|
"mustache": "4.1.0",
|
|
25
|
-
"npm-check-updates": "12.
|
|
25
|
+
"npm-check-updates": "12.4.0",
|
|
26
26
|
"parse-github-url": "1.0.2",
|
|
27
27
|
"semver": "7.3.5",
|
|
28
28
|
"type-guards": "0.15.0"
|
|
@@ -35,21 +35,21 @@
|
|
|
35
35
|
"@types/node": "12.20.40",
|
|
36
36
|
"@types/parse-github-url": "1.0.0",
|
|
37
37
|
"@types/semver": "7.3.9",
|
|
38
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
39
|
-
"eslint": "8.
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "5.12.0",
|
|
39
|
+
"eslint": "8.9.0",
|
|
40
40
|
"eslint-config-standard-with-typescript": "21.0.1",
|
|
41
41
|
"eslint-plugin-import": "2.25.4",
|
|
42
|
-
"eslint-plugin-jest": "26.
|
|
42
|
+
"eslint-plugin-jest": "26.1.1",
|
|
43
43
|
"eslint-plugin-node": "11.1.0",
|
|
44
44
|
"eslint-plugin-promise": "6.0.0",
|
|
45
45
|
"eslint-plugin-tsdoc": "0.2.14",
|
|
46
46
|
"husky": "7.0.4",
|
|
47
47
|
"jest": "27.4.7",
|
|
48
|
-
"lint-staged": "12.3.
|
|
48
|
+
"lint-staged": "12.3.4",
|
|
49
49
|
"npm-run-all": "4.1.5",
|
|
50
50
|
"rimraf": "3.0.2",
|
|
51
51
|
"ts-jest": "27.1.3",
|
|
52
|
-
"ts-node": "10.
|
|
52
|
+
"ts-node": "10.5.0",
|
|
53
53
|
"typescript": "4.5.5",
|
|
54
54
|
"utility-types": "3.10.0"
|
|
55
55
|
},
|
package/.eslintignore
DELETED
package/.eslintrc.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
}
|
package/.github/renovate.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
# https://nodejs.org/en/about/releases/
|
|
11
|
-
node-version: ['12', '14', '16']
|
|
12
|
-
steps:
|
|
13
|
-
- uses: actions/checkout@v2
|
|
14
|
-
- name: Use Node.js ${{ matrix.node-version }}
|
|
15
|
-
uses: actions/setup-node@v2
|
|
16
|
-
with:
|
|
17
|
-
node-version: ${{ matrix.node-version }}
|
|
18
|
-
- run: npm ci
|
|
19
|
-
- run: npm run build --if-present
|
|
20
|
-
- run: npm test
|
package/.husky/pre-commit
DELETED
package/.nvmrc
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
12.20.2
|
package/jest.config.ts
DELETED
package/lint-staged.config.js
DELETED
package/src/bin.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import pkg from '../package.json'
|
|
4
|
-
import { createLogger } from './logger'
|
|
5
|
-
import { main } from './main'
|
|
6
|
-
import { initOptions } from './options'
|
|
7
|
-
|
|
8
|
-
const options = initOptions()
|
|
9
|
-
const logger = createLogger(options.logLevel)
|
|
10
|
-
logger.info(`Start ${pkg.name} v${pkg.version}`)
|
|
11
|
-
|
|
12
|
-
main({
|
|
13
|
-
options,
|
|
14
|
-
logger
|
|
15
|
-
})
|
|
16
|
-
.then(() => {
|
|
17
|
-
logger.info(`End ${pkg.name} v${pkg.version}`)
|
|
18
|
-
})
|
|
19
|
-
.catch((error: unknown) => {
|
|
20
|
-
logger.fatal(error)
|
|
21
|
-
throw error
|
|
22
|
-
})
|
package/src/core/FailedResult.ts
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
left,
|
|
3
|
-
right,
|
|
4
|
-
type Either
|
|
5
|
-
} from 'fp-ts/lib/Either'
|
|
6
|
-
import {
|
|
7
|
-
createBranchName,
|
|
8
|
-
type CommitMessageCreator,
|
|
9
|
-
type Git
|
|
10
|
-
} from '../git'
|
|
11
|
-
import type {
|
|
12
|
-
BranchFinder,
|
|
13
|
-
PullRequestCloser,
|
|
14
|
-
PullRequestCreator,
|
|
15
|
-
PullRequestFinder
|
|
16
|
-
} from '../github'
|
|
17
|
-
import type { Logger } from '../logger'
|
|
18
|
-
import type { Ncu } from '../ncu'
|
|
19
|
-
import type { PackageManager } from '../package-manager'
|
|
20
|
-
import type { FailedResult } from './FailedResult'
|
|
21
|
-
import type { OutdatedPackage } from './OutdatedPackage'
|
|
22
|
-
import type { SucceededResult } from './SucceededResult'
|
|
23
|
-
|
|
24
|
-
// TODO: add test
|
|
25
|
-
export class OutdatedPackageProcessor {
|
|
26
|
-
private readonly git: Git
|
|
27
|
-
private readonly ncu: Ncu
|
|
28
|
-
private readonly packageManager: PackageManager
|
|
29
|
-
private readonly pullRequestCreator: PullRequestCreator
|
|
30
|
-
private readonly branchFinder: BranchFinder
|
|
31
|
-
private readonly logger: Logger
|
|
32
|
-
private readonly commitMessageCreator: CommitMessageCreator
|
|
33
|
-
private readonly pullRequestFinder: PullRequestFinder
|
|
34
|
-
private readonly pullRequestCloser: PullRequestCloser
|
|
35
|
-
|
|
36
|
-
constructor ({
|
|
37
|
-
git,
|
|
38
|
-
ncu,
|
|
39
|
-
packageManager,
|
|
40
|
-
pullRequestCreator,
|
|
41
|
-
branchFinder,
|
|
42
|
-
logger,
|
|
43
|
-
commitMessageCreator,
|
|
44
|
-
pullRequestFinder,
|
|
45
|
-
pullRequestCloser
|
|
46
|
-
}: {
|
|
47
|
-
git: Git
|
|
48
|
-
ncu: Ncu
|
|
49
|
-
packageManager: PackageManager
|
|
50
|
-
pullRequestCreator: PullRequestCreator
|
|
51
|
-
branchFinder: BranchFinder
|
|
52
|
-
logger: Logger
|
|
53
|
-
commitMessageCreator: CommitMessageCreator
|
|
54
|
-
pullRequestFinder: PullRequestFinder
|
|
55
|
-
pullRequestCloser: PullRequestCloser
|
|
56
|
-
}) {
|
|
57
|
-
this.git = git
|
|
58
|
-
this.ncu = ncu
|
|
59
|
-
this.packageManager = packageManager
|
|
60
|
-
this.pullRequestCreator = pullRequestCreator
|
|
61
|
-
this.branchFinder = branchFinder
|
|
62
|
-
this.logger = logger
|
|
63
|
-
this.commitMessageCreator = commitMessageCreator
|
|
64
|
-
this.pullRequestFinder = pullRequestFinder
|
|
65
|
-
this.pullRequestCloser = pullRequestCloser
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Don't run in parallel because it includes file operations.
|
|
70
|
-
*/
|
|
71
|
-
async process (outdatedPackage: OutdatedPackage): Promise<Either<FailedResult, SucceededResult>> {
|
|
72
|
-
const branchName = createBranchName(outdatedPackage)
|
|
73
|
-
this.logger.debug(`branchName=${branchName}`)
|
|
74
|
-
|
|
75
|
-
if (this.branchFinder.findByName(branchName) !== undefined) {
|
|
76
|
-
this.logger.info(`Skip ${outdatedPackage.name} because ${branchName} branch already exists on remote.`)
|
|
77
|
-
return right({
|
|
78
|
-
outdatedPackage,
|
|
79
|
-
skipped: true
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
await this.git.createBranch(branchName)
|
|
84
|
-
this.logger.info(`${branchName} branch has created.`)
|
|
85
|
-
|
|
86
|
-
try {
|
|
87
|
-
try {
|
|
88
|
-
const updatedPackages = await this.ncu.update(outdatedPackage)
|
|
89
|
-
|
|
90
|
-
if (updatedPackages.length !== 1) {
|
|
91
|
-
throw new Error(`Failed to update ${outdatedPackage.name}.`)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
await this.packageManager.install()
|
|
95
|
-
} catch (error) {
|
|
96
|
-
this.logger.error(error)
|
|
97
|
-
return left({
|
|
98
|
-
outdatedPackage,
|
|
99
|
-
error
|
|
100
|
-
})
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
this.logger.info(`${outdatedPackage.name} has updated from v${outdatedPackage.currentVersion.version} to v${outdatedPackage.newVersion.version}`)
|
|
104
|
-
|
|
105
|
-
await this.git.add(this.packageManager.packageFile, this.packageManager.lockFile)
|
|
106
|
-
const message = this.commitMessageCreator.create(outdatedPackage)
|
|
107
|
-
this.logger.debug(`message=${message}`)
|
|
108
|
-
|
|
109
|
-
await this.git.commit(message)
|
|
110
|
-
await this.git.push(branchName)
|
|
111
|
-
|
|
112
|
-
const pullRequest = await this.pullRequestCreator.create({
|
|
113
|
-
outdatedPackage,
|
|
114
|
-
branchName
|
|
115
|
-
})
|
|
116
|
-
this.logger.info(`Pull request for ${outdatedPackage.name} has created. ${pullRequest.html_url}`)
|
|
117
|
-
|
|
118
|
-
const pullRequests = this.pullRequestFinder.findByPackageName(outdatedPackage.name)
|
|
119
|
-
this.logger.debug(`pullRequests=${JSON.stringify(pullRequests)}`)
|
|
120
|
-
|
|
121
|
-
await Promise.all(pullRequests.map(async (pullRequest) => {
|
|
122
|
-
await this.pullRequestCloser.close(pullRequest)
|
|
123
|
-
this.logger.info(`Pull request for ${outdatedPackage.name} has closed. ${pullRequest.html_url}`)
|
|
124
|
-
}))
|
|
125
|
-
return right({
|
|
126
|
-
outdatedPackage,
|
|
127
|
-
created: true
|
|
128
|
-
})
|
|
129
|
-
} finally {
|
|
130
|
-
await this.git.restore(this.packageManager.packageFile, this.packageManager.lockFile)
|
|
131
|
-
await this.git.switch('-')
|
|
132
|
-
await this.git.removeBranch(branchName)
|
|
133
|
-
this.logger.info(`${branchName} branch has removed.`)
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { Either } from 'fp-ts/lib/Either'
|
|
2
|
-
import type { Logger } from '../logger'
|
|
3
|
-
import type { FailedResult } from './FailedResult'
|
|
4
|
-
import type { OutdatedPackage } from './OutdatedPackage'
|
|
5
|
-
import type { OutdatedPackageProcessor } from './OutdatedPackageProcessor'
|
|
6
|
-
import type { SucceededResult } from './SucceededResult'
|
|
7
|
-
|
|
8
|
-
// TODO: add test
|
|
9
|
-
export class OutdatedPackagesProcessor {
|
|
10
|
-
private readonly outdatedPackageProcessor: OutdatedPackageProcessor
|
|
11
|
-
private readonly logger: Logger
|
|
12
|
-
|
|
13
|
-
constructor ({
|
|
14
|
-
outdatedPackageProcessor,
|
|
15
|
-
logger
|
|
16
|
-
}: {
|
|
17
|
-
outdatedPackageProcessor: OutdatedPackageProcessor
|
|
18
|
-
logger: Logger
|
|
19
|
-
}) {
|
|
20
|
-
this.outdatedPackageProcessor = outdatedPackageProcessor
|
|
21
|
-
this.logger = logger
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async process (outdatedPackages: OutdatedPackage[]): Promise<Array<Either<FailedResult, SucceededResult>>> {
|
|
25
|
-
const results: Array<Either<FailedResult, SucceededResult>> = []
|
|
26
|
-
|
|
27
|
-
for (const outdatedPackage of outdatedPackages) {
|
|
28
|
-
this.logger.debug(`outdatedPackage=${JSON.stringify(outdatedPackage)}`)
|
|
29
|
-
const result = await this.outdatedPackageProcessor.process(outdatedPackage)
|
|
30
|
-
results.push(result)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return results
|
|
34
|
-
}
|
|
35
|
-
}
|
package/src/core/index.ts
DELETED
package/src/file/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './readFile'
|
package/src/file/readFile.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { SemVer } from '../semver'
|
|
2
|
-
import { CommitMessageCreator } from './CommitMessageCreator'
|
|
3
|
-
|
|
4
|
-
describe('CommitMessageCreator', () => {
|
|
5
|
-
describe('create', () => {
|
|
6
|
-
it('returns commit message', () => {
|
|
7
|
-
const commitMessageCreator = new CommitMessageCreator('chore(deps): {{level}} update {{{packageName}}} from {{currentVersion}} to v{{newVersion}}')
|
|
8
|
-
const actual = commitMessageCreator.create({
|
|
9
|
-
name: '@npm-update-package/example',
|
|
10
|
-
currentVersion: SemVer.of('1.0.0'),
|
|
11
|
-
newVersion: SemVer.of('2.0.0'),
|
|
12
|
-
level: 'major'
|
|
13
|
-
})
|
|
14
|
-
expect(actual).toBe('chore(deps): major update @npm-update-package/example from 1.0.0 to v2.0.0')
|
|
15
|
-
})
|
|
16
|
-
})
|
|
17
|
-
})
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { render } from 'mustache'
|
|
2
|
-
import type { OutdatedPackage } from '../core'
|
|
3
|
-
|
|
4
|
-
export class CommitMessageCreator {
|
|
5
|
-
constructor (private readonly template: string) {}
|
|
6
|
-
|
|
7
|
-
create (outdatedPackage: OutdatedPackage): string {
|
|
8
|
-
const packageName = outdatedPackage.name
|
|
9
|
-
const currentVersion = outdatedPackage.currentVersion.version
|
|
10
|
-
const newVersion = outdatedPackage.newVersion.version
|
|
11
|
-
const level = outdatedPackage.level
|
|
12
|
-
return render(this.template, {
|
|
13
|
-
packageName,
|
|
14
|
-
currentVersion,
|
|
15
|
-
newVersion,
|
|
16
|
-
level
|
|
17
|
-
})
|
|
18
|
-
}
|
|
19
|
-
}
|
package/src/git/Git.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import type { Terminal } from '../terminal'
|
|
2
|
-
import { GitRepository } from './GitRepository'
|
|
3
|
-
|
|
4
|
-
// TODO: add test
|
|
5
|
-
export class Git {
|
|
6
|
-
constructor (private readonly terminal: Terminal) {}
|
|
7
|
-
|
|
8
|
-
async add (...files: string[]): Promise<void> {
|
|
9
|
-
await this.terminal.run('git', 'add', ...files)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
async commit (message: string): Promise<void> {
|
|
13
|
-
await this.terminal.run('git', 'commit', '--message', message)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async createBranch (branchName: string): Promise<void> {
|
|
17
|
-
await this.terminal.run('git', 'checkout', '-b', branchName)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async getConfig (key: string): Promise<string> {
|
|
21
|
-
const { stdout } = await this.terminal.run('git', 'config', key)
|
|
22
|
-
return stdout.trim()
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async getCurrentBranch (): Promise<string> {
|
|
26
|
-
const { stdout } = await this.terminal.run('git', 'rev-parse', '--abbrev-ref', 'HEAD')
|
|
27
|
-
return stdout.trim()
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async getRemoteUrl (): Promise<string> {
|
|
31
|
-
const { stdout } = await this.terminal.run('git', 'remote', 'get-url', '--push', 'origin')
|
|
32
|
-
return stdout.trim()
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async getRepository (): Promise<GitRepository> {
|
|
36
|
-
const url = await this.getRemoteUrl()
|
|
37
|
-
return GitRepository.of(url)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async push (branchName: string): Promise<void> {
|
|
41
|
-
await this.terminal.run('git', 'push', 'origin', branchName)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async removeBranch (branchName: string): Promise<void> {
|
|
45
|
-
await this.terminal.run('git', 'branch', '-D', branchName)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async restore (...files: string[]): Promise<void> {
|
|
49
|
-
await this.terminal.run('git', 'checkout', ...files)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async setConfig (key: string, value: string): Promise<void> {
|
|
53
|
-
await this.terminal.run('git', 'config', key, value)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async switch (branchName: string): Promise<void> {
|
|
57
|
-
await this.terminal.run('git', 'checkout', branchName)
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { GitRepository } from './GitRepository'
|
|
2
|
-
|
|
3
|
-
describe('GitRepository', () => {
|
|
4
|
-
describe('of', () => {
|
|
5
|
-
describe('returns new GitRepository instance if URL is valid', () => {
|
|
6
|
-
type TestCase = [
|
|
7
|
-
string,
|
|
8
|
-
{
|
|
9
|
-
host: string
|
|
10
|
-
owner: string
|
|
11
|
-
name: string
|
|
12
|
-
apiEndPoint: string
|
|
13
|
-
isGitHubDotCom: boolean
|
|
14
|
-
}
|
|
15
|
-
]
|
|
16
|
-
const cases: TestCase[] = [
|
|
17
|
-
[
|
|
18
|
-
'https://github.com/npm-update-package/npm-update-package.git',
|
|
19
|
-
{
|
|
20
|
-
host: 'github.com',
|
|
21
|
-
owner: 'npm-update-package',
|
|
22
|
-
name: 'npm-update-package',
|
|
23
|
-
apiEndPoint: 'https://api.github.com',
|
|
24
|
-
isGitHubDotCom: true
|
|
25
|
-
}
|
|
26
|
-
],
|
|
27
|
-
[
|
|
28
|
-
'git@github.com:npm-update-package/npm-update-package.git',
|
|
29
|
-
{
|
|
30
|
-
host: 'github.com',
|
|
31
|
-
owner: 'npm-update-package',
|
|
32
|
-
name: 'npm-update-package',
|
|
33
|
-
apiEndPoint: 'https://api.github.com',
|
|
34
|
-
isGitHubDotCom: true
|
|
35
|
-
}
|
|
36
|
-
],
|
|
37
|
-
[
|
|
38
|
-
'https://git.example.com/npm-update-package/npm-update-package.git',
|
|
39
|
-
{
|
|
40
|
-
host: 'git.example.com',
|
|
41
|
-
owner: 'npm-update-package',
|
|
42
|
-
name: 'npm-update-package',
|
|
43
|
-
apiEndPoint: 'https://git.example.com/api/v3',
|
|
44
|
-
isGitHubDotCom: false
|
|
45
|
-
}
|
|
46
|
-
],
|
|
47
|
-
[
|
|
48
|
-
'git@git.example.com:npm-update-package/npm-update-package.git',
|
|
49
|
-
{
|
|
50
|
-
host: 'git.example.com',
|
|
51
|
-
owner: 'npm-update-package',
|
|
52
|
-
name: 'npm-update-package',
|
|
53
|
-
apiEndPoint: 'https://git.example.com/api/v3',
|
|
54
|
-
isGitHubDotCom: false
|
|
55
|
-
}
|
|
56
|
-
]
|
|
57
|
-
]
|
|
58
|
-
|
|
59
|
-
it.each<TestCase>(cases)('url=%p', (url, expected) => {
|
|
60
|
-
const actual = GitRepository.of(url)
|
|
61
|
-
expect(actual).toBeInstanceOf(GitRepository)
|
|
62
|
-
expect(actual.host).toBe(expected.host)
|
|
63
|
-
expect(actual.owner).toBe(expected.owner)
|
|
64
|
-
expect(actual.name).toBe(expected.name)
|
|
65
|
-
expect(actual.apiEndPoint).toBe(expected.apiEndPoint)
|
|
66
|
-
expect(actual.isGitHubDotCom).toBe(expected.isGitHubDotCom)
|
|
67
|
-
})
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
describe('throws error if URL is invalid', () => {
|
|
71
|
-
type TestCase = string
|
|
72
|
-
const cases: TestCase[] = [
|
|
73
|
-
'',
|
|
74
|
-
'https://example.com/'
|
|
75
|
-
]
|
|
76
|
-
|
|
77
|
-
it.each<TestCase>(cases)('url=%p', (url) => {
|
|
78
|
-
expect(() => GitRepository.of(url)).toThrow(Error)
|
|
79
|
-
})
|
|
80
|
-
})
|
|
81
|
-
})
|
|
82
|
-
})
|