arcadible 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ // [import]
4
+
5
+ const execFile = require("node:child_process").execFile;
6
+
7
+ // [function]
8
+
9
+ const isDirty = function (root, cb) {
10
+ execFile("git", ["-C", root, "diff", "--quiet"], (err) => {
11
+ if (err) {
12
+ cb(true);
13
+ return;
14
+ }
15
+ execFile("git", ["-C", root, "diff", "--cached", "--quiet"], (err) => {
16
+ cb(Boolean(err));
17
+ });
18
+ });
19
+ };
20
+
21
+ // [export]
22
+
23
+ module.exports = { isDirty };
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+
3
+ // [import]
4
+
5
+ const chalk = require("chalk");
6
+
7
+ // [function]
8
+
9
+ const log = function (
10
+ out,
11
+ message,
12
+ { bold = false, color = "white", nl = false } = {},
13
+ ) {
14
+ let text = message;
15
+ if (Array.isArray(text)) {
16
+ text = text.join("\n");
17
+ }
18
+ let marker = chalk;
19
+ if (bold) {
20
+ marker = chalk.bold;
21
+ }
22
+ out(marker[color](text.trim().concat(nl ? "\n" : "")));
23
+ };
24
+
25
+ // [function]
26
+
27
+ const h = function (message) {
28
+ log(console.log, message, { bold: true });
29
+ };
30
+
31
+ // [function]
32
+
33
+ const hnl = function (message) {
34
+ log(console.log, message, { bold: true, nl: true });
35
+ };
36
+
37
+ // [function]
38
+
39
+ const p = function (message) {
40
+ log(console.log, message);
41
+ };
42
+
43
+ // [function]
44
+
45
+ const pnl = function (message) {
46
+ log(console.log, message, { nl: true });
47
+ };
48
+
49
+ // [function]
50
+
51
+ const hd = function (message) {
52
+ log(console.error, message, { bold: true, color: "red" });
53
+ };
54
+
55
+ // [function]
56
+
57
+ const hdnl = function (message) {
58
+ log(console.error, message, { bold: true, color: "red", nl: true });
59
+ };
60
+
61
+ // [function]
62
+
63
+ const pd = function (message) {
64
+ log(console.error, message, { color: "white" });
65
+ };
66
+
67
+ // [function]
68
+
69
+ const pdnl = function (message) {
70
+ log(console.error, message, { color: "white", nl: true });
71
+ };
72
+
73
+ // [function]
74
+
75
+ const hs = function (message) {
76
+ log(console.log, message, { bold: true, color: "green" });
77
+ };
78
+
79
+ // [function]
80
+
81
+ const hsnl = function (message) {
82
+ log(console.log, message, { bold: true, color: "green", nl: true });
83
+ };
84
+
85
+ // [function]
86
+
87
+ const ps = function (message) {
88
+ log(console.log, message, { color: "green" });
89
+ };
90
+
91
+ // [function]
92
+
93
+ const psnl = function (message) {
94
+ log(console.log, message, { color: "green", nl: true });
95
+ };
96
+
97
+ // [export]
98
+
99
+ module.exports = { h, hd, hdnl, hnl, hs, hsnl, p, pd, pdnl, pnl, ps, psnl };
package/src/util/md.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ // [import]
4
+
5
+ const marked = require("marked");
6
+
7
+ // [import]
8
+
9
+ const dom = require("./dom");
10
+ const strs = require("./strs");
11
+
12
+ // [use]
13
+
14
+ const stripLeadingInvisible = strs.stripLeadingInvisible;
15
+
16
+ // [function]
17
+
18
+ const parse = function (buf) {
19
+ return dom.sanitize(marked.parse(stripLeadingInvisible(buf)));
20
+ };
21
+
22
+ // [export]
23
+
24
+ module.exports = { parse };
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ // [function]
4
+
5
+ const pruneEmpty = function (value) {
6
+ /* eslint-disable no-undefined */
7
+ if (value === null || value === undefined) {
8
+ return undefined;
9
+ }
10
+ if (Array.isArray(value)) {
11
+ const cleaned = value.map(pruneEmpty).filter((v) => v !== undefined);
12
+ return cleaned.length ? cleaned : undefined;
13
+ }
14
+ if (typeof value === "object") {
15
+ const cleaned = Object.fromEntries(
16
+ Object.entries(value)
17
+ .map(([k, v]) => [k, pruneEmpty(v)])
18
+ .filter(([, v]) => v !== undefined),
19
+ );
20
+ return Object.keys(cleaned).length ? cleaned : undefined;
21
+ }
22
+ return value;
23
+ /* eslint-enable no-undefined */
24
+ };
25
+ // [export];
26
+ module.exports = { pruneEmpty };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ // [function]
4
+
5
+ const aConcat = function (ls) {
6
+ return Array.prototype.concat.bind(ls);
7
+ };
8
+
9
+ // [function]
10
+
11
+ const pConcat = function (fn) {
12
+ return (ls) => fn(ls).then(aConcat(ls));
13
+ };
14
+
15
+ // [function]
16
+
17
+ const pReduce = function (p, fn) {
18
+ return p.then(pConcat(fn));
19
+ };
20
+
21
+ // [function]
22
+
23
+ const serial = function (fns) {
24
+ return fns.reduce(pReduce, Promise.resolve([]));
25
+ };
26
+
27
+ // [export]
28
+
29
+ module.exports = { serial };
package/src/util/rc.js ADDED
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ // [import]
4
+
5
+ const path = require("node:path");
6
+
7
+ // [import]
8
+
9
+ const rc = require("rc");
10
+
11
+ // [use]
12
+
13
+ const join = path.join;
14
+ const resolve = path.resolve;
15
+
16
+ // [function]
17
+
18
+ const cwd = function (argv, option) {
19
+ let dir = ".";
20
+ const idx = argv.findIndex((arg) => option.includes(arg));
21
+ if (idx !== -1 && argv[idx + 1] && !argv[idx + 1].startsWith("-")) {
22
+ dir = argv[idx + 1];
23
+ }
24
+ return dir;
25
+ };
26
+
27
+ // [function]
28
+
29
+ const config = function (cmd, argv, option) {
30
+ return join(resolve(process.cwd(), cwd(argv, option)), `.${cmd}rc`);
31
+ };
32
+
33
+ // [function]
34
+
35
+ const findRc = function (cmd, subcmd, argv, option) {
36
+ return rc(cmd, {}, { config: config(cmd, argv, option) })[subcmd] || {};
37
+ };
38
+
39
+ // [export]
40
+
41
+ module.exports = { findRc };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ // [function]
4
+
5
+ const stripLeadingInvisible = function (str) {
6
+ return String(str).replace(
7
+ // eslint-disable-next-line no-misleading-character-class
8
+ /^[\u200B\u200C\u200D\u2060\u2061\u2062\u2063\uFEFF]+/u,
9
+ "",
10
+ );
11
+ };
12
+
13
+ // [function]
14
+
15
+ const trimWhitespace = function (str) {
16
+ return String(str).trim();
17
+ };
18
+
19
+ // [export]
20
+
21
+ module.exports = { stripLeadingInvisible, trimWhitespace };
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ // [import]
4
+
5
+ const crypto = require("node:crypto");
6
+ const path = require("node:path");
7
+
8
+ // [import]
9
+
10
+ const AdmZip = require("adm-zip");
11
+
12
+ // [use]
13
+
14
+ const createHash = crypto.createHash;
15
+ const join = path.join;
16
+
17
+ // [class]
18
+
19
+ const Main = class {
20
+
21
+ // [constructor]
22
+
23
+ constructor(prefix) {
24
+ this.prefix = prefix;
25
+ this.zip = new AdmZip();
26
+ }
27
+
28
+ // [method]
29
+
30
+ addDir(dir, name = "") {
31
+ this.zip.addLocalFolder(dir, name ? join(this.prefix, name) : this.prefix);
32
+ }
33
+
34
+ // [method]
35
+
36
+ addJson(name, value) {
37
+ const entry = join(this.prefix, name);
38
+ const content = Buffer.from(JSON.stringify(value, null, 2), "utf8");
39
+ this.zip.addFile(entry, content);
40
+ }
41
+
42
+ // [method]
43
+
44
+ stat() {
45
+ const buffer = this.zip.toBuffer();
46
+ const hash = createHash("sha256").update(buffer).digest("hex");
47
+ return { sha256: hash, size: buffer.length };
48
+ }
49
+
50
+ // [method]
51
+
52
+ write(outPath) {
53
+ this.zip.writeZip(outPath);
54
+ }
55
+ };
56
+
57
+ // [export]
58
+
59
+ module.exports = Main;