-
Notifications
You must be signed in to change notification settings - Fork 3
/
saofile.js
80 lines (71 loc) · 2.23 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
const { relative } = require('path');
const validate = require('validate-npm-package-name');
module.exports = {
prompts: require('./prompts'),
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/base',
},
{
type: 'move',
patterns: {
gitignore: '.gitignore',
env: '.env',
// If we use `package.json` directly
// Then `template` folder will be treated as a package too, which isn't safe
'_package.json': 'package.json',
'eslintrc.cjs': '.eslintrc.cjs',
},
},
];
// user wants Vuepress for hosting docs
if (this.answers.docs !== false) {
actions.push({
type: 'add',
files: '**',
templateDir: 'template/features/docs',
});
// If user wants to deploy vuepress docs on
if (this.answers.netlify !== false) {
actions.push({
type: 'add',
files: '**',
templateDir: 'template/features/netlify',
});
}
}
return actions;
},
async completed() {
this.gitInit();
await this.npmInstall({
npmClient: 'npm',
installArgs: ['--force', '--prefer-offline', '--no-audit'],
});
const chalk = this.chalk;
const isNewFolder = this.outDir !== process.cwd();
const relativeOutFolder = relative(process.cwd(), this.outDir);
const cdMsg = isNewFolder ? chalk`\t{cyan cd ${relativeOutFolder}}\n` : '';
console.log(
chalk`\n🎉 {bold Successfully created project} {cyan ${this.answers.name}}\n`,
);
console.log(chalk` {bold To build & start for production:}\n`);
console.log(chalk`${cdMsg}\t{cyan npm run build}`);
console.log(chalk`\t{cyan npm run release:prepare}\n`);
console.log(chalk` {bold To test:}\n`);
console.log(chalk`${cdMsg}\t{cyan npm run test}\n`);
},
};