-
Notifications
You must be signed in to change notification settings - Fork 4
/
static-dodo.js
executable file
·80 lines (70 loc) · 1.79 KB
/
static-dodo.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
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 fs from "fs";
import path from "path";
import process from "process";
import minimist from "minimist";
import { getHelp } from "./lib/help.js";
import { parseConfigFile } from "./lib/config.js";
import { parseInput } from "./lib/input.js";
import { processFile } from "./lib/processFile.js";
const argv = minimist(process.argv.slice(2), {
string: ["input", "stylesheet", "config"],
boolean: ["version", "help"],
alias: {
i: "input",
s: "stylesheet",
c: "config",
v: "version",
h: "help",
},
unknown: (unknownArgument) => {
console.error(`Option '${unknownArgument}' not found.`);
},
});
if (argv.version) {
const packageJsonContent = fs.readFileSync("./package.json", "utf8");
const packageInfo = JSON.parse(packageJsonContent);
console.log(packageInfo.version);
process.exit(0);
}
if (argv.help) {
getHelp();
process.exit(0);
}
if (argv.input) {
console.log(argv.input);
}
if (!argv.input && !argv.config) {
getHelp();
process.exit(0);
}
if (fs.existsSync(path.join(process.cwd(), "dist"))) {
try {
fs.rmSync(path.join(process.cwd(), "dist"), { recursive: true });
} catch {
console.error("Unable to delete ./dist directory.");
process.exit(-1);
}
}
try {
fs.mkdirSync(path.join(process.cwd(), "dist"));
} catch {
console.error("Unable to create ./dist directory.");
process.exit(-1);
}
if (argv.config) {
const { input, stylesheet } = parseConfigFile(argv.config);
argv.input = input;
argv.stylesheet = stylesheet;
}
if (fs.existsSync(argv.input)) {
const { files, currentDir } = parseInput(argv.input);
if (files.length > 0) {
files.forEach((file) => {
processFile(file, currentDir, argv.stylesheet);
});
}
} else {
console.error("File or directory not found!");
process.exit(-1);
}