defuss-ssg 0.3.0 → 0.4.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
@@ -29,7 +29,7 @@ bunx defuss-ssg build ./folder
29
29
  Or install globally or locally in a project:
30
30
 
31
31
  ```bash
32
- npm install -g defuss-ssg
32
+ bun add -g defuss-ssg
33
33
  ```
34
34
 
35
35
  And then run (in an NPM script or globally):
@@ -40,13 +40,13 @@ And then run (in an NPM script or globally):
40
40
  defuss-ssg build ./folder
41
41
  ```
42
42
 
43
- <h4>Serve-mode with automatic re-build on change</h4>
43
+ <h4>Vite-powered development</h4>
44
44
 
45
45
  ```bash
46
- defuss-ssg serve ./folder
46
+ defuss-ssg dev ./folder
47
47
  ```
48
48
 
49
- This starts a local server at http://localhost:3000 and watches for changes in:
49
+ This starts a Vite dev server at http://localhost:3000 and watches for changes in:
50
50
 
51
51
  - `pages/` directory
52
52
  - `components/` directory
@@ -54,6 +54,16 @@ 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
+ The current migration bridge still writes dev output to `dist/` while the request-time Vite renderer is being moved over.
58
+
59
+ <h4>Production serving</h4>
60
+
61
+ ```bash
62
+ defuss-ssg serve ./folder
63
+ ```
64
+
65
+ This serves already-built output with `defuss-express`. Run `defuss-ssg build ./folder` first.
66
+
57
67
  <h4>Local development of SSG and running the example</h4>
58
68
 
59
69
  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.
@@ -61,14 +71,14 @@ Unlike other SSG systems, this package is **not** meant to be installed in a pro
61
71
  Developing this means to clone the repo, install dependencies and run the example site:
62
72
 
63
73
  ```bash
64
- git clone
74
+ git clone https://github.com/kyr0/defuss.git
65
75
 
66
76
  cd defuss/packages/ssg
67
77
 
68
78
  bun i && bun build
69
79
 
70
80
  # for building and serving the example site with auto-rebuild:
71
- bun run cli-serve ./example
81
+ bun run cli-dev ./example
72
82
 
73
83
  # for one-time build of the example site:
74
84
  bun run cli-build ./example
@@ -81,7 +91,7 @@ Please create a PR or issue if you find any bugs or have feature requests.
81
91
  Advanced users may want to use the library programmatically:
82
92
 
83
93
  ```typescript
84
- import { setup, build, serve } from "defuss-ssg";
94
+ import { setup, build, dev, serve } from "defuss-ssg";
85
95
 
86
96
  (async () => {
87
97
 
@@ -98,11 +108,17 @@ import { setup, build, serve } from "defuss-ssg";
98
108
  debug: true,
99
109
  });
100
110
 
101
- // Or serve with auto-rebuild
102
- await serve({
111
+ // Or start the Vite-backed dev server
112
+ await dev({
103
113
  projectDir: "./my-site",
104
114
  debug: true,
105
115
  });
116
+
117
+ // Or serve an already-built production output
118
+ await serve({
119
+ projectDir: "./my-site",
120
+ workers: "auto",
121
+ });
106
122
  })();
107
123
  ```
108
124
 
@@ -112,7 +128,7 @@ Overview
112
128
 
113
129
  > `defuss-ssg` is a CLI tool and library for building static websites using modern JavaScript/TypeScript and `defuss`. It reads content files (Markdown, MDX) from a specified directory, processes them with MDX plugins, compiles components with esbuild, and outputs fully static HTML sites ready for deployment.
114
130
 
115
- > It supports a plugin system for extending the build process at various phases (pre-build, post-build, page-level transformations), automatic file watching and rebuilding in serve mode, and seamless integration with defuss components for interactive features.
131
+ > It supports a plugin system for extending the build process at various phases (pre-build, post-build, page-level transformations), Vite-backed development, and defuss-express production serving.
116
132
 
117
133
  <h3 align="center">
118
134
 
@@ -123,8 +139,9 @@ Features
123
139
  - **MDX Support**: Full Markdown + JSX support with frontmatter parsing
124
140
  - **Component Integration**: Use defuss components in your MDX files
125
141
  - **Plugin System**: Extend the build process with custom plugins at multiple phases
126
- - **Fast Compilation**: Powered by esbuild for quick builds and hot reloading
127
- - **Serve Mode**: Built-in development server with file watching and auto-rebuild
142
+ - **Fast Compilation**: Powered by esbuild today, with Vite now orchestrating development
143
+ - **Dev Mode**: Vite-backed development server with auto-rebuild and full reload
144
+ - **Production Runtime**: `defuss-express` serves static output plus dynamic endpoints and RPC
128
145
  - **TypeScript Ready**: Full TypeScript support for components and configuration
129
146
  - **Asset Handling**: Automatic copying of static assets to output directory
130
147
  - **Flexible Configuration**: Configurable via TypeScript config file with sensible defaults
@@ -139,15 +156,15 @@ Create a project structure like this:
139
156
 
140
157
  ```typescript
141
158
  my-site/
142
- ├── pages/
143
- ├── index.mdx
144
- └── blog/
145
- └── hello-world.mdx
146
- ├── components/
147
- └── button.tsx
148
- ├── assets/
149
- └── styles.css
150
- └── config.ts
159
+ ├-- pages/
160
+ ├-- index.mdx
161
+ └-- blog/
162
+ └-- hello-world.mdx
163
+ ├-- components/
164
+ └-- button.tsx
165
+ ├-- assets/
166
+ └-- styles.css
167
+ └-- config.ts
151
168
  ```
152
169
  Then run `defuss-ssg build ./my-site` and a `dist` folder will be created with the complete static build.
153
170
 
@@ -318,4 +335,4 @@ Commands:
318
335
 
319
336
  <p align="center">
320
337
  <i><b>Come visit us on <code>defuss</code> Island!</b></i>
321
- </p>
338
+ </p>
package/dist/cli.mjs CHANGED
@@ -1,13 +1,17 @@
1
1
  #!/usr/bin/env node
2
- import { v as validateProjectDir, b as build, s as serve } from './serve-C7GCBFVo.mjs';
2
+ import { v as validateProjectDir, b as build } from './vite-DyhxNy3G.mjs';
3
+ import { d as dev, s as serve } from './serve-CLC1GbGD.mjs';
3
4
  import { join, dirname, resolve } from 'node:path';
4
5
  import { existsSync, readFileSync } from 'node:fs';
5
6
  import { spawn } from 'node:child_process';
6
- import 'node:os';
7
- import 'chokidar';
8
- import 'elysia';
9
- import '@elysiajs/static';
10
7
  import 'node:fs/promises';
8
+ import '@mdx-js/rollup';
9
+ import 'fast-glob';
10
+ import 'vite';
11
+ import 'defuss-vite';
12
+ import 'defuss/server';
13
+ import 'node:url';
14
+ import 'node:os';
11
15
  import 'esbuild';
12
16
  import 'rehype-katex';
13
17
  import 'rehype-stringify';
@@ -18,10 +22,8 @@ import 'remark-parse';
18
22
  import 'remark-rehype';
19
23
  import 'remark-mdx-frontmatter';
20
24
  import './tailwind-DV23JSh-.mjs';
21
- import '@mdx-js/esbuild';
22
- import 'fast-glob';
23
- import 'defuss/server';
24
- import 'node:url';
25
+ import 'node:crypto';
26
+ import 'defuss-express';
25
27
 
26
28
  const canResolve = (dep, dir) => {
27
29
  let current = dir;
@@ -68,7 +70,12 @@ const runInstall = (cmd, args, cwd, env) => new Promise((resolve, reject) => {
68
70
  child.on("error", reject);
69
71
  child.on("close", (code) => {
70
72
  if (code === 0) resolve();
71
- else reject(new Error(`${cmd} ${args.join(" ")} exited with code ${code ?? "unknown"}`));
73
+ else
74
+ reject(
75
+ new Error(
76
+ `${cmd} ${args.join(" ")} exited with code ${code ?? "unknown"}`
77
+ )
78
+ );
72
79
  });
73
80
  });
74
81
  const setup = async (projectDir) => {
@@ -109,9 +116,7 @@ const setup = async (projectDir) => {
109
116
  );
110
117
  const allResolvable = depNames.length === 0 || depNames.every((d) => canResolve(d, projectDir));
111
118
  if (allResolvable) {
112
- console.log(
113
- `All dependencies already available \u2014 skipping install.`
114
- );
119
+ console.log(`All dependencies already available - skipping install.`);
115
120
  return { code: "OK", message: "Setup completed (deps already available)" };
116
121
  }
117
122
  console.log(`Setting up project in ${projectDir} using ${pm}...`);
@@ -134,7 +139,7 @@ const setup = async (projectDir) => {
134
139
  const bunEnv = { ...process.env, BUN_WORKSPACE_ROOT: projectDir };
135
140
  await runInstall(
136
141
  pm,
137
- ["install", "--linker", "isolated"],
142
+ pm === "bun" ? ["install", "--no-cache", "--linker", "isolated"] : ["install"],
138
143
  projectDir,
139
144
  pm === "bun" ? bunEnv : void 0
140
145
  );
@@ -151,13 +156,13 @@ Falling back to npm install...`
151
156
  } catch (npmError) {
152
157
  console.warn(
153
158
  `Warning: npm install also failed: ${npmError.message}
154
- Continuing anyway \u2014 dependencies may already be available.`
159
+ Continuing anyway - dependencies may already be available.`
155
160
  );
156
161
  }
157
162
  } else {
158
163
  console.warn(
159
164
  `Warning: ${error.message}
160
- Continuing anyway \u2014 dependencies may already be available.`
165
+ Continuing anyway - dependencies may already be available.`
161
166
  );
162
167
  }
163
168
  }
@@ -169,16 +174,38 @@ Continuing anyway \u2014 dependencies may already be available.`
169
174
  const debug = args.includes("--debug") || args.includes("-d");
170
175
  const multicore = args.includes("--multicore");
171
176
  const positional = args.filter((a) => !a.startsWith("-"));
172
- const command = positional[0];
173
- const folder = positional[1];
174
- const usage = "Usage: defuss-ssg <build|serve> <folder> [--debug] [--multicore]";
175
- if (!command || !folder) {
176
- console.error(usage);
177
- process.exit(1);
177
+ const usage = "Usage: defuss-ssg [dev|build|serve] [folder]\n No args \u2192 serve .\n Single path \u2192 serve <path>\n Single command \u2192 <command> .\n Command + folder \u2192 <command> <folder>\n Flags: [--debug] [--multicore]";
178
+ let command;
179
+ let folder;
180
+ if (positional.length === 0) {
181
+ command = "serve";
182
+ folder = ".";
183
+ } else if (positional.length === 1) {
184
+ const arg = positional[0];
185
+ if (arg === "dev" || arg === "build" || arg === "serve") {
186
+ command = arg;
187
+ folder = ".";
188
+ } else if (arg.startsWith(".") || arg.startsWith("/")) {
189
+ command = "serve";
190
+ folder = arg;
191
+ } else {
192
+ console.error(usage);
193
+ process.exit(1);
194
+ }
195
+ } else {
196
+ command = positional[0];
197
+ folder = positional[1];
178
198
  }
179
199
  const projectDir = resolve(folder);
180
200
  await setup(projectDir);
181
- if (command === "build") {
201
+ if (command === "dev") {
202
+ console.log(`Starting Vite dev server for ${folder}...`);
203
+ await dev({
204
+ projectDir,
205
+ debug,
206
+ writeDevOutput: true
207
+ });
208
+ } else if (command === "build") {
182
209
  console.log(`Building ${folder}...`);
183
210
  await build({
184
211
  projectDir,
@@ -186,11 +213,11 @@ Continuing anyway \u2014 dependencies may already be available.`
186
213
  mode: "build"
187
214
  });
188
215
  } else if (command === "serve") {
189
- console.log(`Serving ${folder}...`);
216
+ console.log(`Serving built output for ${folder}...`);
190
217
  await serve({
191
218
  projectDir,
192
219
  debug,
193
- multicore
220
+ workers: multicore ? "auto" : 1
194
221
  });
195
222
  } else {
196
223
  console.error(usage);