@react-scad/core 0.1.16 → 0.1.18
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.
- package/dist/log.d.ts +5 -3
- package/dist/log.js +20 -10
- package/dist/runtime/root.js +18 -5
- package/dist/runtime/write-on-commit.js +0 -4
- package/dist/serialize/index.js +1 -1
- package/package.json +1 -1
package/dist/log.d.ts
CHANGED
|
@@ -7,7 +7,9 @@ export declare const c: {
|
|
|
7
7
|
bold: (s: string) => string;
|
|
8
8
|
};
|
|
9
9
|
export declare const log: {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
banner(): void;
|
|
11
|
+
progress(msg: string): void;
|
|
12
|
+
complete(ms: number): void;
|
|
13
|
+
outputPath(path: string): void;
|
|
14
|
+
stop(): void;
|
|
13
15
|
};
|
package/dist/log.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
1
2
|
const noColor = process.env.NO_COLOR != null || !process.stdout.isTTY;
|
|
2
3
|
export const c = {
|
|
3
4
|
dim: (s) => (noColor ? s : `\x1b[2m${s}\x1b[0m`),
|
|
@@ -7,19 +8,28 @@ export const c = {
|
|
|
7
8
|
yellow: (s) => (noColor ? s : `\x1b[33m${s}\x1b[0m`),
|
|
8
9
|
bold: (s) => (noColor ? s : `\x1b[1m${s}\x1b[0m`),
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
const require = createRequire(import.meta.url);
|
|
12
|
+
const pkg = require("../package.json");
|
|
13
|
+
const VERSION = pkg.version;
|
|
14
|
+
const TOOL_NAME = "react-scad";
|
|
15
|
+
const PAD = " ";
|
|
16
|
+
function line(msg) {
|
|
17
|
+
console.log(msg);
|
|
12
18
|
}
|
|
13
19
|
export const log = {
|
|
14
|
-
|
|
15
|
-
|
|
20
|
+
banner() {
|
|
21
|
+
line(`${PAD}${c.cyan("◆")} ${c.bold(TOOL_NAME)} ${c.dim(VERSION)} ${c.dim("-")} ${c.dim("Ctrl+C to exit")}`);
|
|
16
22
|
},
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
progress(msg) {
|
|
24
|
+
line(`${PAD}${c.dim("○")} ${c.dim(msg)}`);
|
|
19
25
|
},
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
complete(ms) {
|
|
27
|
+
line(`${PAD}${c.green("✓")} ${c.dim("Built")} ${c.dim(`in ${ms}ms`)}`);
|
|
28
|
+
},
|
|
29
|
+
outputPath(path) {
|
|
30
|
+
line(`${PAD}${c.dim("→")} ${c.cyan(path)}`);
|
|
31
|
+
},
|
|
32
|
+
stop() {
|
|
33
|
+
line(`${PAD}${c.dim("Stopped.")}`);
|
|
24
34
|
},
|
|
25
35
|
};
|
package/dist/runtime/root.js
CHANGED
|
@@ -1,20 +1,33 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
1
2
|
import { log } from "../log.js";
|
|
2
3
|
import { toScad } from "../serialize/index.js";
|
|
3
4
|
import { createScadContainer } from "./node-ops.js";
|
|
4
5
|
import { createFiberRoot, updateContainer } from "./reconciler.js";
|
|
5
|
-
import { registerWriteOnCommit
|
|
6
|
+
import { registerWriteOnCommit } from "./write-on-commit.js";
|
|
6
7
|
export function createRoot(path) {
|
|
7
8
|
const container = createScadContainer();
|
|
8
9
|
const fiberRoot = createFiberRoot(container);
|
|
9
|
-
if (path)
|
|
10
|
+
if (path) {
|
|
11
|
+
log.banner();
|
|
10
12
|
registerWriteOnCommit(container, path);
|
|
13
|
+
const gracefulExit = () => {
|
|
14
|
+
log.stop();
|
|
15
|
+
process.exit(0);
|
|
16
|
+
};
|
|
17
|
+
process.once("SIGINT", gracefulExit);
|
|
18
|
+
process.once("SIGTERM", gracefulExit);
|
|
19
|
+
}
|
|
11
20
|
return {
|
|
12
21
|
render(element) {
|
|
22
|
+
if (path) {
|
|
23
|
+
log.progress("Building...");
|
|
24
|
+
}
|
|
13
25
|
const start = Date.now();
|
|
14
26
|
updateContainer(element, fiberRoot, null, null);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
27
|
+
log.complete(Date.now() - start);
|
|
28
|
+
if (path) {
|
|
29
|
+
log.outputPath(resolve(path));
|
|
30
|
+
}
|
|
18
31
|
},
|
|
19
32
|
toScad() {
|
|
20
33
|
return toScad(container);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { dirname } from "node:path";
|
|
3
|
-
import { log } from "../log.js";
|
|
4
3
|
import { toScad } from "../serialize/index.js";
|
|
5
4
|
const writeOnCommitPaths = new WeakMap();
|
|
6
5
|
export function registerWriteOnCommit(container, path) {
|
|
@@ -9,12 +8,9 @@ export function registerWriteOnCommit(container, path) {
|
|
|
9
8
|
export function writeAfterCommit(container) {
|
|
10
9
|
const path = writeOnCommitPaths.get(container);
|
|
11
10
|
if (path) {
|
|
12
|
-
const start = Date.now();
|
|
13
11
|
const dir = dirname(path);
|
|
14
12
|
if (dir !== ".")
|
|
15
13
|
mkdirSync(dir, { recursive: true });
|
|
16
14
|
writeFileSync(path, toScad(container), "utf8");
|
|
17
|
-
const ms = Date.now() - start;
|
|
18
|
-
log.wrote(path, ms);
|
|
19
15
|
}
|
|
20
16
|
}
|
package/dist/serialize/index.js
CHANGED
|
@@ -71,7 +71,7 @@ function serializeNode(node, indent, ctx) {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
const CREDIT = "// Generated using react-scad (https://github.com/
|
|
74
|
+
const CREDIT = "// Generated using react-scad (https://github.com/react-scad/react-scad)";
|
|
75
75
|
export function toScad(container) {
|
|
76
76
|
const ctx = {
|
|
77
77
|
serializeNode: (n, i) => serializeNode(n, i, ctx),
|