-
Notifications
You must be signed in to change notification settings - Fork 93
/
cli.collect.js
403 lines (379 loc) · 15.4 KB
/
cli.collect.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
const inquirer = require('inquirer');
const joi = require('joi');
const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
const { plantumlVersions } = require('./utils');
const validate = (schema) => (answers) => {
//just in case
if (joi.validate) {
return !joi.validate(answers, schema).error;
} else {
return !schema.validate(answers).error;
}
};
module.exports = async (currentConfiguration, conf, program) => {
if (!currentConfiguration.PROJECT_NAME || program.config) {
responses = await inquirer.prompt({
type: 'input',
name: 'projectName',
message: 'Project Name',
default: currentConfiguration.PROJECT_NAME || path.parse(process.cwd()).name,
validate: validate(joi.string().trim().optional())
});
conf.set('projectName', responses.projectName);
}
if (!currentConfiguration.HOMEPAGE_NAME || program.config) {
responses = await inquirer.prompt({
type: 'input',
name: 'homepageName',
message: 'HomePage Name',
default: currentConfiguration.HOMEPAGE_NAME || 'Overview',
validate: validate(joi.string().trim().optional())
});
conf.set('homepageName', responses.homepageName);
}
if (!currentConfiguration.ROOT_FOLDER || program.config) {
responses = await inquirer.prompt({
type: 'input',
name: 'rootFolder',
message: 'Root documentation folder',
default: currentConfiguration.ROOT_FOLDER || 'src',
validate: (answers) => {
let isValid = validate(joi.string().trim().optional())(answers);
if (isValid) {
if (answers.indexOf('/') !== -1 || answers.indexOf('\\') !== -1) return false;
//check it's an actual folder
let isDirectory = fs.statSync(path.join(process.cwd(), answers)).isDirectory();
if (isDirectory) return true;
}
return false;
}
});
conf.set('rootFolder', responses.rootFolder);
}
if (!currentConfiguration.DIST_FOLDER || program.config) {
responses = await inquirer.prompt({
type: 'input',
name: 'distFolder',
message: 'Destination folder',
default: currentConfiguration.DIST_FOLDER || 'docs',
validate: (answers) => {
let isValid = validate(joi.string().trim().optional());
if (isValid) {
if (answers.indexOf('/') !== -1 || answers.indexOf('\\') !== -1) return false;
return true;
}
return false;
}
});
conf.set('distFolder', responses.distFolder);
}
if (
currentConfiguration.GENERATE_MD === undefined ||
currentConfiguration.GENERATE_COMPLETE_MD_FILE === undefined ||
currentConfiguration.GENERATE_PDF === undefined ||
currentConfiguration.GENERATE_COMPLETE_PDF_FILE === undefined ||
currentConfiguration.GENERATE_WEBSITE === undefined ||
program.config
) {
let defaults = [
currentConfiguration.GENERATE_MD === undefined
? null
: currentConfiguration.GENERATE_MD
? 'generateMD'
: null,
currentConfiguration.GENERATE_PDF === undefined
? 'generatePDF'
: currentConfiguration.GENERATE_PDF
? 'generatePDF'
: null,
currentConfiguration.GENERATE_COMPLETE_MD_FILE === undefined
? null
: currentConfiguration.GENERATE_COMPLETE_MD_FILE
? 'generateCompleteMD'
: null,
currentConfiguration.GENERATE_COMPLETE_PDF_FILE === undefined
? 'generateCompletePDF'
: currentConfiguration.GENERATE_COMPLETE_PDF_FILE
? 'generateCompletePDF'
: null,
currentConfiguration.GENERATE_WEBSITE === undefined
? 'generateWEB'
: currentConfiguration.GENERATE_WEBSITE
? 'generateWEB'
: null
];
responses = await inquirer.prompt({
type: 'checkbox',
name: 'generate',
message: 'Compilation format:',
default: defaults,
choices: [
{
name: 'Multiple markdown files',
value: 'generateMD'
},
{
name: 'Generate a single complete markdown file',
value: 'generateCompleteMD'
},
{
name: 'Generate multiple pdf files',
value: 'generatePDF'
},
{
name: 'Generate a single complete pdf file',
value: 'generateCompletePDF'
},
{
name: 'Generate website',
value: 'generateWEB'
}
]
});
conf.set('generateMD', !!responses.generate.find((x) => x === 'generateMD'));
conf.set('generatePDF', !!responses.generate.find((x) => x === 'generatePDF'));
conf.set('generateCompleteMD', !!responses.generate.find((x) => x === 'generateCompleteMD'));
conf.set('generateCompletePDF', !!responses.generate.find((x) => x === 'generateCompletePDF'));
conf.set('generateWEB', !!responses.generate.find((x) => x === 'generateWEB'));
if (!!responses.generate.find((x) => x === 'generateMD')) {
let mdOptions = await inquirer.prompt({
type: 'confirm',
name: 'includeNavigation',
message: 'Include basic navigation?',
default:
currentConfiguration.INCLUDE_NAVIGATION === undefined
? false
: currentConfiguration.INCLUDE_NAVIGATION
});
conf.set('includeNavigation', mdOptions.includeNavigation);
mdOptions = await inquirer.prompt({
type: 'confirm',
name: 'includeTableOfContents',
message: 'Include navigable table of contents?',
default:
currentConfiguration.INCLUDE_TABLE_OF_CONTENTS === undefined
? true
: currentConfiguration.INCLUDE_TABLE_OF_CONTENTS
});
conf.set('includeTableOfContents', mdOptions.includeTableOfContents);
}
if (!!responses.generate.find((x) => x === 'generateWEB')) {
let webOptions = await inquirer.prompt({
type: 'input',
name: 'webTheme',
message: 'Change the default docsify theme?',
default: currentConfiguration.WEB_THEME || '//unpkg.com/docsify/lib/themes/vue.css'
});
conf.set('webTheme', webOptions.webTheme);
webOptions = await inquirer.prompt({
type: 'input',
name: 'supportSearch',
message: 'Support search on navbar?',
default: true
});
conf.set('supportSearch', webOptions.supportSearch);
webOptions = await inquirer.prompt({
type: 'input',
name: 'repoUrl',
message: 'Include a repository url?',
default: currentConfiguration.REPO_NAME
});
conf.set('repoUrl', webOptions.repoUrl);
webOptions = await inquirer.prompt({
type: 'input',
name: 'docsifyTemplate',
message: 'Path to a specific Docsify template?',
default: ''
});
conf.set('docsifyTemplate', webOptions.docsifyTemplate);
webOptions = await inquirer.prompt({
type: 'input',
name: 'webPort',
message: 'Change the default serve port?',
default: currentConfiguration.WEB_PORT || '3000'
});
conf.set('webPort', webOptions.webPort);
}
if (!!responses.generate.find((x) => x === 'generatePDF' || x === 'generateCompletePDF')) {
let pdfOptions = await inquirer.prompt({
type: 'input',
name: 'pdfCss',
message: 'Add a custom css for the pdf (filename)?',
default: currentConfiguration.PDF_CSS
});
conf.set('pdfCss', pdfOptions.pdfCss);
}
}
let plantumlVersion, ver;
if (currentConfiguration.PLANTUML_VERSION === undefined || program.config) {
let defaultPlantumlVersion =
currentConfiguration.PLANTUML_VERSION === undefined
? 'latest'
: currentConfiguration.PLANTUML_VERSION;
responses = await inquirer.prompt({
type: 'list',
name: 'plantumlVersion',
message: 'PlantUML version:',
default: defaultPlantumlVersion,
choices: plantumlVersions
.map((v) => {
return {
name: v.version,
value: v.version
};
})
.concat({
name: 'latest (compatible with plantuml online server)',
value: 'latest'
})
});
plantumlVersion = responses.plantumlVersion;
conf.set('plantumlVersion', plantumlVersion);
if (
currentConfiguration.PLANTUML_VERSION &&
plantumlVersion !== currentConfiguration.PLANTUML_VERSION
) {
console.log(chalk.bold(chalk.yellow('WARNING:')));
console.log(
chalk.bold(
chalk.yellow(
`You need to update the plantuml file to include https://raw.githubusercontent.com/adrianvlupu/C4-PlantUML/${plantumlVersion}.`
)
)
);
}
} else {
plantumlVersion = currentConfiguration.PLANTUML_VERSION;
}
ver = plantumlVersions.find((v) => v.version === plantumlVersion);
if (plantumlVersion === 'latest') ver = plantumlVersions.find((v) => v.isLatest);
if (!ver) throw new Error(`PlantUML version ${options.PLANTUML_VERSION} not supported`);
if (!ver.isLatest) {
console.log(
chalk.bold(
chalk.yellow(
`Generating diagram images using the online plantuml server will break on version ${ver.version}.`
)
)
);
console.log(
chalk.bold(chalk.yellow(`The build will generate diagram images using the included ${ver.jar}.`))
);
}
if (
currentConfiguration.GENERATE_LOCAL_IMAGES === undefined ||
currentConfiguration.EMBED_DIAGRAM === undefined ||
currentConfiguration.INCLUDE_BREADCRUMBS === undefined ||
currentConfiguration.INCLUDE_LINK_TO_DIAGRAM === undefined ||
currentConfiguration.EXCLUDE_OTHER_FILES === undefined ||
program.config
) {
let defaults = [
currentConfiguration.INCLUDE_BREADCRUMBS === undefined
? 'includeBreadcrumbs'
: currentConfiguration.INCLUDE_BREADCRUMBS
? 'includeBreadcrumbs'
: null,
currentConfiguration.GENERATE_LOCAL_IMAGES === undefined
? null
: currentConfiguration.GENERATE_LOCAL_IMAGES
? 'generateLocalImages'
: null,
currentConfiguration.INCLUDE_LINK_TO_DIAGRAM === undefined
? null
: currentConfiguration.INCLUDE_LINK_TO_DIAGRAM
? 'includeLinkToDiagram'
: null,
currentConfiguration.DIAGRAMS_ON_TOP === undefined
? 'diagramsOnTop'
: currentConfiguration.DIAGRAMS_ON_TOP
? 'diagramsOnTop'
: null,
currentConfiguration.EMBED_DIAGRAM === undefined
? null
: currentConfiguration.EMBED_DIAGRAM
? 'embedDiagram'
: null,
currentConfiguration.EXCLUDE_OTHER_FILES === undefined
? null
: currentConfiguration.EXCLUDE_OTHER_FILES
? 'excludeOtherFiles'
: null
];
let choices = [
{
name: 'Include breadcrumbs',
value: 'includeBreadcrumbs'
},
{
name: 'Replace diagrams with a link',
value: 'includeLinkToDiagram'
},
{
name: 'Place diagrams before text',
value: 'diagramsOnTop'
},
{
name: 'Embed SVG Diagram',
value: 'embedDiagram'
},
{
name: 'Exclude other files',
value: 'excludeOtherFiles'
}
];
if (ver.isLatest)
choices.push({
name: 'Generate diagram images locally',
value: 'generateLocalImages'
});
responses = await inquirer.prompt({
type: 'checkbox',
name: 'generate',
message: 'Compilation format:',
default: defaults,
choices: choices
});
conf.set('includeBreadcrumbs', !!responses.generate.find((x) => x === 'includeBreadcrumbs'));
conf.set('includeLinkToDiagram', !!responses.generate.find((x) => x === 'includeLinkToDiagram'));
conf.set('diagramsOnTop', !!responses.generate.find((x) => x === 'diagramsOnTop'));
conf.set('embedDiagram', !!responses.generate.find((x) => x === 'embedDiagram'));
conf.set('excludeOtherFiles', !!responses.generate.find((x) => x === 'excludeOtherFiles'));
if (ver.isLatest) {
conf.set('generateLocalImages', !!responses.generate.find((x) => x === 'generateLocalImages'));
} else {
conf.set('generateLocalImages', true);
}
}
if (!currentConfiguration.PLANTUML_SERVER_URL || program.config) {
responses = await inquirer.prompt({
type: 'input',
name: 'plantumlServerUrl',
message: 'PlantUML Server URL',
default: currentConfiguration.PLANTUML_SERVER_URL || 'https://www.plantuml.com/plantuml',
validate: validate(joi.string().trim().optional())
});
conf.set('plantumlServerUrl', responses.plantumlServerUrl);
}
if (!currentConfiguration.DIAGRAM_FORMAT || program.config) {
responses = await inquirer.prompt({
type: 'input',
name: 'diagramFormat',
message: 'Diagram Image Format',
default: currentConfiguration.DIAGRAM_FORMAT || 'svg',
validate: validate(joi.string().trim().optional())
});
conf.set('diagramFormat', responses.diagramFormat);
}
if (!currentConfiguration.CHARSET || program.config) {
responses = await inquirer.prompt({
type: 'input',
name: 'charset',
message: 'Change the default charset',
default: currentConfiguration.CHARSET || 'UTF-8'
});
conf.set('charset', responses.charset);
}
};