-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
75 lines (56 loc) · 1.71 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
const path = require("path");
const argv = process.argv;
import * as reader from "./reader";
import * as parser from "./parser";
import * as generator from "./generator";
import { File } from "./shared/IFile";
import logger from "./shared/logger";
import { ICLIConfig } from "./shared/ICLIConfig";
import { FileType } from "./shared/constants";
import { IFileData } from "./shared/IFileData";
let config: ICLIConfig = {
workingDir: null,
outputDir: null,
debug: false,
};
const parseArgs = (args: string[]) => {
// TODO: Include multiple options
logger.log("args:", args);
while (args.length > 0) {
const arg = args.shift();
if (arg == null) break;
if (arg == "--dir") {
const absPath = args.shift();
if (absPath == null) break;
config.workingDir = absPath;
}
if (arg == "--output") {
const outputPath = args.shift();
if (outputPath == null) break;
config.outputDir = outputPath;
}
if (arg == "--debug") {
config.debug = true;
}
}
};
export const verifyArgs = () => {
if (config.workingDir == null) {
logger.err("No working directory specified. Aborting.");
}
if (config.outputDir == null) {
logger.err("No output directory specified. Aborting.");
}
};
export const run = async (args: string[]) => {
parseArgs(args);
verifyArgs();
if (config.debug) {
logger.enableDebugger();
}
process.env.ROOT_PROJECT_PATH = config.workingDir || path.posix.resolve();
let candidateFilePaths: Array<IFileData> = reader.reader(process.env.ROOT_PROJECT_PATH as string);
let fileData: Array<File> = parser.parser(candidateFilePaths);
generator.generator(fileData, config.outputDir as string);
};
run(argv.slice(2, argv.length));