@react-scad/core 0.1.17 → 0.1.19

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 CHANGED
@@ -7,7 +7,9 @@ export declare const c: {
7
7
  bold: (s: string) => string;
8
8
  };
9
9
  export declare const log: {
10
- buildOk(ms: number): void;
11
- wrote(path: string, ms: number): void;
12
- watchCycle(ms: number, code: number | null): void;
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
- function time() {
11
- return new Date().toLocaleTimeString("en-US", { hour12: false });
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
- buildOk(ms) {
15
- console.log(c.dim(`[${time()}] `) + c.green("✓ Built") + c.dim(` in ${ms}ms`));
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
- wrote(path, ms) {
18
- console.log(c.dim(`[${time()}] `) + c.green("✓ Wrote") + c.dim(` ${path} in ${ms}ms`));
23
+ progress(msg) {
24
+ line(`${PAD}${c.dim("")} ${c.dim(msg)}`);
19
25
  },
20
- watchCycle(ms, code) {
21
- const ok = code === 0;
22
- const status = ok ? c.green("done") : c.red(`exit ${code}`);
23
- console.log(` ${ok ? c.green("✓") : c.red("✗")}${c.dim(` ${ms}ms `)}${status}`);
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
  };
@@ -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, writeAfterCommit } from "./write-on-commit.js";
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
- if (path)
16
- writeAfterCommit(container);
17
- log.watchCycle(Date.now() - start, 0);
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-scad/core",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "description": "Render JSX to OpenSCAD models using the React reconciler",
5
5
  "keywords": [
6
6
  "react",