@kagaribi/cli 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 +21 -0
- package/README.md +52 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +100 -0
- package/dist/build-OBIGHRTQ.js +13 -0
- package/dist/chunk-KTJVG255.js +49 -0
- package/dist/chunk-NU4OHXXY.js +136 -0
- package/dist/deploy-3DCEXEPS.js +73 -0
- package/dist/dev-LPF4FIVZ.js +6 -0
- package/dist/dev-XOBA2HG5.js +6 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +6 -0
- package/dist/init-BZRNB37V.js +47 -0
- package/dist/new-22WA7TCS.js +21 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 kagaribi contributors
|
|
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
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# @kagaribi/cli
|
|
2
|
+
|
|
3
|
+
CLI tool for the [kagaribi](https://github.com/goofmint/kagaribi) microservices framework.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @kagaribi/cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
This package provides the `kagaribi` command.
|
|
12
|
+
|
|
13
|
+
## Commands
|
|
14
|
+
|
|
15
|
+
| Command | Description |
|
|
16
|
+
|---------|-------------|
|
|
17
|
+
| `kagaribi init <name> [--target]` | Initialize a new project |
|
|
18
|
+
| `kagaribi dev [port]` | Start development server (default: 3000) |
|
|
19
|
+
| `kagaribi new <name> [--target]` | Create a new package |
|
|
20
|
+
| `kagaribi build [--env name]` | Build for deployment |
|
|
21
|
+
| `kagaribi deploy [pkg] [--target] [--env]` | Deploy packages |
|
|
22
|
+
|
|
23
|
+
## Target Flags
|
|
24
|
+
|
|
25
|
+
| Flag | Target |
|
|
26
|
+
|------|--------|
|
|
27
|
+
| `--cloudflare` | Cloudflare Workers |
|
|
28
|
+
| `--lambda` | AWS Lambda |
|
|
29
|
+
| `--cloudrun` | Google Cloud Run |
|
|
30
|
+
| `--deno` | Deno Deploy |
|
|
31
|
+
| `--node` | Node.js |
|
|
32
|
+
|
|
33
|
+
## Quick Start
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# Create a new project
|
|
37
|
+
kagaribi init my-project
|
|
38
|
+
cd my-project
|
|
39
|
+
|
|
40
|
+
# Start development
|
|
41
|
+
kagaribi dev
|
|
42
|
+
|
|
43
|
+
# Add a package
|
|
44
|
+
kagaribi new auth
|
|
45
|
+
|
|
46
|
+
# Deploy
|
|
47
|
+
kagaribi deploy auth --cloudflare
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## License
|
|
51
|
+
|
|
52
|
+
[MIT](../../LICENSE)
|
package/dist/bin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/bin.ts
|
|
4
|
+
import { register } from "module";
|
|
5
|
+
import { pathToFileURL } from "url";
|
|
6
|
+
register("tsx/esm", pathToFileURL("./"));
|
|
7
|
+
var args = process.argv.slice(2);
|
|
8
|
+
var command = args[0];
|
|
9
|
+
function getEnvFlag() {
|
|
10
|
+
const eqIdx = args.findIndex((a) => a.startsWith("--env="));
|
|
11
|
+
if (eqIdx !== -1) {
|
|
12
|
+
return args[eqIdx].split("=")[1];
|
|
13
|
+
}
|
|
14
|
+
const flagIdx = args.indexOf("--env");
|
|
15
|
+
if (flagIdx !== -1 && args[flagIdx + 1] && !args[flagIdx + 1].startsWith("-")) {
|
|
16
|
+
return args[flagIdx + 1];
|
|
17
|
+
}
|
|
18
|
+
return void 0;
|
|
19
|
+
}
|
|
20
|
+
function getTargetFlag() {
|
|
21
|
+
const flagMap = {
|
|
22
|
+
"--cloudflare": "cloudflare-workers",
|
|
23
|
+
"--lambda": "aws-lambda",
|
|
24
|
+
"--cloudrun": "google-cloud-run",
|
|
25
|
+
"--node": "node",
|
|
26
|
+
"--deno": "deno"
|
|
27
|
+
};
|
|
28
|
+
for (const arg of args) {
|
|
29
|
+
if (arg in flagMap) {
|
|
30
|
+
return flagMap[arg];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return void 0;
|
|
34
|
+
}
|
|
35
|
+
switch (command) {
|
|
36
|
+
case "init": {
|
|
37
|
+
const { initCommand } = await import("./init-BZRNB37V.js");
|
|
38
|
+
const name = args[1];
|
|
39
|
+
if (!name || name.startsWith("--")) {
|
|
40
|
+
console.error("Usage: kagaribi init <project-name> [--node|--cloudflare|--lambda|--cloudrun|--deno]");
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
const target = getTargetFlag();
|
|
44
|
+
await initCommand({ name, target });
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case "dev": {
|
|
48
|
+
const { devServer } = await import("./dev-LPF4FIVZ.js");
|
|
49
|
+
const port = parseInt(args[1] ?? "3000", 10);
|
|
50
|
+
await devServer({ port });
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
case "build": {
|
|
54
|
+
const { buildCommand } = await import("./build-OBIGHRTQ.js");
|
|
55
|
+
await buildCommand({ env: getEnvFlag() });
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
case "new": {
|
|
59
|
+
const { newCommand } = await import("./new-22WA7TCS.js");
|
|
60
|
+
const name = args[1];
|
|
61
|
+
if (!name || name.startsWith("--")) {
|
|
62
|
+
console.error("Usage: kagaribi new <name> [--cloudflare|--lambda|--cloudrun|--node|--deno]");
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
const target = getTargetFlag();
|
|
66
|
+
await newCommand({ name, target });
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case "deploy": {
|
|
70
|
+
const { deployCommand } = await import("./deploy-3DCEXEPS.js");
|
|
71
|
+
const packageName = args[1] && !args[1].startsWith("--") ? args[1] : void 0;
|
|
72
|
+
const target = getTargetFlag();
|
|
73
|
+
const dryRun = args.includes("--dry-run");
|
|
74
|
+
await deployCommand({ packageName, env: getEnvFlag(), target, dryRun });
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
default:
|
|
78
|
+
console.log(`kagaribi - Hono-based microservices framework
|
|
79
|
+
|
|
80
|
+
Usage:
|
|
81
|
+
kagaribi init <name> [--target] Initialize a new project
|
|
82
|
+
kagaribi dev [port] Start development server (default: 3000)
|
|
83
|
+
kagaribi build [--env name] Build for deployment
|
|
84
|
+
kagaribi new <name> [--target] Create a new package
|
|
85
|
+
kagaribi deploy [pkg] [--target] [--env] Deploy packages
|
|
86
|
+
|
|
87
|
+
Target flags:
|
|
88
|
+
--cloudflare Cloudflare Workers
|
|
89
|
+
--lambda AWS Lambda
|
|
90
|
+
--cloudrun Google Cloud Run
|
|
91
|
+
--node Node.js
|
|
92
|
+
--deno Deno Deploy
|
|
93
|
+
|
|
94
|
+
Options:
|
|
95
|
+
--env <name> Specify environment
|
|
96
|
+
--dry-run Show deploy instructions without executing
|
|
97
|
+
--help Show help
|
|
98
|
+
`);
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/commands/build.ts
|
|
2
|
+
import { buildProject } from "@kagaribi/core";
|
|
3
|
+
async function buildCommand(options) {
|
|
4
|
+
const projectRoot = process.cwd();
|
|
5
|
+
await buildProject({
|
|
6
|
+
projectRoot,
|
|
7
|
+
environment: options.env,
|
|
8
|
+
outDir: options.outDir
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
buildCommand
|
|
13
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// src/commands/dev.ts
|
|
2
|
+
import { readdir, stat } from "fs/promises";
|
|
3
|
+
import { join, resolve } from "path";
|
|
4
|
+
import { Hono } from "hono";
|
|
5
|
+
import { serve } from "@hono/node-server";
|
|
6
|
+
async function devServer(options = {}) {
|
|
7
|
+
const port = options.port ?? 3e3;
|
|
8
|
+
const cwd = process.cwd();
|
|
9
|
+
const packagesDir = options.packagesDir ?? join(cwd, "packages");
|
|
10
|
+
console.log("[kagaribi] Scanning packages...");
|
|
11
|
+
const entries = await readdir(packagesDir, { withFileTypes: true });
|
|
12
|
+
const app = new Hono();
|
|
13
|
+
const loadedPackages = [];
|
|
14
|
+
for (const entry of entries) {
|
|
15
|
+
if (!entry.isDirectory()) continue;
|
|
16
|
+
const pkgDir = resolve(packagesDir, entry.name);
|
|
17
|
+
const srcIndex = join(pkgDir, "src", "index.ts");
|
|
18
|
+
const exists = await stat(srcIndex).then((s) => s.isFile()).catch(() => false);
|
|
19
|
+
if (!exists) continue;
|
|
20
|
+
const mod = await import(srcIndex);
|
|
21
|
+
const pkgApp = mod.default ?? mod.app;
|
|
22
|
+
if (!pkgApp) {
|
|
23
|
+
console.warn(
|
|
24
|
+
`[kagaribi] Warning: ${entry.name}/src/index.ts does not export a Hono app`
|
|
25
|
+
);
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const basePath = entry.name === "root" ? "/" : `/${entry.name}`;
|
|
29
|
+
app.route(basePath, pkgApp);
|
|
30
|
+
loadedPackages.push(`${entry.name} -> ${basePath}`);
|
|
31
|
+
}
|
|
32
|
+
if (loadedPackages.length === 0) {
|
|
33
|
+
console.error("[kagaribi] No packages found in", packagesDir);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
console.log("[kagaribi] Loaded packages:");
|
|
37
|
+
for (const pkg of loadedPackages) {
|
|
38
|
+
console.log(` - ${pkg}`);
|
|
39
|
+
}
|
|
40
|
+
console.log(`[kagaribi] Starting dev server on http://localhost:${port}`);
|
|
41
|
+
serve({
|
|
42
|
+
fetch: app.fetch,
|
|
43
|
+
port
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export {
|
|
48
|
+
devServer
|
|
49
|
+
};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// src/commands/dev.ts
|
|
2
|
+
import { readdir, stat } from "fs/promises";
|
|
3
|
+
import { join, resolve } from "path";
|
|
4
|
+
import { Hono } from "hono";
|
|
5
|
+
import { serve } from "@hono/node-server";
|
|
6
|
+
import { registerLocalClient, kagaribiParamsMiddleware } from "@kagaribi/core";
|
|
7
|
+
async function devServer(options = {}) {
|
|
8
|
+
const port = options.port ?? 3e3;
|
|
9
|
+
const cwd = process.cwd();
|
|
10
|
+
const packagesDir = options.packagesDir ?? join(cwd, "packages");
|
|
11
|
+
console.log("[kagaribi] Scanning packages...");
|
|
12
|
+
const entries = await readdir(packagesDir, { withFileTypes: true });
|
|
13
|
+
const loadedPackages = [];
|
|
14
|
+
for (const entry of entries) {
|
|
15
|
+
if (!entry.isDirectory()) continue;
|
|
16
|
+
const pkgDir = resolve(packagesDir, entry.name);
|
|
17
|
+
const srcIndex = join(pkgDir, "src", "index.ts");
|
|
18
|
+
const exists = await stat(srcIndex).then((s) => s.isFile()).catch(() => false);
|
|
19
|
+
if (!exists) continue;
|
|
20
|
+
const mod = await import(srcIndex);
|
|
21
|
+
const pkgApp = mod.default ?? mod.app;
|
|
22
|
+
if (!pkgApp) {
|
|
23
|
+
console.warn(
|
|
24
|
+
`[kagaribi] Warning: ${entry.name}/src/index.ts does not export a Hono app`
|
|
25
|
+
);
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
let routes;
|
|
29
|
+
const manifestPath = join(pkgDir, "kagaribi.package.ts");
|
|
30
|
+
const manifestExists = await stat(manifestPath).then((s) => s.isFile()).catch(() => false);
|
|
31
|
+
if (manifestExists) {
|
|
32
|
+
const manifestMod = await import(manifestPath);
|
|
33
|
+
const definition = manifestMod.default;
|
|
34
|
+
routes = definition?.routes;
|
|
35
|
+
}
|
|
36
|
+
loadedPackages.push({ name: entry.name, app: pkgApp, routes });
|
|
37
|
+
registerLocalClient({ name: entry.name, app: pkgApp });
|
|
38
|
+
}
|
|
39
|
+
if (loadedPackages.length === 0) {
|
|
40
|
+
console.error("[kagaribi] No packages found in", packagesDir);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
const nestedPackages = loadedPackages.filter((p) => p.routes && p.routes.length > 0);
|
|
44
|
+
const normalPackages = loadedPackages.filter((p) => !p.routes || p.routes.length === 0);
|
|
45
|
+
const app = new Hono();
|
|
46
|
+
const mountedRoutes = [];
|
|
47
|
+
for (const pkg of nestedPackages) {
|
|
48
|
+
for (const routePattern of pkg.routes) {
|
|
49
|
+
const hasPathParams = routePattern.includes(":");
|
|
50
|
+
if (hasPathParams) {
|
|
51
|
+
const wrappedApp = new Hono();
|
|
52
|
+
wrappedApp.use("*", kagaribiParamsMiddleware());
|
|
53
|
+
wrappedApp.route("/", pkg.app);
|
|
54
|
+
app.all(`${routePattern}/*`, async (c) => {
|
|
55
|
+
const params = {};
|
|
56
|
+
const paramMatches = routePattern.match(/:([^/]+)/g);
|
|
57
|
+
if (paramMatches) {
|
|
58
|
+
for (const match of paramMatches) {
|
|
59
|
+
const paramName = match.slice(1);
|
|
60
|
+
const value = c.req.param(paramName);
|
|
61
|
+
if (value) {
|
|
62
|
+
params[paramName] = value;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const url = new URL(c.req.url);
|
|
67
|
+
const prefix = routePattern.replace(/:([^/]+)/g, c.req.param.bind(c.req));
|
|
68
|
+
const remainingPath = url.pathname.slice(prefix.length) || "/";
|
|
69
|
+
const newHeaders = new Headers(c.req.raw.headers);
|
|
70
|
+
if (Object.keys(params).length > 0) {
|
|
71
|
+
newHeaders.set("x-kagaribi-params", JSON.stringify(params));
|
|
72
|
+
}
|
|
73
|
+
const newReq = new Request(
|
|
74
|
+
new URL(remainingPath + url.search, "http://localhost").toString(),
|
|
75
|
+
{
|
|
76
|
+
method: c.req.method,
|
|
77
|
+
headers: newHeaders,
|
|
78
|
+
body: c.req.method !== "GET" && c.req.method !== "HEAD" ? await c.req.raw.clone().arrayBuffer() : void 0
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
return pkg.app.request(newReq);
|
|
82
|
+
});
|
|
83
|
+
app.all(routePattern, async (c) => {
|
|
84
|
+
const params = {};
|
|
85
|
+
const paramMatches = routePattern.match(/:([^/]+)/g);
|
|
86
|
+
if (paramMatches) {
|
|
87
|
+
for (const match of paramMatches) {
|
|
88
|
+
const paramName = match.slice(1);
|
|
89
|
+
const value = c.req.param(paramName);
|
|
90
|
+
if (value) {
|
|
91
|
+
params[paramName] = value;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const url = new URL(c.req.url);
|
|
96
|
+
const newHeaders = new Headers(c.req.raw.headers);
|
|
97
|
+
if (Object.keys(params).length > 0) {
|
|
98
|
+
newHeaders.set("x-kagaribi-params", JSON.stringify(params));
|
|
99
|
+
}
|
|
100
|
+
const newReq = new Request(
|
|
101
|
+
new URL("/" + url.search, "http://localhost").toString(),
|
|
102
|
+
{
|
|
103
|
+
method: c.req.method,
|
|
104
|
+
headers: newHeaders,
|
|
105
|
+
body: c.req.method !== "GET" && c.req.method !== "HEAD" ? await c.req.raw.clone().arrayBuffer() : void 0
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
return pkg.app.request(newReq);
|
|
109
|
+
});
|
|
110
|
+
mountedRoutes.push(`${pkg.name} -> ${routePattern}[/*]`);
|
|
111
|
+
} else {
|
|
112
|
+
app.route(routePattern, pkg.app);
|
|
113
|
+
mountedRoutes.push(`${pkg.name} -> ${routePattern}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
for (const pkg of normalPackages) {
|
|
118
|
+
const basePath = pkg.name === "root" ? "/" : `/${pkg.name}`;
|
|
119
|
+
app.route(basePath, pkg.app);
|
|
120
|
+
mountedRoutes.push(`${pkg.name} -> ${basePath}`);
|
|
121
|
+
}
|
|
122
|
+
console.log("[kagaribi] Loaded packages:");
|
|
123
|
+
for (const route of mountedRoutes) {
|
|
124
|
+
console.log(` - ${route}`);
|
|
125
|
+
}
|
|
126
|
+
console.log("[kagaribi] All packages registered as local clients");
|
|
127
|
+
console.log(`[kagaribi] Starting dev server on http://localhost:${port}`);
|
|
128
|
+
serve({
|
|
129
|
+
fetch: app.fetch,
|
|
130
|
+
port
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export {
|
|
135
|
+
devServer
|
|
136
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// src/commands/deploy.ts
|
|
2
|
+
import { resolve } from "path";
|
|
3
|
+
import { stat } from "fs/promises";
|
|
4
|
+
import { scanPackages, resolvePackages } from "@kagaribi/core";
|
|
5
|
+
import { createBuildPlan, getAdapter, deployProject } from "@kagaribi/core";
|
|
6
|
+
async function deployCommand(options) {
|
|
7
|
+
const hasTarget = Boolean(options.target);
|
|
8
|
+
const hasEnv = Boolean(options.env);
|
|
9
|
+
const isDryRun = options.dryRun || !hasTarget && !hasEnv;
|
|
10
|
+
if (isDryRun) {
|
|
11
|
+
await showDeployInstructions(options);
|
|
12
|
+
} else {
|
|
13
|
+
await executeDeployment(options);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
async function executeDeployment(options) {
|
|
17
|
+
const projectRoot = process.cwd();
|
|
18
|
+
console.log("Starting deployment...\n");
|
|
19
|
+
const results = await deployProject({
|
|
20
|
+
projectRoot,
|
|
21
|
+
environment: options.env,
|
|
22
|
+
packageName: options.packageName,
|
|
23
|
+
target: options.target
|
|
24
|
+
});
|
|
25
|
+
if (results.length === 0) {
|
|
26
|
+
console.log("No packages were deployed.");
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
console.log("\n--- Deploy Summary ---");
|
|
30
|
+
for (const result of results) {
|
|
31
|
+
console.log(` ${result.packageName} (${result.target}): ${result.url}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async function showDeployInstructions(options) {
|
|
35
|
+
const projectRoot = process.cwd();
|
|
36
|
+
const packagesDir = resolve(projectRoot, "packages");
|
|
37
|
+
const distDir = resolve(projectRoot, "dist");
|
|
38
|
+
const distExists = await stat(distDir).then((s) => s.isDirectory()).catch(() => false);
|
|
39
|
+
if (!distExists) {
|
|
40
|
+
console.error('Error: dist/ directory not found. Run "kagaribi build" first.');
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
const configPath = resolve(projectRoot, "kagaribi.config.ts");
|
|
44
|
+
const configModule = await import(configPath);
|
|
45
|
+
const config = configModule.default ?? configModule;
|
|
46
|
+
const scanned = await scanPackages(packagesDir);
|
|
47
|
+
const resolved = resolvePackages(scanned, config, options.env);
|
|
48
|
+
const plan = createBuildPlan(projectRoot, resolved, options.env ?? "default");
|
|
49
|
+
console.log("Deploy instructions:\n");
|
|
50
|
+
for (const group of plan.groups) {
|
|
51
|
+
if (options.packageName) {
|
|
52
|
+
const isHost = group.host.name === options.packageName;
|
|
53
|
+
const isColocated = group.colocated.some((p) => p.name === options.packageName);
|
|
54
|
+
if (!isHost && !isColocated) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const adapter = getAdapter(group.target);
|
|
59
|
+
const distPath = resolve(distDir, group.host.name, "index.js");
|
|
60
|
+
const exists = await stat(distPath).then((s) => s.isFile()).catch(() => false);
|
|
61
|
+
const status = exists ? "ready" : "not built";
|
|
62
|
+
const colocatedNames = group.colocated.map((p) => p.name);
|
|
63
|
+
console.log(` ${group.host.name} (${group.target}) [${status}]`);
|
|
64
|
+
if (colocatedNames.length > 0) {
|
|
65
|
+
console.log(` Includes: ${colocatedNames.join(", ")}`);
|
|
66
|
+
}
|
|
67
|
+
console.log(` ${adapter.deployInstructions(group)}`);
|
|
68
|
+
console.log("");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export {
|
|
72
|
+
deployCommand
|
|
73
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface DevServerOptions {
|
|
2
|
+
port?: number;
|
|
3
|
+
packagesDir?: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* kagaribi dev - 開発サーバーを起動する。
|
|
7
|
+
*
|
|
8
|
+
* packages/ 配下の全パッケージを検出し、
|
|
9
|
+
* 全てをローカルモードでルートアプリにマウントして起動する。
|
|
10
|
+
* 同時に各パッケージをクライアントレジストリに登録し、
|
|
11
|
+
* getClient() でパッケージ間呼び出しが可能な状態にする。
|
|
12
|
+
*/
|
|
13
|
+
declare function devServer(options?: DevServerOptions): Promise<void>;
|
|
14
|
+
|
|
15
|
+
export { devServer };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// src/commands/init.ts
|
|
2
|
+
import { createInterface } from "readline/promises";
|
|
3
|
+
import { initProject, exec } from "@kagaribi/core";
|
|
4
|
+
async function askYesNo(question) {
|
|
5
|
+
const rl = createInterface({
|
|
6
|
+
input: process.stdin,
|
|
7
|
+
output: process.stdout
|
|
8
|
+
});
|
|
9
|
+
try {
|
|
10
|
+
const answer = await rl.question(question);
|
|
11
|
+
const trimmed = answer.trim().toLowerCase();
|
|
12
|
+
return trimmed === "" || trimmed === "y" || trimmed === "yes";
|
|
13
|
+
} finally {
|
|
14
|
+
rl.close();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async function initCommand(options) {
|
|
18
|
+
const { name, target } = options;
|
|
19
|
+
const parentDir = process.cwd();
|
|
20
|
+
const projectDir = await initProject({ parentDir, name, target });
|
|
21
|
+
console.log(`
|
|
22
|
+
\u2713 Project "${name}" created at ${projectDir}
|
|
23
|
+
`);
|
|
24
|
+
const shouldInstall = await askYesNo("Install dependencies now? (pnpm install) [Y/n] ");
|
|
25
|
+
if (shouldInstall) {
|
|
26
|
+
console.log("\nInstalling dependencies...\n");
|
|
27
|
+
try {
|
|
28
|
+
const result = await exec("pnpm", ["install"], { cwd: projectDir });
|
|
29
|
+
if (result.stdout) {
|
|
30
|
+
console.log(result.stdout);
|
|
31
|
+
}
|
|
32
|
+
console.log("\u2713 Dependencies installed!\n");
|
|
33
|
+
} catch (e) {
|
|
34
|
+
console.error('Failed to install dependencies. Run "pnpm install" manually.\n');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
console.log(`Next steps:
|
|
38
|
+
cd ${name}${shouldInstall ? "" : "\n pnpm install"}
|
|
39
|
+
kagaribi dev
|
|
40
|
+
|
|
41
|
+
Add a new package:
|
|
42
|
+
kagaribi new <name>
|
|
43
|
+
`);
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
initCommand
|
|
47
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// src/commands/new.ts
|
|
2
|
+
import { scaffoldPackage, updateConfigAddPackage } from "@kagaribi/core";
|
|
3
|
+
async function newCommand(options) {
|
|
4
|
+
const projectRoot = process.cwd();
|
|
5
|
+
const { name, target } = options;
|
|
6
|
+
console.log(`Creating package "${name}"...`);
|
|
7
|
+
await scaffoldPackage({ projectRoot, name, target });
|
|
8
|
+
const config = target ? { target } : { colocateWith: "root" };
|
|
9
|
+
await updateConfigAddPackage(projectRoot, {
|
|
10
|
+
packageName: name,
|
|
11
|
+
config
|
|
12
|
+
});
|
|
13
|
+
console.log(`
|
|
14
|
+
\u2713 Package "${name}" created successfully!`);
|
|
15
|
+
console.log(` packages/${name}/kagaribi.package.ts`);
|
|
16
|
+
console.log(` packages/${name}/src/index.ts`);
|
|
17
|
+
console.log(` kagaribi.config.ts updated`);
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
newCommand
|
|
21
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kagaribi/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI tool for kagaribi microservices framework",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"kagaribi": "./dist/bin.js"
|
|
9
|
+
},
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/goofmint/kagaribi.git",
|
|
24
|
+
"directory": "packages/cli"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/goofmint/kagaribi",
|
|
27
|
+
"keywords": [
|
|
28
|
+
"hono",
|
|
29
|
+
"microservices",
|
|
30
|
+
"cli",
|
|
31
|
+
"deploy",
|
|
32
|
+
"cloudflare-workers",
|
|
33
|
+
"aws-lambda"
|
|
34
|
+
],
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=20.0.0"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"hono": "^4.0.0",
|
|
40
|
+
"@hono/node-server": "^1.0.0",
|
|
41
|
+
"tsx": "^4.0.0",
|
|
42
|
+
"@kagaribi/core": "0.1.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"tsup": "^8.0.0",
|
|
46
|
+
"typescript": "^5.5.0",
|
|
47
|
+
"vitest": "^2.0.0"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsup src/bin.ts src/index.ts --format esm --dts",
|
|
51
|
+
"dev": "tsup src/bin.ts src/index.ts --format esm --dts --watch",
|
|
52
|
+
"typecheck": "tsc --noEmit",
|
|
53
|
+
"test": "vitest run"
|
|
54
|
+
}
|
|
55
|
+
}
|