create-ramonyx-app 0.0.0-stage → 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ramonymous
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 CHANGED
@@ -1,3 +1,17 @@
1
- # Temporary Holding Version
1
+ # create-ramonyx-app
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Scaffolder aplikasi Ramonyx — SSR React + hydration, file routing `src/routes`.
4
+
5
+ > **Alpha (0.1.0)** — butuh **Node.js ≥ 24**.
6
+
7
+ ## Pemakaian
8
+
9
+ ```bash
10
+ pnpm create ramonyx-app aplikasi-saya
11
+ # atau tanpa install:
12
+ pnpm dlx create-ramonyx-app aplikasi-saya
13
+ ```
14
+
15
+ Lanjutkan dengan `cd aplikasi-saya && pnpm install && pnpm build && pnpm start`.
16
+
17
+ Repo: https://github.com/RamonyxJS/ramonyx · Lisensi: MIT
package/dist/cli.js ADDED
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env node
2
+
3
+ // apps/create-app/src/cli.ts
4
+ import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
5
+ import { basename, dirname, join, resolve } from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+ var templateDir = join(dirname(fileURLToPath(import.meta.url)), "..", "template");
8
+ var USAGE = `create-ramonyx-app \u2014 buat aplikasi Ramonyx baru
9
+
10
+ Penggunaan:
11
+ pnpm create ramonyx-app <dir> # dari registry (setelah publikasi)
12
+ pnpm dlx create-ramonyx-app <dir> # tanpa install
13
+ pnpm create:app <dir> # di dalam repo (workspace)
14
+
15
+ Opsi:
16
+ --force, -f Timpa berkas template walau direktori tujuan tidak kosong
17
+ --help, -h Tampilkan bantuan ini
18
+ `;
19
+ function usage(exitCode) {
20
+ const write = exitCode === 0 ? console.log : console.error;
21
+ write(USAGE);
22
+ process.exit(exitCode);
23
+ }
24
+ var args = process.argv.slice(2);
25
+ var force = false;
26
+ var target;
27
+ for (const arg of args) {
28
+ if (arg === "--force" || arg === "-f") {
29
+ force = true;
30
+ } else if (arg === "--help" || arg === "-h") {
31
+ usage(0);
32
+ } else if (arg.startsWith("-")) {
33
+ console.error(`error: flag tidak dikenal: ${arg}`);
34
+ usage(1);
35
+ } else if (target === void 0) {
36
+ target = arg;
37
+ } else {
38
+ console.error(`error: argumen tak terduga: ${arg}`);
39
+ usage(1);
40
+ }
41
+ }
42
+ if (target === void 0) {
43
+ console.error("error: direktori tujuan wajib");
44
+ usage(1);
45
+ }
46
+ var targetDir = resolve(target);
47
+ var appName = basename(targetDir);
48
+ if (existsSync(targetDir)) {
49
+ if (!statSync(targetDir).isDirectory()) {
50
+ console.error(`error: ${target} bukan direktori`);
51
+ process.exit(1);
52
+ }
53
+ const entries = readdirSync(targetDir);
54
+ if (entries.length > 0 && !force) {
55
+ console.error(`error: ${target} tidak kosong (pakai --force untuk menimpa berkas template)`);
56
+ process.exit(1);
57
+ }
58
+ } else {
59
+ mkdirSync(targetDir, { recursive: true });
60
+ }
61
+ function copy(source, destination) {
62
+ if (statSync(source).isDirectory()) {
63
+ mkdirSync(destination, { recursive: true });
64
+ for (const entry of readdirSync(source)) {
65
+ copy(join(source, entry), join(destination, entry));
66
+ }
67
+ return;
68
+ }
69
+ const name = basename(source) === "gitignore" ? ".gitignore" : basename(source);
70
+ const text = readFileSync(source, "utf8").replaceAll("__APP_NAME__", appName);
71
+ writeFileSync(join(dirname(destination), name), text);
72
+ }
73
+ copy(templateDir, targetDir);
74
+ console.log(`\u2713 App "${appName}" dibuat di ${targetDir}
75
+
76
+ Langkah berikutnya:
77
+
78
+ cd ${target}
79
+ pnpm install # atau npm install
80
+ pnpm start # http://127.0.0.1:3000
81
+ `);
package/package.json CHANGED
@@ -1,6 +1,26 @@
1
1
  {
2
2
  "name": "create-ramonyx-app",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Scaffolder aplikasi Ramonyx (SSR React + hydration, file routing src/routes).",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "bin": {
8
+ "create-ramonyx-app": "dist/cli.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "template",
13
+ "README.md",
14
+ "LICENSE"
15
+ ],
16
+ "engines": {
17
+ "node": ">=24"
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/RamonyxJS/ramonyx"
25
+ }
6
26
  }
@@ -0,0 +1,28 @@
1
+ # __APP_NAME__
2
+
3
+ Aplikasi [Ramonyx](https://github.com/ramonyx/ramonyx) — framework full-stack TypeScript
4
+ (Node ≥ 24): halaman **SSR React + hydration** dan route API, dengan konvensi folder
5
+ `src/routes`.
6
+
7
+ ## Menjalankan
8
+
9
+ ```bash
10
+ pnpm install
11
+ pnpm build # bundel klien (wajib sebelum start)
12
+ pnpm start # http://127.0.0.1:3000 (React build produksi: NODE_ENV=production)
13
+ pnpm dev # mode watch (jalankan `pnpm build` setelah mengubah UI klien)
14
+ ```
15
+
16
+ ## Struktur
17
+
18
+ - `src/routes/page.tsx` — halaman (loader + komponen React; `layout.tsx`/`error.tsx` opsional)
19
+ - `src/routes/api/halo/[nama].ts` — route API (`export const GET = route({ ... })`)
20
+ - `src/routes/middleware.ts` — security headers + CSP nonce + aset `/assets/*`
21
+ - `build.ts` — bundel klien (Vite) lewat `@ramonyx/bundler`
22
+ - `ramonyx.config.ts` — port/host + strict validation
23
+
24
+ ## Endpoint contoh
25
+
26
+ - `GET /` — halaman SSR (tombol counter membuktikan hydration)
27
+ - `GET /api/halo/dunia` — JSON `{ "halo": "dunia" }`
28
+ - `GET /api/rahasia` — contoh `HttpError` (403)
@@ -0,0 +1,13 @@
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})`);
@@ -0,0 +1,4 @@
1
+ node_modules/
2
+ dist/
3
+ *.log
4
+ .env
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "__APP_NAME__",
3
+ "private": true,
4
+ "type": "module",
5
+ "engines": {
6
+ "node": ">=24"
7
+ },
8
+ "scripts": {
9
+ "build": "node --import @ramonyx/compiler/register build.ts",
10
+ "start": "NODE_ENV=production node --import @ramonyx/compiler/register src/main.ts",
11
+ "dev": "node --watch --import @ramonyx/compiler/register src/main.ts"
12
+ },
13
+ "dependencies": {
14
+ "@ramonyx/adapter-runtime": "^0.1.0",
15
+ "@ramonyx/bundler": "^0.1.0",
16
+ "@ramonyx/compiler": "^0.1.0",
17
+ "@ramonyx/react": "^0.1.0",
18
+ "@ramonyx/security": "^0.1.0",
19
+ "@ramonyx/server": "^0.1.0",
20
+ "@ramonyx/ssr": "^0.1.0",
21
+ "ramonyx": "^0.1.0",
22
+ "react": "19.3.1",
23
+ "react-dom": "19.3.1"
24
+ },
25
+ "devDependencies": {
26
+ "@types/react": "19.3.0",
27
+ "@types/react-dom": "19.3.0"
28
+ }
29
+ }
@@ -0,0 +1,7 @@
1
+ # Konfigurasi pnpm untuk aplikasi Ramonyx.
2
+ #
3
+ # `esbuild` (loader runtime `@ramonyx/compiler/register`) menjalankan postinstall untuk
4
+ # memverifikasi binary platform; pnpm ≥10 memblokir build script dependensi secara default.
5
+ # npm/yarn tidak memblokir → baris ini hanya relevan untuk pengguna pnpm.
6
+ allowBuilds:
7
+ esbuild: true
@@ -0,0 +1,11 @@
1
+ import { defineConfig } from "ramonyx";
2
+
3
+ export default defineConfig({
4
+ app: {
5
+ strictValidation: true,
6
+ },
7
+ server: {
8
+ port: 3000,
9
+ host: "127.0.0.1",
10
+ },
11
+ });
@@ -0,0 +1,38 @@
1
+ import { fileURLToPath } from "node:url";
2
+ import { createRouteManifest, loadPageRoutes } from "@ramonyx/compiler";
3
+ import { createReactRenderer } from "@ramonyx/react";
4
+ import { createHandler } from "@ramonyx/server";
5
+ import { createPageRoutes } from "@ramonyx/ssr";
6
+ import type { FetchHandler } from "ramonyx";
7
+
8
+ import middleware from "./routes/middleware.ts";
9
+
10
+ /**
11
+ * Aplikasi __APP_NAME__: route API + halaman SSR React dari `src/routes` (file routing),
12
+ * dengan hydration klien (`/assets/client.js` — jalankan `pnpm build` dulu).
13
+ *
14
+ * Konvensi folder `src/routes`:
15
+ * - `page.tsx` — halaman (loader + komponen React; boleh `layout.tsx`, `error.tsx`);
16
+ * - `api/*.ts` — route API (`export const GET = route({ ... })`).
17
+ */
18
+ export async function createApp(): Promise<FetchHandler> {
19
+ const dir = fileURLToPath(new URL("./routes", import.meta.url));
20
+
21
+ const [apiRoutes, pages] = await Promise.all([
22
+ createRouteManifest({ dir }),
23
+ loadPageRoutes({ dir }),
24
+ ]);
25
+
26
+ return createHandler({
27
+ strictValidation: true,
28
+ routes: [
29
+ ...apiRoutes,
30
+ ...createPageRoutes({
31
+ pages,
32
+ renderer: createReactRenderer(),
33
+ client: { script: "/assets/client.js" },
34
+ }),
35
+ ],
36
+ middleware,
37
+ });
38
+ }
@@ -0,0 +1,16 @@
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}`);
@@ -0,0 +1,6 @@
1
+ import { route } from "ramonyx";
2
+
3
+ // Route API dinamis: `GET /api/halo/[nama]`.
4
+ export const GET = route<{ nama: string }>({
5
+ handler: ({ params, json }) => json({ halo: params.nama }),
6
+ });
@@ -0,0 +1,8 @@
1
+ import { HttpError, route } from "ramonyx";
2
+
3
+ // Contoh error HTTP aman (status + pesan publik).
4
+ export const GET = route({
5
+ handler: () => {
6
+ throw new HttpError(403, "Tidak untukmu");
7
+ },
8
+ });
@@ -0,0 +1,16 @@
1
+ import type { LayoutProps } from "@ramonyx/react";
2
+
3
+ export default function RootLayout({ children }: LayoutProps) {
4
+ return (
5
+ <div className="shell">
6
+ <header className="topbar">
7
+ <strong>__APP_NAME__</strong>
8
+ <span>Ramonyx</span>
9
+ </header>
10
+ {children}
11
+ <footer className="kaki">
12
+ Dibuat dengan Ramonyx — <code>src/routes</code> berisi halaman & API.
13
+ </footer>
14
+ </div>
15
+ );
16
+ }
@@ -0,0 +1,42 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { extname, resolve, sep } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { cspNonce, securityHeaders } from "@ramonyx/security";
5
+ import type { Middleware } from "ramonyx";
6
+
7
+ const clientDir = fileURLToPath(new URL("../../dist/client", import.meta.url));
8
+
9
+ const CONTENT_TYPES: Record<string, string> = {
10
+ ".js": "text/javascript; charset=utf-8",
11
+ ".css": "text/css; charset=utf-8",
12
+ ".map": "application/json; charset=utf-8",
13
+ ".svg": "image/svg+xml",
14
+ };
15
+
16
+ /** Aset statis hasil `pnpm build` di `/assets/*` (guard traversal). */
17
+ const staticAssets: Middleware = async (context, next) => {
18
+ const url = new URL(context.request.url);
19
+ if (context.request.method !== "GET" || !url.pathname.startsWith("/assets/")) {
20
+ return next();
21
+ }
22
+
23
+ const relativePath = decodeURIComponent(url.pathname.slice("/assets/".length));
24
+ const filePath = resolve(clientDir, relativePath);
25
+ if (!filePath.startsWith(clientDir + sep)) {
26
+ return next();
27
+ }
28
+
29
+ try {
30
+ const data = await readFile(filePath);
31
+ return new Response(data, {
32
+ headers: {
33
+ "content-type": CONTENT_TYPES[extname(filePath)] ?? "application/octet-stream",
34
+ "cache-control": "no-store",
35
+ },
36
+ });
37
+ } catch {
38
+ return next();
39
+ }
40
+ };
41
+
42
+ export default [securityHeaders(), cspNonce(), staticAssets] satisfies Middleware[];
@@ -0,0 +1,37 @@
1
+ import type { PageProps } from "@ramonyx/react";
2
+ import { useState } from "react";
3
+
4
+ export const metadata = { title: "__APP_NAME__" };
5
+
6
+ export async function loader() {
7
+ return { pesan: "Halo dari SSR Ramonyx", fitur: ["SSR React", "hydration", "route API"] };
8
+ }
9
+
10
+ /** Komponen interaktif: server merender 0, klik menambah setelah hydration. */
11
+ function Counter() {
12
+ const [hitungan, setHitungan] = useState(0);
13
+ return (
14
+ <p>
15
+ <button type="button" onClick={() => setHitungan((nilai) => nilai + 1)}>
16
+ Klik saya: {hitungan}
17
+ </button>
18
+ </p>
19
+ );
20
+ }
21
+
22
+ export default function Beranda({ data }: PageProps<{ pesan: string; fitur: string[] }>) {
23
+ return (
24
+ <main>
25
+ <h1>{data.pesan}</h1>
26
+ <ul>
27
+ {data.fitur.map((item) => (
28
+ <li key={item}>{item}</li>
29
+ ))}
30
+ </ul>
31
+ <Counter />
32
+ <p>
33
+ Coba API dinamis: <a href="/api/halo/dunia">/api/halo/dunia</a>
34
+ </p>
35
+ </main>
36
+ );
37
+ }