create-ramonyx-app 0.1.0 → 0.1.1
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 +1 -1
- package/package.json +1 -1
- package/template/README.md +6 -4
- package/template/package.json +4 -5
- package/template/src/app.ts +47 -22
- package/template/build.ts +0 -13
- package/template/src/main.ts +0 -16
package/README.md
CHANGED
package/package.json
CHANGED
package/template/README.md
CHANGED
|
@@ -8,17 +8,19 @@ Aplikasi [Ramonyx](https://github.com/ramonyx/ramonyx) — framework full-stack
|
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
10
|
pnpm install
|
|
11
|
-
pnpm
|
|
12
|
-
pnpm
|
|
13
|
-
pnpm
|
|
11
|
+
pnpm dev # Vite + HMR (http://localhost:5173) → SSR :3000
|
|
12
|
+
pnpm build # bundel klien (wajib sebelum start produksi)
|
|
13
|
+
pnpm start # http://127.0.0.1:3000 (NODE_ENV=production otomatis)
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
+
Perintah memakai CLI **`ramonyx`** (`@ramonyx/devtools`): `ramonyx dev|build|start|doctor`.
|
|
17
|
+
|
|
16
18
|
## Struktur
|
|
17
19
|
|
|
20
|
+
- `src/app.ts` — mengekspor `createApp(options?)` (dipakai CLI)
|
|
18
21
|
- `src/routes/page.tsx` — halaman (loader + komponen React; `layout.tsx`/`error.tsx` opsional)
|
|
19
22
|
- `src/routes/api/halo/[nama].ts` — route API (`export const GET = route({ ... })`)
|
|
20
23
|
- `src/routes/middleware.ts` — security headers + CSP nonce + aset `/assets/*`
|
|
21
|
-
- `build.ts` — bundel klien (Vite) lewat `@ramonyx/bundler`
|
|
22
24
|
- `ramonyx.config.ts` — port/host + strict validation
|
|
23
25
|
|
|
24
26
|
## Endpoint contoh
|
package/template/package.json
CHANGED
|
@@ -6,14 +6,13 @@
|
|
|
6
6
|
"node": ">=24"
|
|
7
7
|
},
|
|
8
8
|
"scripts": {
|
|
9
|
-
"build": "
|
|
10
|
-
"start": "
|
|
11
|
-
"dev": "
|
|
9
|
+
"build": "ramonyx build",
|
|
10
|
+
"start": "ramonyx start",
|
|
11
|
+
"dev": "ramonyx dev"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@ramonyx/adapter-runtime": "^0.1.0",
|
|
15
|
-
"@ramonyx/bundler": "^0.1.0",
|
|
16
14
|
"@ramonyx/compiler": "^0.1.0",
|
|
15
|
+
"@ramonyx/devtools": "^0.1.0",
|
|
17
16
|
"@ramonyx/react": "^0.1.0",
|
|
18
17
|
"@ramonyx/security": "^0.1.0",
|
|
19
18
|
"@ramonyx/server": "^0.1.0",
|
package/template/src/app.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fileURLToPath } from "node:url";
|
|
2
|
-
import { createRouteManifest, loadPageRoutes } from "@ramonyx/compiler";
|
|
2
|
+
import { createRouteManifest, loadPageRoutes, type ModuleImporter } from "@ramonyx/compiler";
|
|
3
3
|
import { createReactRenderer } from "@ramonyx/react";
|
|
4
4
|
import { createHandler } from "@ramonyx/server";
|
|
5
5
|
import { createPageRoutes } from "@ramonyx/ssr";
|
|
@@ -7,32 +7,57 @@ import type { FetchHandler } from "ramonyx";
|
|
|
7
7
|
|
|
8
8
|
import middleware from "./routes/middleware.ts";
|
|
9
9
|
|
|
10
|
+
export interface CreateAppOptions {
|
|
11
|
+
/** URL bundle klien (produksi "/assets/client.js"; dev via entry Vite). */
|
|
12
|
+
readonly clientScript?: string;
|
|
13
|
+
/** Modul tambahan sebelum entry (mis. "/@vite/client"). */
|
|
14
|
+
readonly clientModules?: readonly string[];
|
|
15
|
+
/** Importer modul (dev: module graph Vite). */
|
|
16
|
+
readonly importer?: ModuleImporter;
|
|
17
|
+
/** Bangun ulang manifest tiap request (dev, tanpa restart). */
|
|
18
|
+
readonly reloadManifests?: boolean;
|
|
19
|
+
readonly strictValidation?: boolean;
|
|
20
|
+
/** SSR streaming untuk halaman (ADR-0047). */
|
|
21
|
+
readonly streaming?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
10
24
|
/**
|
|
11
25
|
* Aplikasi __APP_NAME__: route API + halaman SSR React dari `src/routes` (file routing),
|
|
12
|
-
* dengan hydration klien
|
|
26
|
+
* dengan hydration klien.
|
|
13
27
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* - `api/*.ts` — route API (`export const GET = route({ ... })`).
|
|
28
|
+
* Dijalankan lewat CLI: `ramonyx dev` (Vite + HMR), `ramonyx build` (bundle klien),
|
|
29
|
+
* `ramonyx start` (produksi — `NODE_ENV=production` otomatis).
|
|
17
30
|
*/
|
|
18
|
-
export async function createApp(): Promise<FetchHandler> {
|
|
31
|
+
export async function createApp(options: CreateAppOptions = {}): Promise<FetchHandler> {
|
|
19
32
|
const dir = fileURLToPath(new URL("./routes", import.meta.url));
|
|
33
|
+
const client =
|
|
34
|
+
options.clientScript === undefined
|
|
35
|
+
? undefined
|
|
36
|
+
: { script: options.clientScript, extraModules: options.clientModules };
|
|
37
|
+
|
|
38
|
+
const build = async (): Promise<FetchHandler> => {
|
|
39
|
+
const [apiRoutes, pages] = await Promise.all([
|
|
40
|
+
createRouteManifest({ dir, importer: options.importer }),
|
|
41
|
+
loadPageRoutes({ dir, importer: options.importer }),
|
|
42
|
+
]);
|
|
20
43
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
44
|
+
return createHandler({
|
|
45
|
+
routes: [
|
|
46
|
+
...apiRoutes,
|
|
47
|
+
...createPageRoutes({
|
|
48
|
+
pages,
|
|
49
|
+
renderer: createReactRenderer(),
|
|
50
|
+
client,
|
|
51
|
+
streaming: options.streaming,
|
|
52
|
+
}),
|
|
53
|
+
],
|
|
54
|
+
middleware,
|
|
55
|
+
strictValidation: options.strictValidation,
|
|
56
|
+
});
|
|
57
|
+
};
|
|
25
58
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
...createPageRoutes({
|
|
31
|
-
pages,
|
|
32
|
-
renderer: createReactRenderer(),
|
|
33
|
-
client: { script: "/assets/client.js" },
|
|
34
|
-
}),
|
|
35
|
-
],
|
|
36
|
-
middleware,
|
|
37
|
-
});
|
|
59
|
+
if (options.reloadManifests === true) {
|
|
60
|
+
return async (request) => (await build())(request);
|
|
61
|
+
}
|
|
62
|
+
return build();
|
|
38
63
|
}
|
package/template/build.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// Build client (React + hydration) lewat Vite — jalankan `pnpm build` sebelum `pnpm start`
|
|
2
|
-
// di produksi. Hasil: `dist/client/client.js` disajikan di `/assets/client.js`.
|
|
3
|
-
|
|
4
|
-
import { join } from "node:path";
|
|
5
|
-
import { fileURLToPath } from "node:url";
|
|
6
|
-
import { buildClient } from "@ramonyx/bundler";
|
|
7
|
-
import { loadPageRoutes } from "@ramonyx/compiler";
|
|
8
|
-
|
|
9
|
-
const appDir = fileURLToPath(new URL(".", import.meta.url));
|
|
10
|
-
const pages = await loadPageRoutes({ dir: join(appDir, "src/routes") });
|
|
11
|
-
const result = await buildClient({ appDir, pages });
|
|
12
|
-
|
|
13
|
-
console.log(`✓ client bundle: ${result.scriptPath} (${result.outDir})`);
|
package/template/src/main.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { createNodeHost } from "@ramonyx/adapter-runtime";
|
|
2
|
-
import { resolveConfig } from "ramonyx";
|
|
3
|
-
|
|
4
|
-
import config from "../ramonyx.config.ts";
|
|
5
|
-
import { createApp } from "./app.ts";
|
|
6
|
-
|
|
7
|
-
const resolved = resolveConfig(config);
|
|
8
|
-
const host = createNodeHost();
|
|
9
|
-
const app = await createApp();
|
|
10
|
-
|
|
11
|
-
const server = await host.serve(app, {
|
|
12
|
-
port: resolved.server.port,
|
|
13
|
-
host: resolved.server.host,
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
console.log(`__APP_NAME__ berjalan di ${server.url}`);
|