forked from nuxt/create-nuxt-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sao.js
143 lines (136 loc) · 3.51 KB
/
sao.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
const superb = require('superb')
const glob = require('glob')
const join = require('path').join
const rootDir = __dirname
const moveFramework = (answer, to = '') => {
if (answer === 'none') return
return move(`frameworks/${answer}`, to)
}
const move = (from, to = '') => {
const result = {}
const options = { cwd: join(rootDir, 'template'), nodir: true, dot: true }
for (const file of glob.sync(`${from}/**`, options)) {
result[file] = (to ? to + '/' : '') + file.replace(`${from}/`, '')
}
return result
}
module.exports = {
prompts: {
name: {
message: 'Project name',
default: ':folderName:'
},
description: {
message: 'Project description',
default: `My ${superb()} Nuxt.js project`
},
server: {
message: 'Use a custom server framework',
type: 'list',
choices: [
'none',
'express',
'koa',
'adonis',
'hapi',
'feathers',
'micro'
],
default: 'none'
},
ui: {
message: 'Use a custom UI framework',
type: 'list',
choices: [
'none',
'bootstrap',
'vuetify',
'bulma',
'tailwind',
'element-ui'
],
default: 'none'
},
mode: {
message: 'Choose rendering mode',
type: 'list',
choices: [
{name: 'Universal', value: 'universal'},
{name: 'Single Page App', value: 'spa'}
],
default: 'universal'
},
axios: {
message: 'Use axios module',
type: 'list',
choices: ['no', 'yes'],
default: 'no'
},
eslint: {
message: 'Use eslint',
type: 'list',
choices: ['no', 'yes'],
default: 'no'
},
author: {
type: 'string',
message: 'Author name',
default: ':gitUser:',
store: true
}
},
filters: {
'server/index-express.js': 'server === "express"',
'server/index-koa.js': 'server === "koa"',
'server/index-adonis.js': 'server === "adonis"',
'server/index-hapi.js': 'server === "hapi"',
'server/index-feathers.js': 'server === "feathers"',
'server/index-micro.js': 'server === "micro"',
'frameworks/adonis/**': 'server === "adonis"',
'frameworks/feathers/**': 'server === "feathers"',
'frameworks/micro/**': 'server === "micro"',
'frameworks/vuetify/**': 'ui === "vuetify"',
'frameworks/element-ui/**': 'ui === "element-ui"',
'frameworks/tailwind/**': 'ui === "tailwind"',
'.eslintrc.js': 'eslint === "yes"'
},
move(answers) {
const moveable = {
'gitignore': '.gitignore',
'_package.json': 'package.json',
'server/index-*.js': 'server/index.js'
}
let nuxtDir
if (answers.server === 'adonis') {
nuxtDir = 'resources'
}
return Object.assign(
moveable,
move('nuxt', nuxtDir),
moveFramework(answers.server),
moveFramework(answers.ui, nuxtDir),
answers.server === 'adonis' ? {
'server/index-*.js': 'server.js',
'nuxt/nuxt.config.js': 'config/nuxt.js'
} : null
)
},
post({ npmInstall, gitInit, chalk, isNewFolder, folderName }) {
gitInit()
npmInstall()
const cd = () => {
if (isNewFolder) {
console.log(` ${chalk.cyan('cd')} ${folderName}`)
}
}
console.log()
console.log(chalk.bold(` To get started:\n`))
cd()
console.log(` npm run dev\n`)
console.log(chalk.bold(` To build & start for production:\n`))
cd()
console.log(` npm run build`)
console.log(` npm start`)
console.log()
}
}