UNPKG

1.83 kBJavaScriptView Raw
1#!/usr/bin/env node
2const chalk = require('chalk');
3const clear = require('clear');
4const figlet = require('figlet');
5const path = require('path');
6const fs = require('fs');
7
8const inquirer = require('./lib/inquirer');
9const Listr = require('./lib/listr');
10const files = require('./lib/files');
11
12clear();
13
14// console.log(
15// chalk.red('path.dirname(process.cwd())', path.dirname(process.cwd()))
16// );
17
18// show hello message
19console.log(
20 chalk.yellow(
21 figlet.textSync(`Component
22 Creator`, { horizontalLayout: 'full' })
23 )
24);
25
26const result = {};
27
28const 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
43const 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
61const componentTypeQ = async () => {
62 const quest = await inquirer.componentType();
63 result.componentType = quest.componentType;
64
65 return quest.componentType;
66}
67
68const 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
79run();
\No newline at end of file