defuss-ssg 0.0.2 → 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 +27 -3
- package/dist/cli.mjs +98 -7
- package/dist/components/index.cjs +4 -2
- package/dist/components/index.d.cts +3 -2
- package/dist/components/index.d.mts +3 -2
- package/dist/components/index.mjs +4 -2
- package/dist/index.cjs +563 -27
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +8 -5
- package/dist/plugins/index.cjs +0 -0
- package/dist/plugins/index.d.cts +1 -1
- package/dist/plugins/index.d.mts +1 -1
- package/dist/plugins/index.mjs +0 -0
- package/dist/runtime.cjs +201 -21
- package/dist/runtime.d.cts +13 -2
- package/dist/runtime.d.mts +13 -2
- package/dist/runtime.mjs +195 -21
- package/dist/{serve-C-BY5Ydk.mjs → serve-BR2MS6bN.mjs} +198 -70
- package/dist/{types-BWD2Kt6_.d.ts → types-BhV8wSVk.d.cts} +3 -3
- package/dist/types-BhV8wSVk.d.mts +106 -0
- package/package.json +40 -23
- package/dist/cli.cjs +0 -48
- package/dist/serve-DvB62foO.cjs +0 -437
package/README.md
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
<h1 align="center">
|
|
2
2
|
|
|
3
|
-
<img src="assets/defuss_mascott.png" width="100px" />
|
|
3
|
+
<img src="https://github.com/kyr0/defuss/blob/main/assets/defuss_mascott.png?raw=true" width="100px" />
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
6
|
+
|
|
6
7
|
<code>defuss-ssg</code>
|
|
8
|
+
|
|
7
9
|
</p>
|
|
8
10
|
|
|
9
11
|
<sup align="center">
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
Static Site Generator (SSG) for defuss
|
|
12
14
|
|
|
13
15
|
</sup>
|
|
14
16
|
|
|
@@ -18,7 +20,7 @@ Simple Static Site Generator (SSG) for defuss - with support for Markdown, MDX,
|
|
|
18
20
|
Usage
|
|
19
21
|
</h3>
|
|
20
22
|
|
|
21
|
-
Simply generate a static site from a content directory to an output directory with full
|
|
23
|
+
Simply generate a static site from a content directory to an output directory with full defuss-MDX (GFM + Frontmatter) support:
|
|
22
24
|
|
|
23
25
|
```bash
|
|
24
26
|
npx defuss-ssg build ./folder
|
|
@@ -52,6 +54,28 @@ This starts a local server at http://localhost:3000 and watches for changes in:
|
|
|
52
54
|
|
|
53
55
|
Changes trigger automatic rebuilds, with the last change always taking priority to prevent build queueing issues.
|
|
54
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
|
+
|
|
55
79
|
<h4>Programmatic API</h4>
|
|
56
80
|
|
|
57
81
|
Advanced users may want to use the library programmatically:
|
package/dist/cli.mjs
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import { resolve } from 'node:path';
|
|
2
|
+
import { v as validateProjectDir, b as build, s as serve } from './serve-BR2MS6bN.mjs';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
5
|
+
import { spawn } from 'node:child_process';
|
|
4
6
|
import 'chokidar';
|
|
5
|
-
import 'express';
|
|
6
|
-
import 'serve-static';
|
|
7
|
-
import 'node:fs';
|
|
7
|
+
import 'ultimate-express';
|
|
8
8
|
import 'esbuild';
|
|
9
|
-
import 'remark-frontmatter';
|
|
10
9
|
import 'rehype-katex';
|
|
10
|
+
import 'rehype-stringify';
|
|
11
|
+
import 'remark-frontmatter';
|
|
11
12
|
import 'remark-math';
|
|
13
|
+
import 'remark-gfm';
|
|
14
|
+
import 'remark-parse';
|
|
15
|
+
import 'remark-rehype';
|
|
12
16
|
import 'remark-mdx-frontmatter';
|
|
13
17
|
import './tailwind-DV23JSh-.mjs';
|
|
14
18
|
import '@mdx-js/esbuild';
|
|
@@ -16,7 +20,93 @@ import 'fast-glob';
|
|
|
16
20
|
import 'defuss/server';
|
|
17
21
|
import 'node:fs/promises';
|
|
18
22
|
import 'node:url';
|
|
19
|
-
import 'node:
|
|
23
|
+
import 'node:module';
|
|
24
|
+
|
|
25
|
+
const setup = async (projectDir) => {
|
|
26
|
+
const projectDirStatus = validateProjectDir(projectDir);
|
|
27
|
+
if (projectDirStatus.code !== "OK") return projectDirStatus;
|
|
28
|
+
const packageJsonPath = join(projectDir, "package.json");
|
|
29
|
+
if (!existsSync(packageJsonPath)) {
|
|
30
|
+
return {
|
|
31
|
+
code: "MISSING_PACKAGE_JSON",
|
|
32
|
+
message: `package.json not found in ${projectDir}`
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
let packageJson;
|
|
36
|
+
try {
|
|
37
|
+
packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
38
|
+
} catch (error) {
|
|
39
|
+
return {
|
|
40
|
+
code: "INVALID_JSON",
|
|
41
|
+
message: `Error reading package.json in ${projectDir}: ${error.message}`
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const packageManager = packageJson.packageManager || "npm";
|
|
45
|
+
const pm = packageManager.split("@")[0];
|
|
46
|
+
const validPMs = ["npm", "yarn", "pnpm", "bun"];
|
|
47
|
+
if (!validPMs.includes(pm)) {
|
|
48
|
+
return {
|
|
49
|
+
code: "UNSUPPORTED_PM",
|
|
50
|
+
message: `Unsupported package manager: ${pm}`
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
console.log(`Setting up project in ${projectDir} using ${pm}...`);
|
|
54
|
+
try {
|
|
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
|
+
});
|
|
101
|
+
console.log("Dependencies installed successfully.");
|
|
102
|
+
} catch (error) {
|
|
103
|
+
return {
|
|
104
|
+
code: "INSTALL_FAILED",
|
|
105
|
+
message: `Failed to install dependencies: ${error.message}`
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
return { code: "OK", message: "Setup completed successfully" };
|
|
109
|
+
};
|
|
20
110
|
|
|
21
111
|
(async () => {
|
|
22
112
|
const args = process.argv.slice(2);
|
|
@@ -28,6 +118,7 @@ import 'node:child_process';
|
|
|
28
118
|
process.exit(1);
|
|
29
119
|
}
|
|
30
120
|
const projectDir = resolve(folder);
|
|
121
|
+
await setup(projectDir);
|
|
31
122
|
if (command === "build") {
|
|
32
123
|
console.log(`Building ${folder}...`);
|
|
33
124
|
await build({
|
|
@@ -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):
|
|
8
|
+
declare function Hydrate({ module, exportName, props, children, }: HydrateProps): JSX.Element;
|
|
9
9
|
|
|
10
|
-
export { Hydrate
|
|
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):
|
|
8
|
+
declare function Hydrate({ module, exportName, props, children, }: HydrateProps): JSX.Element;
|
|
9
9
|
|
|
10
|
-
export { Hydrate
|
|
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) })
|