-
-
Notifications
You must be signed in to change notification settings - Fork 154
/
sao.js
173 lines (160 loc) · 4.48 KB
/
sao.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
const githubUsernameRegex = require('github-username-regex');
const isURL = require('is-url');
const isEmail = require('is-email');
const superb = require('superb');
const camelcase = require('camelcase');
const uppercamelcase = require('uppercamelcase');
const slug = require('speakingurl');
const npmConf = require('npm-conf');
const isValidNpmName = require('is-valid-npm-name');
const conf = npmConf();
module.exports = {
enforceNewFolder: true,
templateOptions: {
context: {
camelcase,
uppercamelcase,
slug
}
},
prompts: {
name: {
message: 'What is the name of the new project',
default: ':folderName:',
validate: (value) => {
if (process.env.NODE_ENV === 'test' && value === 'lad') return true;
return isValidNpmName(value);
}
},
description: {
message: 'How would you describe the new project',
default: `my ${superb.random()} project`
},
pm: {
message: 'Choose a package manager',
choices: ['npm', 'yarn'],
type: 'list',
default: 'npm',
store: true
},
author: {
message: 'What is your name (the author’s)',
default: conf.get('init-author-name') || ':gitUser:',
store: true
},
email: {
message: 'What is your email (the author’s)',
default: conf.get('init-author-email') || ':gitEmail:',
store: true,
validate: (value) => (isEmail(value) ? true : 'Invalid email')
},
website: {
message: 'What is your personal website (the author’s)',
default: conf.get('init-author-url') || '',
store: true,
validate: (value) => (value === '' || isURL(value) ? true : 'Invalid URL')
},
username: {
message: 'What is your GitHub username or organization',
default: ':gitUser:',
store: true,
validate: (value) =>
githubUsernameRegex.test(value) ? true : 'Invalid GitHub username'
},
repo: {
message: 'What is your GitHub repository’s URL',
default(answers) {
return `https://github.com/${slug(answers.username)}/${slug(
slug(answers.name)
)}`;
},
validate: (value) =>
isURL(value) &&
value.indexOf('https://github.com/') === 0 &&
value.lastIndexOf('/') !== value.length - 1
? true
: 'Please include a valid GitHub.com URL without a trailing slash'
},
web: {
message: 'Do you need a web server (@ladjs/web)',
type: 'confirm',
default: true
},
api: {
message: 'Do you need an API server (@ladjs/api)',
type: 'confirm',
default: true
},
bree: {
message: 'Do you need a job scheduler (bree)',
type: 'confirm',
default: true
},
proxy: {
message: 'Do you need a proxy (http => https redirect)',
type: 'confirm',
default: true
},
i18n: {
message: 'Do you need automatic multi-lingual support',
type: 'confirm',
default: true,
when: (answers) => answers.web || answers.api
}
},
filters: {
// keeping this here as a safety guard per this gh issue
// <https://github.com/saojs/sao/issues/59>
'node_modules/**': false,
// never copy env file
'.env': false,
// ignore standard dev files
'coverage/**': false,
'build/**': false,
'.nyc_output/**': false,
'*.log': false,
'web.js': 'web === true',
'api.js': 'api === true',
'bree.js': 'bree === true',
'proxy.js': 'proxy === true',
'jobs/**': 'bree === true',
'test/config/snapshots/': false,
'test/config/snapshots/**': false,
'test/web/snapshots/': false,
'test/web/snapshots/**': false
},
move: {
// We keep `.gitignore` as `gitignore` in the project
// Because when it's published to npm
// `.gitignore` file will be ignored!
gitignore: '.gitignore',
README: 'README.md',
env: '.env'
},
post: async (ctx) => {
ctx.gitInit();
// TODO: ctx.answers.bree
// - remove from pkg
// - remove config
// - remove tests
// TODO: ctx.answers.web
// - remove from pkg
// - remove config
// - remove tests
// TODO: ctx.answers.i18n
// - remove from pkg
// - remove config
// - remove tests
// TODO: ctx.answers.api
// - remove from pkg
// - remove config
// - remove tests
// TODO: fix `template/package.json` "author" field
if (ctx.answers.pm === 'yarn') {
ctx.yarnInstall();
} else {
ctx.npmInstall();
}
ctx.showTip();
}
};