json-api-builder-create-app 0.0.0-stage → 1.0.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 +21 -0
- package/README.md +139 -3
- package/docs/index.html +351 -0
- package/package.json +37 -4
- package/src/index.js +1 -0
- package/src/v1/create-app.js +18 -0
- package/src/v1/hook-app-strategies.js +67 -0
- package/src/v1/index.js +3 -0
- package/src/v1/start-server.js +10 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 KeshavSoft
|
|
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,139 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# json-api-builder-create-app
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/json-api-builder-create-app)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
[](package.json)
|
|
6
|
+
[](https://github.com/keshavsoft/json-api-builder-create-app)
|
|
7
|
+
[](https://keshavsoft.github.io/json-api-builder-create-app/)
|
|
8
|
+
|
|
9
|
+
> **Stage 5 of 8**: Stage 5: Root Application Bootstrap, Strategy Middleware & Server Lifecycle
|
|
10
|
+
|
|
11
|
+
Part of the modular **[JSON API Builder](https://github.com/keshavsoft/json-api-builder-orchestrator)** ecosystem by [KeshavSoft](https://github.com/keshavsoft).
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## The Story
|
|
16
|
+
|
|
17
|
+
Creates the root app.js application entry point, mounts top-level API routes and middleware strategies, and provides @hono/node-server startup capabilities.
|
|
18
|
+
|
|
19
|
+
### The Problem It Solves
|
|
20
|
+
Developers frequently struggle with boilerplate integration: connecting routers, mounting file sync endpoints, setting up CORS, and configuring the Node HTTP server.
|
|
21
|
+
|
|
22
|
+
### The Solution
|
|
23
|
+
Assembles the root app.js, mounts all top-level routes (/api, /fs), injects application middleware strategies, and provides an optional startServer helper to boot the app instantly.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Architecture & Pipeline Position
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
[1. Folders] ──▶ [2. Files] ──▶ [3. Content] ──▶ [4. Hook Routes]
|
|
31
|
+
│
|
|
32
|
+
[8. Orchestrator] ◀── [7. Validate] ◀── [6. Endpoints] ◀── [5. App]
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**This repository implements Stage 5 in isolation.** It can be used independently in custom build workflows or composed automatically via `json-api-builder`.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm install json-api-builder-create-app
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Quick Start
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
import { createApp, hookAppStrategies } from "json-api-builder-create-app";
|
|
51
|
+
|
|
52
|
+
createApp({ outputRoot: "./output" });
|
|
53
|
+
hookAppStrategies({ outputRoot: "./output" });
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Input Specification
|
|
59
|
+
|
|
60
|
+
Application runtime and middleware configuration parameters.
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"port": 3000,
|
|
65
|
+
"strategies": ["cors", "logger", "file-sync"]
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Output Transformation
|
|
72
|
+
|
|
73
|
+
Production-ready root application entrypoint app.js.
|
|
74
|
+
|
|
75
|
+
```text
|
|
76
|
+
import { Hono } from "hono";
|
|
77
|
+
import apiRoutes from "./api/routes.js";
|
|
78
|
+
import fsRoutes from "./endpoints/fs/routes.js";
|
|
79
|
+
|
|
80
|
+
const app = new Hono();
|
|
81
|
+
|
|
82
|
+
app.route("/api", apiRoutes);
|
|
83
|
+
app.route("/fs", fsRoutes);
|
|
84
|
+
|
|
85
|
+
export default app;
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## API Reference
|
|
91
|
+
|
|
92
|
+
### `createApp`, `hookAppStrategies`, `startServer`
|
|
93
|
+
|
|
94
|
+
Accepts an options object with the following configuration:
|
|
95
|
+
|
|
96
|
+
| Option | Type | Default | Description |
|
|
97
|
+
| :--- | :--- | :--- | :--- |
|
|
98
|
+
| `clientRoot` | `string` | `process.cwd()` | Root path of the client project. |
|
|
99
|
+
| `outputRoot` | `string` | `path.join(clientRoot, 'output')` | Target output directory. |
|
|
100
|
+
| `port` | `number` | `3000` | Port for @hono/node-server when startServer() is called. |
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Sibling Pipeline Packages
|
|
105
|
+
|
|
106
|
+
| Stage | Package | Description |
|
|
107
|
+
| :---: | :--- | :--- |
|
|
108
|
+
| **01** | [json-api-builder-create-folders](https://github.com/keshavsoft/json-api-builder-create-folders) | Directory hierarchy scaffolding |
|
|
109
|
+
| **02** | [json-api-builder-create-files](https://github.com/keshavsoft/json-api-builder-create-files) | Non-destructive placeholder file creation |
|
|
110
|
+
| **03** | [json-api-builder-insert-content](https://github.com/keshavsoft/json-api-builder-insert-content) | ESTree template to JavaScript insertion |
|
|
111
|
+
| **04** | [json-api-builder-alter-content](https://github.com/keshavsoft/json-api-builder-alter-content) | Hierarchical route hooking & AST imports |
|
|
112
|
+
| **05** | [json-api-builder-create-app](https://github.com/keshavsoft/json-api-builder-create-app) | Root app.js assembly & server runtime |
|
|
113
|
+
| **06** | [json-api-builder-create-endpoints](https://github.com/keshavsoft/json-api-builder-create-endpoints) | CRUD endpoints & local JSON file sync |
|
|
114
|
+
| **07** | [json-api-builder-validation](https://github.com/keshavsoft/json-api-builder-validation) | Specification linting & artifact checks |
|
|
115
|
+
| **08** | [json-api-builder](https://github.com/keshavsoft/json-api-builder-orchestrator) | Master orchestrator coordinating all stages |
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Development & Testing
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
# Install dependencies
|
|
123
|
+
npm install
|
|
124
|
+
|
|
125
|
+
# Run automated tests
|
|
126
|
+
npm test
|
|
127
|
+
|
|
128
|
+
# Run syntax check
|
|
129
|
+
npm run check
|
|
130
|
+
|
|
131
|
+
# Prepublish verification
|
|
132
|
+
npm run prepublishOnly
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## License
|
|
138
|
+
|
|
139
|
+
[MIT](LICENSE) © 2026 [KeshavSoft](https://github.com/keshavsoft)
|
package/docs/index.html
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>json-api-builder-create-app — Stage 5: Root Application Bootstrap, Strategy Middleware & Server Lifecycle</title>
|
|
7
|
+
<!-- Tailwind CSS CDN -->
|
|
8
|
+
<script src="https://cdn.tailwindcss.com"></script>
|
|
9
|
+
<!-- Bootstrap Icons -->
|
|
10
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
|
11
|
+
</head>
|
|
12
|
+
<body class="bg-zinc-950 text-zinc-100 antialiased min-h-screen flex flex-col font-sans selection:bg-amber-500/30 selection:text-amber-200">
|
|
13
|
+
|
|
14
|
+
<!-- Top Navbar -->
|
|
15
|
+
<nav class="border-b border-zinc-800 bg-zinc-900/90 backdrop-blur-md sticky top-0 z-50">
|
|
16
|
+
<div class="max-w-7xl mx-auto px-4 sm:px-6 h-14 flex items-center justify-between gap-4">
|
|
17
|
+
<div class="flex items-center gap-2.5 shrink-0">
|
|
18
|
+
<i class="bi bi-server text-amber-400 text-xl"></i>
|
|
19
|
+
<a href="https://github.com/keshavsoft/json-api-builder-orchestrator" class="font-bold text-sm tracking-wider uppercase text-zinc-200 hover:text-white">JSON API Builder</a>
|
|
20
|
+
<span class="text-[10px] font-semibold text-amber-400 bg-amber-950/80 border border-amber-800/80 px-2 py-0.5 rounded-full">Stage 5 of 8</span>
|
|
21
|
+
</div>
|
|
22
|
+
<div class="flex items-center gap-3 text-xs font-mono">
|
|
23
|
+
<a href="#story" class="text-zinc-400 hover:text-zinc-200 transition hidden sm:inline">The Story</a>
|
|
24
|
+
<a href="#quick-start" class="text-zinc-400 hover:text-zinc-200 transition hidden sm:inline">Quick Start</a>
|
|
25
|
+
<a href="#pipeline" class="text-zinc-400 hover:text-zinc-200 transition hidden md:inline">Full Pipeline</a>
|
|
26
|
+
<a href="https://www.npmjs.com/package/json-api-builder-create-app" target="_blank" rel="noopener noreferrer" class="text-zinc-400 hover:text-red-400 transition" title="View on npm">
|
|
27
|
+
<i class="bi bi-box-seam text-base"></i>
|
|
28
|
+
</a>
|
|
29
|
+
<a href="https://github.com/keshavsoft/json-api-builder-create-app" target="_blank" rel="noopener noreferrer" class="text-zinc-400 hover:text-zinc-100 transition" title="View Source on GitHub">
|
|
30
|
+
<i class="bi bi-github text-base"></i>
|
|
31
|
+
</a>
|
|
32
|
+
</div>
|
|
33
|
+
</div>
|
|
34
|
+
</nav>
|
|
35
|
+
|
|
36
|
+
<!-- Horizontal Pipeline Navigation Bar -->
|
|
37
|
+
<div class="border-b border-zinc-800/80 bg-zinc-900/40 py-2 overflow-x-auto">
|
|
38
|
+
<div class="max-w-7xl mx-auto px-4 sm:px-6 flex items-center gap-2 whitespace-nowrap">
|
|
39
|
+
<span class="text-[11px] font-mono text-zinc-500 uppercase tracking-wider mr-2">Pipeline:</span>
|
|
40
|
+
|
|
41
|
+
<a href="https://keshavsoft.github.io/json-api-builder-create-folders/" class="text-xs font-mono px-2.5 py-1 rounded-md border transition flex items-center gap-1.5 text-zinc-400 hover:text-zinc-200 hover:bg-zinc-800/60 border-transparent">
|
|
42
|
+
<span class="w-1.5 h-1.5 rounded-full bg-zinc-600"></span>
|
|
43
|
+
<span>1. create-folders</span>
|
|
44
|
+
</a>
|
|
45
|
+
<a href="https://keshavsoft.github.io/json-api-builder-create-files/" class="text-xs font-mono px-2.5 py-1 rounded-md border transition flex items-center gap-1.5 text-zinc-400 hover:text-zinc-200 hover:bg-zinc-800/60 border-transparent">
|
|
46
|
+
<span class="w-1.5 h-1.5 rounded-full bg-zinc-600"></span>
|
|
47
|
+
<span>2. create-files</span>
|
|
48
|
+
</a>
|
|
49
|
+
<a href="https://keshavsoft.github.io/json-api-builder-insert-content/" class="text-xs font-mono px-2.5 py-1 rounded-md border transition flex items-center gap-1.5 text-zinc-400 hover:text-zinc-200 hover:bg-zinc-800/60 border-transparent">
|
|
50
|
+
<span class="w-1.5 h-1.5 rounded-full bg-zinc-600"></span>
|
|
51
|
+
<span>3. insert-content</span>
|
|
52
|
+
</a>
|
|
53
|
+
<a href="https://keshavsoft.github.io/json-api-builder-alter-content/" class="text-xs font-mono px-2.5 py-1 rounded-md border transition flex items-center gap-1.5 text-zinc-400 hover:text-zinc-200 hover:bg-zinc-800/60 border-transparent">
|
|
54
|
+
<span class="w-1.5 h-1.5 rounded-full bg-zinc-600"></span>
|
|
55
|
+
<span>4. alter-content</span>
|
|
56
|
+
</a>
|
|
57
|
+
<a href="https://keshavsoft.github.io/json-api-builder-create-app/" class="text-xs font-mono px-2.5 py-1 rounded-md border transition flex items-center gap-1.5 bg-amber-500/20 text-amber-300 border-amber-500/40">
|
|
58
|
+
<span class="w-1.5 h-1.5 rounded-full bg-amber-400"></span>
|
|
59
|
+
<span>5. create-app</span>
|
|
60
|
+
</a>
|
|
61
|
+
<a href="https://keshavsoft.github.io/json-api-builder-create-endpoints/" class="text-xs font-mono px-2.5 py-1 rounded-md border transition flex items-center gap-1.5 text-zinc-400 hover:text-zinc-200 hover:bg-zinc-800/60 border-transparent">
|
|
62
|
+
<span class="w-1.5 h-1.5 rounded-full bg-zinc-600"></span>
|
|
63
|
+
<span>6. create-endpoints</span>
|
|
64
|
+
</a>
|
|
65
|
+
<a href="https://keshavsoft.github.io/json-api-builder-validation/" class="text-xs font-mono px-2.5 py-1 rounded-md border transition flex items-center gap-1.5 text-zinc-400 hover:text-zinc-200 hover:bg-zinc-800/60 border-transparent">
|
|
66
|
+
<span class="w-1.5 h-1.5 rounded-full bg-zinc-600"></span>
|
|
67
|
+
<span>7. validation</span>
|
|
68
|
+
</a>
|
|
69
|
+
<a href="https://keshavsoft.github.io/json-api-builder-orchestrator/" class="text-xs font-mono px-2.5 py-1 rounded-md border transition flex items-center gap-1.5 text-zinc-400 hover:text-zinc-200 hover:bg-zinc-800/60 border-transparent">
|
|
70
|
+
<span class="w-1.5 h-1.5 rounded-full bg-zinc-600"></span>
|
|
71
|
+
<span>8. json-api-builder</span>
|
|
72
|
+
</a>
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
|
|
76
|
+
<!-- Hero Section -->
|
|
77
|
+
<main class="flex-1 max-w-5xl mx-auto px-4 sm:px-6 py-12 flex flex-col items-center text-center">
|
|
78
|
+
|
|
79
|
+
<!-- Status Badge -->
|
|
80
|
+
<div class="inline-flex items-center gap-2 bg-zinc-900 border border-amber-800/60 text-amber-400 px-3.5 py-1 rounded-full text-xs font-medium mb-6 shadow-sm">
|
|
81
|
+
<span class="inline-block w-2 h-2 rounded-full bg-emerald-400 animate-pulse"></span>
|
|
82
|
+
<span>Live on GitHub & Ready for npm: <code class="font-mono text-zinc-200">json-api-builder-create-app</code></span>
|
|
83
|
+
</div>
|
|
84
|
+
|
|
85
|
+
<!-- Title -->
|
|
86
|
+
<h1 class="text-3xl sm:text-5xl md:text-6xl font-extrabold tracking-tight text-white max-w-4xl leading-tight mb-4">
|
|
87
|
+
<span class="text-transparent bg-clip-text bg-gradient-to-r from-amber-400 via-orange-400 to-amber-500">json-api-builder-create-app</span>
|
|
88
|
+
</h1>
|
|
89
|
+
|
|
90
|
+
<p class="text-base sm:text-lg text-zinc-400 max-w-2xl mb-8 leading-relaxed">
|
|
91
|
+
Stage 5: Root Application Bootstrap, Strategy Middleware & Server Lifecycle
|
|
92
|
+
</p>
|
|
93
|
+
|
|
94
|
+
<!-- Terminal Run Pill -->
|
|
95
|
+
<div class="w-full max-w-xl bg-zinc-900 border border-zinc-800 rounded-xl p-3 mb-10 flex items-center justify-between text-left font-mono text-xs text-zinc-300 shadow-xl">
|
|
96
|
+
<div class="flex items-center gap-2 overflow-x-auto">
|
|
97
|
+
<span class="text-amber-400">$</span>
|
|
98
|
+
<span>npm install json-api-builder-create-app</span>
|
|
99
|
+
</div>
|
|
100
|
+
<button onclick="navigator.clipboard.writeText('npm install json-api-builder-create-app')" class="hover:text-white text-zinc-400 transition ml-3 px-2 py-1 bg-zinc-800 rounded hover:bg-zinc-700" title="Copy command">
|
|
101
|
+
<i class="bi bi-clipboard"></i>
|
|
102
|
+
</button>
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
<!-- The Story Section -->
|
|
106
|
+
<section id="story" class="w-full text-left bg-zinc-900/60 border border-zinc-800 rounded-2xl p-6 sm:p-8 mb-12 shadow-lg">
|
|
107
|
+
<div class="flex items-center gap-2 text-amber-400 font-semibold text-xs tracking-wider uppercase mb-3">
|
|
108
|
+
<i class="bi bi-book-half"></i>
|
|
109
|
+
<span>The Stage Story</span>
|
|
110
|
+
</div>
|
|
111
|
+
<h2 class="text-2xl font-bold text-white mb-4">Why this stage exists</h2>
|
|
112
|
+
<p class="text-zinc-300 text-sm leading-relaxed mb-6">
|
|
113
|
+
Creates the root app.js application entry point, mounts top-level API routes and middleware strategies, and provides @hono/node-server startup capabilities.
|
|
114
|
+
</p>
|
|
115
|
+
|
|
116
|
+
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 pt-4 border-t border-zinc-800/80">
|
|
117
|
+
<div class="bg-zinc-950/60 p-4 rounded-xl border border-red-950/60">
|
|
118
|
+
<div class="text-red-400 text-xs font-bold uppercase tracking-wider mb-1 flex items-center gap-1.5">
|
|
119
|
+
<i class="bi bi-exclamation-triangle-fill"></i>
|
|
120
|
+
<span>The Problem</span>
|
|
121
|
+
</div>
|
|
122
|
+
<p class="text-xs text-zinc-400 leading-relaxed">Developers frequently struggle with boilerplate integration: connecting routers, mounting file sync endpoints, setting up CORS, and configuring the Node HTTP server.</p>
|
|
123
|
+
</div>
|
|
124
|
+
<div class="bg-zinc-950/60 p-4 rounded-xl border border-emerald-950/60">
|
|
125
|
+
<div class="text-emerald-400 text-xs font-bold uppercase tracking-wider mb-1 flex items-center gap-1.5">
|
|
126
|
+
<i class="bi bi-check-circle-fill"></i>
|
|
127
|
+
<span>The Solution</span>
|
|
128
|
+
</div>
|
|
129
|
+
<p class="text-xs text-zinc-400 leading-relaxed">Assembles the root app.js, mounts all top-level routes (/api, /fs), injects application middleware strategies, and provides an optional startServer helper to boot the app instantly.</p>
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
</section>
|
|
133
|
+
|
|
134
|
+
<!-- Visual Transformation Flow -->
|
|
135
|
+
<section class="w-full text-left bg-zinc-900/60 border border-zinc-800 rounded-2xl p-6 sm:p-8 mb-12 shadow-lg">
|
|
136
|
+
<div class="flex items-center gap-2 text-amber-400 font-semibold text-xs tracking-wider uppercase mb-3">
|
|
137
|
+
<i class="bi bi-arrow-left-right"></i>
|
|
138
|
+
<span>Data Transformation</span>
|
|
139
|
+
</div>
|
|
140
|
+
<h2 class="text-2xl font-bold text-white mb-6">Input to Output Contract</h2>
|
|
141
|
+
|
|
142
|
+
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
|
143
|
+
<div>
|
|
144
|
+
<div class="flex items-center justify-between text-xs font-mono text-zinc-400 mb-2">
|
|
145
|
+
<span>INPUT SPECIFICATION</span>
|
|
146
|
+
<span class="text-zinc-500">source-of-truth</span>
|
|
147
|
+
</div>
|
|
148
|
+
<div class="bg-zinc-950 rounded-xl p-4 border border-zinc-800 font-mono text-xs text-amber-200/90 overflow-x-auto max-h-72">
|
|
149
|
+
<pre><code>{
|
|
150
|
+
"port": 3000,
|
|
151
|
+
"strategies": ["cors", "logger", "file-sync"]
|
|
152
|
+
}</code></pre>
|
|
153
|
+
</div>
|
|
154
|
+
<p class="text-xs text-zinc-500 mt-2">Application runtime and middleware configuration parameters.</p>
|
|
155
|
+
</div>
|
|
156
|
+
|
|
157
|
+
<div>
|
|
158
|
+
<div class="flex items-center justify-between text-xs font-mono text-zinc-400 mb-2">
|
|
159
|
+
<span>GENERATED ARTIFACT</span>
|
|
160
|
+
<span class="text-zinc-500">output directory</span>
|
|
161
|
+
</div>
|
|
162
|
+
<div class="bg-zinc-950 rounded-xl p-4 border border-zinc-800 font-mono text-xs text-emerald-200/90 overflow-x-auto max-h-72">
|
|
163
|
+
<pre><code>import { Hono } from "hono";
|
|
164
|
+
import apiRoutes from "./api/routes.js";
|
|
165
|
+
import fsRoutes from "./endpoints/fs/routes.js";
|
|
166
|
+
|
|
167
|
+
const app = new Hono();
|
|
168
|
+
|
|
169
|
+
app.route("/api", apiRoutes);
|
|
170
|
+
app.route("/fs", fsRoutes);
|
|
171
|
+
|
|
172
|
+
export default app;</code></pre>
|
|
173
|
+
</div>
|
|
174
|
+
<p class="text-xs text-zinc-500 mt-2">Production-ready root application entrypoint app.js.</p>
|
|
175
|
+
</div>
|
|
176
|
+
</div>
|
|
177
|
+
</section>
|
|
178
|
+
|
|
179
|
+
<!-- Quick Start Code Example -->
|
|
180
|
+
<section id="quick-start" class="w-full text-left bg-zinc-900/60 border border-zinc-800 rounded-2xl p-6 sm:p-8 mb-12 shadow-lg">
|
|
181
|
+
<div class="flex items-center gap-2 text-amber-400 font-semibold text-xs tracking-wider uppercase mb-3">
|
|
182
|
+
<i class="bi bi-play-circle-fill"></i>
|
|
183
|
+
<span>Implementation Guide</span>
|
|
184
|
+
</div>
|
|
185
|
+
<h2 class="text-2xl font-bold text-white mb-4">How to Use This Stage</h2>
|
|
186
|
+
|
|
187
|
+
<div class="bg-zinc-950 rounded-xl p-4 border border-zinc-800 font-mono text-xs text-zinc-200 overflow-x-auto mb-6">
|
|
188
|
+
<pre><code>import { createApp, hookAppStrategies } from "json-api-builder-create-app";
|
|
189
|
+
|
|
190
|
+
createApp({ outputRoot: "./output" });
|
|
191
|
+
hookAppStrategies({ outputRoot: "./output" });</code></pre>
|
|
192
|
+
</div>
|
|
193
|
+
|
|
194
|
+
<h3 class="text-sm font-semibold text-zinc-300 uppercase tracking-wider mb-3">Options & Parameters</h3>
|
|
195
|
+
<div class="overflow-x-auto">
|
|
196
|
+
<table class="w-full text-left text-xs font-mono border-collapse">
|
|
197
|
+
<thead>
|
|
198
|
+
<tr class="border-b border-zinc-800 text-zinc-400">
|
|
199
|
+
<th class="py-2 px-3 font-semibold">Parameter</th>
|
|
200
|
+
<th class="py-2 px-3 font-semibold">Type</th>
|
|
201
|
+
<th class="py-2 px-3 font-semibold">Default</th>
|
|
202
|
+
<th class="py-2 px-3 font-semibold">Description</th>
|
|
203
|
+
</tr>
|
|
204
|
+
</thead>
|
|
205
|
+
<tbody class="divide-y divide-zinc-800/60 text-zinc-300 font-sans">
|
|
206
|
+
|
|
207
|
+
<tr>
|
|
208
|
+
<td class="py-2.5 px-3 font-mono text-amber-400 font-bold">clientRoot</td>
|
|
209
|
+
<td class="py-2.5 px-3 font-mono text-zinc-400">string</td>
|
|
210
|
+
<td class="py-2.5 px-3 font-mono text-zinc-500">process.cwd()</td>
|
|
211
|
+
<td class="py-2.5 px-3 text-xs text-zinc-300">Root path of the client project.</td>
|
|
212
|
+
</tr>
|
|
213
|
+
<tr>
|
|
214
|
+
<td class="py-2.5 px-3 font-mono text-amber-400 font-bold">outputRoot</td>
|
|
215
|
+
<td class="py-2.5 px-3 font-mono text-zinc-400">string</td>
|
|
216
|
+
<td class="py-2.5 px-3 font-mono text-zinc-500">path.join(clientRoot, 'output')</td>
|
|
217
|
+
<td class="py-2.5 px-3 text-xs text-zinc-300">Target output directory.</td>
|
|
218
|
+
</tr>
|
|
219
|
+
<tr>
|
|
220
|
+
<td class="py-2.5 px-3 font-mono text-amber-400 font-bold">port</td>
|
|
221
|
+
<td class="py-2.5 px-3 font-mono text-zinc-400">number</td>
|
|
222
|
+
<td class="py-2.5 px-3 font-mono text-zinc-500">3000</td>
|
|
223
|
+
<td class="py-2.5 px-3 text-xs text-zinc-300">Port for @hono/node-server when startServer() is called.</td>
|
|
224
|
+
</tr>
|
|
225
|
+
</tbody>
|
|
226
|
+
</table>
|
|
227
|
+
</div>
|
|
228
|
+
</section>
|
|
229
|
+
|
|
230
|
+
<!-- Sibling Ecosystem Grid -->
|
|
231
|
+
<section id="pipeline" class="w-full text-left mb-12">
|
|
232
|
+
<div class="flex items-center gap-2 text-amber-400 font-semibold text-xs tracking-wider uppercase mb-3">
|
|
233
|
+
<i class="bi bi-diagram-2-fill"></i>
|
|
234
|
+
<span>The Modular Ecosystem</span>
|
|
235
|
+
</div>
|
|
236
|
+
<h2 class="text-2xl font-bold text-white mb-2">The 8 Stages of JSON API Builder</h2>
|
|
237
|
+
<p class="text-xs text-zinc-400 mb-6">Every stage is published as an autonomous, self-contained package under KeshavSoft.</p>
|
|
238
|
+
|
|
239
|
+
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-4 gap-3">
|
|
240
|
+
|
|
241
|
+
<a href="https://keshavsoft.github.io/json-api-builder-create-folders/" class="block p-4 rounded-xl border transition bg-zinc-900/50 border-zinc-800 hover:border-zinc-700 hover:bg-zinc-900">
|
|
242
|
+
<div class="flex items-center justify-between text-xs mb-1.5">
|
|
243
|
+
<span class="font-mono text-zinc-500">Stage 1</span>
|
|
244
|
+
<span class="text-[10px] font-semibold px-2 py-0.5 rounded-full bg-zinc-800 text-zinc-400">Module</span>
|
|
245
|
+
</div>
|
|
246
|
+
<div class="font-bold text-sm text-zinc-200 mb-1 flex items-center gap-2">
|
|
247
|
+
<i class="bi bi-folder-plus text-amber-400"></i>
|
|
248
|
+
<span>json-api-builder-create-folders</span>
|
|
249
|
+
</div>
|
|
250
|
+
<p class="text-xs text-zinc-400 line-clamp-2">Stage 1: Structural Directory Scaffolding from JSON Specification Trees</p>
|
|
251
|
+
</a>
|
|
252
|
+
<a href="https://keshavsoft.github.io/json-api-builder-create-files/" class="block p-4 rounded-xl border transition bg-zinc-900/50 border-zinc-800 hover:border-zinc-700 hover:bg-zinc-900">
|
|
253
|
+
<div class="flex items-center justify-between text-xs mb-1.5">
|
|
254
|
+
<span class="font-mono text-zinc-500">Stage 2</span>
|
|
255
|
+
<span class="text-[10px] font-semibold px-2 py-0.5 rounded-full bg-zinc-800 text-zinc-400">Module</span>
|
|
256
|
+
</div>
|
|
257
|
+
<div class="font-bold text-sm text-zinc-200 mb-1 flex items-center gap-2">
|
|
258
|
+
<i class="bi bi-file-earmark-plus text-amber-400"></i>
|
|
259
|
+
<span>json-api-builder-create-files</span>
|
|
260
|
+
</div>
|
|
261
|
+
<p class="text-xs text-zinc-400 line-clamp-2">Stage 2: Non-Destructive Leaf File Provisioning for JSON API Builder</p>
|
|
262
|
+
</a>
|
|
263
|
+
<a href="https://keshavsoft.github.io/json-api-builder-insert-content/" class="block p-4 rounded-xl border transition bg-zinc-900/50 border-zinc-800 hover:border-zinc-700 hover:bg-zinc-900">
|
|
264
|
+
<div class="flex items-center justify-between text-xs mb-1.5">
|
|
265
|
+
<span class="font-mono text-zinc-500">Stage 3</span>
|
|
266
|
+
<span class="text-[10px] font-semibold px-2 py-0.5 rounded-full bg-zinc-800 text-zinc-400">Module</span>
|
|
267
|
+
</div>
|
|
268
|
+
<div class="font-bold text-sm text-zinc-200 mb-1 flex items-center gap-2">
|
|
269
|
+
<i class="bi bi-code-slash text-amber-400"></i>
|
|
270
|
+
<span>json-api-builder-insert-content</span>
|
|
271
|
+
</div>
|
|
272
|
+
<p class="text-xs text-zinc-400 line-clamp-2">Stage 3: ESTree AST Template Compilation & Router Content Insertion</p>
|
|
273
|
+
</a>
|
|
274
|
+
<a href="https://keshavsoft.github.io/json-api-builder-alter-content/" class="block p-4 rounded-xl border transition bg-zinc-900/50 border-zinc-800 hover:border-zinc-700 hover:bg-zinc-900">
|
|
275
|
+
<div class="flex items-center justify-between text-xs mb-1.5">
|
|
276
|
+
<span class="font-mono text-zinc-500">Stage 4</span>
|
|
277
|
+
<span class="text-[10px] font-semibold px-2 py-0.5 rounded-full bg-zinc-800 text-zinc-400">Module</span>
|
|
278
|
+
</div>
|
|
279
|
+
<div class="font-bold text-sm text-zinc-200 mb-1 flex items-center gap-2">
|
|
280
|
+
<i class="bi bi-diagram-3 text-amber-400"></i>
|
|
281
|
+
<span>json-api-builder-alter-content</span>
|
|
282
|
+
</div>
|
|
283
|
+
<p class="text-xs text-zinc-400 line-clamp-2">Stage 4: Hierarchical Route Hooking & AST Route Tree Composition</p>
|
|
284
|
+
</a>
|
|
285
|
+
<a href="https://keshavsoft.github.io/json-api-builder-create-app/" class="block p-4 rounded-xl border transition bg-amber-950/20 border-amber-800/80 ring-1 ring-amber-500/30">
|
|
286
|
+
<div class="flex items-center justify-between text-xs mb-1.5">
|
|
287
|
+
<span class="font-mono text-zinc-500">Stage 5</span>
|
|
288
|
+
<span class="text-[10px] font-semibold px-2 py-0.5 rounded-full bg-amber-500/20 text-amber-300">Current</span>
|
|
289
|
+
</div>
|
|
290
|
+
<div class="font-bold text-sm text-zinc-200 mb-1 flex items-center gap-2">
|
|
291
|
+
<i class="bi bi-server text-amber-400"></i>
|
|
292
|
+
<span>json-api-builder-create-app</span>
|
|
293
|
+
</div>
|
|
294
|
+
<p class="text-xs text-zinc-400 line-clamp-2">Stage 5: Root Application Bootstrap, Strategy Middleware & Server Lifecycle</p>
|
|
295
|
+
</a>
|
|
296
|
+
<a href="https://keshavsoft.github.io/json-api-builder-create-endpoints/" class="block p-4 rounded-xl border transition bg-zinc-900/50 border-zinc-800 hover:border-zinc-700 hover:bg-zinc-900">
|
|
297
|
+
<div class="flex items-center justify-between text-xs mb-1.5">
|
|
298
|
+
<span class="font-mono text-zinc-500">Stage 6</span>
|
|
299
|
+
<span class="text-[10px] font-semibold px-2 py-0.5 rounded-full bg-zinc-800 text-zinc-400">Module</span>
|
|
300
|
+
</div>
|
|
301
|
+
<div class="font-bold text-sm text-zinc-200 mb-1 flex items-center gap-2">
|
|
302
|
+
<i class="bi bi-hdd-network text-amber-400"></i>
|
|
303
|
+
<span>json-api-builder-create-endpoints</span>
|
|
304
|
+
</div>
|
|
305
|
+
<p class="text-xs text-zinc-400 line-clamp-2">Stage 6: REST Endpoints & Local JSON File-Sync Handlers</p>
|
|
306
|
+
</a>
|
|
307
|
+
<a href="https://keshavsoft.github.io/json-api-builder-validation/" class="block p-4 rounded-xl border transition bg-zinc-900/50 border-zinc-800 hover:border-zinc-700 hover:bg-zinc-900">
|
|
308
|
+
<div class="flex items-center justify-between text-xs mb-1.5">
|
|
309
|
+
<span class="font-mono text-zinc-500">Stage 7</span>
|
|
310
|
+
<span class="text-[10px] font-semibold px-2 py-0.5 rounded-full bg-zinc-800 text-zinc-400">Module</span>
|
|
311
|
+
</div>
|
|
312
|
+
<div class="font-bold text-sm text-zinc-200 mb-1 flex items-center gap-2">
|
|
313
|
+
<i class="bi bi-shield-check text-amber-400"></i>
|
|
314
|
+
<span>json-api-builder-validation</span>
|
|
315
|
+
</div>
|
|
316
|
+
<p class="text-xs text-zinc-400 line-clamp-2">Stage 7: Pre-Flight Tree Linting & Post-Build Artifact Verification</p>
|
|
317
|
+
</a>
|
|
318
|
+
<a href="https://keshavsoft.github.io/json-api-builder-orchestrator/" class="block p-4 rounded-xl border transition bg-zinc-900/50 border-zinc-800 hover:border-zinc-700 hover:bg-zinc-900">
|
|
319
|
+
<div class="flex items-center justify-between text-xs mb-1.5">
|
|
320
|
+
<span class="font-mono text-zinc-500">Stage 8</span>
|
|
321
|
+
<span class="text-[10px] font-semibold px-2 py-0.5 rounded-full bg-zinc-800 text-zinc-400">Module</span>
|
|
322
|
+
</div>
|
|
323
|
+
<div class="font-bold text-sm text-zinc-200 mb-1 flex items-center gap-2">
|
|
324
|
+
<i class="bi bi-boxes text-amber-400"></i>
|
|
325
|
+
<span>json-api-builder</span>
|
|
326
|
+
</div>
|
|
327
|
+
<p class="text-xs text-zinc-400 line-clamp-2">Master Orchestrator: End-to-End JSON-Driven Backend API Generator</p>
|
|
328
|
+
</a>
|
|
329
|
+
</div>
|
|
330
|
+
</section>
|
|
331
|
+
|
|
332
|
+
</main>
|
|
333
|
+
|
|
334
|
+
<!-- Footer -->
|
|
335
|
+
<footer class="border-t border-zinc-800 bg-zinc-900/60 py-8 text-center text-xs text-zinc-500 font-mono">
|
|
336
|
+
<div class="max-w-7xl mx-auto px-4 flex flex-col sm:flex-row items-center justify-between gap-4">
|
|
337
|
+
<div>
|
|
338
|
+
<span>© 2026 </span>
|
|
339
|
+
<a href="https://github.com/keshavsoft" class="text-zinc-400 hover:text-amber-400 transition">KeshavSoft</a>
|
|
340
|
+
<span> — Modular JSON API Builder Ecosystem</span>
|
|
341
|
+
</div>
|
|
342
|
+
<div class="flex items-center gap-4">
|
|
343
|
+
<a href="https://github.com/keshavsoft/json-api-builder-create-app" class="hover:text-zinc-300 transition">GitHub</a>
|
|
344
|
+
<a href="https://www.npmjs.com/package/json-api-builder-create-app" class="hover:text-zinc-300 transition">npm</a>
|
|
345
|
+
<a href="https://github.com/keshavsoft/json-api-builder-create-app/blob/main/LICENSE" class="hover:text-zinc-300 transition">MIT License</a>
|
|
346
|
+
</div>
|
|
347
|
+
</div>
|
|
348
|
+
</footer>
|
|
349
|
+
|
|
350
|
+
</body>
|
|
351
|
+
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-api-builder-create-app",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Create app and hook app strategies stage for JSON API Builder.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE",
|
|
14
|
+
"docs"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"check": "node scripts/check.mjs",
|
|
18
|
+
"test": "node --test \"test/**/*.test.js\""
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=20"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@hono/node-server": "^1.19.6"
|
|
28
|
+
},
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"author": "KeshavSoft",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/keshavsoft/json-api-builder-create-app.git"
|
|
34
|
+
},
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/keshavsoft/json-api-builder-create-app/issues"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://keshavsoft.github.io/json-api-builder-create-app/"
|
|
39
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './v1/index.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
export function createApp(options = {}) {
|
|
5
|
+
const clientRoot = path.resolve(options.clientRoot ?? process.cwd());
|
|
6
|
+
const outputRoot = path.resolve(options.outputRoot ?? path.join(clientRoot, "output"));
|
|
7
|
+
const appPath = path.join(outputRoot, "app.js");
|
|
8
|
+
fs.mkdirSync(outputRoot, { recursive: true });
|
|
9
|
+
fs.writeFileSync(appPath, [
|
|
10
|
+
'import { Hono } from "hono";',
|
|
11
|
+
"",
|
|
12
|
+
"const app = new Hono();",
|
|
13
|
+
"",
|
|
14
|
+
"export default app;",
|
|
15
|
+
""
|
|
16
|
+
].join("\n"), "utf8");
|
|
17
|
+
return { appPath, outputRoot };
|
|
18
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
export function hookAppStrategies(options = {}) {
|
|
5
|
+
const clientRoot = path.resolve(options.clientRoot ?? process.cwd());
|
|
6
|
+
const outputRoot = path.resolve(options.outputRoot ?? path.join(clientRoot, "output"));
|
|
7
|
+
const apiPath = path.resolve(clientRoot, options.apiPath ?? "input/api.json");
|
|
8
|
+
const appPath = path.join(outputRoot, "app.js");
|
|
9
|
+
|
|
10
|
+
if (!fs.existsSync(apiPath)) throw new Error(`API configuration not found: ${apiPath}`);
|
|
11
|
+
if (!fs.existsSync(appPath)) throw new Error(`app.js not found. Run createApp first: ${appPath}`);
|
|
12
|
+
|
|
13
|
+
const api = JSON.parse(fs.readFileSync(apiPath, "utf8"));
|
|
14
|
+
let source = fs.readFileSync(appPath, "utf8");
|
|
15
|
+
const imports = [];
|
|
16
|
+
const mounts = [];
|
|
17
|
+
const startup = [];
|
|
18
|
+
|
|
19
|
+
if (api.root) {
|
|
20
|
+
imports.push(`import apiRoutes from "./${api.root}/routes.js";`);
|
|
21
|
+
mounts.push(`app.route("/${api.root}", apiRoutes);`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
for (const [strategyName, strategyConfig] of Object.entries(api.strategies ?? {})) {
|
|
25
|
+
if (strategyName === "fs" && strategyConfig?.["file-sync"]) {
|
|
26
|
+
imports.push('import fsRoutes from "./endpoints/fs/routes.js";');
|
|
27
|
+
imports.push('import { serve } from "@hono/node-server";');
|
|
28
|
+
imports.push('import { pathToFileURL } from "node:url";');
|
|
29
|
+
imports.push('import path from "node:path";');
|
|
30
|
+
mounts.push('app.route("/fs", fsRoutes);');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const lines = source.split("\n").filter(line =>
|
|
35
|
+
!/^import apiRoutes from /.test(line) &&
|
|
36
|
+
!/^import fsRoutes from /.test(line) &&
|
|
37
|
+
!/^import \{ serve \} from /.test(line) &&
|
|
38
|
+
!/^import \{ pathToFileURL \} from /.test(line) &&
|
|
39
|
+
!/^import path from /.test(line) &&
|
|
40
|
+
!/^app\.route\("\/(?:api|fs)",/.test(line)
|
|
41
|
+
);
|
|
42
|
+
const exportIndex = lines.findIndex(line => line.trim() === "export default app;");
|
|
43
|
+
if (exportIndex < 0) throw new Error(`Default app export not found: ${appPath}`);
|
|
44
|
+
|
|
45
|
+
const skeleton = lines.slice(0, exportIndex).filter(line => line.trim() !== "");
|
|
46
|
+
const finalSource = [
|
|
47
|
+
...new Set([...lines.filter(line => line.startsWith("import ")), ...imports]),
|
|
48
|
+
"",
|
|
49
|
+
...skeleton.filter(line => !line.startsWith("import ")),
|
|
50
|
+
"",
|
|
51
|
+
...mounts,
|
|
52
|
+
"",
|
|
53
|
+
"export default app;",
|
|
54
|
+
"",
|
|
55
|
+
"export function startServer(port = Number(process.env.PORT ?? " + Number(api.port ?? 3000) + ")) {",
|
|
56
|
+
' return serve({ fetch: app.fetch, port, hostname: "0.0.0.0" });',
|
|
57
|
+
"}",
|
|
58
|
+
"",
|
|
59
|
+
'if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) {',
|
|
60
|
+
` startServer(Number(process.env.PORT ?? ${Number(api.port ?? 3000)}));`,
|
|
61
|
+
` console.log("API server listening on port ${Number(api.port ?? 3000)}");`,
|
|
62
|
+
"}",
|
|
63
|
+
""
|
|
64
|
+
].join("\n");
|
|
65
|
+
fs.writeFileSync(appPath, finalSource, "utf8");
|
|
66
|
+
return { appPath, hookedStrategies: Object.keys(api.strategies ?? {}) };
|
|
67
|
+
}
|
package/src/v1/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { serve } from "@hono/node-server";
|
|
2
|
+
|
|
3
|
+
export function startServer(app, options = {}) {
|
|
4
|
+
const port = Number(options.port ?? process.env.PORT ?? 3000);
|
|
5
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535) {
|
|
6
|
+
throw new Error(`Invalid server port: ${options.port}`);
|
|
7
|
+
}
|
|
8
|
+
const server = serve({ fetch: app.fetch, port, hostname: options.hostname ?? "127.0.0.1" });
|
|
9
|
+
return server;
|
|
10
|
+
}
|