-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
107 lines (105 loc) · 2.59 KB
/
index.js
File metadata and controls
107 lines (105 loc) · 2.59 KB
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
// @ts-check
const path = require('path')
const { name, version } = require('./package.json')
/** @type {import('caz').Template} */
module.exports = {
name,
version,
metadata: {
// TODO: predefined template metadata
year: new Date().getFullYear()
},
prompts: [
// TODO: custom template prompts
{
name: 'name',
type: 'text',
message: 'Project name'
},
{
name: 'version',
type: 'text',
message: 'Project version'
},
{
name: 'description',
type: 'text',
message: 'Project description',
initial: 'Awesome react apps.'
},
{
name: 'author',
type: 'text',
message: 'Project author name'
},
{
name: 'email',
type: 'text',
message: 'Project author email'
},
{
name: 'url',
type: 'text',
message: 'Project author url'
},
{
name: 'github',
type: 'text',
message: 'GitHub username or organization',
initial: 'zce'
},
{
name: 'features',
type: 'multiselect',
message: 'Choose the features you need',
instructions: false,
choices: [
{ title: 'Automatic test', value: 'test', selected: true }
]
},
{
name: 'install',
type: 'confirm',
message: 'Install dependencies',
initial: true
},
{
name: 'pm',
type: prev => process.env.NODE_ENV === 'test' || prev ? 'select' : null,
message: 'Package manager',
hint: ' ',
choices: [
{ title: 'npm', value: 'npm' },
{ title: 'pnpm', value: 'pnpm' },
{ title: 'yarn', value: 'yarn' }
]
}
],
filters: {
// TODO: custom template filters
/** @param {{ features: string[] }} answers */
'src/*.test.js': answers => answers.features.includes('test'),
'src/setupTests.js': answers => answers.features.includes('test')
},
helpers: {
// TODO: custom template helpers
upper: input => input.toUpperCase()
},
setup: async ctx => {
ctx.config.install = ctx.answers.install && ctx.answers.pm
},
complete: async ctx => {
// TODO: custom complete callback
console.clear()
console.log(`Created a new project in ${ctx.project} by the ${ctx.template} template.\n`)
console.log('Getting Started:')
if (ctx.dest !== process.cwd()) {
console.log(` $ cd ${path.relative(process.cwd(), ctx.dest)}`)
}
if (ctx.config.install === false) {
console.log(' $ npm install')
}
console.log(` $ ${ctx.config.install ? ctx.config.install : 'npm'} run start`)
console.log('\nHappy hacking :)\n')
}
}