-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
66 lines (63 loc) · 3.16 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
#!/usr/bin/env node
const program = require('commander')
const shell = require('shelljs')
const fs = require('fs')
program
.version('2.1.1')
.arguments('[dir]')
.option('-y, --yarn', 'use yarn instead of npm')
.option('-t, --typescript', 'use typescript support')
.option('-c, --cra', 'if it is a project generated by create-react-app or not')
.action(function(dir, cmd) {
if (dir) {
shell.cd(dir)
}
const isTs = cmd.typescript
const isYarn = cmd.yarn
const isCra = cmd.cra
fs.readFile('package.json', 'utf8', (err, package) => {
if (err) {
throw err
} else {
shell.exec('git clone git@github.com:justb/specification-front.git')
shell.exec('rm -rf ./specification-front/.git')
shell.exec('mv ./specification-front/.[!.]* . && mv ./specification-front/* .')
shell.exec('rm -rf ./specification-front')
fs.readFile('husky.json', 'utf8', (err, husky) => {
if (err) {
throw err
} else {
let pack = Object.assign(JSON.parse(package || '{}'), JSON.parse(husky))
if (!pack.scripts) {
pack.scripts = {}
}
pack.scripts['commit'] = 'git-cz'
pack.scripts['eslint'] = 'eslint --cache --fix "app/**/*.{js,jsx}"'
pack.scripts['stylelint'] = 'stylelint "app/**/*.{css,less,scss,sss}" --fix'
fs.writeFile('package.json', JSON.stringify(pack), err => {
if (err) throw err
shell.exec('rm -rf husky.json')
// eslint babel-eslint eslint-plugin-import eslint-plugin-flowtype eslint-plugin-jsx-a11y eslint-config-react-app eslint-plugin-react
let nodeModules =
' lint-staged@8.2.1 husky commitizen prettier eslint-config-prettier eslint-plugin-prettier '
let scss = ' stylelint stylelint-config-recommended '
nodeModules += scss
if (!isCra) {
nodeModules +=
' eslint babel-eslint eslint-plugin-react-hooks eslint-plugin-import eslint-plugin-flowtype eslint-plugin-jsx-a11y eslint-config-react-app eslint-plugin-react '
}
if (isTs) {
nodeModules += '@typescript-eslint/eslint-plugin @typescript-eslint/parser'
shell.exec('mv ./ts/.[!.]* . && mv ./ts/* .')
}
shell.exec('rm -rf ts')
shell.exec('rm -rf .stylint.json')
shell.exec((isYarn ? 'yarn add' : 'npm i') + nodeModules)
console.log('It is finished!')
})
}
})
}
})
})
program.parse(process.argv)