Skip to content

Commit 2a0d7d1

Browse files
committed
Add lint and type-check commands
1 parent ce2b477 commit 2a0d7d1

8 files changed

Lines changed: 727 additions & 108 deletions

File tree

.eslintrc.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"env": {
3+
"node": true
4+
},
5+
"extends": [
6+
"eslint:recommended",
7+
"plugin:@typescript-eslint/eslint-recommended",
8+
"plugin:@typescript-eslint/recommended",
9+
"plugin:prettier/recommended",
10+
"prettier/@typescript-eslint"
11+
],
12+
"overrides": [
13+
{
14+
"files": ["**/*.test.ts"],
15+
"env": { "jest": true },
16+
"extends": ["plugin:jest/recommended"]
17+
}
18+
],
19+
"parser": "@typescript-eslint/parser",
20+
"parserOptions": {
21+
"ecmaVersion": 2018,
22+
"sourceType": "module"
23+
},
24+
"plugins": ["wyze"],
25+
"rules": {
26+
"@typescript-eslint/array-type": ["error", { "default": "array-simple" }],
27+
"@typescript-eslint/camelcase": ["error", { "allow": ["tag_name"] }],
28+
"@typescript-eslint/explicit-function-return-type": "off",
29+
"@typescript-eslint/member-delimiter-style": [
30+
"error",
31+
{
32+
"multiline": {
33+
"delimiter": "none",
34+
"requireLast": true
35+
},
36+
"singleline": {
37+
"delimiter": "semi",
38+
"requireLast": false
39+
}
40+
}
41+
],
42+
"@typescript-eslint/prefer-optional-chain": "error",
43+
"wyze/sort-imports": "error"
44+
}
45+
}

package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
"scripts": {
1616
"build": "rio -o bin/index.js -b '#!/usr/bin/env node' -e execa,gh-got,read-pkg bin/src/index.ts",
1717
"clean": "rimraf bin/index.js",
18+
"lint": "eslint \"{bin,src}/**/*.ts\"",
1819
"postbuild": "shx chmod a+x bin/index.js",
1920
"postversion": "node bin",
2021
"prebuild": "yarn clean",
2122
"prettier": "prettier --write \"{bin,src}/**/*.ts\"",
2223
"preversion": "yarn build",
2324
"test": "jest",
25+
"type-check": "tsc",
2426
"version": "changelog"
2527
},
2628
"files": [
@@ -45,11 +47,19 @@
4547
"@types/jest": "^25.1.4",
4648
"@types/node": "^13.9.5",
4749
"@types/read-pkg": "^5.1.0",
50+
"@typescript-eslint/eslint-plugin": "^2.25.0",
51+
"@typescript-eslint/parser": "^2.25.0",
4852
"@wyze/rio": "^1.2.0",
53+
"eslint": "^6.8.0",
54+
"eslint-config-prettier": "^6.10.1",
55+
"eslint-plugin-jest": "^23.8.2",
56+
"eslint-plugin-prettier": "^3.1.2",
57+
"eslint-plugin-wyze": "^3.4.0",
4958
"jest": "^25.2.3",
5059
"prettier": "^2.0.2",
5160
"rimraf": "^3.0.2",
52-
"shx": "^0.3.2"
61+
"shx": "^0.3.2",
62+
"typescript": "^3.8.3"
5363
},
5464
"babel": {
5565
"presets": [

src/__tests__/index.test.ts

Lines changed: 0 additions & 92 deletions
This file was deleted.

src/index.test.ts

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import * as execa from 'execa'
2+
import * as ghGot from 'gh-got'
3+
import * as readPkg from 'read-pkg'
4+
import fs from 'fs'
5+
6+
jest.mock('execa')
7+
jest.mock('fs')
8+
jest.mock('gh-got')
9+
jest.mock('read-pkg')
10+
11+
afterEach(jest.resetAllMocks)
12+
13+
it('creates initial github release', async () => {
14+
jest.spyOn(execa, 'default').mockImplementation((_command, subCommands) => {
15+
const output = require.requireActual('execa').sync('node', ['--version'])
16+
17+
return (subCommands as string[])[0] === 'rev-list'
18+
? { ...output, stdout: '0a1b2c3d4e5f' }
19+
: output
20+
})
21+
22+
jest.spyOn(readPkg, 'default').mockResolvedValue({
23+
name: 'a-fixture',
24+
version: '1.0.0',
25+
license: 'MIT',
26+
repository: {
27+
type: 'git',
28+
url: 'git+https://github.com/wyze/a-fixture.git',
29+
},
30+
})
31+
32+
jest.spyOn(ghGot, 'default').mockImplementation()
33+
34+
// Read changelog
35+
jest
36+
.spyOn(fs, 'readFile')
37+
.mockImplementationOnce((_, cb) =>
38+
cb(
39+
null,
40+
Buffer.from(
41+
'## Change Log\n\n### [v1.0.0](https://github.com/wyze/a-fixture/releases/tag/v1.0.0) (2017-05-05)\n\n* A bug fix PR ([@wyze](https://github.com/wyze) in [#1](https://github.com/wyze/a-fixture/pull/1))\n* Initial Commit ([@wyze](https://github.com/wyze) in [65578dd](https://github.com/wyze/a-fixture/commit/65578dd))\n\n'
42+
)
43+
)
44+
)
45+
46+
await require('.').default()
47+
48+
expect(execa).toHaveBeenNthCalledWith(1, 'git', ['push', '--follow-tags'])
49+
expect(execa).toHaveBeenNthCalledWith(2, 'git', [
50+
'rev-list',
51+
'--max-parents=0',
52+
'HEAD',
53+
])
54+
expect(ghGot).toHaveBeenCalledWith('repos/wyze/a-fixture/releases', {
55+
json: {
56+
body:
57+
'* A bug fix PR ([@wyze](https://github.com/wyze) in [#1](https://github.com/wyze/a-fixture/pull/1))\n* Initial Commit ([@wyze](https://github.com/wyze) in [65578dd](https://github.com/wyze/a-fixture/commit/65578dd))\n\nhttps://github.com/wyze/a-fixture/compare/0a1b2c3...v1.0.0',
58+
tag_name: 'v1.0.0',
59+
},
60+
})
61+
})
62+
63+
it('creates second github release', async () => {
64+
jest.spyOn(execa, 'default').mockImplementation()
65+
66+
jest.spyOn(readPkg, 'default').mockResolvedValue({
67+
name: 'a-fixture',
68+
version: '2.0.0',
69+
license: 'MIT',
70+
repository: {
71+
type: 'git',
72+
url: 'git+https://github.com/wyze/a-fixture.git',
73+
},
74+
})
75+
76+
jest.spyOn(ghGot, 'default').mockImplementation()
77+
78+
// Read changelog
79+
jest
80+
.spyOn(fs, 'readFile')
81+
.mockImplementationOnce((_, cb) =>
82+
cb(
83+
null,
84+
Buffer.from(
85+
'## Change Log\n\n### [v2.0.0](https://github.com/wyze/a-fixture/releases/tag/v2.0.0) (2019-05-05)\n\n* A breaking change ([@wyze](https://github.com/wyze) in [#2](https://github.com/wyze/a-fixture/pull/2))\n\n### [v1.0.0](https://github.com/wyze/a-fixture/releases/tag/v1.0.0) (2017-05-05)\n\n* A bug fix PR ([@wyze](https://github.com/wyze) in [#1](https://github.com/wyze/a-fixture/pull/1))\n* Initial Commit ([@wyze](https://github.com/wyze) in [65578dd](https://github.com/wyze/a-fixture/commit/65578dd))\n\n'
86+
)
87+
)
88+
)
89+
90+
await require('.').default()
91+
92+
expect(execa).toHaveBeenCalledWith('git', ['push', '--follow-tags'])
93+
expect(ghGot).toHaveBeenCalledWith('repos/wyze/a-fixture/releases', {
94+
json: {
95+
body:
96+
'* A breaking change ([@wyze](https://github.com/wyze) in [#2](https://github.com/wyze/a-fixture/pull/2))\n\nhttps://github.com/wyze/a-fixture/compare/v1.0.0...v2.0.0',
97+
tag_name: 'v2.0.0',
98+
},
99+
})
100+
})

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const readFile = promisify(fs.readFile)
1919

2020
const getUrlAndVersion = async (): Promise<UrlVersion> => {
2121
const { repository, version } = await readPkg()
22-
const url = repository.url.replace(/(^git\+|\.git$)/g, '')
22+
const url = repository?.url.replace(/(^git\+|\.git$)/g, '') ?? ''
2323
const slug = url.split('/').slice(-2).join('/')
2424

2525
return { slug, url, version }
@@ -41,7 +41,7 @@ const createGithubRelease = async ({
4141
version,
4242
}: ChangesUrlVersion) =>
4343
await ghGot(`repos/${slug}/releases`, {
44-
body: {
44+
json: {
4545
body: changes.join('\n') + `\n\n${url}/compare/${latest}...v${version}`,
4646
tag_name: `v${version}`,
4747
},
@@ -60,7 +60,7 @@ export default async () => {
6060
.filter((value) => value !== '')
6161
const latest =
6262
endIndex > 0
63-
? rawChanges[endIndex].match(/\[([^\]]+)\]/)[1]
63+
? rawChanges[endIndex].match(/\[([^\]]+)\]/)?.[1] ?? ''
6464
: (
6565
await execa('git', ['rev-list', '--max-parents=0', 'HEAD'])
6666
).stdout.slice(0, 7)

tsconfig.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"lib": ["esnext"],
5+
"skipLibCheck": true,
6+
"strict": true,
7+
"forceConsistentCasingInFileNames": true,
8+
"noEmit": true,
9+
"esModuleInterop": true,
10+
"module": "esnext",
11+
"moduleResolution": "node",
12+
"resolveJsonModule": true
13+
},
14+
"exclude": ["node_modules"],
15+
"include": ["**/*.ts"]
16+
}

types.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module 'gh-got' {
2+
export { default } from 'got'
3+
}

0 commit comments

Comments
 (0)