1 | #!/usr/bin/env node
|
2 | const chalk = require('chalk');
|
3 | const clear = require('clear');
|
4 | const figlet = require('figlet');
|
5 | const path = require('path');
|
6 | const fs = require('fs');
|
7 |
|
8 | const inquirer = require('./lib/inquirer');
|
9 | const Listr = require('./lib/listr');
|
10 | const files = require('./lib/files');
|
11 |
|
12 | clear();
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | console.log(
|
20 | chalk.yellow(
|
21 | figlet.textSync(`Component
|
22 | Creator`, { horizontalLayout: 'full' })
|
23 | )
|
24 | );
|
25 |
|
26 | const result = {};
|
27 |
|
28 | const distQ = async () => {
|
29 | const { dist } = await inquirer.distination();
|
30 |
|
31 | if (!files.isExistFolder(dist)) {
|
32 | const create = await inquirer.folderExist(dist, false);
|
33 |
|
34 | if (!create[`exist_${dist}`]) {
|
35 | return await distQ();
|
36 | }
|
37 | }
|
38 |
|
39 | result.dist = dist;
|
40 | return dist;
|
41 | }
|
42 |
|
43 | const componentNameQ = async (dist) => {
|
44 | const { componentName } = await inquirer.componentName();
|
45 | const path = `${dist}/${componentName}`;
|
46 | if (files.isExistFolder(path)) {
|
47 |
|
48 | const create = await inquirer.folderExist(componentName, true);
|
49 |
|
50 |
|
51 | if (!create[`exist_${componentName}`]) {
|
52 |
|
53 | return await componentNameQ(dist);
|
54 | }
|
55 | }
|
56 |
|
57 | result.componentName = componentName;
|
58 | return componentName;
|
59 | }
|
60 |
|
61 | const componentTypeQ = async () => {
|
62 | const quest = await inquirer.componentType();
|
63 | result.componentType = quest.componentType;
|
64 |
|
65 | return quest.componentType;
|
66 | }
|
67 |
|
68 | const run = async () => {
|
69 | const dist = await distQ();
|
70 | const name = await componentNameQ(dist);
|
71 | const type = await componentTypeQ();
|
72 | const componentParams = { dist, name, type };
|
73 | const path = `${dist}/${name}`;
|
74 |
|
75 | console.log('result', result);
|
76 | Listr.run(path, componentParams);
|
77 | }
|
78 |
|
79 | run(); |
\ | No newline at end of file |