-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
80 lines (70 loc) · 2.19 KB
/
index.ts
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
#!/usr/bin/env node
import { Command } from 'commander';
import path from 'path';
import { Config, getConfig, validateConfig } from './src/util/config';
import { generateNavBar } from './src/components/NavBar';
import { generateSideBar } from './src/components/SideBar';
import { generateDropUp } from './src/components/DropUp';
import { genFiles } from './src/util/generateComponents';
import chalk from 'chalk';
const PATH = process.cwd() + '/essential.config.json';
const USE_TS = false;
let config: Config;
try {
config = getConfig(PATH);
config = validateConfig(config);
} catch (err) {
// throw err;
console.error(chalk.red(err.message));
process.exit(1);
}
// config is safe now
const { componentDir, stylesDir } = config;
// let relativePathToCSS = path.relative(componentDir, stylesDir);
let relativePathToCSS = String.raw`${path.relative(
componentDir,
stylesDir
)}`.replace(/\\/g, '/');
if (relativePathToCSS.trim() == '') relativePathToCSS = '.';
const program = new Command();
program
.option('-n, --name <type>', 'name of the component')
.requiredOption(
'-t, --component-type <type>',
'Type of component to generate'
)
.option('-ts, --typescript', 'Use Typescript', false);
program.parse(process.argv);
const options = program.opts();
switch (options.componentType) {
case 'NavBar':
generateNavBar({
cssPath: relativePathToCSS,
name: options.name ? options.name : options.componentType,
useTS: options.typescript,
config,
genFiles,
});
break;
case 'SideBar':
generateSideBar({
cssPath: relativePathToCSS,
name: options.name ? options.name : options.componentType,
useTS: options.typescript,
config,
genFiles,
});
break;
case 'DropUp':
generateDropUp({
cssPath: relativePathToCSS,
name: options.name ? options.name : options.componentType,
useTS: options.typescript,
config,
genFiles,
});
break;
default:
console.error(chalk.red('Invalid component type'));
process.exit(1);
}