@hashrock/ono 0.1.3 ā 0.2.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 +56 -0
- package/package.json +14 -13
- package/src/barrels.js +230 -0
- package/src/browser/compiler.js +71 -193
- package/src/browser/unocss.js +5 -1
- package/src/builder.js +109 -230
- package/src/bundler.js +215 -64
- package/src/cli.js +22 -191
- package/src/commands/build.js +141 -0
- package/src/commands/dev.js +54 -0
- package/src/constants.js +74 -0
- package/src/jsx-runtime.js +15 -5
- package/src/parser.js +555 -0
- package/src/renderer.js +29 -48
- package/src/server.js +88 -74
- package/src/transformer.js +1 -18
- package/src/unocss.js +20 -24
- package/src/utils.js +55 -0
- package/src/watcher.js +98 -125
- package/src/content.js +0 -272
- package/src/resolver.js +0 -137
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dev command for Ono CLI
|
|
3
|
+
*/
|
|
4
|
+
import { resolve, relative } from "node:path";
|
|
5
|
+
import { stat } from "node:fs/promises";
|
|
6
|
+
import { createDevServer } from "../server.js";
|
|
7
|
+
import { buildFile, buildFiles, generateUnoCSS } from "../builder.js";
|
|
8
|
+
import { watchFile, watchFiles } from "../watcher.js";
|
|
9
|
+
import { copyPublicFiles, initializeBarrels, parseCommandArgs } from "./build.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Run the dev command
|
|
13
|
+
* @param {string[]} args - Command line arguments (after 'dev')
|
|
14
|
+
* @returns {Promise<void>}
|
|
15
|
+
*/
|
|
16
|
+
export async function runDevCommand(args) {
|
|
17
|
+
const { input, port, outputDir } = parseCommandArgs(args);
|
|
18
|
+
|
|
19
|
+
// Generate barrel files if barrels directory exists
|
|
20
|
+
await initializeBarrels();
|
|
21
|
+
|
|
22
|
+
const inputPath = resolve(process.cwd(), input);
|
|
23
|
+
const inputStat = await stat(inputPath);
|
|
24
|
+
const isDirectory = inputStat.isDirectory();
|
|
25
|
+
|
|
26
|
+
const initialBuild = isDirectory
|
|
27
|
+
? await buildFiles(input, { outputDir })
|
|
28
|
+
: [await buildFile(input, { outputDir })];
|
|
29
|
+
|
|
30
|
+
await copyPublicFiles(outputDir);
|
|
31
|
+
await generateUnoCSS({ outputDir });
|
|
32
|
+
|
|
33
|
+
const mode = isDirectory ? "pages" : "single";
|
|
34
|
+
const indexFile = isDirectory
|
|
35
|
+
? "index.html"
|
|
36
|
+
: relative(outputDir, initialBuild[0].outputPath);
|
|
37
|
+
|
|
38
|
+
const { port: serverPort, reload } = await createDevServer({
|
|
39
|
+
outputDir,
|
|
40
|
+
port,
|
|
41
|
+
mode,
|
|
42
|
+
indexFile,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const watchOpts = {
|
|
46
|
+
outputDir,
|
|
47
|
+
reload,
|
|
48
|
+
onRebuild: () => copyPublicFiles(outputDir),
|
|
49
|
+
};
|
|
50
|
+
await (isDirectory ? watchFiles(input, watchOpts) : watchFile(input, watchOpts));
|
|
51
|
+
|
|
52
|
+
console.log(`\nš Server running at http://localhost:${serverPort}`);
|
|
53
|
+
console.log(`š Serving: ${input}/ ā ${outputDir}/`);
|
|
54
|
+
}
|
package/src/constants.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants for Ono SSG
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Default port configuration
|
|
7
|
+
*/
|
|
8
|
+
export const PORTS = {
|
|
9
|
+
/** Default HTTP server port */
|
|
10
|
+
SERVER: 3000,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Default directory names
|
|
15
|
+
*/
|
|
16
|
+
export const DIRS = {
|
|
17
|
+
/** Default input directory for pages */
|
|
18
|
+
PAGES: "pages",
|
|
19
|
+
/** Default output directory for built files */
|
|
20
|
+
OUTPUT: "dist",
|
|
21
|
+
/** Directory for static public files */
|
|
22
|
+
PUBLIC: "public",
|
|
23
|
+
/** Directory for barrel file sources */
|
|
24
|
+
BARRELS: "barrels",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Timing configuration
|
|
29
|
+
*/
|
|
30
|
+
export const TIMING = {
|
|
31
|
+
/** Debounce delay for file watcher in milliseconds */
|
|
32
|
+
DEBOUNCE_MS: 100,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Self-closing HTML tags (void elements)
|
|
37
|
+
*/
|
|
38
|
+
export const SELF_CLOSING_TAGS = new Set([
|
|
39
|
+
"area",
|
|
40
|
+
"base",
|
|
41
|
+
"br",
|
|
42
|
+
"col",
|
|
43
|
+
"embed",
|
|
44
|
+
"hr",
|
|
45
|
+
"img",
|
|
46
|
+
"input",
|
|
47
|
+
"link",
|
|
48
|
+
"meta",
|
|
49
|
+
"param",
|
|
50
|
+
"source",
|
|
51
|
+
"track",
|
|
52
|
+
"wbr",
|
|
53
|
+
]);
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Content-Type mappings for file extensions
|
|
57
|
+
*/
|
|
58
|
+
export const MIME_TYPES = {
|
|
59
|
+
".html": "text/html; charset=utf-8",
|
|
60
|
+
".css": "text/css; charset=utf-8",
|
|
61
|
+
".js": "application/javascript; charset=utf-8",
|
|
62
|
+
".json": "application/json; charset=utf-8",
|
|
63
|
+
".png": "image/png",
|
|
64
|
+
".jpg": "image/jpeg",
|
|
65
|
+
".jpeg": "image/jpeg",
|
|
66
|
+
".gif": "image/gif",
|
|
67
|
+
".svg": "image/svg+xml",
|
|
68
|
+
".ico": "image/x-icon",
|
|
69
|
+
".webp": "image/webp",
|
|
70
|
+
".woff": "font/woff",
|
|
71
|
+
".woff2": "font/woff2",
|
|
72
|
+
".ttf": "font/ttf",
|
|
73
|
+
".eot": "application/vnd.ms-fontobject",
|
|
74
|
+
};
|
package/src/jsx-runtime.js
CHANGED
|
@@ -1,22 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* JSX Runtime - createElement function
|
|
3
3
|
* Creates a VNode (Virtual Node) from JSX
|
|
4
|
+
*
|
|
5
|
+
* This module is self-contained (no imports) so the builder can inject it
|
|
6
|
+
* verbatim into compiled pages as the single source of truth for the runtime.
|
|
7
|
+
* It must stay browser-compatible for the REPL.
|
|
4
8
|
*/
|
|
5
9
|
|
|
6
10
|
/**
|
|
7
|
-
*
|
|
11
|
+
* Fragment symbol for grouping elements without a wrapper.
|
|
12
|
+
* Symbol.for keeps identity stable even if the runtime is evaluated twice.
|
|
13
|
+
*/
|
|
14
|
+
export const Fragment = Symbol.for("ono.fragment");
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Flatten array recursively and filter out null/undefined/boolean children
|
|
18
|
+
* @param {any[]} children - Array of children to flatten
|
|
19
|
+
* @returns {any[]} Flattened array
|
|
8
20
|
*/
|
|
9
21
|
function flattenChildren(children) {
|
|
10
22
|
const result = [];
|
|
11
23
|
|
|
12
24
|
for (const child of children) {
|
|
13
|
-
if (child === null || child === undefined || typeof child ===
|
|
14
|
-
// Skip null, undefined, and boolean values
|
|
25
|
+
if (child === null || child === undefined || typeof child === "boolean") {
|
|
15
26
|
continue;
|
|
16
27
|
}
|
|
17
28
|
|
|
18
29
|
if (Array.isArray(child)) {
|
|
19
|
-
// Recursively flatten arrays
|
|
20
30
|
result.push(...flattenChildren(child));
|
|
21
31
|
} else {
|
|
22
32
|
result.push(child);
|
|
@@ -44,7 +54,7 @@ export function createElement(tag, props, ...children) {
|
|
|
44
54
|
/**
|
|
45
55
|
* JSX runtime function (react-jsx transform)
|
|
46
56
|
* @param {string|Function} tag - HTML tag name or component function
|
|
47
|
-
* @param {
|
|
57
|
+
* @param {Record<string, any> | null | undefined} props - Element properties/attributes (includes children)
|
|
48
58
|
* @returns {Object} VNode object
|
|
49
59
|
*/
|
|
50
60
|
export function jsx(tag, props) {
|