-
Notifications
You must be signed in to change notification settings - Fork 0
/
sherry-config.js
152 lines (133 loc) · 2.89 KB
/
sherry-config.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
144
145
146
147
148
149
150
151
152
const chalk = require('chalk')
const path = require('path')
const fs = require('fs')
const defaultPkg = require('./template/package.json')
const pkg = resolvePkg()
const isNewProject = !pkg
const { name, description } = pkg || {}
if (pkg) {
tip('Detected existing project!')
} else {
tip('You are creating a new project!')
}
module.exports = {
prompts() {
return [
{
name: 'name',
message: 'Project\'s name?',
default: isNewProject
? this.outFolder
: name
},
{
name: 'description',
message: 'Project\'s description?',
default: description
},
{
name: 'username',
message: 'Your name?',
default: this.gitUser.name,
},
{
name: 'email',
message: 'What is your GitHub email',
default: process.env.NODE_ENV === 'test'
? 'a@b.com'
: this.gitUser.email,
store: true,
validate: v => /.+@.+/.test(v)
},
{
name: 'title',
message: 'Project\'s title?',
default({ name }) {
return name
}
},
{
name: 'base',
message: 'Project\'s base url?',
default({ name }) {
return `/`
},
},
{
name: 'pm',
message: 'Choose a package manager',
choices: ['npm', 'yarn'],
type: 'list',
default: 'yarn'
}
]
},
actions() {
return [
{
type: 'add',
files: '**',
filters: {
'package.json': isNewProject,
"gitignore": isNewProject
}
},
{
type: 'move',
patterns: {
'gitignore': '.gitignore'
}
},
]
},
completed() {
console.log(`Success`)
// console.log(arguments)
// const { pm, installScript } = stream.meta.merged
// console.log(`
// Develop your docs: ${coloredCommand(localizeScript(pm, 'docs:dev'))}\n
// Build dir as static site: ${coloredCommand(localizeScript(pm, 'docs:build'))}\n
// Release you docs: ${coloredCommand(localizeScript(pm, 'docs:release'))}\n`
// )
}
}
/**
* Resolve package.json
* @returns {Object}
*/
function resolvePkg() {
if (process.env.NODE_ENV === 'test') {
return
}
const target = path.resolve(process.cwd(), 'package.json')
if (fs.existsSync(target)) {
return require(target)
}
}
/**
* Simple tip logger
* @param {string} msg
*/
function tip(msg) {
console.log(`\n${chalk.bgGreen(chalk.black(' TIP '))} ${msg}\n`)
}
/**
*
* @param {string} pm package manager
* @param {string} command
* @returns {string}
*/
function localizeScript(pm, command) {
if (pm === 'npm') {
return `npm run ${command}`
}
return `yarn ${command}`
}
/**
* Colored command string
* @param {string} cmd
* @returns {string}
*/
function coloredCommand(cmd) {
return chalk.blueBright(cmd)
}