defuss-ssg 0.0.3 → 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.
package/README.md CHANGED
@@ -54,6 +54,28 @@ This starts a local server at http://localhost:3000 and watches for changes in:
54
54
 
55
55
  Changes trigger automatic rebuilds, with the last change always taking priority to prevent build queueing issues.
56
56
 
57
+ <h4>Local development of SSG and running the example</h4>
58
+
59
+ Unlike other SSG systems, this package is **not** meant to be installed in a project, but rather used as a global CLI tool or programmatically.
60
+
61
+ Developing this means to clone the repo, install dependencies and run the example site:
62
+
63
+ ```bash
64
+ git clone
65
+
66
+ cd defuss/packages/ssg
67
+
68
+ bun i && bun build
69
+
70
+ # for building and serving the example site with auto-rebuild:
71
+ bun run cli-serve ./example
72
+
73
+ # for one-time build of the example site:
74
+ bun run cli-build ./example
75
+ ```
76
+
77
+ Please create a PR or issue if you find any bugs or have feature requests.
78
+
57
79
  <h4>Programmatic API</h4>
58
80
 
59
81
  Advanced users may want to use the library programmatically:
package/dist/cli.mjs CHANGED
@@ -1,11 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import { v as validateProjectDir, d as build, s as serve } from './serve-CzCDilBA.mjs';
2
+ import { v as validateProjectDir, b as build, s as serve } from './serve-BR2MS6bN.mjs';
3
3
  import { join, resolve } from 'node:path';
4
4
  import { existsSync, readFileSync } from 'node:fs';
5
- import { execSync } from 'node:child_process';
5
+ import { spawn } from 'node:child_process';
6
6
  import 'chokidar';
7
- import 'express';
8
- import 'serve-static';
7
+ import 'ultimate-express';
9
8
  import 'esbuild';
10
9
  import 'rehype-katex';
11
10
  import 'rehype-stringify';
@@ -21,6 +20,7 @@ import 'fast-glob';
21
20
  import 'defuss/server';
22
21
  import 'node:fs/promises';
23
22
  import 'node:url';
23
+ import 'node:module';
24
24
 
25
25
  const setup = async (projectDir) => {
26
26
  const projectDirStatus = validateProjectDir(projectDir);
@@ -52,7 +52,52 @@ const setup = async (projectDir) => {
52
52
  }
53
53
  console.log(`Setting up project in ${projectDir} using ${pm}...`);
54
54
  try {
55
- execSync(`${pm} install`, { cwd: projectDir, stdio: "inherit" });
55
+ await new Promise((resolve, reject) => {
56
+ const child = spawn(pm, ["install"], {
57
+ cwd: projectDir,
58
+ shell: true,
59
+ stdio: ["inherit", "pipe", "pipe"]
60
+ });
61
+ const lastLines = [];
62
+ let printedLines = 0;
63
+ const pushLine = (line) => {
64
+ lastLines.push(line);
65
+ if (lastLines.length > 3) lastLines.shift();
66
+ if (process.stdout.isTTY) {
67
+ for (let i = 0; i < printedLines; i++) {
68
+ process.stdout.write("\x1B[1A\x1B[2K");
69
+ }
70
+ for (const l of lastLines) {
71
+ process.stdout.write(`${l}
72
+ `);
73
+ }
74
+ printedLines = lastLines.length;
75
+ } else {
76
+ process.stdout.write(`${line}
77
+ `);
78
+ }
79
+ };
80
+ const handleData = (chunk) => {
81
+ const lines = chunk.toString().split(/\r\n|\n|\r/).filter((l) => l.trim().length > 0);
82
+ for (const line of lines) {
83
+ pushLine(line);
84
+ }
85
+ };
86
+ child.stdout?.on("data", handleData);
87
+ child.stderr?.on("data", handleData);
88
+ child.on("error", reject);
89
+ child.on("close", (code) => {
90
+ if (code === 0) {
91
+ resolve();
92
+ } else {
93
+ reject(
94
+ new Error(
95
+ `${pm} install exited with code ${code ?? "unknown"}`
96
+ )
97
+ );
98
+ }
99
+ });
100
+ });
56
101
  console.log("Dependencies installed successfully.");
57
102
  } catch (error) {
58
103
  return {
@@ -9,15 +9,17 @@ function Hydrate({
9
9
  children
10
10
  }) {
11
11
  const id = `dh_${Math.random().toString(36).slice(2)}`;
12
+ console.log("vdom HYDRATE", children);
12
13
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
13
- children,
14
14
  /* @__PURE__ */ jsxRuntime.jsx(
15
15
  "div",
16
16
  {
17
17
  "data-hydrate": true,
18
+ "data-vdom": JSON.stringify(children),
18
19
  "data-module": module,
19
20
  "data-export": exportName,
20
- "data-props-id": id
21
+ "data-props-id": id,
22
+ children
21
23
  }
22
24
  ),
23
25
  /* @__PURE__ */ jsxRuntime.jsx("script", { type: "application/json", id, children: JSON.stringify(props) })
@@ -5,6 +5,7 @@ interface HydrateProps extends Props {
5
5
  exportName?: string;
6
6
  props?: Record<string, any>;
7
7
  }
8
- declare function Hydrate({ module, exportName, props, children, }: HydrateProps): any;
8
+ declare function Hydrate({ module, exportName, props, children, }: HydrateProps): JSX.Element;
9
9
 
10
- export { Hydrate, type HydrateProps };
10
+ export { Hydrate };
11
+ export type { HydrateProps };
@@ -5,6 +5,7 @@ interface HydrateProps extends Props {
5
5
  exportName?: string;
6
6
  props?: Record<string, any>;
7
7
  }
8
- declare function Hydrate({ module, exportName, props, children, }: HydrateProps): any;
8
+ declare function Hydrate({ module, exportName, props, children, }: HydrateProps): JSX.Element;
9
9
 
10
- export { Hydrate, type HydrateProps };
10
+ export { Hydrate };
11
+ export type { HydrateProps };
@@ -7,15 +7,17 @@ function Hydrate({
7
7
  children
8
8
  }) {
9
9
  const id = `dh_${Math.random().toString(36).slice(2)}`;
10
+ console.log("vdom HYDRATE", children);
10
11
  return /* @__PURE__ */ jsxs(Fragment, { children: [
11
- children,
12
12
  /* @__PURE__ */ jsx(
13
13
  "div",
14
14
  {
15
15
  "data-hydrate": true,
16
+ "data-vdom": JSON.stringify(children),
16
17
  "data-module": module,
17
18
  "data-export": exportName,
18
- "data-props-id": id
19
+ "data-props-id": id,
20
+ children
19
21
  }
20
22
  ),
21
23
  /* @__PURE__ */ jsx("script", { type: "application/json", id, children: JSON.stringify(props) })