npm-update-package 0.8.0 → 0.9.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/dist/app.js +1 -1
- package/package.json +10 -6
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -23
- package/.github/FUNDING.yml +0 -2
- package/.github/renovate.json +0 -15
- package/.github/workflows/eslint.yml +0 -14
- package/.github/workflows/test.yml +0 -19
- package/.husky/pre-commit +0 -4
- package/.nvmrc +0 -1
- package/jest.config.ts +0 -11
- package/lint-staged.config.js +0 -4
- package/npm-update-package.code-workspace +0 -8
- package/src/app.ts +0 -5
- package/src/bin.ts +0 -20
- package/src/git/BranchNameCreator.test.ts +0 -17
- package/src/git/BranchNameCreator.ts +0 -19
- package/src/git/CommitMessageCreator.test.ts +0 -17
- package/src/git/CommitMessageCreator.ts +0 -19
- package/src/git/Committer.ts +0 -49
- package/src/git/Git.ts +0 -55
- package/src/git/GitRepository.test.ts +0 -61
- package/src/git/GitRepository.ts +0 -57
- package/src/git/index.ts +0 -5
- package/src/github/Branch.ts +0 -4
- package/src/github/GitHub.ts +0 -27
- package/src/github/PullRequest.ts +0 -3
- package/src/github/PullRequestBodyCreator.test.ts +0 -32
- package/src/github/PullRequestBodyCreator.ts +0 -26
- package/src/github/PullRequestCreator.ts +0 -65
- package/src/github/PullRequestTitleCreator.test.ts +0 -17
- package/src/github/PullRequestTitleCreator.ts +0 -19
- package/src/github/RemoteBranchExistenceChecker.ts +0 -15
- package/src/github/Repository.ts +0 -3
- package/src/github/createGitHub.ts +0 -18
- package/src/github/createOctokit.ts +0 -28
- package/src/github/index.ts +0 -9
- package/src/logger/LogLevel.ts +0 -8
- package/src/logger/Logger.ts +0 -1
- package/src/logger/createLogger.ts +0 -10
- package/src/logger/index.ts +0 -6
- package/src/main.ts +0 -128
- package/src/ncu/Ncu.ts +0 -43
- package/src/ncu/NcuOutdatedPackages.ts +0 -6
- package/src/ncu/NcuOutdatedPackagesConverter.ts +0 -25
- package/src/ncu/OutdatedPackage.ts +0 -9
- package/src/ncu/PackageVersion.test.ts +0 -25
- package/src/ncu/PackageVersion.ts +0 -40
- package/src/ncu/UpdateType.ts +0 -9
- package/src/ncu/index.ts +0 -7
- package/src/ncu/isNcuOutdatedPackages.ts +0 -6
- package/src/ncu/toUpdateType.test.ts +0 -21
- package/src/ncu/toUpdateType.ts +0 -18
- package/src/options/Options.ts +0 -30
- package/src/options/index.ts +0 -2
- package/src/options/initOptions.ts +0 -53
- package/src/package-json/Package.ts +0 -24
- package/src/package-json/PackageDependencies.ts +0 -10
- package/src/package-json/PackageJsonParser.ts +0 -19
- package/src/package-json/PackageJsonReader.ts +0 -27
- package/src/package-json/index.ts +0 -3
- package/src/package-manager/Npm.ts +0 -19
- package/src/package-manager/PackageManager.ts +0 -4
- package/src/package-manager/PackageManagerName.ts +0 -8
- package/src/package-manager/Yarn.ts +0 -19
- package/src/package-manager/createPackageManager.ts +0 -21
- package/src/package-manager/index.ts +0 -8
- package/src/processors/OutdatedPackageProcessor.ts +0 -109
- package/src/processors/OutdatedPackagesProcessor.ts +0 -32
- package/src/processors/Result.ts +0 -7
- package/src/processors/index.ts +0 -2
- package/src/terminal/Terminal.ts +0 -30
- package/src/terminal/index.ts +0 -1
- package/src/terminal/isExecaReturnValue.ts +0 -30
- package/tsconfig.base.json +0 -3
- package/tsconfig.build.json +0 -13
- package/tsconfig.json +0 -9
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { PackageVersion } from '../ncu'
|
|
2
|
-
import { PullRequestTitleCreator } from './PullRequestTitleCreator'
|
|
3
|
-
|
|
4
|
-
describe('PullRequestTitleCreator', () => {
|
|
5
|
-
describe('create', () => {
|
|
6
|
-
it('returns pull request title', () => {
|
|
7
|
-
const pullRequestTitleCreator = new PullRequestTitleCreator('chore(deps): {{updateType}} update {{{packageName}}} from {{currentVersion}} to v{{newVersion}}')
|
|
8
|
-
const actual = pullRequestTitleCreator.create({
|
|
9
|
-
name: '@typescript-eslint/eslint-plugin',
|
|
10
|
-
currentVersion: PackageVersion.of('1.0.0'),
|
|
11
|
-
newVersion: PackageVersion.of('2.0.0'),
|
|
12
|
-
type: 'major'
|
|
13
|
-
})
|
|
14
|
-
expect(actual).toBe('chore(deps): major update @typescript-eslint/eslint-plugin 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 '../ncu'
|
|
3
|
-
|
|
4
|
-
export class PullRequestTitleCreator {
|
|
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 updateType = outdatedPackage.type
|
|
12
|
-
return render(this.template, {
|
|
13
|
-
packageName,
|
|
14
|
-
currentVersion,
|
|
15
|
-
newVersion,
|
|
16
|
-
updateType
|
|
17
|
-
})
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Branch } from './Branch'
|
|
2
|
-
|
|
3
|
-
// TODO: add test
|
|
4
|
-
export class RemoteBranchExistenceChecker {
|
|
5
|
-
constructor (private readonly remoteBranchNames: string[]) {}
|
|
6
|
-
|
|
7
|
-
static of (remoteBranches: Branch[]): RemoteBranchExistenceChecker {
|
|
8
|
-
const remoteBranchNames = remoteBranches.map(({ name }) => name)
|
|
9
|
-
return new RemoteBranchExistenceChecker(remoteBranchNames)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
check (branchName: string): boolean {
|
|
13
|
-
return this.remoteBranchNames.includes(branchName)
|
|
14
|
-
}
|
|
15
|
-
}
|
package/src/github/Repository.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { GitRepository } from '../git'
|
|
2
|
-
import { createOctokit } from './createOctokit'
|
|
3
|
-
import { GitHub } from './GitHub'
|
|
4
|
-
|
|
5
|
-
// TODO: add test
|
|
6
|
-
export const createGitHub = ({
|
|
7
|
-
repository,
|
|
8
|
-
token
|
|
9
|
-
}: {
|
|
10
|
-
repository: GitRepository
|
|
11
|
-
token: string
|
|
12
|
-
}): GitHub => {
|
|
13
|
-
const octokit = createOctokit({
|
|
14
|
-
repository,
|
|
15
|
-
token
|
|
16
|
-
})
|
|
17
|
-
return new GitHub(octokit)
|
|
18
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Octokit } from '@octokit/rest'
|
|
2
|
-
import { app } from '../app'
|
|
3
|
-
import type { GitRepository } from '../git'
|
|
4
|
-
|
|
5
|
-
// TODO: add test
|
|
6
|
-
export const createOctokit = ({
|
|
7
|
-
repository,
|
|
8
|
-
token
|
|
9
|
-
}: {
|
|
10
|
-
repository: GitRepository
|
|
11
|
-
token: string
|
|
12
|
-
}): Octokit => {
|
|
13
|
-
const auth = `token ${token}`
|
|
14
|
-
const userAgent = `${app.name}/${app.version}`
|
|
15
|
-
|
|
16
|
-
if (repository.isGitHubDotCom) {
|
|
17
|
-
return new Octokit({
|
|
18
|
-
auth,
|
|
19
|
-
userAgent
|
|
20
|
-
})
|
|
21
|
-
} else {
|
|
22
|
-
return new Octokit({
|
|
23
|
-
auth,
|
|
24
|
-
userAgent,
|
|
25
|
-
baseUrl: repository.apiEndPoint
|
|
26
|
-
})
|
|
27
|
-
}
|
|
28
|
-
}
|
package/src/github/index.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export type { Branch } from './Branch'
|
|
2
|
-
export { createGitHub } from './createGitHub'
|
|
3
|
-
export { GitHub } from './GitHub'
|
|
4
|
-
export type { PullRequest } from './PullRequest'
|
|
5
|
-
export { PullRequestBodyCreator } from './PullRequestBodyCreator'
|
|
6
|
-
export { PullRequestCreator } from './PullRequestCreator'
|
|
7
|
-
export { PullRequestTitleCreator } from './PullRequestTitleCreator'
|
|
8
|
-
export { RemoteBranchExistenceChecker } from './RemoteBranchExistenceChecker'
|
|
9
|
-
export type { Repository } from './Repository'
|
package/src/logger/LogLevel.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
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)
|
package/src/logger/Logger.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type { Logger } from 'log4js'
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { getLogger } from 'log4js'
|
|
2
|
-
import type { Logger } from './Logger'
|
|
3
|
-
import type { LogLevel } from './LogLevel'
|
|
4
|
-
|
|
5
|
-
// TODO: add test
|
|
6
|
-
export const createLogger = (logLevel: LogLevel): Logger => {
|
|
7
|
-
const logger = getLogger()
|
|
8
|
-
logger.level = logLevel
|
|
9
|
-
return logger
|
|
10
|
-
}
|
package/src/logger/index.ts
DELETED
package/src/main.ts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BranchNameCreator,
|
|
3
|
-
CommitMessageCreator,
|
|
4
|
-
Committer,
|
|
5
|
-
Git
|
|
6
|
-
} from './git'
|
|
7
|
-
import {
|
|
8
|
-
createGitHub,
|
|
9
|
-
PullRequestBodyCreator,
|
|
10
|
-
PullRequestCreator,
|
|
11
|
-
PullRequestTitleCreator,
|
|
12
|
-
RemoteBranchExistenceChecker
|
|
13
|
-
} from './github'
|
|
14
|
-
import type { Logger } from './logger'
|
|
15
|
-
import { Ncu } from './ncu'
|
|
16
|
-
import type { Options } from './options'
|
|
17
|
-
import {
|
|
18
|
-
PackageJsonParser,
|
|
19
|
-
PackageJsonReader
|
|
20
|
-
} from './package-json'
|
|
21
|
-
import { createPackageManager } from './package-manager'
|
|
22
|
-
import {
|
|
23
|
-
OutdatedPackageProcessor,
|
|
24
|
-
OutdatedPackagesProcessor
|
|
25
|
-
} from './processors'
|
|
26
|
-
import { Terminal } from './terminal'
|
|
27
|
-
|
|
28
|
-
// TODO: add test
|
|
29
|
-
export const main = async ({
|
|
30
|
-
options,
|
|
31
|
-
logger
|
|
32
|
-
}: {
|
|
33
|
-
options: Options
|
|
34
|
-
logger: Logger
|
|
35
|
-
}): Promise<void> => {
|
|
36
|
-
logger.debug(`options=${JSON.stringify(options)}`)
|
|
37
|
-
|
|
38
|
-
const packageJsonParser = new PackageJsonParser(logger)
|
|
39
|
-
const packageJsonReader = new PackageJsonReader({
|
|
40
|
-
packageJsonParser,
|
|
41
|
-
logger
|
|
42
|
-
})
|
|
43
|
-
const ncu = new Ncu(packageJsonReader)
|
|
44
|
-
const outdatedPackages = await ncu.check()
|
|
45
|
-
logger.debug(`outdatedPackages=${JSON.stringify(outdatedPackages)}`)
|
|
46
|
-
|
|
47
|
-
if (outdatedPackages.length === 0) {
|
|
48
|
-
logger.info('All packages are up-to-date.')
|
|
49
|
-
return
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
logger.info(`There are ${outdatedPackages.length} outdated packages.`)
|
|
53
|
-
|
|
54
|
-
const terminal = new Terminal()
|
|
55
|
-
const git = new Git(terminal)
|
|
56
|
-
const gitRepo = await git.getRepository()
|
|
57
|
-
logger.debug(`gitRepo=${JSON.stringify(gitRepo)}`)
|
|
58
|
-
|
|
59
|
-
const github = createGitHub({
|
|
60
|
-
repository: gitRepo,
|
|
61
|
-
token: options.githubToken
|
|
62
|
-
})
|
|
63
|
-
const githubRepo = await github.fetchRepository({
|
|
64
|
-
owner: gitRepo.owner,
|
|
65
|
-
repo: gitRepo.name
|
|
66
|
-
})
|
|
67
|
-
logger.debug(`githubRepo=${JSON.stringify(githubRepo)}`)
|
|
68
|
-
|
|
69
|
-
const remoteBranches = await github.fetchBranches({
|
|
70
|
-
owner: gitRepo.owner,
|
|
71
|
-
repo: gitRepo.name
|
|
72
|
-
})
|
|
73
|
-
logger.debug(`remoteBranches=${JSON.stringify(remoteBranches)}`)
|
|
74
|
-
|
|
75
|
-
const remoteBranchExistenceChecker = RemoteBranchExistenceChecker.of(remoteBranches)
|
|
76
|
-
const committer = new Committer({
|
|
77
|
-
git,
|
|
78
|
-
user: {
|
|
79
|
-
name: options.gitUserName,
|
|
80
|
-
email: options.gitUserEmail
|
|
81
|
-
}
|
|
82
|
-
})
|
|
83
|
-
const packageManager = createPackageManager({
|
|
84
|
-
terminal,
|
|
85
|
-
packageManager: options.packageManager
|
|
86
|
-
})
|
|
87
|
-
const pullRequestTitleCreator = new PullRequestTitleCreator(options.pullRequestTitle)
|
|
88
|
-
const pullRequestBodyCreator = new PullRequestBodyCreator(options.pullRequestBody)
|
|
89
|
-
const pullRequestCreator = new PullRequestCreator({
|
|
90
|
-
github,
|
|
91
|
-
gitRepo,
|
|
92
|
-
githubRepo,
|
|
93
|
-
pullRequestTitleCreator,
|
|
94
|
-
pullRequestBodyCreator,
|
|
95
|
-
logger
|
|
96
|
-
})
|
|
97
|
-
const branchNameCreator = new BranchNameCreator(options.branchName)
|
|
98
|
-
const commitMessageCreator = new CommitMessageCreator(options.commitMessage)
|
|
99
|
-
const outdatedPackageProcessor = new OutdatedPackageProcessor({
|
|
100
|
-
committer,
|
|
101
|
-
git,
|
|
102
|
-
ncu,
|
|
103
|
-
packageManager,
|
|
104
|
-
pullRequestCreator,
|
|
105
|
-
remoteBranchExistenceChecker,
|
|
106
|
-
logger,
|
|
107
|
-
branchNameCreator,
|
|
108
|
-
commitMessageCreator
|
|
109
|
-
})
|
|
110
|
-
const outdatedPackagesProcessor = new OutdatedPackagesProcessor({
|
|
111
|
-
outdatedPackageProcessor,
|
|
112
|
-
logger
|
|
113
|
-
})
|
|
114
|
-
const results = await outdatedPackagesProcessor.process(outdatedPackages)
|
|
115
|
-
logger.debug(`results=${JSON.stringify(results)}`)
|
|
116
|
-
|
|
117
|
-
const updatedPackages = results
|
|
118
|
-
.filter(({ updated }) => updated)
|
|
119
|
-
.map(({ outdatedPackage }) => outdatedPackage)
|
|
120
|
-
logger.debug(`updatedPackages=${JSON.stringify(updatedPackages)}`)
|
|
121
|
-
|
|
122
|
-
const skippedPackages = results
|
|
123
|
-
.filter(({ skipped }) => skipped)
|
|
124
|
-
.map(({ outdatedPackage }) => outdatedPackage)
|
|
125
|
-
logger.debug(`skippedPackages=${JSON.stringify(skippedPackages)}`)
|
|
126
|
-
|
|
127
|
-
logger.info(`${updatedPackages.length} packages has updated. ${skippedPackages.length} packages has skipped.`)
|
|
128
|
-
}
|
package/src/ncu/Ncu.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { run } from 'npm-check-updates'
|
|
2
|
-
import type { Options } from 'npm-check-updates/build/src/types'
|
|
3
|
-
import type { OutdatedPackage } from '../ncu'
|
|
4
|
-
import type { PackageJsonReader } from '../package-json'
|
|
5
|
-
import { isNcuOutdatedPackages } from './isNcuOutdatedPackages'
|
|
6
|
-
import { NcuOutdatedPackagesConverter } from './NcuOutdatedPackagesConverter'
|
|
7
|
-
|
|
8
|
-
// TODO: add test
|
|
9
|
-
export class Ncu {
|
|
10
|
-
constructor (private readonly packageJsonReader: PackageJsonReader) {}
|
|
11
|
-
|
|
12
|
-
async check (): Promise<OutdatedPackage[]> {
|
|
13
|
-
return await this.run({
|
|
14
|
-
jsonUpgraded: true
|
|
15
|
-
})
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async update (outdatedPackage: OutdatedPackage): Promise<OutdatedPackage[]> {
|
|
19
|
-
return await this.run({
|
|
20
|
-
jsonUpgraded: true,
|
|
21
|
-
filter: outdatedPackage.name,
|
|
22
|
-
upgrade: true
|
|
23
|
-
})
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
private async run (options: Options): Promise<OutdatedPackage[]> {
|
|
27
|
-
const pkg = await this.packageJsonReader.read('./package.json')
|
|
28
|
-
const currentDependencies = {
|
|
29
|
-
...pkg.dependencies,
|
|
30
|
-
...pkg.devDependencies,
|
|
31
|
-
...pkg.peerDependencies,
|
|
32
|
-
...pkg.optionalDependencies
|
|
33
|
-
}
|
|
34
|
-
const result = await run(options)
|
|
35
|
-
|
|
36
|
-
if (!isNcuOutdatedPackages(result)) {
|
|
37
|
-
throw new Error('result is not NcuOutdatedPackages')
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const ncuOutdatedPackagesConverter = new NcuOutdatedPackagesConverter(currentDependencies)
|
|
41
|
-
return ncuOutdatedPackagesConverter.toOutdatedPackages(result)
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { PackageDependencies } from '../package-json'
|
|
2
|
-
import type { NcuOutdatedPackages } from './NcuOutdatedPackages'
|
|
3
|
-
import type { OutdatedPackage } from './OutdatedPackage'
|
|
4
|
-
import { PackageVersion } from './PackageVersion'
|
|
5
|
-
import { toUpdateType } from './toUpdateType'
|
|
6
|
-
|
|
7
|
-
// TODO: add test
|
|
8
|
-
export class NcuOutdatedPackagesConverter {
|
|
9
|
-
constructor (private readonly currentDependencies: PackageDependencies) {}
|
|
10
|
-
|
|
11
|
-
toOutdatedPackages (outdatedPackages: NcuOutdatedPackages): OutdatedPackage[] {
|
|
12
|
-
return Object.entries(outdatedPackages)
|
|
13
|
-
.map(([name, newVersion]) => ({
|
|
14
|
-
name,
|
|
15
|
-
currentVersion: PackageVersion.of(this.currentDependencies[name]),
|
|
16
|
-
newVersion: PackageVersion.of(newVersion)
|
|
17
|
-
}))
|
|
18
|
-
.map(({ name, currentVersion, newVersion }) => ({
|
|
19
|
-
name,
|
|
20
|
-
currentVersion,
|
|
21
|
-
newVersion,
|
|
22
|
-
type: toUpdateType(currentVersion, newVersion)
|
|
23
|
-
}))
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { PackageVersion } from './PackageVersion'
|
|
2
|
-
|
|
3
|
-
describe('PackageVersion', () => {
|
|
4
|
-
describe('of', () => {
|
|
5
|
-
describe('if version is valid', () => {
|
|
6
|
-
const version = '^1.2.3'
|
|
7
|
-
|
|
8
|
-
it('returns new PackageVersion instance', () => {
|
|
9
|
-
const packageVersion = PackageVersion.of(version)
|
|
10
|
-
expect(packageVersion.version).toBe('1.2.3')
|
|
11
|
-
expect(packageVersion.major).toBe(1)
|
|
12
|
-
expect(packageVersion.minor).toBe(2)
|
|
13
|
-
expect(packageVersion.patch).toBe(3)
|
|
14
|
-
})
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
describe('if version is invalid', () => {
|
|
18
|
-
const version = ''
|
|
19
|
-
|
|
20
|
-
it('throws error', () => {
|
|
21
|
-
expect(() => PackageVersion.of(version)).toThrow(Error)
|
|
22
|
-
})
|
|
23
|
-
})
|
|
24
|
-
})
|
|
25
|
-
})
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { coerce } from 'semver'
|
|
2
|
-
|
|
3
|
-
export class PackageVersion {
|
|
4
|
-
readonly version: string
|
|
5
|
-
readonly major: number
|
|
6
|
-
readonly minor: number
|
|
7
|
-
readonly patch: number
|
|
8
|
-
|
|
9
|
-
private constructor ({
|
|
10
|
-
version,
|
|
11
|
-
major,
|
|
12
|
-
minor,
|
|
13
|
-
patch
|
|
14
|
-
}: {
|
|
15
|
-
version: string
|
|
16
|
-
major: number
|
|
17
|
-
minor: number
|
|
18
|
-
patch: number
|
|
19
|
-
}) {
|
|
20
|
-
this.version = version
|
|
21
|
-
this.major = major
|
|
22
|
-
this.minor = minor
|
|
23
|
-
this.patch = patch
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
static of (version: string): PackageVersion {
|
|
27
|
-
const semver = coerce(version)
|
|
28
|
-
|
|
29
|
-
if (semver === null) {
|
|
30
|
-
throw new Error(`Failed to parse package version. version=${version}`)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return new PackageVersion({
|
|
34
|
-
version: semver.version,
|
|
35
|
-
major: semver.major,
|
|
36
|
-
minor: semver.minor,
|
|
37
|
-
patch: semver.patch
|
|
38
|
-
})
|
|
39
|
-
}
|
|
40
|
-
}
|
package/src/ncu/UpdateType.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export const UpdateType = {
|
|
2
|
-
Major: 'major',
|
|
3
|
-
Minor: 'minor',
|
|
4
|
-
Patch: 'patch'
|
|
5
|
-
} as const
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
7
|
-
export type UpdateType = typeof UpdateType[keyof typeof UpdateType]
|
|
8
|
-
const updateTypes = Object.values(UpdateType)
|
|
9
|
-
export const isUpdateType = (value: any): value is UpdateType => updateTypes.includes(value)
|
package/src/ncu/index.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { NcuOutdatedPackages } from './NcuOutdatedPackages'
|
|
2
|
-
|
|
3
|
-
// TODO: add test
|
|
4
|
-
export const isNcuOutdatedPackages = (value: unknown): value is NcuOutdatedPackages => {
|
|
5
|
-
return typeof value === 'object' && value !== null && Object.values(value).every(value => typeof value === 'string')
|
|
6
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { PackageVersion } from './PackageVersion'
|
|
2
|
-
import { toUpdateType } from './toUpdateType'
|
|
3
|
-
import { UpdateType } from './UpdateType'
|
|
4
|
-
|
|
5
|
-
describe('toUpdateType', () => {
|
|
6
|
-
const currentVersion = PackageVersion.of('1.0.0')
|
|
7
|
-
|
|
8
|
-
describe('if both versions are different', () => {
|
|
9
|
-
it('returns UpdateType', () => {
|
|
10
|
-
expect(toUpdateType(currentVersion, PackageVersion.of('1.0.1'))).toBe(UpdateType.Patch)
|
|
11
|
-
expect(toUpdateType(currentVersion, PackageVersion.of('1.1.1'))).toBe(UpdateType.Minor)
|
|
12
|
-
expect(toUpdateType(currentVersion, PackageVersion.of('2.1.1'))).toBe(UpdateType.Major)
|
|
13
|
-
})
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
describe('if both versions are same', () => {
|
|
17
|
-
it('throws error', () => {
|
|
18
|
-
expect(() => toUpdateType(currentVersion, PackageVersion.of('1.0.0'))).toThrow(Error)
|
|
19
|
-
})
|
|
20
|
-
})
|
|
21
|
-
})
|
package/src/ncu/toUpdateType.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { PackageVersion } from './PackageVersion'
|
|
2
|
-
import { UpdateType } from './UpdateType'
|
|
3
|
-
|
|
4
|
-
export const toUpdateType = (currentVersion: PackageVersion, newVersion: PackageVersion): UpdateType => {
|
|
5
|
-
if (currentVersion.major !== newVersion.major) {
|
|
6
|
-
return UpdateType.Major
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
if (currentVersion.minor !== newVersion.minor) {
|
|
10
|
-
return UpdateType.Minor
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (currentVersion.patch !== newVersion.patch) {
|
|
14
|
-
return UpdateType.Patch
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
throw new Error('Both versions are same.')
|
|
18
|
-
}
|
package/src/options/Options.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
intersection,
|
|
3
|
-
literal,
|
|
4
|
-
partial,
|
|
5
|
-
string,
|
|
6
|
-
type,
|
|
7
|
-
union
|
|
8
|
-
} from 'io-ts'
|
|
9
|
-
import type { TypeOf } from 'io-ts'
|
|
10
|
-
import { LogLevel } from '../logger'
|
|
11
|
-
import { PackageManagerName } from '../package-manager'
|
|
12
|
-
|
|
13
|
-
const Options = intersection([
|
|
14
|
-
type({
|
|
15
|
-
branchName: string,
|
|
16
|
-
commitMessage: string,
|
|
17
|
-
githubToken: string,
|
|
18
|
-
logLevel: union([literal(LogLevel.Info), literal(LogLevel.Debug)]),
|
|
19
|
-
packageManager: union([literal(PackageManagerName.Npm), literal(PackageManagerName.Yarn)]),
|
|
20
|
-
pullRequestBody: string,
|
|
21
|
-
pullRequestTitle: string
|
|
22
|
-
}),
|
|
23
|
-
partial({
|
|
24
|
-
gitUserEmail: string,
|
|
25
|
-
gitUserName: string
|
|
26
|
-
})
|
|
27
|
-
])
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
29
|
-
export type Options = TypeOf<typeof Options>
|
|
30
|
-
export const isOptions = Options.is
|
package/src/options/index.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Option,
|
|
3
|
-
program
|
|
4
|
-
} from 'commander'
|
|
5
|
-
import { app } from '../app'
|
|
6
|
-
import { LogLevel } from '../logger'
|
|
7
|
-
import { PackageManagerName } from '../package-manager'
|
|
8
|
-
import { isOptions } from './Options'
|
|
9
|
-
import type { Options } from './Options'
|
|
10
|
-
|
|
11
|
-
// TODO: add test
|
|
12
|
-
export const initOptions = (): Options => {
|
|
13
|
-
program
|
|
14
|
-
.version(app.version)
|
|
15
|
-
.option('--branch-name <value>', 'Branch name template', 'npm-update-package/{{{packageName}}}/v{{newVersion}}')
|
|
16
|
-
.option('--commit-message <value>', 'Commit message template', 'chore(deps): {{updateType}} update {{{packageName}}} to v{{newVersion}}')
|
|
17
|
-
.option('--git-user-email <value>', 'User email of commit')
|
|
18
|
-
.option('--git-user-name <value>', 'User name of commit')
|
|
19
|
-
.requiredOption('--github-token <value>', 'GitHub token')
|
|
20
|
-
.addOption(
|
|
21
|
-
new Option('--log-level <value>', 'Log level to show')
|
|
22
|
-
.choices([
|
|
23
|
-
LogLevel.Info,
|
|
24
|
-
LogLevel.Debug
|
|
25
|
-
])
|
|
26
|
-
.default(LogLevel.Info)
|
|
27
|
-
)
|
|
28
|
-
.addOption(
|
|
29
|
-
new Option('--package-manager <value>', 'Package manager of your project')
|
|
30
|
-
.choices([
|
|
31
|
-
PackageManagerName.Npm,
|
|
32
|
-
PackageManagerName.Yarn
|
|
33
|
-
])
|
|
34
|
-
.default(PackageManagerName.Npm)
|
|
35
|
-
)
|
|
36
|
-
.option('--pull-request-body <value>', 'Pull request body template', `This PR updates these packages:
|
|
37
|
-
|
|
38
|
-
|package|type|current version|new version|
|
|
39
|
-
|---|---|---|---|
|
|
40
|
-
|[{{{packageName}}}](https://www.npmjs.com/package/{{{packageName}}})|{{updateType}}|\`{{currentVersion}}\`|\`{{newVersion}}\`|
|
|
41
|
-
|
|
42
|
-
---
|
|
43
|
-
This PR has been generated by [{{{appName}}}]({{{appWeb}}}) v{{appVersion}}`)
|
|
44
|
-
.option('--pull-request-title <value>', 'Pull request title template', 'chore(deps): {{updateType}} update {{{packageName}}} to v{{newVersion}}')
|
|
45
|
-
program.parse(process.argv)
|
|
46
|
-
const options = program.opts()
|
|
47
|
-
|
|
48
|
-
if (!isOptions(options)) {
|
|
49
|
-
throw new Error(`Failed to parse command-line options. options=${JSON.stringify(options)}`)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return options
|
|
53
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
intersection,
|
|
3
|
-
partial,
|
|
4
|
-
string,
|
|
5
|
-
type
|
|
6
|
-
} from 'io-ts'
|
|
7
|
-
import type { TypeOf } from 'io-ts'
|
|
8
|
-
import { PackageDependencies } from './PackageDependencies'
|
|
9
|
-
|
|
10
|
-
const Package = intersection([
|
|
11
|
-
type({
|
|
12
|
-
name: string,
|
|
13
|
-
version: string
|
|
14
|
-
}),
|
|
15
|
-
partial({
|
|
16
|
-
dependencies: PackageDependencies,
|
|
17
|
-
devDependencies: PackageDependencies,
|
|
18
|
-
peerDependencies: PackageDependencies,
|
|
19
|
-
optionalDependencies: PackageDependencies
|
|
20
|
-
})
|
|
21
|
-
])
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
23
|
-
export type Package = TypeOf<typeof Package>
|
|
24
|
-
export const isPackage = Package.is
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
record,
|
|
3
|
-
string
|
|
4
|
-
} from 'io-ts'
|
|
5
|
-
import type { TypeOf } from 'io-ts'
|
|
6
|
-
|
|
7
|
-
export const PackageDependencies = record(string, string)
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
9
|
-
export type PackageDependencies = TypeOf<typeof PackageDependencies>
|
|
10
|
-
export const isPackageDependencies = PackageDependencies.is
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Logger } from '../logger'
|
|
2
|
-
import { isPackage } from './Package'
|
|
3
|
-
import type { Package } from './Package'
|
|
4
|
-
|
|
5
|
-
// TODO: add test
|
|
6
|
-
export class PackageJsonParser {
|
|
7
|
-
constructor (private readonly logger: Logger) {}
|
|
8
|
-
|
|
9
|
-
parse (json: string): Package {
|
|
10
|
-
const parsed: unknown = JSON.parse(json)
|
|
11
|
-
this.logger.debug(`parsed=${JSON.stringify(parsed)}`)
|
|
12
|
-
|
|
13
|
-
if (isPackage(parsed)) {
|
|
14
|
-
return parsed
|
|
15
|
-
} else {
|
|
16
|
-
throw new Error(`Failed to parse package.json. json=${json}`)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|