-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnodelib.ts
97 lines (90 loc) · 2.59 KB
/
nodelib.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { rule as readme } from '../rules/readme'
import { Rule } from '../interfaces' // eslint-disable-line no-unused-vars
import { create as createScriptRule } from '../rules/script'
import { create as createGitHooksRule } from '../rules/githook'
const SRC_GLOB = "'{src,scripts,test}/**/*.{js,jsx,ts,tsx}'"
const onPrecommit = createGitHooksRule({
devDependencies: [{ name: 'lint-staged', range: '*' }],
name: 'lint-format-on-precommit',
hooks: {
'pre-commit': 'lint-staged'
}
})
const lintStaged: Rule = {
name: 'configure-lint-staged',
plan: ({ ctx: { packageJson, logger } }) => {
if (packageJson['lint-staged']) {
logger.debug(
`lint-staged already exists: ${JSON.stringify(
packageJson['lint-staged']
)}`
)
return null
}
return () => {
packageJson['lint-staged'] = {
linters: {
[SRC_GLOB]: ['npm run format', 'npm run lint', 'git add']
}
}
}
}
}
export const format = createScriptRule({
devDependencies: [{ name: 'prettier-standard', range: '*' }],
name: 'format',
scriptName: 'format',
scriptCommand: `prettier-standard ${SRC_GLOB}`
})
export const lintJs = createScriptRule({
devDependencies: [{ name: 'standard', range: '*' }],
name: 'lint',
scriptCommand: "standard '{src,ts}/**/*.{js,jsx}'",
scriptName: 'lint'
})
const tsLintWithoutParser = createScriptRule({
devDependencies: [{ name: 'standard', range: '*' }],
name: 'lint',
scriptCommand: "standard '{src,ts}/**/*.{js,jsx}'",
scriptName: 'lint'
})
export const tsLint: Rule = {
...tsLintWithoutParser,
devDependencies: [
{ name: '@typescript-eslint/parser', range: '*' },
...tsLintWithoutParser.devDependencies!
],
plan: async opts => {
const {
ctx: { packageJson }
} = opts
const tsLintWithoutParserMigration = await tsLintWithoutParser.plan!(opts)
return async () => {
if (tsLintWithoutParserMigration) await tsLintWithoutParserMigration()
const standard = (packageJson.standard = packageJson.standard || {})
standard.parser = '@typescript-eslint/parser'
standard.plugins = Array.from(
new Set(standard.plugins || []).add('typescript')
)
standard.ignore = Array.from(
new Set(standard.ignore || []).add('**/*.d.ts')
)
}
}
}
const tsBuild = createScriptRule({
name: 'typescript-build',
devDependencies: [{ name: 'typescript', range: '*' }],
scriptName: 'build',
scriptCommand: 'tsc'
})
export const rules = {
common: { format, readme, lintStaged, onPrecommit },
js: {
lintJs
},
ts: {
tsLint,
tsBuild
}
}