-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
50 lines (42 loc) · 1.28 KB
/
main.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
const fs = require("fs");
const { getGenerator } = require("./generators/GeneratorList");
const process = require("process");
/**
* the abstract class for the adapter
*/
function generateTemplate() {
// used for generating a template
const templateName = process.argv.slice(2)[0]; // the first argument is the template name (without .js)
let generatorName = process.argv.slice(2)[1]; // the second argument is the generator format name (such as json,xlsx, csv)
// dynamically import the generator
const GeneratorType = getGenerator(generatorName);
// run the generator
const Generator = new GeneratorType(templateName);
Generator.run();
}
/**
* initialize the environment
* @param {String[]} folderList
* @returns {Boolean}
*/
function initializeEnvironment(folderList) {
let isInitialized = true;
// used for create the directories if they don't exist
for (const folder of folderList) {
if (!fs.existsSync("./" + folder)) {
fs.mkdirSync("./" + folder);
isInitialized = false;
}
}
return isInitialized;
}
/**
* the main function
*/
function start() {
const folderList = ["template", "source", "output", "demo"];
if (initializeEnvironment(folderList)) {
generateTemplate();
}
}
start();