This repository has been archived by the owner on Jul 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
saofile.js
160 lines (145 loc) · 3.7 KB
/
saofile.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
const { join } = require('path')
const glob = require('glob')
const spawn = require('cross-spawn')
const validate = require('validate-npm-package-name')
const rootDir = __dirname
module.exports = {
prompts: [
{
name: 'name',
message: 'Project name',
default: '{outFolder}'
},
{
name: 'description',
message: 'Project description',
default: 'My Nuxt.js project'
},
{
name: 'features',
message: 'Choose features to install',
type: 'checkbox',
choices: [
{
name: 'Progressive Web App (PWA) Support',
value: 'pwa'
},
{
name: 'Linter / Formatter',
value: 'linter'
},
{
name: 'Prettier',
value: 'prettier'
},
{
name: 'Axios',
value: 'axios'
}
],
default: []
},
{
name: 'mode',
message: 'Choose rendering mode',
type: 'list',
choices: [
{ name: 'Universal', value: 'universal' },
{ name: 'Single Page App', value: 'spa' }
],
default: 'universal'
},
{
name: 'author',
type: 'string',
message: 'Author name',
default: '{gitUser.name}',
store: true
},
{
name: 'pm',
message: 'Choose a package manager',
choices: ['npm', 'yarn'],
type: 'list',
default: 'npm'
}
],
templateData() {
const edge = process.argv.includes('--edge')
const pwa = this.answers.features.includes('pwa')
const linter = this.answers.features.includes('linter')
const prettier = this.answers.features.includes('prettier')
const axios = this.answers.features.includes('axios')
return {
edge,
pwa: pwa ? 'yes' : 'no',
eslint: linter ? 'yes' : 'no',
prettier: prettier ? 'yes' : 'no',
axios: axios ? 'yes' : 'no'
}
},
actions() {
const validation = validate(this.answers.name)
validation.warnings && validation.warnings.forEach((warn) => {
console.warn('Warning:', warn)
})
validation.errors && validation.errors.forEach((err) => {
console.error('Error:', err)
})
validation.errors && validation.errors.length && process.exit(1)
const actions = [{
type: 'add',
files: '**',
templateDir: 'template/nuxt',
filters: {
'static/icon.png': 'features.includes("pwa")'
}
}]
actions.push({
type: 'add',
files: '*',
filters: {
'_.eslintrc.js': 'features.includes("linter")',
'_.prettierrc': 'features.includes("prettier")'
}
})
actions.push({
type: 'move',
patterns: {
'_.gitignore': '.gitignore',
'_.eslintrc.js': '.eslintrc.js',
'_.prettierrc': '.prettierrc'
}
})
return actions
},
async completed() {
this.gitInit()
await this.npmInstall({ npmClient: this.answers.pm })
const isNewFolder = this.outDir !== process.cwd()
const cd = () => {
if (isNewFolder) {
console.log(`\t${this.chalk.cyan('cd')} ${this.outFolder}`)
}
}
if (this.answers.features.includes('linter')) {
const options = ['run', 'lint', '--', '--fix']
if (this.answers.pm === 'yarn') {
options.splice(2, 1)
}
spawn.sync(this.answers.pm, options, {
cwd: this.outDir,
stdio: 'inherit'
})
}
console.log()
console.log(this.chalk.bold(` To get started:\n`))
cd()
console.log(`\t${this.answers.pm} run dev\n`)
console.log(this.chalk.bold(` To build & start for production:\n`))
cd()
console.log(`\t${this.answers.pm} run build`)
console.log(`\t${this.answers.pm} start`)
console.log()
}
}