-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmhtml-to-html-node.js
executable file
·42 lines (34 loc) · 1.17 KB
/
mhtml-to-html-node.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
#!/usr/bin/env -S node
/* global TextEncoder */
import process from "node:process";
import { readFile, writeFile } from "node:fs/promises";
import { Glob, globSync } from "glob";
import { convert } from "./lib/mod-node.js";
import packageInfo from "./package.json" with { type: "json" };
import { initDependencies, main } from "./mod.js";
const args = process.argv.slice(2);
const moduleVersion = packageInfo.version;
initDependencies({ expandGlob, isGlob, args, readFile, writeTextFile, exit, moduleVersion, convert });
await main();
function expandGlob(pattern) {
const glob = new Glob(pattern, {});
const iterator = glob.iterate();
return {
[Symbol.asyncIterator]: () => ({
next: async () => {
const { done, value } = await iterator.next();
return { done, value: value ? { path: value } : undefined };
}
})
};
}
function isGlob(pattern) {
const files = globSync(pattern);
return files.length > 1 || (files.length === 1 && files[0] !== pattern);
}
function writeTextFile(path, data) {
return writeFile(path, new TextEncoder().encode(data));
}
function exit(code) {
process.exit(code);
}