-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
81 lines (71 loc) · 2.11 KB
/
index.js
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
#!/usr/bin/env node
const path = require('path')
const fs = require('fs')
const inquirer = require('inquirer')
const projectPath = process.cwd()
const eslintConfig = path.resolve(projectPath, '.eslintrc.js')
const eslintIgnoreConfig = path.resolve(projectPath, '.eslintignore')
const huskyConfig = path.resolve(projectPath, '.huskyrc')
const commitlintConfig = path.resolve(projectPath, '.commitlintrc.js')
const packageJson = path.resolve(projectPath, 'package.json')
const editorConfig = path.resolve(projectPath, '.editorconfig')
;(async () => {
const answers = await inquirer.prompt([
{
type: 'list',
name: 'eslintType',
message: 'eslint 类型',
choices: [
{ name: 'JS', value: '' },
{ name: 'TS', value: '/ts' },
{ name: 'Vue.js', value: '/vue' },
{ name: 'Vue.ts', value: '/vue-ts' }
]
}
])
const warn = msg => console.log(msg)
if (!fs.existsSync(packageJson)) {
// eslint-disable-next-line no-throw-literal
throw 'error: package.json not exist'
}
if (fs.existsSync(editorConfig)) {
warn('warn: editor conf exist')
} else {
fs.writeFileSync(editorConfig, fs.readFileSync(path.resolve(__dirname, '.editorconfig')))
}
if (fs.existsSync(eslintConfig)) {
warn('warn: eslint conf exist')
} else {
const eslintConfigString =
`module.exports = {
extends: [
'yyued${answers.eslintType}'
]
}
`
fs.writeFileSync(eslintConfig, eslintConfigString)
}
if (fs.existsSync(eslintIgnoreConfig)) {
warn('warn: eslint ignore conf exist')
} else {
const eslintIgnoreConfigString =
`dist
assets
`
fs.writeFileSync(eslintIgnoreConfig, eslintIgnoreConfigString)
}
if (fs.existsSync(huskyConfig)) {
warn('warn: husky conf exist')
} else {
fs.writeFileSync(huskyConfig, JSON.stringify({
hooks: {
'commit-msg': 'eslint "**/*.{js,vue}" && commitlint -e $GIT_PARAMS'
}
}, null, 2))
}
if (fs.existsSync(commitlintConfig)) {
warn('warn: commitlint conf exist')
} else {
fs.writeFileSync(commitlintConfig, fs.readFileSync(path.resolve(__dirname, 'commitlint.config.js')))
}
})()