-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.hooks.js
45 lines (42 loc) · 1.33 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
const { resolve } = require("path")
module.exports = {
async afterInit({
print,
fs,
prompt,
configs
}) {
try {
const { resourcePath } = configs;
const targetPath = resolve(resourcePath, "./package.json");
const clone = require(targetPath);
let ifUseFrame;
/**
* 通过询问用户是否使用框架,然后给package.json写入useFrame字段.
*/
const { useFrame } = await prompt([
{
type: "list",
name: "useFrame",
message: "Do you want use framework such as vue or svelte?",
choices: ["yes", "no"]
}
]);
if (useFrame === "yes") {
ifUseFrame = true;
} else if (useFrame === "no") {
ifUseFrame = false;
}
clone.useFrame = ifUseFrame;
await fs.outputFile(targetPath, JSON.stringify(clone, null, 2), "utf-8");
print.warn(`
npm install or yarn 安装依赖
npm test 本地mocha框架单元测试
npm run build 打包代码
npm publish --access=pubilc 发布npm包
`);
} catch (error) {
print.error(error);
}
}
}