create-sanifyfe 0.2.0 → 0.3.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 CHANGED
@@ -1,20 +1,20 @@
1
1
  # create-sanifyfe
2
2
 
3
- Scaffolder project [Sanify Frontend](https://www.npmjs.com/package/@sanify/core).
3
+ Scaffolder for [Sanify Frontend](https://www.npmjs.com/package/@sanify/core) projects.
4
4
 
5
- ## Pakai
5
+ ## Usage
6
6
 
7
7
  ```bash
8
8
  bun create sanifyfe my-app
9
- # atau
9
+ # or
10
10
  npm create sanifyfe my-app
11
11
  ```
12
12
 
13
- Tanpa argumen nama, CLI akan menanyakannya secara interaktif.
13
+ Without a name argument, the CLI prompts for one interactively.
14
14
 
15
- ## Hasil
15
+ ## Output
16
16
 
17
- Project siap jalan berisi contoh todo (signal, router, persist + cross-tab sync) dengan dev server Bun:
17
+ A ready-to-run showcase app (signals, stores, keyed lists, nested routing, resource) with a Bun dev server and HMR:
18
18
 
19
19
  ```bash
20
20
  cd my-app
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-sanifyfe",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Scaffold project Sanify baru — bun create sanifyfe",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,8 +1,8 @@
1
1
  # __PROJECT_NAME__
2
2
 
3
- Project frontend berbasis [Sanify](https://www.npmjs.com/package/@sanify/core) — framework reaktif fine-grained di atas Web Components.
3
+ A frontend project built on [Sanify](https://www.npmjs.com/package/@sanify/core) — a fine-grained reactive framework on top of Web Components.
4
4
 
5
- ## Prasyarat
5
+ ## Prerequisites
6
6
 
7
7
  - [Bun](https://bun.sh) >= 1.3.0
8
8
 
@@ -12,34 +12,41 @@ Project frontend berbasis [Sanify](https://www.npmjs.com/package/@sanify/core)
12
12
  bun install
13
13
  ```
14
14
 
15
- ## Perintah
15
+ ## Commands
16
16
 
17
- | Perintah | Fungsi |
17
+ | Command | Purpose |
18
18
  | --- | --- |
19
- | `bun dev` | Jalankan dev server di http://localhost:3000 |
20
- | `bun run build` | Bundle produksi ke `dist/` |
21
- | `bun run typecheck` | Cek tipe TypeScript |
19
+ | `bun dev` | Dev server at http://localhost:3000 with **HMR** |
20
+ | `bun run build` | Production bundle into `dist/` |
21
+ | `bun run typecheck` | TypeScript type check |
22
22
 
23
- ## Struktur
23
+ ## Structure
24
24
 
25
25
  ```
26
26
  src/
27
- main.ts entry: memuat app-root
28
- app.ts root + router (termasuk nested route + outlet)
29
- state/ todos (persisted), settings (createStore nested)
30
- data/ data contoh + simulasi fetch async
27
+ main.ts entry: loads app-root
28
+ app.ts root + router (including nested routes + outlet)
29
+ state/ todos (persisted), settings (nested createStore)
30
+ data/ sample data + simulated async fetch
31
31
  components/ nav-bar, users-sidebar, todo-item, live-clock
32
32
  pages/ home, todos, settings, user-list, user-detail, about
33
- index.html halaman host, memuat main.js hasil bundling
34
- dev-server.ts server dev Bun, transpile TS on-the-fly
33
+ index.html host page, loads the bundled main.js
34
+ dev-server.ts Bun dev server with HMR + automatic bundling
35
35
  ```
36
36
 
37
- ## Fitur yang dicontohkan
37
+ ## Showcased features
38
38
 
39
- | Halaman | Fitur Sanify |
39
+ | Page | Sanify features |
40
40
  | --- | --- |
41
41
  | Home | `signal`, `onMount`/`onCleanup` (live-clock) |
42
- | Todos | `For` (list keyed), `persisted` + cross-tab, `computed` |
43
- | Settings | `createStore` objek nested fine-grained (update by path) |
44
- | Users | router **nested + outlet** (layout bertahan), `params()` reaktif, `resource` (fetch async) |
45
- | About | `query()` reaktif |
42
+ | Todos | `For` (keyed list), `persisted` + cross-tab, `computed` |
43
+ | Settings | `createStore` fine-grained nested object (update by path) |
44
+ | Users | **nested router + outlet** (persistent layout), reactive `params()`, `resource` (async fetch) |
45
+ | About | reactive `query()` |
46
+
47
+ ## HMR
48
+
49
+ `bun dev` supports Hot Module Replacement. Edit a component file → the UI updates
50
+ without a reload, and global state (`persisted`/`createStore`) is preserved.
51
+ Local state inside `setup` (e.g. a signal) resets on hot-remount. Each component
52
+ file ends with `if (import.meta.hot) import.meta.hot.accept();`.
@@ -1,42 +1,13 @@
1
- // dev-server.ts — dev server sederhana pakai Bun, transpile TS on-the-fly
1
+ // dev-server.ts — dev server Bun dengan HMR (import.meta.hot) + bundling otomatis
2
2
 
3
- const PORT = 3000;
3
+ import index from "./index.html";
4
4
 
5
5
  const server = Bun.serve({
6
- port: PORT,
7
- development: true,
8
- async fetch(req) {
9
- const url = new URL(req.url);
10
- let path = url.pathname;
11
- if (path === "/") path = "/index.html";
12
-
13
- // bundel entry TS aplikasi on-the-fly
14
- if (path === "/main.js") {
15
- const built = await Bun.build({
16
- entrypoints: ["./src/main.ts"],
17
- target: "browser",
18
- });
19
- if (!built.success) {
20
- return new Response("Build error:\n" + built.logs.join("\n"), {
21
- status: 500,
22
- headers: { "Content-Type": "text/plain" },
23
- });
24
- }
25
- const js = await built.outputs[0]!.text();
26
- return new Response(js, {
27
- headers: { "Content-Type": "application/javascript" },
28
- });
29
- }
30
-
31
- // file statis dari root project
32
- const file = Bun.file("." + path);
33
- if (await file.exists()) return new Response(file);
34
-
35
- // SPA fallback: route apa pun → index.html
36
- return new Response(Bun.file("./index.html"), {
37
- headers: { "Content-Type": "text/html" },
38
- });
6
+ port: 3000,
7
+ development: { hmr: true, console: true },
8
+ routes: {
9
+ "/*": index, // SPA: semua route → index.html
39
10
  },
40
11
  });
41
12
 
42
- console.log(`Dev server: http://localhost:${server.port}`);
13
+ console.log(`Dev server: ${server.url}`);
@@ -0,0 +1,14 @@
1
+ // Tipe fitur dev Bun: import file .html & HMR (import.meta.hot).
2
+
3
+ declare module "*.html" {
4
+ const content: import("bun").HTMLBundle;
5
+ export default content;
6
+ }
7
+
8
+ interface ImportMeta {
9
+ hot?: {
10
+ accept(callback?: (module: unknown) => void): void;
11
+ dispose(callback: (data: unknown) => void): void;
12
+ data: unknown;
13
+ };
14
+ }
@@ -8,6 +8,6 @@
8
8
  </head>
9
9
  <body class="bg-slate-50 text-slate-800">
10
10
  <app-root></app-root>
11
- <script type="module" src="/main.js"></script>
11
+ <script type="module" src="./src/main.ts"></script>
12
12
  </body>
13
13
  </html>
@@ -9,7 +9,7 @@
9
9
  "typecheck": "tsc --noEmit"
10
10
  },
11
11
  "dependencies": {
12
- "@sanify/core": "^0.2.0"
12
+ "@sanify/core": "^0.3.0"
13
13
  },
14
14
  "devDependencies": {
15
15
  "typescript": "^5.9.0",
@@ -44,3 +44,5 @@ component("app-root", () => {
44
44
  <main>${view}</main>
45
45
  `;
46
46
  });
47
+
48
+ if (import.meta.hot) import.meta.hot.accept();
@@ -12,3 +12,5 @@ component("live-clock", () => {
12
12
 
13
13
  return () => html`<span class="font-mono">${() => now()}</span>`;
14
14
  });
15
+
16
+ if (import.meta.hot) import.meta.hot.accept();
@@ -35,3 +35,5 @@ component("nav-bar", () => {
35
35
  </nav>
36
36
  `;
37
37
  });
38
+
39
+ if (import.meta.hot) import.meta.hot.accept();
@@ -34,3 +34,5 @@ component<TodoItemProps>(
34
34
  },
35
35
  { props: ["todo"] },
36
36
  );
37
+
38
+ if (import.meta.hot) import.meta.hot.accept();
@@ -27,3 +27,5 @@ component("users-sidebar", () => {
27
27
  </aside>
28
28
  `;
29
29
  });
30
+
31
+ if (import.meta.hot) import.meta.hot.accept();
@@ -22,3 +22,5 @@ component("about-page", () => {
22
22
  </div>
23
23
  `;
24
24
  });
25
+
26
+ if (import.meta.hot) import.meta.hot.accept();
@@ -30,3 +30,5 @@ component("home-page", () => {
30
30
  </div>
31
31
  `;
32
32
  });
33
+
34
+ if (import.meta.hot) import.meta.hot.accept();
@@ -45,3 +45,5 @@ component("settings-page", () => {
45
45
  </div>
46
46
  `;
47
47
  });
48
+
49
+ if (import.meta.hot) import.meta.hot.accept();
@@ -49,3 +49,5 @@ component("todos-page", () => {
49
49
  </div>
50
50
  `;
51
51
  });
52
+
53
+ if (import.meta.hot) import.meta.hot.accept();
@@ -30,3 +30,5 @@ component("user-detail", () => {
30
30
  </div>
31
31
  `;
32
32
  });
33
+
34
+ if (import.meta.hot) import.meta.hot.accept();
@@ -9,3 +9,5 @@ component("user-list", () => {
9
9
  </p>
10
10
  `;
11
11
  });
12
+
13
+ if (import.meta.hot) import.meta.hot.accept();
@@ -18,5 +18,5 @@
18
18
 
19
19
  "types": ["bun"]
20
20
  },
21
- "include": ["src", "dev-server.ts"]
21
+ "include": ["src", "dev-server.ts", "env.d.ts"]
22
22
  }