npm-update-package 0.6.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/README.md +98 -16
- package/dist/app.js +1 -1
- package/dist/github/PullRequestBodyCreator.js +29 -0
- package/dist/github/PullRequestCreator.js +5 -5
- package/dist/github/PullRequestTitleCreator.js +22 -0
- package/dist/github/index.js +5 -1
- package/dist/main.js +4 -0
- package/dist/options/Options.js +6 -2
- package/dist/options/initOptions.js +10 -1
- package/package.json +11 -7
- 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/dist/github/createPullRequestBody.js +0 -19
- package/dist/github/createPullRequestTitle.js +0 -10
- 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/PullRequestCreator.ts +0 -57
- 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/createPullRequestBody.test.ts +0 -64
- package/src/github/createPullRequestBody.ts +0 -17
- package/src/github/createPullRequestTitle.test.ts +0 -42
- package/src/github/createPullRequestTitle.ts +0 -8
- package/src/github/index.ts +0 -7
- 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 -122
- 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 -26
- package/src/options/index.ts +0 -2
- package/src/options/initOptions.ts +0 -44
- 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
package/src/git/Git.ts
DELETED
|
@@ -1,55 +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 checkout (branchName: string): Promise<void> {
|
|
13
|
-
await this.terminal.run('git', 'checkout', branchName)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async commit (message: string): Promise<void> {
|
|
17
|
-
await this.terminal.run('git', 'commit', '--message', message)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async createBranch (branchName: string): Promise<void> {
|
|
21
|
-
await this.terminal.run('git', 'checkout', '-b', branchName)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async getConfig (key: string): Promise<string> {
|
|
25
|
-
const { stdout } = await this.terminal.run('git', 'config', key)
|
|
26
|
-
return stdout.trim()
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async getCurrentBranch (): Promise<string> {
|
|
30
|
-
const { stdout } = await this.terminal.run('git', 'rev-parse', '--abbrev-ref', 'HEAD')
|
|
31
|
-
return stdout.trim()
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async getRemoteUrl (): Promise<string> {
|
|
35
|
-
const { stdout } = await this.terminal.run('git', 'remote', 'get-url', '--push', 'origin')
|
|
36
|
-
return stdout.trim()
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async getRepository (): Promise<GitRepository> {
|
|
40
|
-
const url = await this.getRemoteUrl()
|
|
41
|
-
return GitRepository.of(url)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async push (branchName: string): Promise<void> {
|
|
45
|
-
await this.terminal.run('git', 'push', 'origin', branchName)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async removeBranch (branchName: string): Promise<void> {
|
|
49
|
-
await this.terminal.run('git', 'branch', '-D', branchName)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async setConfig (key: string, value: string): Promise<void> {
|
|
53
|
-
await this.terminal.run('git', 'config', key, value)
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { GitRepository } from './GitRepository'
|
|
2
|
-
|
|
3
|
-
describe('GitRepository', () => {
|
|
4
|
-
describe('of', () => {
|
|
5
|
-
describe('if URL is HTTPS', () => {
|
|
6
|
-
describe('if URL is github.com', () => {
|
|
7
|
-
const url = 'https://github.com/npm-update-package/npm-update-package.git'
|
|
8
|
-
|
|
9
|
-
it('returns new GitRepository instance', () => {
|
|
10
|
-
const repo = GitRepository.of(url)
|
|
11
|
-
expect(repo.host).toBe('github.com')
|
|
12
|
-
expect(repo.owner).toBe('npm-update-package')
|
|
13
|
-
expect(repo.name).toBe('npm-update-package')
|
|
14
|
-
expect(repo.apiEndPoint).toBe('https://api.github.com')
|
|
15
|
-
expect(repo.isGitHubDotCom).toBe(true)
|
|
16
|
-
})
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
describe('if URL is not github.com', () => {
|
|
20
|
-
const url = 'https://git.example.com/npm-update-package/npm-update-package.git'
|
|
21
|
-
|
|
22
|
-
it('returns new GitRepository instance', () => {
|
|
23
|
-
const repo = GitRepository.of(url)
|
|
24
|
-
expect(repo.host).toBe('git.example.com')
|
|
25
|
-
expect(repo.owner).toBe('npm-update-package')
|
|
26
|
-
expect(repo.name).toBe('npm-update-package')
|
|
27
|
-
expect(repo.apiEndPoint).toBe('https://git.example.com/api/v3')
|
|
28
|
-
expect(repo.isGitHubDotCom).toBe(false)
|
|
29
|
-
})
|
|
30
|
-
})
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
describe('if URL is SSH', () => {
|
|
34
|
-
describe('if URL is github.com', () => {
|
|
35
|
-
const url = 'git@github.com:npm-update-package/npm-update-package.git'
|
|
36
|
-
|
|
37
|
-
it('returns new GitRepository instance', () => {
|
|
38
|
-
const repo = GitRepository.of(url)
|
|
39
|
-
expect(repo.host).toBe('github.com')
|
|
40
|
-
expect(repo.owner).toBe('npm-update-package')
|
|
41
|
-
expect(repo.name).toBe('npm-update-package')
|
|
42
|
-
expect(repo.apiEndPoint).toBe('https://api.github.com')
|
|
43
|
-
expect(repo.isGitHubDotCom).toBe(true)
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
describe('if URL is not github.com', () => {
|
|
48
|
-
const url = 'git@git.example.com:npm-update-package/npm-update-package.git'
|
|
49
|
-
|
|
50
|
-
it('returns new GitRepository instance', () => {
|
|
51
|
-
const repo = GitRepository.of(url)
|
|
52
|
-
expect(repo.host).toBe('git.example.com')
|
|
53
|
-
expect(repo.owner).toBe('npm-update-package')
|
|
54
|
-
expect(repo.name).toBe('npm-update-package')
|
|
55
|
-
expect(repo.apiEndPoint).toBe('https://git.example.com/api/v3')
|
|
56
|
-
expect(repo.isGitHubDotCom).toBe(false)
|
|
57
|
-
})
|
|
58
|
-
})
|
|
59
|
-
})
|
|
60
|
-
})
|
|
61
|
-
})
|
package/src/git/GitRepository.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import parse from 'parse-github-url'
|
|
2
|
-
|
|
3
|
-
export class GitRepository {
|
|
4
|
-
readonly host: string
|
|
5
|
-
readonly owner: string
|
|
6
|
-
readonly name: string
|
|
7
|
-
|
|
8
|
-
private constructor ({
|
|
9
|
-
host,
|
|
10
|
-
owner,
|
|
11
|
-
name
|
|
12
|
-
}: {
|
|
13
|
-
host: string
|
|
14
|
-
owner: string
|
|
15
|
-
name: string
|
|
16
|
-
}) {
|
|
17
|
-
this.host = host
|
|
18
|
-
this.owner = owner
|
|
19
|
-
this.name = name
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
static of (url: string): GitRepository {
|
|
23
|
-
const parsed = parse(url)
|
|
24
|
-
|
|
25
|
-
if (parsed === null) {
|
|
26
|
-
throw new Error(`Failed to parse url. url=${url}`)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const {
|
|
30
|
-
host,
|
|
31
|
-
owner,
|
|
32
|
-
name
|
|
33
|
-
} = parsed
|
|
34
|
-
|
|
35
|
-
if (host === null || owner === null || name === null) {
|
|
36
|
-
throw new Error(`Failed to parse url. url=${url}`)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return new GitRepository({
|
|
40
|
-
host,
|
|
41
|
-
owner,
|
|
42
|
-
name
|
|
43
|
-
})
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
get apiEndPoint (): string {
|
|
47
|
-
if (this.isGitHubDotCom) {
|
|
48
|
-
return 'https://api.github.com'
|
|
49
|
-
} else {
|
|
50
|
-
return `https://${this.host}/api/v3`
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
get isGitHubDotCom (): boolean {
|
|
55
|
-
return this.host === 'github.com'
|
|
56
|
-
}
|
|
57
|
-
}
|
package/src/git/index.ts
DELETED
package/src/github/Branch.ts
DELETED
package/src/github/GitHub.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Octokit,
|
|
3
|
-
RestEndpointMethodTypes
|
|
4
|
-
} from '@octokit/rest'
|
|
5
|
-
import type { Branch } from './Branch'
|
|
6
|
-
import type { PullRequest } from './PullRequest'
|
|
7
|
-
import type { Repository } from './Repository'
|
|
8
|
-
|
|
9
|
-
// TODO: add test
|
|
10
|
-
export class GitHub {
|
|
11
|
-
constructor (private readonly octokit: Octokit) {}
|
|
12
|
-
|
|
13
|
-
async createPullRequest (params: RestEndpointMethodTypes['pulls']['create']['parameters']): Promise<PullRequest> {
|
|
14
|
-
const { data } = await this.octokit.pulls.create(params)
|
|
15
|
-
return data
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async fetchBranches (params: RestEndpointMethodTypes['repos']['listBranches']['parameters']): Promise<Branch[]> {
|
|
19
|
-
const { data } = await this.octokit.repos.listBranches(params)
|
|
20
|
-
return data
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async fetchRepository (params: RestEndpointMethodTypes['repos']['get']['parameters']): Promise<Repository> {
|
|
24
|
-
const { data } = await this.octokit.repos.get(params)
|
|
25
|
-
return data
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type { GitRepository } from '../git'
|
|
2
|
-
import type { Logger } from '../logger'
|
|
3
|
-
import type { OutdatedPackage } from '../ncu'
|
|
4
|
-
import { createPullRequestBody } from './createPullRequestBody'
|
|
5
|
-
import { createPullRequestTitle } from './createPullRequestTitle'
|
|
6
|
-
import type { GitHub } from './GitHub'
|
|
7
|
-
import type { Repository as GitHubRepository } from './Repository'
|
|
8
|
-
|
|
9
|
-
// TODO: add test
|
|
10
|
-
export class PullRequestCreator {
|
|
11
|
-
private readonly github: GitHub
|
|
12
|
-
private readonly gitRepo: GitRepository
|
|
13
|
-
private readonly githubRepo: GitHubRepository
|
|
14
|
-
private readonly logger: Logger
|
|
15
|
-
|
|
16
|
-
constructor ({
|
|
17
|
-
github,
|
|
18
|
-
gitRepo,
|
|
19
|
-
githubRepo,
|
|
20
|
-
logger
|
|
21
|
-
}: {
|
|
22
|
-
github: GitHub
|
|
23
|
-
gitRepo: GitRepository
|
|
24
|
-
githubRepo: GitHubRepository
|
|
25
|
-
logger: Logger
|
|
26
|
-
}) {
|
|
27
|
-
this.github = github
|
|
28
|
-
this.gitRepo = gitRepo
|
|
29
|
-
this.githubRepo = githubRepo
|
|
30
|
-
this.logger = logger
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async create ({
|
|
34
|
-
outdatedPackage,
|
|
35
|
-
branchName
|
|
36
|
-
}: {
|
|
37
|
-
outdatedPackage: OutdatedPackage
|
|
38
|
-
branchName: string
|
|
39
|
-
}): Promise<void> {
|
|
40
|
-
const title = createPullRequestTitle(outdatedPackage)
|
|
41
|
-
this.logger.debug(`title=${title}`)
|
|
42
|
-
|
|
43
|
-
const body = createPullRequestBody(outdatedPackage)
|
|
44
|
-
this.logger.debug(`body=${body}`)
|
|
45
|
-
|
|
46
|
-
const createdPullRequest = await this.github.createPullRequest({
|
|
47
|
-
owner: this.gitRepo.owner,
|
|
48
|
-
repo: this.gitRepo.name,
|
|
49
|
-
base: this.githubRepo.default_branch,
|
|
50
|
-
head: branchName,
|
|
51
|
-
title,
|
|
52
|
-
body
|
|
53
|
-
})
|
|
54
|
-
this.logger.debug(`createdPullRequest=${JSON.stringify(createdPullRequest)}`)
|
|
55
|
-
this.logger.info(`Pull request for ${outdatedPackage.name} has created. ${createdPullRequest.html_url}`)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -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
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PackageVersion,
|
|
3
|
-
UpdateType
|
|
4
|
-
} from '../ncu'
|
|
5
|
-
import { createPullRequestBody } from './createPullRequestBody'
|
|
6
|
-
|
|
7
|
-
describe('createPullRequestBody', () => {
|
|
8
|
-
describe('if update type is patch', () => {
|
|
9
|
-
it('returns pull request body', () => {
|
|
10
|
-
const actual = createPullRequestBody({
|
|
11
|
-
name: '@typescript-eslint/eslint-plugin',
|
|
12
|
-
currentVersion: PackageVersion.of('1.0.0'),
|
|
13
|
-
newVersion: PackageVersion.of('1.0.1'),
|
|
14
|
-
type: UpdateType.Patch
|
|
15
|
-
})
|
|
16
|
-
expect(actual).toBe(`This PR updates these packages:
|
|
17
|
-
|
|
18
|
-
|package|type|current version|new version|
|
|
19
|
-
|---|---|---|---|
|
|
20
|
-
|[@typescript-eslint/eslint-plugin](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin)|patch|\`1.0.0\`|\`1.0.1\`|
|
|
21
|
-
|
|
22
|
-
---
|
|
23
|
-
This PR has been generated by [npm-update-package](https://github.com/npm-update-package/npm-update-package)`)
|
|
24
|
-
})
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
describe('if update type is minor', () => {
|
|
28
|
-
it('returns pull request body', () => {
|
|
29
|
-
const actual = createPullRequestBody({
|
|
30
|
-
name: '@typescript-eslint/eslint-plugin',
|
|
31
|
-
currentVersion: PackageVersion.of('1.0.0'),
|
|
32
|
-
newVersion: PackageVersion.of('1.1.0'),
|
|
33
|
-
type: UpdateType.Minor
|
|
34
|
-
})
|
|
35
|
-
expect(actual).toBe(`This PR updates these packages:
|
|
36
|
-
|
|
37
|
-
|package|type|current version|new version|
|
|
38
|
-
|---|---|---|---|
|
|
39
|
-
|[@typescript-eslint/eslint-plugin](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin)|minor|\`1.0.0\`|\`1.1.0\`|
|
|
40
|
-
|
|
41
|
-
---
|
|
42
|
-
This PR has been generated by [npm-update-package](https://github.com/npm-update-package/npm-update-package)`)
|
|
43
|
-
})
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
describe('if update type is major', () => {
|
|
47
|
-
it('returns pull request body', () => {
|
|
48
|
-
const actual = createPullRequestBody({
|
|
49
|
-
name: '@typescript-eslint/eslint-plugin',
|
|
50
|
-
currentVersion: PackageVersion.of('1.0.0'),
|
|
51
|
-
newVersion: PackageVersion.of('2.0.0'),
|
|
52
|
-
type: UpdateType.Major
|
|
53
|
-
})
|
|
54
|
-
expect(actual).toBe(`This PR updates these packages:
|
|
55
|
-
|
|
56
|
-
|package|type|current version|new version|
|
|
57
|
-
|---|---|---|---|
|
|
58
|
-
|[@typescript-eslint/eslint-plugin](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin)|major|\`1.0.0\`|\`2.0.0\`|
|
|
59
|
-
|
|
60
|
-
---
|
|
61
|
-
This PR has been generated by [npm-update-package](https://github.com/npm-update-package/npm-update-package)`)
|
|
62
|
-
})
|
|
63
|
-
})
|
|
64
|
-
})
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { app } from '../app'
|
|
2
|
-
import type { OutdatedPackage } from '../ncu'
|
|
3
|
-
|
|
4
|
-
export const createPullRequestBody = (outdatedPackage: OutdatedPackage): string => {
|
|
5
|
-
const packageName = outdatedPackage.name
|
|
6
|
-
const currentVersion = outdatedPackage.currentVersion.version
|
|
7
|
-
const newVersion = outdatedPackage.newVersion.version
|
|
8
|
-
const updateType = outdatedPackage.type
|
|
9
|
-
return `This PR updates these packages:
|
|
10
|
-
|
|
11
|
-
|package|type|current version|new version|
|
|
12
|
-
|---|---|---|---|
|
|
13
|
-
|[${packageName}](https://www.npmjs.com/package/${packageName})|${updateType}|\`${currentVersion}\`|\`${newVersion}\`|
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
This PR has been generated by [${app.name}](${app.web})`
|
|
17
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { UpdateType, PackageVersion } from '../ncu'
|
|
2
|
-
import { createPullRequestTitle } from './createPullRequestTitle'
|
|
3
|
-
|
|
4
|
-
describe('createPullRequestTitle', () => {
|
|
5
|
-
const currentVersion = PackageVersion.of('1.0.0')
|
|
6
|
-
|
|
7
|
-
describe('if update type is patch', () => {
|
|
8
|
-
it('returns pull request title', () => {
|
|
9
|
-
const actual = createPullRequestTitle({
|
|
10
|
-
name: '@typescript-eslint/eslint-plugin',
|
|
11
|
-
currentVersion,
|
|
12
|
-
newVersion: PackageVersion.of('1.0.1'),
|
|
13
|
-
type: UpdateType.Patch
|
|
14
|
-
})
|
|
15
|
-
expect(actual).toBe('chore(deps): patch update @typescript-eslint/eslint-plugin to v1.0.1')
|
|
16
|
-
})
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
describe('if update type is minor', () => {
|
|
20
|
-
it('returns pull request title', () => {
|
|
21
|
-
const actual = createPullRequestTitle({
|
|
22
|
-
name: '@typescript-eslint/eslint-plugin',
|
|
23
|
-
currentVersion,
|
|
24
|
-
newVersion: PackageVersion.of('1.1.0'),
|
|
25
|
-
type: UpdateType.Minor
|
|
26
|
-
})
|
|
27
|
-
expect(actual).toBe('chore(deps): minor update @typescript-eslint/eslint-plugin to v1.1.0')
|
|
28
|
-
})
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
describe('if update type is major', () => {
|
|
32
|
-
it('returns pull request title', () => {
|
|
33
|
-
const actual = createPullRequestTitle({
|
|
34
|
-
name: '@typescript-eslint/eslint-plugin',
|
|
35
|
-
currentVersion,
|
|
36
|
-
newVersion: PackageVersion.of('2.0.0'),
|
|
37
|
-
type: UpdateType.Major
|
|
38
|
-
})
|
|
39
|
-
expect(actual).toBe('chore(deps): major update @typescript-eslint/eslint-plugin to v2.0.0')
|
|
40
|
-
})
|
|
41
|
-
})
|
|
42
|
-
})
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { OutdatedPackage } from '../ncu'
|
|
2
|
-
|
|
3
|
-
export const createPullRequestTitle = (outdatedPackage: OutdatedPackage): string => {
|
|
4
|
-
const packageName = outdatedPackage.name
|
|
5
|
-
const newVersion = outdatedPackage.newVersion.version
|
|
6
|
-
const updateType = outdatedPackage.type
|
|
7
|
-
return `chore(deps): ${updateType} update ${packageName} to v${newVersion}`
|
|
8
|
-
}
|
package/src/github/index.ts
DELETED
|
@@ -1,7 +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 { PullRequestCreator } from './PullRequestCreator'
|
|
6
|
-
export { RemoteBranchExistenceChecker } from './RemoteBranchExistenceChecker'
|
|
7
|
-
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,122 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BranchNameCreator,
|
|
3
|
-
CommitMessageCreator,
|
|
4
|
-
Committer,
|
|
5
|
-
Git
|
|
6
|
-
} from './git'
|
|
7
|
-
import {
|
|
8
|
-
createGitHub,
|
|
9
|
-
PullRequestCreator,
|
|
10
|
-
RemoteBranchExistenceChecker
|
|
11
|
-
} from './github'
|
|
12
|
-
import type { Logger } from './logger'
|
|
13
|
-
import { Ncu } from './ncu'
|
|
14
|
-
import type { Options } from './options'
|
|
15
|
-
import {
|
|
16
|
-
PackageJsonParser,
|
|
17
|
-
PackageJsonReader
|
|
18
|
-
} from './package-json'
|
|
19
|
-
import { createPackageManager } from './package-manager'
|
|
20
|
-
import {
|
|
21
|
-
OutdatedPackageProcessor,
|
|
22
|
-
OutdatedPackagesProcessor
|
|
23
|
-
} from './processors'
|
|
24
|
-
import { Terminal } from './terminal'
|
|
25
|
-
|
|
26
|
-
// TODO: add test
|
|
27
|
-
export const main = async ({
|
|
28
|
-
options,
|
|
29
|
-
logger
|
|
30
|
-
}: {
|
|
31
|
-
options: Options
|
|
32
|
-
logger: Logger
|
|
33
|
-
}): Promise<void> => {
|
|
34
|
-
logger.debug(`options=${JSON.stringify(options)}`)
|
|
35
|
-
|
|
36
|
-
const packageJsonParser = new PackageJsonParser(logger)
|
|
37
|
-
const packageJsonReader = new PackageJsonReader({
|
|
38
|
-
packageJsonParser,
|
|
39
|
-
logger
|
|
40
|
-
})
|
|
41
|
-
const ncu = new Ncu(packageJsonReader)
|
|
42
|
-
const outdatedPackages = await ncu.check()
|
|
43
|
-
logger.debug(`outdatedPackages=${JSON.stringify(outdatedPackages)}`)
|
|
44
|
-
|
|
45
|
-
if (outdatedPackages.length === 0) {
|
|
46
|
-
logger.info('All packages are up-to-date.')
|
|
47
|
-
return
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
logger.info(`There are ${outdatedPackages.length} outdated packages.`)
|
|
51
|
-
|
|
52
|
-
const terminal = new Terminal()
|
|
53
|
-
const git = new Git(terminal)
|
|
54
|
-
const gitRepo = await git.getRepository()
|
|
55
|
-
logger.debug(`gitRepo=${JSON.stringify(gitRepo)}`)
|
|
56
|
-
|
|
57
|
-
const github = createGitHub({
|
|
58
|
-
repository: gitRepo,
|
|
59
|
-
token: options.githubToken
|
|
60
|
-
})
|
|
61
|
-
const githubRepo = await github.fetchRepository({
|
|
62
|
-
owner: gitRepo.owner,
|
|
63
|
-
repo: gitRepo.name
|
|
64
|
-
})
|
|
65
|
-
logger.debug(`githubRepo=${JSON.stringify(githubRepo)}`)
|
|
66
|
-
|
|
67
|
-
const remoteBranches = await github.fetchBranches({
|
|
68
|
-
owner: gitRepo.owner,
|
|
69
|
-
repo: gitRepo.name
|
|
70
|
-
})
|
|
71
|
-
logger.debug(`remoteBranches=${JSON.stringify(remoteBranches)}`)
|
|
72
|
-
|
|
73
|
-
const remoteBranchExistenceChecker = RemoteBranchExistenceChecker.of(remoteBranches)
|
|
74
|
-
const committer = new Committer({
|
|
75
|
-
git,
|
|
76
|
-
user: {
|
|
77
|
-
name: options.gitUserName,
|
|
78
|
-
email: options.gitUserEmail
|
|
79
|
-
}
|
|
80
|
-
})
|
|
81
|
-
const packageManager = createPackageManager({
|
|
82
|
-
terminal,
|
|
83
|
-
packageManager: options.packageManager
|
|
84
|
-
})
|
|
85
|
-
const pullRequestCreator = new PullRequestCreator({
|
|
86
|
-
github,
|
|
87
|
-
gitRepo,
|
|
88
|
-
githubRepo,
|
|
89
|
-
logger
|
|
90
|
-
})
|
|
91
|
-
const branchNameCreator = new BranchNameCreator(options.branchName)
|
|
92
|
-
const commitMessageCreator = new CommitMessageCreator(options.commitMessage)
|
|
93
|
-
const outdatedPackageProcessor = new OutdatedPackageProcessor({
|
|
94
|
-
committer,
|
|
95
|
-
git,
|
|
96
|
-
ncu,
|
|
97
|
-
packageManager,
|
|
98
|
-
pullRequestCreator,
|
|
99
|
-
remoteBranchExistenceChecker,
|
|
100
|
-
logger,
|
|
101
|
-
branchNameCreator,
|
|
102
|
-
commitMessageCreator
|
|
103
|
-
})
|
|
104
|
-
const outdatedPackagesProcessor = new OutdatedPackagesProcessor({
|
|
105
|
-
outdatedPackageProcessor,
|
|
106
|
-
logger
|
|
107
|
-
})
|
|
108
|
-
const results = await outdatedPackagesProcessor.process(outdatedPackages)
|
|
109
|
-
logger.debug(`results=${JSON.stringify(results)}`)
|
|
110
|
-
|
|
111
|
-
const updatedPackages = results
|
|
112
|
-
.filter(({ updated }) => updated)
|
|
113
|
-
.map(({ outdatedPackage }) => outdatedPackage)
|
|
114
|
-
logger.debug(`updatedPackages=${JSON.stringify(updatedPackages)}`)
|
|
115
|
-
|
|
116
|
-
const skippedPackages = results
|
|
117
|
-
.filter(({ skipped }) => skipped)
|
|
118
|
-
.map(({ outdatedPackage }) => outdatedPackage)
|
|
119
|
-
logger.debug(`skippedPackages=${JSON.stringify(skippedPackages)}`)
|
|
120
|
-
|
|
121
|
-
logger.info(`${updatedPackages.length} packages has updated. ${skippedPackages.length} packages has skipped.`)
|
|
122
|
-
}
|