-
Notifications
You must be signed in to change notification settings - Fork 0
/
lessc-wrapper.js
executable file
·65 lines (57 loc) · 1.75 KB
/
lessc-wrapper.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
#!/usr/bin/env node
const path = require("path");
const child_process = require("child_process");
let relativeOutputDir = "../css";
let quiet = false;
const lessArgs = [];
const lessFiles = [];
const [, , ...args] = process.argv;
for (const arg of args) {
if (arg.startsWith("--wrapper-")) {
const parts = arg.substring("--wrapper-".length).split("=");
const [key, value] = [parts.shift(), parts.join("=")];
switch (key) {
case "output": {
relativeOutputDir = value;
break;
}
case "quiet": {
quiet = true;
break;
}
}
} else if (arg.startsWith("--")) {
lessArgs.push(arg);
} else {
lessFiles.push(arg);
}
}
if (!quiet) {
console.log(`less args: ${lessArgs}`);
console.log(`less files: ${lessFiles}`);
console.log(`relative output dir: ${relativeOutputDir}`);
console.log("");
}
const lessc = path.join(__dirname, "node_modules", ".bin", "lessc");
for (const less of lessFiles) {
const p = path.parse(less);
const css = path.join(p.dir, relativeOutputDir, `${p.name}.css`);
const newArgs = [...lessArgs, less, css];
if (!quiet) console.log(`Running: lessc ${newArgs.join(" ")}`);
try {
const stdout = child_process.execFileSync(lessc, newArgs, {
stdio: "pipe",
encoding: "utf-8"
});
if (!quiet) console.log(stdout);
} catch (err) {
if (err.code) {
// spawning failed
console.error("Could spawn process: ${err.code}, ${err}");
} else {
const {stdout, stderr} = err;
if (stdout) console.log(stdout);
if (stderr) console.error(stderr);
}
}
}