@hashrock/ono 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/LICENSE +21 -0
- package/README.md +299 -0
- package/package.json +49 -0
- package/src/bundler.js +73 -0
- package/src/cli.js +1014 -0
- package/src/jsx-runtime.js +45 -0
- package/src/renderer.js +128 -0
- package/src/resolver.js +137 -0
- package/src/transformer.js +48 -0
- package/src/unocss.js +75 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 hashrock
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
# Ono
|
|
2
|
+
|
|
3
|
+
A lightweight JSX library for static site generation with UnoCSS support.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Minimal JSX runtime for building static HTML sites
|
|
8
|
+
- Built-in bundler for JSX files
|
|
9
|
+
- CLI tool for building JSX to HTML
|
|
10
|
+
- Development server with live reload
|
|
11
|
+
- File watching for automatic rebuilds
|
|
12
|
+
- Support for components and props
|
|
13
|
+
- Integrated UnoCSS for atomic CSS generation
|
|
14
|
+
- Quick project initialization with templates
|
|
15
|
+
- Pages directory support for multi-page sites
|
|
16
|
+
- Uses TypeScript's JSX transform
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
### Global Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install -g @hashrock/ono
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Local Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @hashrock/ono
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Quick Start
|
|
33
|
+
|
|
34
|
+
Initialize a new project:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
ono init my-project
|
|
38
|
+
cd my-project
|
|
39
|
+
npm run dev
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
This creates a complete project structure with:
|
|
43
|
+
- `pages/` directory with example page
|
|
44
|
+
- `components/` directory with Layout and Hello components
|
|
45
|
+
- `public/` directory for static assets
|
|
46
|
+
- UnoCSS integration pre-configured
|
|
47
|
+
- Development and build scripts
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
### CLI Commands
|
|
52
|
+
|
|
53
|
+
**Init** - Initialize a new Ono project:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
ono init
|
|
57
|
+
ono init my-project
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**Build** - Build a JSX file to HTML:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
ono build example/index.jsx
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**Build Pages** - Build all pages in a directory:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
ono build pages
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**Build with Watch** - Watch for changes and rebuild automatically:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
ono build pages --watch
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
This will:
|
|
79
|
+
- Build your JSX files to HTML
|
|
80
|
+
- Watch for changes in `.jsx` files
|
|
81
|
+
- Automatically rebuild when files change
|
|
82
|
+
- No live reload (simple file watching)
|
|
83
|
+
|
|
84
|
+
**Dev Server** - Start a development server with live reload:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
ono dev
|
|
88
|
+
ono dev pages
|
|
89
|
+
ono dev example/index.jsx
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
This will:
|
|
93
|
+
- Build your JSX file(s) to HTML
|
|
94
|
+
- Start an HTTP server (default: http://localhost:3000)
|
|
95
|
+
- Watch for changes and rebuild automatically
|
|
96
|
+
- Live reload the browser when files change
|
|
97
|
+
- Generate UnoCSS automatically
|
|
98
|
+
|
|
99
|
+
You can specify custom options:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
ono dev --port 8080 --output build
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**Help** - Show usage information:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
ono --help
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### JSX Example
|
|
112
|
+
|
|
113
|
+
Create a JSX file with components:
|
|
114
|
+
|
|
115
|
+
```jsx
|
|
116
|
+
// example/index.jsx
|
|
117
|
+
export default function App() {
|
|
118
|
+
return (
|
|
119
|
+
<html>
|
|
120
|
+
<head>
|
|
121
|
+
<title>My Site</title>
|
|
122
|
+
</head>
|
|
123
|
+
<body>
|
|
124
|
+
<Header title="Welcome" />
|
|
125
|
+
<main>
|
|
126
|
+
<p>Hello, Ono!</p>
|
|
127
|
+
</main>
|
|
128
|
+
</body>
|
|
129
|
+
</html>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function Header({ title }) {
|
|
134
|
+
return (
|
|
135
|
+
<header>
|
|
136
|
+
<h1>{title}</h1>
|
|
137
|
+
</header>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Build it:
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
ono build example/index.jsx
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
This generates `dist/index.html`:
|
|
149
|
+
|
|
150
|
+
```html
|
|
151
|
+
<!DOCTYPE html>
|
|
152
|
+
<html>
|
|
153
|
+
<head>
|
|
154
|
+
<title>My Site</title>
|
|
155
|
+
</head>
|
|
156
|
+
<body>
|
|
157
|
+
<header>
|
|
158
|
+
<h1>Welcome</h1>
|
|
159
|
+
</header>
|
|
160
|
+
<main>
|
|
161
|
+
<p>Hello, Ono!</p>
|
|
162
|
+
</main>
|
|
163
|
+
</body>
|
|
164
|
+
</html>
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### UnoCSS Integration
|
|
168
|
+
|
|
169
|
+
Ono automatically integrates with UnoCSS. Simply use utility classes in your JSX:
|
|
170
|
+
|
|
171
|
+
```jsx
|
|
172
|
+
export default function App() {
|
|
173
|
+
return (
|
|
174
|
+
<div class="max-w-800px mx-auto p-8">
|
|
175
|
+
<h1 class="text-3xl font-bold text-blue-600">
|
|
176
|
+
Welcome to Ono
|
|
177
|
+
</h1>
|
|
178
|
+
<p class="mt-4 text-gray-700">
|
|
179
|
+
UnoCSS utilities are automatically generated!
|
|
180
|
+
</p>
|
|
181
|
+
</div>
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
The CSS will be automatically generated to `dist/uno.css` and included in your HTML.
|
|
187
|
+
|
|
188
|
+
### Custom UnoCSS Configuration
|
|
189
|
+
|
|
190
|
+
Create a `uno.config.js` file in your project root:
|
|
191
|
+
|
|
192
|
+
```javascript
|
|
193
|
+
import { presetUno } from "unocss";
|
|
194
|
+
|
|
195
|
+
export default {
|
|
196
|
+
presets: [presetUno()],
|
|
197
|
+
theme: {
|
|
198
|
+
colors: {
|
|
199
|
+
primary: "#0070f3",
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
shortcuts: {
|
|
203
|
+
"btn": "px-4 py-2 rounded bg-primary text-white",
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Configuration
|
|
209
|
+
|
|
210
|
+
### TypeScript/JSX Setup
|
|
211
|
+
|
|
212
|
+
Add to your `tsconfig.json`:
|
|
213
|
+
|
|
214
|
+
```json
|
|
215
|
+
{
|
|
216
|
+
"compilerOptions": {
|
|
217
|
+
"jsx": "react-jsx",
|
|
218
|
+
"jsxImportSource": "@hashrock/ono"
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
Or use JSDoc comments in your `.jsx` files:
|
|
224
|
+
|
|
225
|
+
```jsx
|
|
226
|
+
/** @jsxImportSource @hashrock/ono */
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Development
|
|
230
|
+
|
|
231
|
+
### Install Dependencies
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
npm install
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Run Tests
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
npm test
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Watch Mode
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
npm run test:watch
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Link for Local Development
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
npm link
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
This allows you to use the `ono` command globally while developing.
|
|
256
|
+
|
|
257
|
+
## API
|
|
258
|
+
|
|
259
|
+
### JSX Runtime
|
|
260
|
+
|
|
261
|
+
```javascript
|
|
262
|
+
import { createElement } from '@hashrock/ono/jsx-runtime';
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
The JSX runtime automatically handles JSX transformation when using TypeScript or Babel.
|
|
266
|
+
|
|
267
|
+
### Renderer
|
|
268
|
+
|
|
269
|
+
```javascript
|
|
270
|
+
import { renderToString } from '@hashrock/ono';
|
|
271
|
+
|
|
272
|
+
const html = renderToString(<div>Hello</div>);
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Bundler
|
|
276
|
+
|
|
277
|
+
```javascript
|
|
278
|
+
import { bundle } from '@hashrock/ono';
|
|
279
|
+
|
|
280
|
+
const code = await bundle('./path/to/file.jsx');
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
## Pages Mode
|
|
284
|
+
|
|
285
|
+
Ono supports building multi-page sites by placing JSX files in a `pages/` directory:
|
|
286
|
+
|
|
287
|
+
```
|
|
288
|
+
pages/
|
|
289
|
+
├── index.jsx → dist/index.html
|
|
290
|
+
├── about.jsx → dist/about.html
|
|
291
|
+
└── blog/
|
|
292
|
+
└── first-post.jsx → dist/blog/first-post.html
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Each file should export a default function that returns a complete HTML document. Use the Layout component pattern for shared structure across pages.
|
|
296
|
+
|
|
297
|
+
## License
|
|
298
|
+
|
|
299
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hashrock/ono",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A lightweight JSX library for static site generation with UnoCSS support",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/jsx-runtime.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"ono": "src/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "node --test test/**/*.test.js",
|
|
17
|
+
"test:watch": "node --test --watch test/**/*.test.js"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"jsx",
|
|
21
|
+
"ssg",
|
|
22
|
+
"static-site-generator",
|
|
23
|
+
"unocss",
|
|
24
|
+
"atomic-css",
|
|
25
|
+
"ono",
|
|
26
|
+
"lightweight"
|
|
27
|
+
],
|
|
28
|
+
"author": "hashrock",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/hashrock/ono.git"
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/hashrock/ono/issues"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/hashrock/ono#readme",
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=18.0.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"typescript": "^5.9.3"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@unocss/preset-uno": "^66.5.4",
|
|
46
|
+
"unocss": "^66.5.4",
|
|
47
|
+
"ws": "^8.18.3"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/bundler.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bundler - Bundle JSX files into a single executable module
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import fs from "node:fs/promises";
|
|
6
|
+
import { collectDependencies } from "./resolver.js";
|
|
7
|
+
import { transformJSX } from "./transformer.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Bundle a JSX file and all its dependencies
|
|
11
|
+
* @param {string} entryFile - Absolute path to entry file
|
|
12
|
+
* @returns {Promise<string>} Bundled JavaScript code
|
|
13
|
+
*/
|
|
14
|
+
export async function bundle(entryFile) {
|
|
15
|
+
// Collect all dependencies
|
|
16
|
+
const { order } = await collectDependencies(entryFile);
|
|
17
|
+
|
|
18
|
+
const modules = [];
|
|
19
|
+
|
|
20
|
+
// Process each module in dependency order
|
|
21
|
+
for (let i = 0; i < order.length; i++) {
|
|
22
|
+
const filePath = order[i];
|
|
23
|
+
const isEntry = i === order.length - 1; // Last file is entry
|
|
24
|
+
|
|
25
|
+
// Read the file
|
|
26
|
+
const source = await fs.readFile(filePath, "utf-8");
|
|
27
|
+
|
|
28
|
+
// Transform JSX to JS
|
|
29
|
+
const transformed = transformJSX(source, filePath);
|
|
30
|
+
|
|
31
|
+
// Remove import statements (they're already resolved)
|
|
32
|
+
const withoutImports = removeImports(transformed);
|
|
33
|
+
|
|
34
|
+
// Remove export default from non-entry files
|
|
35
|
+
const withoutExports = isEntry ? withoutImports : removeExportDefault(withoutImports);
|
|
36
|
+
|
|
37
|
+
modules.push({
|
|
38
|
+
path: filePath,
|
|
39
|
+
code: withoutExports,
|
|
40
|
+
isEntry
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Combine all modules into one
|
|
45
|
+
const bundledCode = modules.map(m => m.code).join("\n\n");
|
|
46
|
+
|
|
47
|
+
return bundledCode;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Remove import statements from code
|
|
52
|
+
* @param {string} code - JavaScript code
|
|
53
|
+
* @returns {string} Code without imports
|
|
54
|
+
*/
|
|
55
|
+
function removeImports(code) {
|
|
56
|
+
// Remove import statements
|
|
57
|
+
const lines = code.split("\n");
|
|
58
|
+
const filteredLines = lines.filter(line => {
|
|
59
|
+
const trimmed = line.trim();
|
|
60
|
+
return !trimmed.startsWith("import ") && trimmed !== "import";
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return filteredLines.join("\n");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Remove export default from code
|
|
68
|
+
* @param {string} code - JavaScript code
|
|
69
|
+
* @returns {string} Code without export default
|
|
70
|
+
*/
|
|
71
|
+
function removeExportDefault(code) {
|
|
72
|
+
return code.replace(/export\s+default\s+/g, "");
|
|
73
|
+
}
|