@hashrock/ono 0.1.2 → 0.1.3
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/package.json +1 -1
- package/src/builder.js +12 -13
- package/README.md +0 -341
package/package.json
CHANGED
package/src/builder.js
CHANGED
|
@@ -6,6 +6,7 @@ import { resolve, join, dirname, basename, relative, extname } from "node:path";
|
|
|
6
6
|
import { transformJSX } from "./transformer.js";
|
|
7
7
|
import { renderToString } from "./renderer.js";
|
|
8
8
|
import { generateCSSFromFiles } from "./unocss.js";
|
|
9
|
+
import { bundle } from "./bundler.js";
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Check if a route is dynamic (contains [param])
|
|
@@ -42,13 +43,11 @@ export async function buildFile(inputFile, options = {}) {
|
|
|
42
43
|
const outDir = resolve(process.cwd(), outputDir);
|
|
43
44
|
const resolvedInput = resolve(process.cwd(), inputFile);
|
|
44
45
|
|
|
45
|
-
//
|
|
46
|
-
const
|
|
47
|
-
const transformed = await transformJSX(jsx, resolvedInput);
|
|
46
|
+
// Bundle the file with all its dependencies
|
|
47
|
+
const bundledCode = await bundle(resolvedInput);
|
|
48
48
|
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
const codeWithRuntime = INLINE_JSX_RUNTIME + transformed;
|
|
49
|
+
// Add inline JSX runtime
|
|
50
|
+
const codeWithRuntime = INLINE_JSX_RUNTIME + bundledCode;
|
|
52
51
|
|
|
53
52
|
// Write transformed JS temporarily
|
|
54
53
|
const tempFile = join(outDir, `_temp_${Date.now()}.js`);
|
|
@@ -98,12 +97,11 @@ export async function buildDynamicRoute(inputFile, options = {}) {
|
|
|
98
97
|
const outDir = resolve(process.cwd(), outputDir);
|
|
99
98
|
const resolvedInput = resolve(process.cwd(), inputFile);
|
|
100
99
|
|
|
101
|
-
//
|
|
102
|
-
const
|
|
103
|
-
const transformed = await transformJSX(jsx, resolvedInput);
|
|
100
|
+
// Bundle the file with all its dependencies
|
|
101
|
+
const bundledCode = await bundle(resolvedInput);
|
|
104
102
|
|
|
105
103
|
// Add inline JSX runtime
|
|
106
|
-
const codeWithRuntime = INLINE_JSX_RUNTIME +
|
|
104
|
+
const codeWithRuntime = INLINE_JSX_RUNTIME + bundledCode;
|
|
107
105
|
|
|
108
106
|
// Write transformed JS temporarily
|
|
109
107
|
const tempFile = join(outDir, `_temp_${Date.now()}.js`);
|
|
@@ -238,11 +236,12 @@ async function getAllJSXFiles(dir) {
|
|
|
238
236
|
*/
|
|
239
237
|
export async function getDynamicRoutePaths(file) {
|
|
240
238
|
const outDir = resolve(process.cwd(), "dist");
|
|
241
|
-
|
|
242
|
-
|
|
239
|
+
|
|
240
|
+
// Bundle the file with all its dependencies
|
|
241
|
+
const bundledCode = await bundle(file);
|
|
243
242
|
|
|
244
243
|
// Add inline JSX runtime
|
|
245
|
-
const codeWithRuntime = INLINE_JSX_RUNTIME +
|
|
244
|
+
const codeWithRuntime = INLINE_JSX_RUNTIME + bundledCode;
|
|
246
245
|
|
|
247
246
|
const tempFile = join(outDir, `_temp_paths_${Date.now()}.js`);
|
|
248
247
|
await mkdir(dirname(tempFile), { recursive: true });
|
package/README.md
DELETED
|
@@ -1,341 +0,0 @@
|
|
|
1
|
-
# Ono
|
|
2
|
-
|
|
3
|
-
Minimalist SSG framework with JSX, powered by TypeScript's JSX transformer
|
|
4
|
-
|
|
5
|
-
## Why Ono?
|
|
6
|
-
|
|
7
|
-
Ono is designed to be a minimal alternative to Astro, leveraging TypeScript's built-in JSX transformation capabilities. The core philosophy is:
|
|
8
|
-
|
|
9
|
-
- **Minimal Dependencies**: Uses TypeScript's standard `tsx` transform feature, avoiding complex build toolchains
|
|
10
|
-
- **High Portability**: Designed to be lightweight enough to run in Web Workers or even entirely in the browser
|
|
11
|
-
- **Simple Architecture**: A minimal subset of static site generation features, focusing on what matters most
|
|
12
|
-
- **Future Vision**: Enable browser-based REPL experiences and client-side static site generation
|
|
13
|
-
|
|
14
|
-
Unlike heavyweight frameworks, Ono embraces simplicity. It's perfect for developers who want the power of JSX and component-based development without the complexity of a full framework.
|
|
15
|
-
|
|
16
|
-
## Features
|
|
17
|
-
|
|
18
|
-
- Minimal JSX runtime for building static HTML sites
|
|
19
|
-
- Built-in bundler for JSX files
|
|
20
|
-
- CLI tool for building JSX to HTML
|
|
21
|
-
- Development server with live reload
|
|
22
|
-
- File watching for automatic rebuilds
|
|
23
|
-
- Support for components and props
|
|
24
|
-
- Integrated UnoCSS for atomic CSS generation
|
|
25
|
-
- Pages directory support for multi-page sites
|
|
26
|
-
- Content collections with Markdown support
|
|
27
|
-
- Dynamic routes with `[slug].jsx` pattern
|
|
28
|
-
- Uses TypeScript's JSX transform
|
|
29
|
-
|
|
30
|
-
## Installation
|
|
31
|
-
|
|
32
|
-
### Global Installation
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
npm install -g @hashrock/ono
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
### Local Installation
|
|
39
|
-
|
|
40
|
-
```bash
|
|
41
|
-
npm install @hashrock/ono
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
## Quick Start
|
|
45
|
-
|
|
46
|
-
**Try it online**: [Ono REPL](https://hashrock.github.io/ono/) - Worker-powered JSX playground!
|
|
47
|
-
|
|
48
|
-
Or create a simple JSX file and build it:
|
|
49
|
-
|
|
50
|
-
```bash
|
|
51
|
-
# Create a JSX file
|
|
52
|
-
echo '/** @jsxImportSource @hashrock/ono */
|
|
53
|
-
export default function App() {
|
|
54
|
-
return (
|
|
55
|
-
<html>
|
|
56
|
-
<head><title>Hello Ono</title></head>
|
|
57
|
-
<body>
|
|
58
|
-
<h1>Hello, Ono!</h1>
|
|
59
|
-
</body>
|
|
60
|
-
</html>
|
|
61
|
-
);
|
|
62
|
-
}' > index.jsx
|
|
63
|
-
|
|
64
|
-
# Build it
|
|
65
|
-
npx @hashrock/ono build index.jsx
|
|
66
|
-
|
|
67
|
-
# Or start a dev server
|
|
68
|
-
npx @hashrock/ono dev index.jsx
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
## Usage
|
|
72
|
-
|
|
73
|
-
### CLI Commands
|
|
74
|
-
|
|
75
|
-
**Build** - Build JSX files to static HTML:
|
|
76
|
-
|
|
77
|
-
```bash
|
|
78
|
-
ono build # Build all pages in pages/ directory
|
|
79
|
-
ono build pages # Build all pages in pages/ directory
|
|
80
|
-
ono build example/index.jsx # Build a single file
|
|
81
|
-
ono build --output dist # Specify output directory
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
This will:
|
|
85
|
-
- Build your JSX file(s) to HTML
|
|
86
|
-
- Copy files from `public/` directory
|
|
87
|
-
- Generate UnoCSS automatically
|
|
88
|
-
|
|
89
|
-
**Dev Server** - Start a development server with live reload:
|
|
90
|
-
|
|
91
|
-
```bash
|
|
92
|
-
ono dev # Start dev server for pages/ directory
|
|
93
|
-
ono dev pages # Start dev server for pages/ directory
|
|
94
|
-
ono dev example/index.jsx # Start dev server for a single file
|
|
95
|
-
ono dev --port 8080 # Start dev server on custom port
|
|
96
|
-
ono dev --output build # Use custom output directory
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
This will:
|
|
100
|
-
- Build your JSX file(s) to HTML
|
|
101
|
-
- Start an HTTP server (default: http://localhost:3000)
|
|
102
|
-
- Watch for changes and rebuild automatically
|
|
103
|
-
- Live reload the browser when files change
|
|
104
|
-
- Generate UnoCSS automatically
|
|
105
|
-
|
|
106
|
-
**Help** - Show usage information:
|
|
107
|
-
|
|
108
|
-
```bash
|
|
109
|
-
ono --help
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
### JSX Example
|
|
113
|
-
|
|
114
|
-
Create a JSX file with components:
|
|
115
|
-
|
|
116
|
-
```jsx
|
|
117
|
-
// example/index.jsx
|
|
118
|
-
export default function App() {
|
|
119
|
-
return (
|
|
120
|
-
<html>
|
|
121
|
-
<head>
|
|
122
|
-
<title>My Site</title>
|
|
123
|
-
</head>
|
|
124
|
-
<body>
|
|
125
|
-
<Header title="Welcome" />
|
|
126
|
-
<main>
|
|
127
|
-
<p>Hello, Ono!</p>
|
|
128
|
-
</main>
|
|
129
|
-
</body>
|
|
130
|
-
</html>
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function Header({ title }) {
|
|
135
|
-
return (
|
|
136
|
-
<header>
|
|
137
|
-
<h1>{title}</h1>
|
|
138
|
-
</header>
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
Build it:
|
|
144
|
-
|
|
145
|
-
```bash
|
|
146
|
-
ono build example/index.jsx
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
This generates `dist/index.html`:
|
|
150
|
-
|
|
151
|
-
```html
|
|
152
|
-
<!DOCTYPE html>
|
|
153
|
-
<html>
|
|
154
|
-
<head>
|
|
155
|
-
<title>My Site</title>
|
|
156
|
-
</head>
|
|
157
|
-
<body>
|
|
158
|
-
<header>
|
|
159
|
-
<h1>Welcome</h1>
|
|
160
|
-
</header>
|
|
161
|
-
<main>
|
|
162
|
-
<p>Hello, Ono!</p>
|
|
163
|
-
</main>
|
|
164
|
-
</body>
|
|
165
|
-
</html>
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
### UnoCSS Integration
|
|
169
|
-
|
|
170
|
-
Ono automatically integrates with UnoCSS. Simply use utility classes in your JSX:
|
|
171
|
-
|
|
172
|
-
```jsx
|
|
173
|
-
export default function App() {
|
|
174
|
-
return (
|
|
175
|
-
<div class="max-w-800px mx-auto p-8">
|
|
176
|
-
<h1 class="text-3xl font-bold text-blue-600">
|
|
177
|
-
Welcome to Ono
|
|
178
|
-
</h1>
|
|
179
|
-
<p class="mt-4 text-gray-700">
|
|
180
|
-
UnoCSS utilities are automatically generated!
|
|
181
|
-
</p>
|
|
182
|
-
</div>
|
|
183
|
-
);
|
|
184
|
-
}
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
The CSS will be automatically generated to `dist/uno.css` and included in your HTML.
|
|
188
|
-
|
|
189
|
-
### Custom UnoCSS Configuration
|
|
190
|
-
|
|
191
|
-
Create a `uno.config.js` file in your project root:
|
|
192
|
-
|
|
193
|
-
```javascript
|
|
194
|
-
import { presetUno } from "unocss";
|
|
195
|
-
|
|
196
|
-
export default {
|
|
197
|
-
presets: [presetUno()],
|
|
198
|
-
theme: {
|
|
199
|
-
colors: {
|
|
200
|
-
primary: "#0070f3",
|
|
201
|
-
},
|
|
202
|
-
},
|
|
203
|
-
shortcuts: {
|
|
204
|
-
"btn": "px-4 py-2 rounded bg-primary text-white",
|
|
205
|
-
},
|
|
206
|
-
};
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
## Configuration
|
|
210
|
-
|
|
211
|
-
### TypeScript/JSX Setup
|
|
212
|
-
|
|
213
|
-
Add to your `tsconfig.json`:
|
|
214
|
-
|
|
215
|
-
```json
|
|
216
|
-
{
|
|
217
|
-
"compilerOptions": {
|
|
218
|
-
"jsx": "react-jsx",
|
|
219
|
-
"jsxImportSource": "@hashrock/ono"
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
Or use JSDoc comments in your `.jsx` files:
|
|
225
|
-
|
|
226
|
-
```jsx
|
|
227
|
-
/** @jsxImportSource @hashrock/ono */
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
## Development
|
|
231
|
-
|
|
232
|
-
### Install Dependencies
|
|
233
|
-
|
|
234
|
-
```bash
|
|
235
|
-
npm install
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
### Run Tests
|
|
239
|
-
|
|
240
|
-
Run all unit tests:
|
|
241
|
-
|
|
242
|
-
```bash
|
|
243
|
-
npm test
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
Run snapshot tests:
|
|
247
|
-
|
|
248
|
-
```bash
|
|
249
|
-
npm run test:snapshot
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
Run all tests (unit + snapshot):
|
|
253
|
-
|
|
254
|
-
```bash
|
|
255
|
-
npm run test:all
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
Update snapshots after intentional changes:
|
|
259
|
-
|
|
260
|
-
```bash
|
|
261
|
-
npm run test:snapshot:update
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
### Watch Mode
|
|
265
|
-
|
|
266
|
-
```bash
|
|
267
|
-
npm run test:watch
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
### Testing Strategy
|
|
271
|
-
|
|
272
|
-
This project uses a comprehensive testing approach:
|
|
273
|
-
|
|
274
|
-
- **Unit Tests**: Traditional assertion-based tests for core functionality
|
|
275
|
-
- **Snapshot Tests**: Capture and verify output consistency for HTML rendering, JSX transformation, and CLI commands
|
|
276
|
-
- **Integration Tests**: End-to-end testing of build processes and content collections
|
|
277
|
-
|
|
278
|
-
For more details about snapshot testing, see [SNAPSHOT_TESTING.md](./SNAPSHOT_TESTING.md).
|
|
279
|
-
|
|
280
|
-
### Continuous Integration
|
|
281
|
-
|
|
282
|
-
This project uses GitHub Actions for automated testing. The CI pipeline:
|
|
283
|
-
|
|
284
|
-
- Tests on Node.js 22.x with Ubuntu
|
|
285
|
-
- Runs comprehensive unit and snapshot tests
|
|
286
|
-
- Validates CLI commands and build processes
|
|
287
|
-
- Ensures output consistency across environments
|
|
288
|
-
|
|
289
|
-
See `.github/workflows/ci.yml` for the full configuration
|
|
290
|
-
|
|
291
|
-
### Link for Local Development
|
|
292
|
-
|
|
293
|
-
```bash
|
|
294
|
-
npm link
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
This allows you to use the `ono` command globally while developing.
|
|
298
|
-
|
|
299
|
-
## API
|
|
300
|
-
|
|
301
|
-
### JSX Runtime
|
|
302
|
-
|
|
303
|
-
```javascript
|
|
304
|
-
import { createElement } from '@hashrock/ono/jsx-runtime';
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
The JSX runtime automatically handles JSX transformation when using TypeScript or Babel.
|
|
308
|
-
|
|
309
|
-
### Renderer
|
|
310
|
-
|
|
311
|
-
```javascript
|
|
312
|
-
import { renderToString } from '@hashrock/ono';
|
|
313
|
-
|
|
314
|
-
const html = renderToString(<div>Hello</div>);
|
|
315
|
-
```
|
|
316
|
-
|
|
317
|
-
### Bundler
|
|
318
|
-
|
|
319
|
-
```javascript
|
|
320
|
-
import { bundle } from '@hashrock/ono';
|
|
321
|
-
|
|
322
|
-
const code = await bundle('./path/to/file.jsx');
|
|
323
|
-
```
|
|
324
|
-
|
|
325
|
-
## Pages Mode
|
|
326
|
-
|
|
327
|
-
Ono supports building multi-page sites by placing JSX files in a `pages/` directory:
|
|
328
|
-
|
|
329
|
-
```
|
|
330
|
-
pages/
|
|
331
|
-
├── index.jsx → dist/index.html
|
|
332
|
-
├── about.jsx → dist/about.html
|
|
333
|
-
└── blog/
|
|
334
|
-
└── first-post.jsx → dist/blog/first-post.html
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
Each file should export a default function that returns a complete HTML document. Use the Layout component pattern for shared structure across pages.
|
|
338
|
-
|
|
339
|
-
## License
|
|
340
|
-
|
|
341
|
-
MIT
|