create-ramonyx-app 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +16 -2
- package/dist/cli.js +81 -0
- package/package.json +23 -3
- package/template/README.md +30 -0
- package/template/gitignore +4 -0
- package/template/package.json +28 -0
- package/template/pnpm-workspace.yaml +7 -0
- package/template/ramonyx.config.ts +11 -0
- package/template/src/app.ts +63 -0
- package/template/src/routes/api/halo/[nama].ts +6 -0
- package/template/src/routes/api/rahasia.ts +8 -0
- package/template/src/routes/layout.tsx +16 -0
- package/template/src/routes/middleware.ts +42 -0
- package/template/src/routes/page.tsx +37 -0
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
|
-
#
|
|
1
|
+
# create-ramonyx-app
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Scaffolder aplikasi Ramonyx — SSR React + hydration, file routing `src/routes`.
|
|
4
|
+
|
|
5
|
+
> **Alpha (0.1.1)** — 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.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
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,30 @@
|
|
|
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 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
|
+
```
|
|
15
|
+
|
|
16
|
+
Perintah memakai CLI **`ramonyx`** (`@ramonyx/devtools`): `ramonyx dev|build|start|doctor`.
|
|
17
|
+
|
|
18
|
+
## Struktur
|
|
19
|
+
|
|
20
|
+
- `src/app.ts` — mengekspor `createApp(options?)` (dipakai CLI)
|
|
21
|
+
- `src/routes/page.tsx` — halaman (loader + komponen React; `layout.tsx`/`error.tsx` opsional)
|
|
22
|
+
- `src/routes/api/halo/[nama].ts` — route API (`export const GET = route({ ... })`)
|
|
23
|
+
- `src/routes/middleware.ts` — security headers + CSP nonce + aset `/assets/*`
|
|
24
|
+
- `ramonyx.config.ts` — port/host + strict validation
|
|
25
|
+
|
|
26
|
+
## Endpoint contoh
|
|
27
|
+
|
|
28
|
+
- `GET /` — halaman SSR (tombol counter membuktikan hydration)
|
|
29
|
+
- `GET /api/halo/dunia` — JSON `{ "halo": "dunia" }`
|
|
30
|
+
- `GET /api/rahasia` — contoh `HttpError` (403)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "__APP_NAME__",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=24"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "ramonyx build",
|
|
10
|
+
"start": "ramonyx start",
|
|
11
|
+
"dev": "ramonyx dev"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@ramonyx/compiler": "^0.1.0",
|
|
15
|
+
"@ramonyx/devtools": "^0.1.0",
|
|
16
|
+
"@ramonyx/react": "^0.1.0",
|
|
17
|
+
"@ramonyx/security": "^0.1.0",
|
|
18
|
+
"@ramonyx/server": "^0.1.0",
|
|
19
|
+
"@ramonyx/ssr": "^0.1.0",
|
|
20
|
+
"ramonyx": "^0.1.0",
|
|
21
|
+
"react": "19.3.1",
|
|
22
|
+
"react-dom": "19.3.1"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/react": "19.3.0",
|
|
26
|
+
"@types/react-dom": "19.3.0"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -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,63 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
import { createRouteManifest, loadPageRoutes, type ModuleImporter } 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
|
+
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
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Aplikasi __APP_NAME__: route API + halaman SSR React dari `src/routes` (file routing),
|
|
26
|
+
* dengan hydration klien.
|
|
27
|
+
*
|
|
28
|
+
* Dijalankan lewat CLI: `ramonyx dev` (Vite + HMR), `ramonyx build` (bundle klien),
|
|
29
|
+
* `ramonyx start` (produksi — `NODE_ENV=production` otomatis).
|
|
30
|
+
*/
|
|
31
|
+
export async function createApp(options: CreateAppOptions = {}): Promise<FetchHandler> {
|
|
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
|
+
]);
|
|
43
|
+
|
|
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
|
+
};
|
|
58
|
+
|
|
59
|
+
if (options.reloadManifests === true) {
|
|
60
|
+
return async (request) => (await build())(request);
|
|
61
|
+
}
|
|
62
|
+
return build();
|
|
63
|
+
}
|
|
@@ -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
|
+
}
|