-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.hooks.js
57 lines (54 loc) · 1.59 KB
/
template.hooks.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
const { resolve } = require("path")
module.exports = {
// 模板初始前询问是使用ts还是js
async beforeInit({
print,
fs,
prompt,
configs
}) {
const question = [
{
type: "list",
name: "useWhichEsType",
message: "whether use ts or js?",
choices: ["typescript", "ecmascript"]
}
]
try {
const TS_FOLDER_PATH = resolve(configs.resourcePath, "./templateList/ts")
const JS_FOLDER_PATH = resolve(configs.resourcePath, "./templateList/js")
const ROOT_TEMPLATE_PATH = resolve(configs.resourcePath, "./template")
let targetDir = ""
const { useWhichEsType } = await prompt(question)
if(useWhichEsType === "typescript") {
targetDir = TS_FOLDER_PATH
}
if(useWhichEsType === "ecmascript") {
targetDir = JS_FOLDER_PATH
}
await fs.move(targetDir, ROOT_TEMPLATE_PATH, {
overwrite: true
})
} catch (error) {
print.error(error)
}
},
afterInit({
print,
configs
}) {
const { cliMessage } = configs
print.warn(
`
cd ${cliMessage.name}
npm install or yarn 安装依赖
npm start 运行main文件,启动服务器
npm run watch 监听src目录
npm run watch:quiet 监听src目录,不输出日志
npm test 运行测试
npm run build 打包代码
`
)
}
}