rapidkit 0.21.2 → 0.23.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 +75 -11
- package/dist/chunk-74G6C57B.js +24 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +3452 -201
- package/dist/package.json +3 -2
- package/dist/pythonRapidkitExec-YIFUZLND.js +1 -0
- package/package.json +3 -2
- package/scripts/enforce-package-manager.cjs +10 -0
- package/dist/chunk-D2ZRDZOE.js +0 -17
- package/dist/pythonRapidkitExec-GFCAVUOY.js +0 -1
package/README.md
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
### Build Production-Ready APIs in Seconds
|
|
6
6
|
|
|
7
|
-
FastAPI
|
|
7
|
+
FastAPI, NestJS, Go/Fiber, and Go/Gin scaffolding with production-ready defaults.
|
|
8
|
+
**27+ plug-and-play modules** are available for FastAPI & NestJS projects.
|
|
8
9
|
Clean architecture • Zero boilerplate • Instant deployment.
|
|
9
10
|
|
|
10
11
|
[](https://www.npmjs.com/package/rapidkit)
|
|
@@ -13,14 +14,22 @@ Clean architecture • Zero boilerplate • Instant deployment.
|
|
|
13
14
|
[](https://github.com/getrapidkit/rapidkit-npm/stargazers)
|
|
14
15
|
|
|
15
16
|
```bash
|
|
17
|
+
# 1. Create a workspace — shared Python env for all your projects
|
|
16
18
|
npx rapidkit init
|
|
17
19
|
cd my-workspace
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
|
|
21
|
+
# 2. Scaffold a project inside the workspace
|
|
22
|
+
npx rapidkit create project fastapi.standard my-api
|
|
23
|
+
cd my-api
|
|
24
|
+
|
|
25
|
+
# 3. Install deps & start the dev server
|
|
20
26
|
npx rapidkit init && npx rapidkit dev
|
|
21
27
|
# ✅ Production-ready API running at http://localhost:8000
|
|
22
28
|
```
|
|
23
29
|
|
|
30
|
+
> **Workspace approach:** one shared Python environment hosts multiple projects (FastAPI, NestJS, or both).
|
|
31
|
+
> Each project gets its own folder, clean architecture, Docker, and CI/CD — but shares a single `~150 MB` venv.
|
|
32
|
+
|
|
24
33
|
Using Node.js/NestJS? Use this direct kit command (inside or outside a workspace):
|
|
25
34
|
|
|
26
35
|
```bash
|
|
@@ -32,6 +41,15 @@ npx rapidkit create project fastapi.standard my-service # standard kit
|
|
|
32
41
|
npx rapidkit create project fastapi.ddd my-service # DDD kit
|
|
33
42
|
```
|
|
34
43
|
|
|
44
|
+
Using Go? Use these direct kit commands (inside or outside a workspace):
|
|
45
|
+
```bash
|
|
46
|
+
npx rapidkit create project gofiber.standard my-service # Go Fiber standard kit
|
|
47
|
+
npx rapidkit create project gogin.standard my-service # Go Gin standard kit
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
> ℹ️ **Module support note:** `npx rapidkit add module ...` is currently supported for **FastAPI** and **NestJS** projects only.
|
|
51
|
+
> Go kits (`gofiber.standard`, `gogin.standard`) do not support RapidKit modules in this release.
|
|
52
|
+
|
|
35
53
|
[Quick Start](#-quick-start) • [Docs](https://getrapidkit.com) • [VS Code Extension](https://marketplace.visualstudio.com/items?itemName=rapidkit.rapidkit-vscode) • [Examples](https://github.com/getrapidkit/rapidkit-examples)
|
|
36
54
|
|
|
37
55
|
---
|
|
@@ -52,7 +70,7 @@ No account. No config. No pain. Just build.
|
|
|
52
70
|
|-------------------------------|-------------------------------|--------------------------------|
|
|
53
71
|
| Project in 30 seconds | 27+ plug-and-play modules | Docker + CI/CD included |
|
|
54
72
|
| Zero configuration needed | Add features in 1 command | Best practices baked in |
|
|
55
|
-
| FastAPI &
|
|
73
|
+
| FastAPI, NestJS & Go kits | Auth/DB/Cache modules (Python/Node kits) | Clean architecture guaranteed |
|
|
56
74
|
|
|
57
75
|
### 🔥 From This...
|
|
58
76
|
|
|
@@ -107,22 +125,43 @@ Use this when you want the quickest complete flow (workspace + project + run):
|
|
|
107
125
|
|
|
108
126
|
```bash
|
|
109
127
|
cd ~/my-empty-folder
|
|
128
|
+
|
|
129
|
+
# Creates my-workspace/ with a shared Python environment
|
|
110
130
|
npx rapidkit init
|
|
111
131
|
cd my-workspace
|
|
112
|
-
|
|
113
|
-
|
|
132
|
+
|
|
133
|
+
# Scaffold a project (interactive, or pass kit + name directly)
|
|
134
|
+
npx rapidkit create project fastapi.standard my-api
|
|
135
|
+
cd my-api
|
|
136
|
+
|
|
137
|
+
# Install project deps & start dev server
|
|
114
138
|
npx rapidkit init && npx rapidkit dev
|
|
139
|
+
# ✅ http://localhost:8000
|
|
115
140
|
```
|
|
116
141
|
|
|
117
142
|
This is the recommended quickest onboarding path for most users.
|
|
118
143
|
`npx rapidkit init` is context-aware and auto-detects plain folders, workspace roots, and project directories.
|
|
119
144
|
|
|
145
|
+
**Why workspace?** All projects under `my-workspace/` share one Python virtualenv — so adding a second or third service costs almost no extra disk space, and the RapidKit Core version stays consistent across all of them.
|
|
146
|
+
|
|
120
147
|
Prefer direct kit selection (works both inside and outside a workspace):
|
|
121
148
|
|
|
122
149
|
```bash
|
|
123
150
|
npx rapidkit create project fastapi.standard my-service
|
|
124
151
|
npx rapidkit create project fastapi.ddd my-service
|
|
125
152
|
npx rapidkit create project nestjs.standard my-service
|
|
153
|
+
npx rapidkit create project gofiber.standard my-service
|
|
154
|
+
npx rapidkit create project gogin.standard my-service
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Interactive kit picker (`npx rapidkit create project`) includes:
|
|
158
|
+
|
|
159
|
+
```text
|
|
160
|
+
1) fastapi — FastAPI Standard Kit
|
|
161
|
+
2) fastapi — FastAPI DDD Kit
|
|
162
|
+
3) nestjs — NestJS Standard Kit
|
|
163
|
+
4) go/fiber — Go Fiber Standard Kit
|
|
164
|
+
5) go/gin — Go Gin Standard Kit
|
|
126
165
|
```
|
|
127
166
|
|
|
128
167
|
### Option 1: Single Project (Fastest)
|
|
@@ -159,6 +198,21 @@ npx rapidkit add module auth
|
|
|
159
198
|
npx rapidkit add module db_postgres
|
|
160
199
|
```
|
|
161
200
|
|
|
201
|
+
**Go (Fiber/Gin):**
|
|
202
|
+
```bash
|
|
203
|
+
# Create project
|
|
204
|
+
npx rapidkit create project gofiber.standard my-api
|
|
205
|
+
# or
|
|
206
|
+
npx rapidkit create project gogin.standard my-api
|
|
207
|
+
|
|
208
|
+
# Start developing
|
|
209
|
+
cd my-api
|
|
210
|
+
npx rapidkit init # Install Go deps + tools + generate Swagger docs
|
|
211
|
+
npx rapidkit dev # Start dev server with hot reload
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
> ℹ️ Go kits do not support `npx rapidkit add module ...` in this version.
|
|
215
|
+
|
|
162
216
|
### Option 2: Workspace (Recommended for Multiple Projects)
|
|
163
217
|
|
|
164
218
|
Organize multiple microservices with a shared environment:
|
|
@@ -213,7 +267,7 @@ npx rapidkit build # Build for production
|
|
|
213
267
|
npx rapidkit start # Start production server
|
|
214
268
|
|
|
215
269
|
# Explore modules
|
|
216
|
-
npx rapidkit modules list # List all 27+ modules
|
|
270
|
+
npx rapidkit modules list # List all 27+ modules (FastAPI/NestJS only)
|
|
217
271
|
npx rapidkit modules info db_postgres # View module details
|
|
218
272
|
|
|
219
273
|
# Health check
|
|
@@ -392,6 +446,9 @@ my-service/
|
|
|
392
446
|
|
|
393
447
|
RapidKit's modules are plug-and-play components that extend your project:
|
|
394
448
|
|
|
449
|
+
> ℹ️ The module system currently supports **FastAPI** and **NestJS** kits.
|
|
450
|
+
> Go kits (`gofiber.standard`, `gogin.standard`) currently do not support module installation.
|
|
451
|
+
|
|
395
452
|
```bash
|
|
396
453
|
# Add authentication
|
|
397
454
|
rapidkit add module auth
|
|
@@ -444,7 +501,7 @@ rapidkit ai generate-embeddings # Generate embeddings (~$0.50)
|
|
|
444
501
|
|
|
445
502
|
## 🧩 Module Ecosystem
|
|
446
503
|
|
|
447
|
-
RapidKit includes **27 production-ready modules** across 10 categories:
|
|
504
|
+
RapidKit includes **27 production-ready modules** across 10 categories for **FastAPI** and **NestJS** projects:
|
|
448
505
|
|
|
449
506
|
### Quick Overview
|
|
450
507
|
|
|
@@ -513,7 +570,7 @@ npx rapidkit create project <kit> <name> # Direct creation
|
|
|
513
570
|
|
|
514
571
|
# Information
|
|
515
572
|
npx rapidkit list # List kits
|
|
516
|
-
npx rapidkit modules list # List modules
|
|
573
|
+
npx rapidkit modules list # List modules (FastAPI/NestJS kits)
|
|
517
574
|
npx rapidkit kits info <name> # Kit details
|
|
518
575
|
npx rapidkit modules info <name> # Module details
|
|
519
576
|
|
|
@@ -576,6 +633,9 @@ npx rapidkit modules list # List available modules
|
|
|
576
633
|
npx rapidkit modules info <slug> # Module details
|
|
577
634
|
```
|
|
578
635
|
|
|
636
|
+
> ℹ️ `add module` and `modules ...` commands apply to **FastAPI/NestJS** projects.
|
|
637
|
+
> For Go kits, these commands are intentionally unavailable in this release.
|
|
638
|
+
|
|
579
639
|
### Advanced Options
|
|
580
640
|
|
|
581
641
|
```bash
|
|
@@ -601,9 +661,9 @@ npx rapidkit create --no-update-check # Skip version check
|
|
|
601
661
|
| `init` | Context-aware dependency setup | Folder / workspace / project |
|
|
602
662
|
| `dev` | Start dev server | Inside project |
|
|
603
663
|
| `test` | Run tests | Inside project |
|
|
604
|
-
| `add module` | Add module to project | Inside project |
|
|
664
|
+
| `add module` | Add module to project (FastAPI/NestJS) | Inside project |
|
|
605
665
|
| `list` | List kits | Anywhere |
|
|
606
|
-
| `modules list` | List modules | Anywhere |
|
|
666
|
+
| `modules list` | List modules (FastAPI/NestJS) | Anywhere |
|
|
607
667
|
| `doctor` | Health check | Anywhere |
|
|
608
668
|
| `workspace` | Manage workspaces | Anywhere |
|
|
609
669
|
|
|
@@ -627,6 +687,10 @@ npx rapidkit create --no-update-check # Skip version check
|
|
|
627
687
|
- Node.js 20.19.6+
|
|
628
688
|
- npm
|
|
629
689
|
|
|
690
|
+
**Go Projects (Fiber/Gin Kits):**
|
|
691
|
+
- Go 1.23+ (or the version configured by the selected kit)
|
|
692
|
+
- Make (recommended for `make dev/test/build/docs` targets)
|
|
693
|
+
|
|
630
694
|
### Optional but Recommended
|
|
631
695
|
|
|
632
696
|
- **Docker**: For containerized development
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import z from'crypto';import B from'os';import c from'path';import*as d from'fs-extra';import {execa}from'execa';var W=["version","project","create","init","dev","start","build","test","lint","format","add","list","info","upgrade","diff","doctor","license","commands","reconcile","rollback","uninstall","checkpoint","optimize","snapshot","frameworks","modules","merge"],A=new Set(W);var y=class extends Error{code;constructor(n,e){super(e),this.code=n;}};function C(t){if(t instanceof y)switch(t.code){case "PYTHON_NOT_FOUND":return "RapidKit (npm) could not find Python (python3/python) on your PATH.\nInstall Python 3.10+ and ensure `python3` is available, then retry.\nTip: if you are inside a RapidKit project, use the local ./rapidkit launcher.";case "BRIDGE_VENV_CREATE_FAILED":return `RapidKit (npm) failed to create its bridge virtual environment.
|
|
2
|
+
Ensure Python venv support is installed (e.g., python3-venv).
|
|
3
|
+
Details: ${t.message}`;case "BRIDGE_PIP_BOOTSTRAP_FAILED":return `RapidKit (npm) could not bootstrap pip inside the bridge virtual environment.
|
|
4
|
+
Install python3-venv/python3-pip and retry.
|
|
5
|
+
Details: ${t.message}`;case "BRIDGE_PIP_UPGRADE_FAILED":return `RapidKit (npm) could not upgrade pip in the bridge virtual environment.
|
|
6
|
+
Check your network/proxy or disable RAPIDKIT_BRIDGE_UPGRADE_PIP.
|
|
7
|
+
Details: ${t.message}`;case "BRIDGE_PIP_INSTALL_FAILED":return `RapidKit (npm) could not install rapidkit-core in the bridge virtual environment.
|
|
8
|
+
Check your network/proxy, or install manually with: pipx install rapidkit-core.
|
|
9
|
+
Details: ${t.message}`;default:return `RapidKit (npm) bridge error: ${t.message}`}return `RapidKit (npm) failed to run the Python core engine: ${t instanceof Error?t.message:String(t)}`}function S(){let t=process.env.RAPIDKIT_CORE_PYTHON_PACKAGE;return t&&t.trim()?t.trim():"rapidkit-core"}function X(){let t=S(),n=process.env.RAPIDKIT_CORE_PYTHON_PACKAGE_ID,e=n&&n.trim()?`${t}|${n.trim()}`:t;return z.createHash("sha256").update(e).digest("hex").slice(0,12)}function R(){let t=process.env.XDG_CACHE_HOME;return t&&t.trim()?t:c.join(B.homedir(),".cache")}function q(){return c.join(R(),"rapidkit","npm-bridge","venv")}function F(){let t=X();return c.join(R(),"rapidkit","npm-bridge",`venv-${t}`)}function O(t){return process.platform==="win32"?c.join(t,"Scripts","python.exe"):c.join(t,"bin","python")}function N(t){return process.platform==="win32"?c.join(t,"Scripts","rapidkit.exe"):c.join(t,"bin","rapidkit")}function Q(t){return /[<>=!~]=|@|\.whl$|\.tar\.gz$|\.zip$|git\+|https?:\/\//.test(t)}function Z(t){return c.dirname(c.dirname(t))}function G(){return c.join(R(),"rapidkit","npm-bridge","core-commands.json")}async function V(t){let n=!!process.env.RAPIDKIT_DEBUG,e=r=>{n&&process.stderr.write(`[DEBUG] tryRapidkit(${t}): ${r}
|
|
10
|
+
`);};try{e("probing interpreter-specific rapidkit script");let s=((await execa(t,["-c","import sysconfig, os; print(os.path.join(sysconfig.get_path('scripts'), 'rapidkit'))"],{reject:false,stdio:"pipe",timeout:2e3})).stdout??"").toString().trim();if(e(`script path: ${s}`),s)try{if(await d.pathExists(s)){e(`found script at ${s}; invoking --version --json`);let i=await execa(s,["--version","--json"],{reject:false,stdio:"pipe",timeout:4e3});if(e(`script exitCode=${i.exitCode}`),i.exitCode===0){let a=(i.stdout??"").toString().trim();try{let o=JSON.parse(a),p=!!o&&typeof o=="object"&&o!==null&&"version"in o;if(e(`script JSON parse ok=${p}`),p)return true}catch{e("script output not valid JSON");}}}}catch(i){e(`interpreter-specific script probe failed: ${String(i)}`);}}catch(r){e(`interpreter-specific script probe error: ${String(r)}`);}try{e('probing importlib.find_spec("rapidkit")');let r=await execa(t,["-c","import importlib.util; print(1 if importlib.util.find_spec('rapidkit') else 0)"],{reject:false,stdio:"pipe",timeout:2e3});if(e(`import probe exitCode=${r.exitCode} stdout=${(r.stdout??"").toString().trim()}`),r.exitCode===0&&(r.stdout??"").toString().trim()==="1")return true}catch(r){e(`import probe error: ${String(r)}`);}try{e("probing python -m rapidkit");let r=await execa(t,["-m","rapidkit","--version","--json"],{reject:false,stdio:"pipe",timeout:8e3});if(e(`-m probe exitCode=${r.exitCode}`),r.exitCode===0)return true}catch(r){e(`-m probe error: ${String(r)}`);}try{e("probing PATH for rapidkit executables");let r=(process.env.PATH??"").split(c.delimiter).filter(Boolean);for(let s of r){let i=c.join(s,process.platform==="win32"?"rapidkit.exe":"rapidkit");try{if(await d.pathExists(i)){e(`found candidate on PATH: ${i}; invoking --version --json`);let a=await execa(i,["--version","--json"],{reject:false,stdio:"pipe",timeout:4e3});if(e(`candidate exitCode=${a.exitCode}`),a.exitCode===0){let o=(a.stdout??"").toString().trim();try{let p=JSON.parse(o);if(p&&typeof p=="object"&&p!==null&&"version"in p)return true}catch{e("candidate output not valid JSON, skipping");}}}}catch(a){e(`error probing candidate ${i}: ${String(a)}`);}}return e("no valid rapidkit found on PATH"),false}catch(r){return e(`PATH probe error: ${String(r)}`),false}}async function D(t){let n=(t??"").toString().trim();if(!n)return false;try{let e=JSON.parse(n);return !!e&&typeof e=="object"&&e!==null&&"version"in e}catch{return false}}async function tt(t){let n=process.platform==="win32",e=n?c.join(".venv","Scripts","rapidkit.exe"):c.join(".venv","bin","rapidkit"),r=n?c.join(".venv","Scripts","python.exe"):c.join(".venv","bin","python"),s=t;for(let i=0;i<25;i+=1){let a=c.join(s,e);if(await d.pathExists(a)){let l=await execa(a,["--version","--json"],{reject:false,stdio:"pipe",timeout:1500,cwd:s});if(l.exitCode===0&&await D(l.stdout))return {cmd:a,baseArgs:[]}}let o=c.join(s,r);if(await d.pathExists(o)){let l=await execa(o,["-m","rapidkit","--version","--json"],{reject:false,stdio:"pipe",timeout:1500,cwd:s});if(l.exitCode===0&&await D(l.stdout))return {cmd:o,baseArgs:["-m","rapidkit"]}}let p=c.dirname(s);if(p===s)break;s=p;}return null}async function et(t){try{let n=c.join(t,".python-version");if(await d.pathExists(n)){let r=(await d.readFile(n,"utf-8")).trim();if(r)return r}}catch{}try{let n=c.join(t,".rapidkit-workspace");if(await d.pathExists(n)){let e=await d.readFile(n,"utf-8"),r=JSON.parse(e);if(r.pythonVersion)return r.pythonVersion}}catch{}return null}async function j(t){if(t&&t.trim())try{let i=await tt(t);if(i){let a=c.dirname(i.cmd).includes(".venv")?c.dirname(c.dirname(c.dirname(i.cmd))):c.dirname(i.cmd),o=await et(a);return o&&(process.env.PYENV_VERSION=o),i}}catch{}let n=await rt();if(n.kind==="venv"){let i=Z(n.pythonPath),a=N(i);return await d.pathExists(a)?{cmd:a,baseArgs:[]}:{cmd:n.pythonPath,baseArgs:["-m","rapidkit"]}}try{if((await execa(n.cmd,["-m","rapidkit","--version","--json"],{reject:false,stdio:"pipe",timeout:4e3})).exitCode===0)return {cmd:n.cmd,baseArgs:["-m","rapidkit"]}}catch{}try{let a=((await execa(n.cmd,["-c","import sysconfig, os; print(os.path.join(sysconfig.get_path('scripts'), 'rapidkit'))"],{reject:false,stdio:"pipe",timeout:2e3})).stdout??"").toString().trim();if(a&&await d.pathExists(a))try{let o=await execa(a,["--version","--json"],{reject:false,stdio:"pipe",timeout:4e3});if(o.exitCode===0&&await D(o.stdout))return {cmd:a,baseArgs:[]}}catch{}}catch{}let e=F(),r=await x(n.cmd),s=N(e);return await d.pathExists(s)?{cmd:s,baseArgs:[]}:{cmd:r,baseArgs:["-m","rapidkit"]}}async function I(){for(let t of ["python3","python"])try{return await execa(t,["--version"],{reject:false,stdio:"pipe",timeout:2e3}),t}catch{}return null}async function nt(){let t=!!process.env.RAPIDKIT_DEBUG,n=e=>{t&&process.stderr.write(`[DEBUG] checkRapidkitCore: ${e}
|
|
11
|
+
`);};for(let e of ["python3","python","python3.10","python3.11","python3.12"])try{n(`Method 1: trying ${e} import`);let r=await execa(e,["-c","import rapidkit_core; print(1)"],{reject:false,stdio:"pipe",timeout:3e3});if(r.exitCode===0&&r.stdout?.trim()==="1")return n(`\u2713 Found via ${e} import`),true}catch{continue}for(let e of ["python3","python"])try{n(`Method 2: trying ${e} -m pip show`);let r=await execa(e,["-m","pip","show","rapidkit-core"],{reject:false,stdio:"pipe",timeout:3e3});if(r.exitCode===0&&r.stdout?.includes("Name: rapidkit-core"))return n(`\u2713 Found via ${e} -m pip show`),true}catch{continue}for(let e of ["pip","pip3"])try{n(`Method 3: trying ${e} show`);let r=await execa(e,["show","rapidkit-core"],{reject:false,stdio:"pipe",timeout:3e3});if(r.exitCode===0&&r.stdout?.includes("Name: rapidkit-core"))return n(`\u2713 Found via ${e} show`),true}catch{continue}try{n("Method 4: checking pyenv versions");let e=await execa("pyenv",["versions","--bare"],{reject:false,stdio:"pipe",timeout:3e3});if(e.exitCode===0&&e.stdout){let r=e.stdout.split(`
|
|
12
|
+
`).filter(s=>s.trim());n(`Found pyenv versions: ${r.join(", ")}`);for(let s of r){let i=process.env.PYENV_ROOT||c.join(B.homedir(),".pyenv"),a=c.join(i,"versions",s.trim(),"bin","pip");try{let o=await execa(a,["show","rapidkit-core"],{reject:false,stdio:"pipe",timeout:3e3});if(o.exitCode===0&&o.stdout?.includes("Name: rapidkit-core"))return n(`\u2713 Found in pyenv ${s}`),true}catch{try{let o=await execa("bash",["-c",`PYENV_VERSION=${s.trim()} pyenv exec pip show rapidkit-core`],{reject:false,stdio:"pipe",timeout:3e3});if(o.exitCode===0&&o.stdout?.includes("Name: rapidkit-core"))return n(`\u2713 Found in pyenv ${s} via PYENV_VERSION`),true}catch{continue}}}}}catch{n("pyenv not available");}for(let e of ["python3","python"])try{n(`Method 5: checking ${e} user site`);let r=await execa(e,["-m","site","--user-site"],{reject:false,stdio:"pipe",timeout:3e3});if(r.exitCode===0&&r.stdout){let s=r.stdout.trim(),i=c.join(s,"rapidkit_core");if(await d.pathExists(i))return n("\u2713 Found in user site-packages"),true}}catch{continue}try{n("Method 6: checking pipx");let e=await execa("pipx",["list"],{reject:false,stdio:"pipe",timeout:3e3});if(e.exitCode===0&&e.stdout?.includes("rapidkit-core"))return n("\u2713 Found via pipx"),true}catch{n("pipx not available");}try{if(n("Method 7: checking poetry"),(await execa("poetry",["show","rapidkit-core"],{reject:false,stdio:"pipe",timeout:3e3})).exitCode===0)return n("\u2713 Found via poetry"),true}catch{n("poetry check failed");}try{n("Method 8: checking conda");let e=await execa("conda",["list","rapidkit-core"],{reject:false,stdio:"pipe",timeout:3e3});if(e.exitCode===0&&e.stdout?.includes("rapidkit-core"))return n("\u2713 Found via conda"),true}catch{n("conda not available");}return n("\u2717 Not found in any environment"),false}async function x(t){let n=F(),e=q(),r=S(),s=[n];!Q(r)&&!await d.pathExists(n)&&await d.pathExists(e)&&s.push(e);for(let m of s){let h=O(m);if(await d.pathExists(h))try{let f=await execa(h,["-c","import importlib.util; print(1 if importlib.util.find_spec('rapidkit') else 0)"],{reject:false,stdio:"pipe",timeout:2e3});if(f.exitCode===0&&(f.stdout??"").toString().trim()==="1")return h;await d.remove(m);}catch{await d.remove(m);}}let i=n,a={...process.env,PIP_DISABLE_PIP_VERSION_CHECK:"1",PIP_NO_PYTHON_VERSION_WARNING:"1"},o=Math.max(0,Number(process.env.RAPIDKIT_BRIDGE_PIP_RETRY??"2")),p=Math.max(200,Number(process.env.RAPIDKIT_BRIDGE_PIP_RETRY_DELAY_MS??"800")),l=Math.max(1e4,Number(process.env.RAPIDKIT_BRIDGE_PIP_TIMEOUT_MS??"120000")),w=m=>new Promise(h=>setTimeout(h,m)),v=async(m,h,f)=>{let g=await execa(m,h,{reject:false,stdio:["ignore","pipe","inherit"],env:a,timeout:f});if(g.exitCode===0)return;let k=(g.stdout??"").toString(),b=(g.stderr??"").toString(),P=[k,b].filter(Boolean).join(`
|
|
13
|
+
`),H=P?`${m} ${h.join(" ")}
|
|
14
|
+
${P}`:`${m} ${h.join(" ")}`;throw new Error(H)},E=async(m,h,f)=>{let g=0;for(;;)try{await v(m,h,f);return}catch(k){if(g>=o)throw k;let b=Math.floor(Math.random()*200),P=p*Math.pow(2,g)+b;g+=1,await w(P);}};try{await d.ensureDir(c.dirname(i));try{await v(t,["-m","venv",i],6e4);}catch(f){let g=f instanceof Error?f.message:String(f);throw new y("BRIDGE_VENV_CREATE_FAILED",g)}let m=O(i);if((await execa(m,["-m","pip","--version"],{reject:false,stdio:"pipe",timeout:2e3})).exitCode!==0&&(await execa(m,["-m","ensurepip","--default-pip"],{reject:false,stdio:["ignore","pipe","inherit"],env:a,timeout:6e4})).exitCode!==0)throw new y("BRIDGE_PIP_BOOTSTRAP_FAILED","ensurepip failed; install python3-venv/python3-pip and retry.");if(process.env.RAPIDKIT_BRIDGE_UPGRADE_PIP==="1")try{await E(m,["-m","pip","install","-U","pip"],l);}catch(f){let g=f instanceof Error?f.message:String(f);throw new y("BRIDGE_PIP_UPGRADE_FAILED",g)}try{await E(m,["-m","pip","install","-U",S()],l);}catch(f){let g=f instanceof Error?f.message:String(f);throw new y("BRIDGE_PIP_INSTALL_FAILED",g)}return m}catch(m){if(m instanceof y)throw m;let h=m instanceof Error?m.message:String(m);throw new y("BRIDGE_VENV_BOOTSTRAP_FAILED",h)}}async function rt(){if(process.env.RAPIDKIT_BRIDGE_FORCE_VENV==="1"){let e=await I();if(!e)throw new y("PYTHON_NOT_FOUND","No Python interpreter found (python3/python).");return {kind:"venv",pythonPath:await x(e)}}for(let e of ["python3","python"])if(await V(e))return {kind:"system",cmd:e};let t=await I();if(!t)throw new y("PYTHON_NOT_FOUND","No Python interpreter found (python3/python).");return {kind:"venv",pythonPath:await x(t)}}async function ht(t,n){try{let e=await j(n?.cwd),r=e.cmd,s=[...e.baseArgs,...t],i=await execa(r,s,{cwd:n?.cwd,env:{...process.env,...n?.env},reject:false,stdio:"inherit"});return typeof i.exitCode=="number"?i.exitCode:1}catch(e){return process.stderr.write(`${C(e)}
|
|
15
|
+
`),1}}var it=[{pattern:/RapidKitError:\s*Directory '([^']+)' exists and force is not set/,message:t=>`\u274C Directory "${c.basename(t[1])}" already exists.
|
|
16
|
+
\u{1F4A1} Choose a different name, or remove the existing directory first:
|
|
17
|
+
rm -rf ${t[1]}`},{pattern:/RapidKitError:\s*Project name '([^']+)' is (invalid|not allowed)/i,message:t=>`\u274C Invalid project name: "${t[1]}"
|
|
18
|
+
\u{1F4A1} Use lowercase letters, numbers, and hyphens only (e.g. my-api).`},{pattern:/RapidKitError:\s*Kit '([^']+)' not found/i,message:t=>`\u274C Unknown kit: "${t[1]}"
|
|
19
|
+
\u{1F4A1} Run "npx rapidkit list" to see available kits.`},{pattern:/RapidKitError:\s*(.+)/,message:t=>`\u274C ${t[1].trim()}`}];async function gt(t,n){let{spawn:e}=await import('child_process');try{let r=await j(n?.cwd),s=r.cmd,i=[...r.baseArgs,...t];return await new Promise(a=>{let o=e(s,i,{cwd:n?.cwd,env:{...process.env,...n?.env},stdio:["inherit","inherit","pipe"]}),p=[];o.stderr?.on("data",l=>{p.push(l);}),o.on("close",l=>{let w=l??1;if(w!==0&&p.length>0){let v=Buffer.concat(p).toString("utf8");for(let{pattern:E,message:m}of it){let h=v.match(E);if(h){process.stderr.write(m(h)+`
|
|
20
|
+
`),a(w);return}}process.stderr.write(v);}a(w);}),o.on("error",l=>{process.stderr.write(`${C(l)}
|
|
21
|
+
`),a(1);});})}catch(r){return process.stderr.write(`${C(r)}
|
|
22
|
+
`),1}}async function _(t,n){try{let e=await j(n?.cwd),r=e.cmd,s=[...e.baseArgs,...t],i=await execa(r,s,{cwd:n?.cwd,env:{...process.env,...n?.env},reject:false,stdio:"pipe"});return {exitCode:typeof i.exitCode=="number"?i.exitCode:1,stdout:(i.stdout??"").toString(),stderr:(i.stderr??"").toString()}}catch(e){return {exitCode:1,stdout:"",stderr:`${C(e)}
|
|
23
|
+
`}}}function K(t){let n=new Set,e=t.split(`
|
|
24
|
+
`),r=false;for(let s of e){let i=s.replace(/\r$/,"");if(!r){/^\s*Commands:\s*$/i.test(i)&&(r=true);let p=i.match(/^\s*rapidkit\s+([a-z0-9_-]+)\b/i);if(p){let l=p[1].trim();l&&!l.startsWith("-")&&n.add(l);}continue}if(!i.trim())break;if(/^\s*(Options|Arguments|Usage|Commands)\s*:/i.test(i))continue;let a=i.match(/^\s*([a-z0-9][a-z0-9_-]*)\b/i);if(!a)continue;let o=a[1].trim();o&&!o.startsWith("-")&&n.add(o);}return n}async function L(){let t=G();if(!await d.pathExists(t))return null;try{let n=await d.readJson(t);if(n&&n.schema_version===1&&Array.isArray(n.commands))return n}catch{}return null}async function T(t){let n=G();await d.ensureDir(c.dirname(n)),await d.writeJson(n,t,{spaces:2});}async function ot(){let t=await _(["version","--json"],{cwd:process.cwd()});if(t.exitCode===0)try{let e=JSON.parse(t.stdout)?.version;return typeof e=="string"?e:void 0}catch{return}}async function st(){let t=await _(["commands","--json"],{cwd:process.cwd()});if(t.exitCode!==0)return null;try{let n=JSON.parse(t.stdout);if(n?.schema_version!==1||!Array.isArray(n.commands))return null;let e=n.commands.filter(r=>typeof r=="string");return e.length?e:null}catch{return null}}async function yt(){let n=Date.now(),e=await L(),r=await ot(),s=!!e?.commands?.length;if(s&&n-e.fetched_at<864e5&&(!r||!e.rapidkit_version||e.rapidkit_version===r))return new Set(e.commands);let i=await st();if(i?.length){let l=Array.from(new Set(i)).sort();return await T({schema_version:1,fetched_at:n,rapidkit_version:r,commands:l}),new Set(l)}let a=await _(["--help"],{cwd:process.cwd()});if(a.exitCode!==0)return s&&e?.commands?new Set(e.commands):new Set(A);let o=K(a.stdout);if(o.size===0)return new Set(A);let p=Array.from(o).sort();return await T({schema_version:1,fetched_at:n,rapidkit_version:r,commands:p}),o}async function wt(){let n=Date.now(),e=await L();return !e||n-e.fetched_at>=864e5||!e.commands?.length?null:new Set(e.commands)}function J(){return c.join(R(),"rapidkit","npm-bridge","modules-catalog.json")}async function at(){let t=J();if(!await d.pathExists(t))return null;try{let n=await d.readJson(t);if(n&&n.schema_version===1&&Array.isArray(n.modules))return n}catch{}return null}async function $(t){let n=J();await d.ensureDir(c.dirname(n)),await d.writeJson(n,t,{spaces:2});}function M(t){try{return JSON.parse(t)}catch{return null}}async function vt(t={}){let n=typeof t.ttlMs=="number"?t.ttlMs:18e5,e=Date.now(),r=await at();if(r?.fetched_at&&e-r.fetched_at<n)return r;let s=["modules","list","--json-schema","1"];t.category&&s.push("--category",t.category),t.tag&&s.push("--tag",t.tag),t.detailed&&s.push("--detailed");let i=await _(s,{cwd:t.cwd,env:t.env});if(i.exitCode===0){let o=M(i.stdout);if(o&&o.schema_version===1&&Array.isArray(o.modules)){let p={...o,fetched_at:e};return await $(p),p}}let a=await _(["modules","list","--json"],{cwd:t.cwd,env:t.env});if(a.exitCode===0){let o=M(a.stdout);if(Array.isArray(o)){let p={schema_version:1,generated_at:new Date().toISOString(),filters:{category:t.category??null,tag:t.tag??null,detailed:!!t.detailed},stats:{total:o.length,returned:o.length,invalid:0},modules:o,source:"legacy-json",fetched_at:e};return await $(p),p}}return r||null}var _t={pickSystemPython:I,ensureBridgeVenv:x,parseCoreCommandsFromHelp:K,tryRapidkit:V,checkRapidkitCoreAvailable:nt};export{A as a,nt as b,rt as c,ht as d,gt as e,_ as f,yt as g,wt as h,vt as i,_t as j};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
declare function handleCreateOrFallback(args: string[]): Promise<number>;
|
|
3
|
+
declare function handleBootstrapCommand(args: string[], initRunner?: (nextArgs: string[]) => Promise<number>): Promise<number>;
|
|
4
|
+
declare function handleSetupCommand(args: string[]): Promise<number>;
|
|
5
|
+
declare function handleCacheCommand(args: string[]): Promise<number>;
|
|
6
|
+
declare function handleInitCommand(args: string[]): Promise<number>;
|
|
7
|
+
declare function shouldForwardToCore(args: string[]): Promise<boolean>;
|
|
3
8
|
|
|
4
|
-
export { handleCreateOrFallback };
|
|
9
|
+
export { handleBootstrapCommand, handleCacheCommand, handleCreateOrFallback, handleInitCommand, handleSetupCommand, shouldForwardToCore };
|