This repository has been archived by the owner on Nov 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
executable file
·62 lines (49 loc) · 1.83 KB
/
index.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
#!/usr/bin/env node
const path = require('path');
const prompts = require('prompts');
const QUESTIONS = require('./config/questions');
const component = require('./lib/factory');
const log = require('./lib/log');
const componentConfig = ({ name, component, isLazy }) => {
return { component: name, isLazy, ...component };
};
const getName = async () => {
if (process.argv[2]) {
return { name: process.argv[2].trim() };
}
return prompts(QUESTIONS.main);
};
const isTest = () => Array.from(process.argv).includes('--test');
(async () => {
try {
if (isTest()) {
const data = await prompts(QUESTIONS.specs);
const specFactory = require('./lib/specFactory');
const files = require('./lib/readSrc').getFiles();
const { spec } = data;
const file = files[spec.type].find(({ name }) => name === spec.file);
return specFactory(file, spec);
}
const answers = await getName();
const data = await prompts(QUESTIONS.component);
answers.component = data;
if (answers.component.type !== 'module') {
const { module } = await prompts(QUESTIONS.bindModule);
answers.component.module = module;
if (!module) {
throw new Error('You must select a module');
}
if ('directive' === answers.component.type || 'modal' === answers.component.type) {
const data = await prompts(QUESTIONS.directives);
answers.component.options = data;
}
}
if (answers.component.type === 'module') {
const { isLazy } = await prompts(QUESTIONS.module);
answers.isLazy = isLazy;
}
await component.create(componentConfig(answers));
} catch (e) {
log.error(e);
}
})();