forked from lydell/elm-safe-virtual-dom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bin.js
executable file
·46 lines (35 loc) · 981 Bytes
/
bin.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
#!/usr/bin/env node
const fs = require("fs");
const runReplacements = require(".");
function run(argv) {
if (argv.includes("--help") || argv.includes("-h") || argv.length === 0) {
console.log(help());
process.exit(0);
}
if (argv.length > 1) {
console.error(`Expected one argument, but got ${argv.length}.`);
process.exit(1);
}
const [file] = argv;
try {
overwrite(file, runReplacements);
} catch (error) {
console.error(error.message);
process.exit(1);
}
console.log("Success!");
}
function overwrite(file, transform) {
fs.writeFileSync(file, transform(fs.readFileSync(file, "utf8")));
}
function help() {
return `
Usage: elm-safe-virtual-dom path/to/elm/output.js
path/to/elm/output.js:
- Should contain the output of \`elm make\`.
- Should NOT be minified.
- The Elm code should use \`import Browser\`.
This tool overwrites the file, changing parts of the JavaScript code.
`.trimStart();
}
run(process.argv.slice(2));