rapidkit 0.24.2 → 0.25.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 +49 -23
- package/dist/chunk-D46IWAXH.js +33 -0
- package/dist/chunk-FXRDNZGB.js +1 -0
- package/dist/chunk-T62GANVU.js +786 -0
- package/dist/{create-3OT5GA5W.js → create-EFY5NQWP.js} +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +223 -195
- package/dist/package.json +7 -2
- package/dist/{pythonRapidkitExec-EXCX5QGH.js → pythonRapidkitExec-7LPE3JUQ.js} +1 -1
- package/dist/{workspace-6SADFTND.js → workspace-J5UUDMHW.js} +52 -49
- package/package.json +8 -3
- package/dist/chunk-5JB4MOC5.js +0 -33
- package/dist/chunk-XP4GTL4L.js +0 -776
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# RapidKit NPM CLI
|
|
2
2
|
|
|
3
|
-
###
|
|
3
|
+
### RapidKit is an open-source workspace platform that standardizes how teams build, scale, and deploy backend services.
|
|
4
4
|
|
|
5
5
|
FastAPI, NestJS, Go/Fiber, and Go/Gin scaffolding with production-ready defaults.
|
|
6
6
|
**27+ plug-and-play modules** are available for FastAPI & NestJS projects.
|
|
@@ -36,30 +36,32 @@ Or run directly with `npx`:
|
|
|
36
36
|
npx rapidkit --help
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
+
All three commands above render the same root help output.
|
|
40
|
+
|
|
39
41
|
## Quick Start (Recommended)
|
|
40
42
|
|
|
41
43
|
### 1) Create a workspace
|
|
42
44
|
|
|
43
45
|
```bash
|
|
44
|
-
rapidkit create workspace my-workspace --yes --profile polyglot
|
|
46
|
+
npx rapidkit create workspace my-workspace --yes --profile polyglot
|
|
45
47
|
cd my-workspace
|
|
46
48
|
```
|
|
47
49
|
|
|
48
50
|
### 2) Bootstrap and setup runtimes
|
|
49
51
|
|
|
50
52
|
```bash
|
|
51
|
-
rapidkit bootstrap --profile polyglot
|
|
52
|
-
rapidkit setup python
|
|
53
|
-
rapidkit setup node --warm-deps
|
|
54
|
-
rapidkit setup go --warm-deps
|
|
53
|
+
npx rapidkit bootstrap --profile polyglot
|
|
54
|
+
npx rapidkit setup python
|
|
55
|
+
npx rapidkit setup node --warm-deps
|
|
56
|
+
npx rapidkit setup go --warm-deps
|
|
55
57
|
```
|
|
56
58
|
|
|
57
59
|
### 3) Create projects
|
|
58
60
|
|
|
59
61
|
```bash
|
|
60
|
-
rapidkit create project fastapi.standard my-api --yes --skip-install
|
|
61
|
-
rapidkit create project nestjs.standard my-nest --yes --skip-install
|
|
62
|
-
rapidkit create project gofiber.standard my-fiber --yes --skip-install
|
|
62
|
+
npx rapidkit create project fastapi.standard my-api --yes --skip-install
|
|
63
|
+
npx rapidkit create project nestjs.standard my-nest --yes --skip-install
|
|
64
|
+
npx rapidkit create project gofiber.standard my-fiber --yes --skip-install
|
|
63
65
|
```
|
|
64
66
|
|
|
65
67
|
## Core Commands
|
|
@@ -67,28 +69,32 @@ rapidkit create project gofiber.standard my-fiber --yes --skip-install
|
|
|
67
69
|
### Workspace lifecycle
|
|
68
70
|
|
|
69
71
|
```bash
|
|
70
|
-
rapidkit create
|
|
71
|
-
rapidkit
|
|
72
|
-
rapidkit
|
|
73
|
-
rapidkit
|
|
72
|
+
npx rapidkit create # Prompts: workspace | project
|
|
73
|
+
npx rapidkit create workspace <name> [--profile <profile>] [--author <name>] [--yes]
|
|
74
|
+
npx rapidkit bootstrap [--profile <profile>] [--json]
|
|
75
|
+
npx rapidkit setup <python|node|go> [--warm-deps]
|
|
76
|
+
npx rapidkit workspace policy show
|
|
77
|
+
npx rapidkit workspace policy set <key> <value>
|
|
78
|
+
npx rapidkit doctor workspace [--fix]
|
|
79
|
+
npx rapidkit workspace list # Display all workspaces created on this system
|
|
74
80
|
```
|
|
75
81
|
|
|
76
82
|
### Project lifecycle
|
|
77
83
|
|
|
78
84
|
```bash
|
|
79
|
-
rapidkit create project <kit> <name> [--yes] [--skip-install]
|
|
80
|
-
rapidkit init
|
|
81
|
-
rapidkit dev
|
|
82
|
-
rapidkit test
|
|
83
|
-
rapidkit build
|
|
84
|
-
rapidkit start
|
|
85
|
+
npx rapidkit create project <kit> <name> [--yes] [--skip-install]
|
|
86
|
+
npx rapidkit init
|
|
87
|
+
npx rapidkit dev
|
|
88
|
+
npx rapidkit test
|
|
89
|
+
npx rapidkit build
|
|
90
|
+
npx rapidkit start
|
|
85
91
|
```
|
|
86
92
|
|
|
87
93
|
### Operations
|
|
88
94
|
|
|
89
95
|
```bash
|
|
90
|
-
rapidkit cache <status|clear|prune|repair>
|
|
91
|
-
rapidkit mirror <status|sync|verify|rotate>
|
|
96
|
+
npx rapidkit cache <status|clear|prune|repair>
|
|
97
|
+
npx rapidkit mirror <status|sync|verify|rotate>
|
|
92
98
|
```
|
|
93
99
|
|
|
94
100
|
## Profiles
|
|
@@ -107,6 +113,26 @@ rapidkit mirror <status|sync|verify|rotate>
|
|
|
107
113
|
- `warn` (default): report violations, continue
|
|
108
114
|
- `strict`: block incompatible operations
|
|
109
115
|
|
|
116
|
+
## Workspace Policy Management
|
|
117
|
+
|
|
118
|
+
Manage `.rapidkit/policies.yml` via CLI (recommended, avoids manual YAML edits):
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
npx rapidkit workspace policy show
|
|
122
|
+
npx rapidkit workspace policy set mode strict
|
|
123
|
+
npx rapidkit workspace policy set dependency_sharing_mode shared-runtime-caches
|
|
124
|
+
npx rapidkit workspace policy set rules.enforce_toolchain_lock true
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Supported keys:
|
|
128
|
+
- `mode`
|
|
129
|
+
- `dependency_sharing_mode`
|
|
130
|
+
- `rules.enforce_workspace_marker`
|
|
131
|
+
- `rules.enforce_toolchain_lock`
|
|
132
|
+
- `rules.disallow_untrusted_tool_sources`
|
|
133
|
+
- `rules.enforce_compatibility_matrix`
|
|
134
|
+
- `rules.require_mirror_lock_for_offline`
|
|
135
|
+
|
|
110
136
|
## Setup and Warm Dependencies
|
|
111
137
|
|
|
112
138
|
`setup <runtime>` validates toolchain and updates `.rapidkit/toolchain.lock`.
|
|
@@ -170,12 +196,12 @@ Link local CLI globally for manual testing:
|
|
|
170
196
|
|
|
171
197
|
```bash
|
|
172
198
|
npm run install:local
|
|
173
|
-
rapidkit --version
|
|
199
|
+
npx rapidkit --version
|
|
174
200
|
```
|
|
175
201
|
|
|
176
202
|
## Troubleshooting
|
|
177
203
|
|
|
178
|
-
- If setup output looks stale, run `rapidkit setup <runtime>` again to refresh `.rapidkit/toolchain.lock`.
|
|
204
|
+
- If setup output looks stale, run `npx rapidkit setup <runtime>` again to refresh `.rapidkit/toolchain.lock`.
|
|
179
205
|
- If dependency warm-up is skipped, verify you are inside the corresponding project directory (`package.json` for Node, `go.mod` for Go).
|
|
180
206
|
- For strict-mode blocks, inspect `.rapidkit/policies.yml` and workspace profile in `.rapidkit/workspace.json`.
|
|
181
207
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {a,d as d$1,e,f,c,g}from'./chunk-FXRDNZGB.js';import it from'crypto';import U from'os';import u from'path';import*as d from'fs-extra';import {execa}from'execa';var rt=["version","project","create","add","list","info","upgrade","diff","doctor","license","commands","reconcile","rollback","uninstall","checkpoint","optimize","snapshot","frameworks","modules","merge"],j=new Set(rt);function Y(){return d$1()}function w(t,e){return t==="py"?["-3",...e]:e}function V(t){if(!t)return t;let e=["Installed Poetry version does not support '--no-update'. Falling back to 'poetry lock'."];return t.split(/\r?\n/).filter(o=>!e.some(i=>o.includes(i))).join(`
|
|
2
|
+
`)}var y=class extends Error{code;constructor(e,r){super(r),this.code=e;}};function k(t){if(t instanceof y)switch(t.code){case "PYTHON_NOT_FOUND":return `RapidKit (npm) could not find Python (python3/python/py) on your PATH.
|
|
3
|
+
Install Python 3.10+ and ensure \`${c()}\` is available, then retry.
|
|
4
|
+
Tip: 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.
|
|
5
|
+
`+(a()?`Ensure Python is installed with venv support.
|
|
6
|
+
`:`Ensure Python venv support is installed (e.g., python3-venv).
|
|
7
|
+
`)+`Details: ${t.message}`;case "BRIDGE_PIP_BOOTSTRAP_FAILED":return `RapidKit (npm) could not bootstrap pip inside the bridge virtual environment.
|
|
8
|
+
`+(a()?`Ensure pip is available for your Python installation and retry.
|
|
9
|
+
`:`Install python3-venv/python3-pip and retry.
|
|
10
|
+
`)+`Details: ${t.message}`;case "BRIDGE_PIP_UPGRADE_FAILED":return `RapidKit (npm) could not upgrade pip in the bridge virtual environment.
|
|
11
|
+
Check your network/proxy or disable RAPIDKIT_BRIDGE_UPGRADE_PIP.
|
|
12
|
+
Details: ${t.message}`;case "BRIDGE_PIP_INSTALL_FAILED":return `RapidKit (npm) could not install rapidkit-core in the bridge virtual environment.
|
|
13
|
+
Check your network/proxy, or install manually with: pipx install rapidkit-core.
|
|
14
|
+
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 N(){let t=process.env.RAPIDKIT_CORE_PYTHON_PACKAGE;return t&&t.trim()?t.trim():"rapidkit-core"}function ot(){let t=N(),e=process.env.RAPIDKIT_CORE_PYTHON_PACKAGE_ID,r=e&&e.trim()?`${t}|${e.trim()}`:t;return it.createHash("sha256").update(r).digest("hex").slice(0,12)}function b(){let t=process.env.XDG_CACHE_HOME;return t&&t.trim()?t:u.join(U.homedir(),".cache")}function st(){return u.join(b(),"rapidkit","npm-bridge","venv")}function W(){let t=ot();return u.join(b(),"rapidkit","npm-bridge",`venv-${t}`)}function G(t){return f(t)}function K(t){return g(t)}function at(t){return /[<>=!~]=|@|\.whl$|\.tar\.gz$|\.zip$|git\+|https?:\/\//.test(t)}function ct(t){return u.dirname(u.dirname(t))}function z(){return u.join(b(),"rapidkit","npm-bridge","core-commands.json")}async function X(t){let e=!!process.env.RAPIDKIT_DEBUG,r=n=>{e&&process.stderr.write(`[DEBUG] tryRapidkit(${t}): ${n}
|
|
15
|
+
`);};try{r("probing interpreter-specific rapidkit script");let o=((await execa(t,w(t,["-c","import sysconfig, os; print(os.path.join(sysconfig.get_path('scripts'), 'rapidkit'))"]),{reject:false,stdio:"pipe",timeout:2e3})).stdout??"").toString().trim();if(r(`script path: ${o}`),o)try{if(await d.pathExists(o)){r(`found script at ${o}; invoking --version --json`);let i=await execa(o,["--version","--json"],{reject:false,stdio:"pipe",timeout:4e3});if(r(`script exitCode=${i.exitCode}`),i.exitCode===0){let a=(i.stdout??"").toString().trim();try{let s=JSON.parse(a),c=!!s&&typeof s=="object"&&s!==null&&"version"in s;if(r(`script JSON parse ok=${c}`),c)return true}catch{r("script output not valid JSON");}}}}catch(i){r(`interpreter-specific script probe failed: ${String(i)}`);}}catch(n){r(`interpreter-specific script probe error: ${String(n)}`);}try{r('probing importlib.find_spec("rapidkit")');let n=await execa(t,w(t,["-c","import importlib.util; print(1 if importlib.util.find_spec('rapidkit') else 0)"]),{reject:false,stdio:"pipe",timeout:2e3});if(r(`import probe exitCode=${n.exitCode} stdout=${(n.stdout??"").toString().trim()}`),n.exitCode===0&&(n.stdout??"").toString().trim()==="1")return true}catch(n){r(`import probe error: ${String(n)}`);}try{r("probing python -m rapidkit");let n=await execa(t,w(t,["-m","rapidkit","--version","--json"]),{reject:false,stdio:"pipe",timeout:8e3});if(r(`-m probe exitCode=${n.exitCode}`),n.exitCode===0)return true}catch(n){r(`-m probe error: ${String(n)}`);}try{r("probing PATH for rapidkit executables");let n=(process.env.PATH??"").split(u.delimiter).filter(Boolean);for(let o of n){let i=u.join(o,a()?"rapidkit.exe":"rapidkit");try{if(await d.pathExists(i)){r(`found candidate on PATH: ${i}; invoking --version --json`);let a=await execa(i,["--version","--json"],{reject:false,stdio:"pipe",timeout:4e3});if(r(`candidate exitCode=${a.exitCode}`),a.exitCode===0){let s=(a.stdout??"").toString().trim();try{let c=JSON.parse(s);if(c&&typeof c=="object"&&c!==null&&"version"in c)return true}catch{r("candidate output not valid JSON, skipping");}}}}catch(a){r(`error probing candidate ${i}: ${String(a)}`);}}return r("no valid rapidkit found on PATH"),false}catch(n){return r(`PATH probe error: ${String(n)}`),false}}async function T(t){let e=(t??"").toString().trim();if(!e)return false;try{let r=JSON.parse(e);return !!r&&typeof r=="object"&&r!==null&&"version"in r}catch{return false}}async function dt(t){let e=u.relative(".",g(".venv")),r=u.relative(".",f(".venv")),n=t;for(let o=0;o<25;o+=1){let i=u.join(n,e);if(await d.pathExists(i)){let c=await execa(i,["--version","--json"],{reject:false,stdio:"pipe",timeout:1500,cwd:n});if(c.exitCode===0&&await T(c.stdout))return {cmd:i,baseArgs:[]}}let a=u.join(n,r);if(await d.pathExists(a)){let c=await execa(a,["-m","rapidkit","--version","--json"],{reject:false,stdio:"pipe",timeout:1500,cwd:n});if(c.exitCode===0&&await T(c.stdout))return {cmd:a,baseArgs:["-m","rapidkit"]}}let s=u.dirname(n);if(s===n)break;n=s;}return null}async function pt(t){try{let e=u.join(t,".python-version");if(await d.pathExists(e)){let n=(await d.readFile(e,"utf-8")).trim();if(n)return n}}catch{}try{let e=u.join(t,".rapidkit-workspace");if(await d.pathExists(e)){let r=await d.readFile(e,"utf-8"),n=JSON.parse(r);if(n.pythonVersion)return n.pythonVersion}}catch{}return null}async function M(t){if(t&&t.trim())try{let i=await dt(t);if(i){let a=u.dirname(i.cmd).includes(".venv")?u.dirname(u.dirname(u.dirname(i.cmd))):u.dirname(i.cmd),s=await pt(a);return s&&(process.env.PYENV_VERSION=s),i}}catch{}let e=await mt();if(e.kind==="venv"){let i=ct(e.pythonPath),a=K(i);return await d.pathExists(a)?{cmd:a,baseArgs:[]}:{cmd:e.pythonPath,baseArgs:["-m","rapidkit"]}}try{if((await execa(e.cmd,["-m","rapidkit","--version","--json"],{reject:false,stdio:"pipe",timeout:4e3})).exitCode===0)return {cmd:e.cmd,baseArgs:["-m","rapidkit"]}}catch{}try{let a=((await execa(e.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 s=await execa(a,["--version","--json"],{reject:false,stdio:"pipe",timeout:4e3});if(s.exitCode===0&&await T(s.stdout))return {cmd:a,baseArgs:[]}}catch{}}catch{}let r=W(),n=await R(e.cmd),o=K(r);return await d.pathExists(o)?{cmd:o,baseArgs:[]}:{cmd:n,baseArgs:["-m","rapidkit"]}}async function $(){for(let t of Y())try{return await execa(t,w(t,["--version"]),{reject:false,stdio:"pipe",timeout:2e3}),t}catch{}return null}async function ut(){let t=!!process.env.RAPIDKIT_DEBUG,e$1=n=>{t&&process.stderr.write(`[DEBUG] checkRapidkitCore: ${n}
|
|
16
|
+
`);},r=Array.from(new Set([...d$1(),...e(14,10).map(n=>n.command)]));for(let n of r)try{e$1(`Method 1: trying ${n} import`);let o=await execa(n,w(n,["-c","import rapidkit_core; print(1)"]),{reject:false,stdio:"pipe",timeout:3e3});if(o.exitCode===0&&o.stdout?.trim()==="1")return e$1(`\u2713 Found via ${n} import`),true}catch{continue}for(let n of r)try{e$1(`Method 2: trying ${n} -m pip show`);let o=await execa(n,w(n,["-m","pip","show","rapidkit-core"]),{reject:false,stdio:"pipe",timeout:3e3});if(o.exitCode===0&&o.stdout?.includes("Name: rapidkit-core"))return e$1(`\u2713 Found via ${n} -m pip show`),true}catch{continue}for(let n of ["pip","pip3"])try{e$1(`Method 3: trying ${n} show`);let o=await execa(n,["show","rapidkit-core"],{reject:false,stdio:"pipe",timeout:3e3});if(o.exitCode===0&&o.stdout?.includes("Name: rapidkit-core"))return e$1(`\u2713 Found via ${n} show`),true}catch{continue}try{e$1("Method 4: checking pyenv versions");let n=await execa("pyenv",["versions","--bare"],{reject:false,stdio:"pipe",timeout:3e3});if(n.exitCode===0&&n.stdout){let o=n.stdout.split(`
|
|
17
|
+
`).filter(i=>i.trim());e$1(`Found pyenv versions: ${o.join(", ")}`);for(let i of o){let a=process.env.PYENV_ROOT||u.join(U.homedir(),".pyenv"),s=u.join(a,"versions",i.trim(),"bin","pip");try{let c=await execa(s,["show","rapidkit-core"],{reject:false,stdio:"pipe",timeout:3e3});if(c.exitCode===0&&c.stdout?.includes("Name: rapidkit-core"))return e$1(`\u2713 Found in pyenv ${i}`),true}catch{try{let c=await execa("pyenv",["exec","pip","show","rapidkit-core"],{reject:false,stdio:"pipe",timeout:3e3,env:{...process.env,PYENV_VERSION:i.trim()}});if(c.exitCode===0&&c.stdout?.includes("Name: rapidkit-core"))return e$1(`\u2713 Found in pyenv ${i} via PYENV_VERSION`),true}catch{continue}}}}}catch{e$1("pyenv not available");}for(let n of r)try{e$1(`Method 5: checking ${n} user site`);let o=await execa(n,w(n,["-m","site","--user-site"]),{reject:false,stdio:"pipe",timeout:3e3});if(o.exitCode===0&&o.stdout){let i=o.stdout.trim(),a=u.join(i,"rapidkit_core");if(await d.pathExists(a))return e$1("\u2713 Found in user site-packages"),true}}catch{continue}try{e$1("Method 6: checking pipx");let n=await execa("pipx",["list"],{reject:false,stdio:"pipe",timeout:3e3});if(n.exitCode===0&&n.stdout?.includes("rapidkit-core"))return e$1("\u2713 Found via pipx"),true}catch{e$1("pipx not available");}for(let n of r)try{e$1(`Method 6: checking ${n} -m pipx list`);let o=await execa(n,w(n,["-m","pipx","list"]),{reject:false,stdio:"pipe",timeout:3e3});if(o.exitCode===0&&o.stdout?.includes("rapidkit-core"))return e$1(`\u2713 Found via ${n} -m pipx list`),true}catch{continue}try{if(e$1("Method 7: checking poetry"),(await execa("poetry",["show","rapidkit-core"],{reject:false,stdio:"pipe",timeout:3e3})).exitCode===0)return e$1("\u2713 Found via poetry"),true}catch{e$1("poetry check failed");}for(let n of r)try{if(e$1(`Method 7: checking ${n} -m poetry show rapidkit-core`),(await execa(n,w(n,["-m","poetry","show","rapidkit-core"]),{reject:false,stdio:"pipe",timeout:3e3})).exitCode===0)return e$1(`\u2713 Found via ${n} -m poetry`),true}catch{continue}try{e$1("Method 8: checking conda");let n=await execa("conda",["list","rapidkit-core"],{reject:false,stdio:"pipe",timeout:3e3});if(n.exitCode===0&&n.stdout?.includes("rapidkit-core"))return e$1("\u2713 Found via conda"),true}catch{e$1("conda not available");}return e$1("\u2717 Not found in any environment"),false}async function R(t){let e=W(),r=st(),n=N(),o=[e];!at(n)&&!await d.pathExists(e)&&await d.pathExists(r)&&o.push(r);for(let m of o){let h=G(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=e,a={...process.env,PIP_DISABLE_PIP_VERSION_CHECK:"1",PIP_NO_PYTHON_VERSION_WARNING:"1"},s=Math.max(0,Number(process.env.RAPIDKIT_BRIDGE_PIP_RETRY??"2")),c=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")),v=m=>new Promise(h=>setTimeout(h,m)),P=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 A=(g.stdout??"").toString(),I=(g.stderr??"").toString(),C=[A,I].filter(Boolean).join(`
|
|
18
|
+
`),tt=C?`${m} ${h.join(" ")}
|
|
19
|
+
${C}`:`${m} ${h.join(" ")}`;throw new Error(tt)},_=async(m,h,f)=>{let g=0;for(;;)try{await P(m,h,f);return}catch(A){if(g>=s)throw A;let I=Math.floor(Math.random()*200),C=c*Math.pow(2,g)+I;g+=1,await v(C);}};try{await d.ensureDir(u.dirname(i));try{await P(t,w(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=G(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 _(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 _(m,["-m","pip","install","-U",N()],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 mt(){if(process.env.RAPIDKIT_BRIDGE_FORCE_VENV==="1"){let r=await $();if(!r)throw new y("PYTHON_NOT_FOUND","No Python interpreter found (python3/python/py).");return {kind:"venv",pythonPath:await R(r)}}for(let r of Y())if(await X(r))return {kind:"system",cmd:r};let t=await $();if(!t)throw new y("PYTHON_NOT_FOUND","No Python interpreter found (python3/python/py).");return {kind:"venv",pythonPath:await R(t)}}async function kt(t,e){try{let r=await M(e?.cwd),n=r.cmd,o=[...r.baseArgs,...t];if(t[0]==="init"){let s=await execa(n,o,{cwd:e?.cwd,env:{...process.env,...e?.env},reject:false,stdio:"pipe"}),c=V((s.stdout??"").toString()),l=V((s.stderr??"").toString());return c&&process.stdout.write(c.endsWith(`
|
|
20
|
+
`)?c:`${c}
|
|
21
|
+
`),l&&process.stderr.write(l.endsWith(`
|
|
22
|
+
`)?l:`${l}
|
|
23
|
+
`),typeof s.exitCode=="number"?s.exitCode:1}let a=await execa(n,o,{cwd:e?.cwd,env:{...process.env,...e?.env},reject:false,stdio:"inherit"});return typeof a.exitCode=="number"?a.exitCode:1}catch(r){return process.stderr.write(`${k(r)}
|
|
24
|
+
`),1}}var lt=[{pattern:/RapidKitError:\s*Directory '([^']+)' exists and force is not set/,message:t=>`\u274C Directory "${u.basename(t[1])}" already exists.
|
|
25
|
+
\u{1F4A1} Choose a different name, or remove the existing directory first:
|
|
26
|
+
rm -rf ${t[1]}`},{pattern:/RapidKitError:\s*Project name '([^']+)' is (invalid|not allowed)/i,message:t=>`\u274C Invalid project name: "${t[1]}"
|
|
27
|
+
\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]}"
|
|
28
|
+
\u{1F4A1} Run "npx rapidkit list" to see available kits.`},{pattern:/RapidKitError:\s*(.+)/,message:t=>`\u274C ${t[1].trim()}`}];async function Rt(t,e){let{spawn:r}=await import('child_process');try{let n=await M(e?.cwd),o=n.cmd,i=[...n.baseArgs,...t];return await new Promise(a=>{let s=r(o,i,{cwd:e?.cwd,env:{...process.env,...e?.env},stdio:["inherit","inherit","pipe"]}),c=[];s.stderr?.on("data",l=>{c.push(l);}),s.on("close",l=>{let v=l??1;if(v!==0&&c.length>0){let P=Buffer.concat(c).toString("utf8");for(let{pattern:_,message:m}of lt){let h=P.match(_);if(h){process.stderr.write(m(h)+`
|
|
29
|
+
`),a(v);return}}process.stderr.write(P);}a(v);}),s.on("error",l=>{process.stderr.write(`${k(l)}
|
|
30
|
+
`),a(1);});})}catch(n){return process.stderr.write(`${k(n)}
|
|
31
|
+
`),1}}async function E(t,e){try{let r=await M(e?.cwd),n=r.cmd,o=[...r.baseArgs,...t],i=await execa(n,o,{cwd:e?.cwd,env:{...process.env,...e?.env},reject:false,stdio:"pipe"});return {exitCode:typeof i.exitCode=="number"?i.exitCode:1,stdout:(i.stdout??"").toString(),stderr:(i.stderr??"").toString()}}catch(r){return {exitCode:1,stdout:"",stderr:`${k(r)}
|
|
32
|
+
`}}}function q(t){let e=new Set,r=t.split(`
|
|
33
|
+
`),n=false;for(let o of r){let i=o.replace(/\r$/,"");if(!n){/^\s*Commands:\s*$/i.test(i)&&(n=true);let c=i.match(/^\s*rapidkit\s+([a-z0-9_-]+)\b/i);if(c){let l=c[1].trim();l&&!l.startsWith("-")&&e.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 s=a[1].trim();s&&!s.startsWith("-")&&e.add(s);}return e}async function Q(){let t=z();if(!await d.pathExists(t))return null;try{let e=await d.readJson(t);if(e&&e.schema_version===1&&Array.isArray(e.commands))return e}catch{}return null}async function L(t){let e=z();await d.ensureDir(u.dirname(e)),await d.writeJson(e,t,{spaces:2});}async function ft(){let t=await E(["version","--json"],{cwd:process.cwd()});if(t.exitCode===0)try{let r=JSON.parse(t.stdout)?.version;return typeof r=="string"?r:void 0}catch{return}}async function ht(){let t=await E(["commands","--json"],{cwd:process.cwd()});if(t.exitCode!==0)return null;try{let e=JSON.parse(t.stdout);if(e?.schema_version!==1||!Array.isArray(e.commands))return null;let r=e.commands.filter(n=>typeof n=="string");return r.length?r:null}catch{return null}}async function bt(){let e=Date.now(),r=await Q(),n=await ft(),o=!!r?.commands?.length;if(o&&e-r.fetched_at<864e5&&(!n||!r.rapidkit_version||r.rapidkit_version===n))return new Set(r.commands);let i=await ht();if(i?.length){let l=Array.from(new Set(i)).sort();return await L({schema_version:1,fetched_at:e,rapidkit_version:n,commands:l}),new Set(l)}let a=await E(["--help"],{cwd:process.cwd()});if(a.exitCode!==0)return o&&r?.commands?new Set(r.commands):new Set(j);let s=q(a.stdout);if(s.size===0)return new Set(j);let c=Array.from(s).sort();return await L({schema_version:1,fetched_at:e,rapidkit_version:n,commands:c}),s}async function At(){let e=Date.now(),r=await Q();return !r||e-r.fetched_at>=864e5||!r.commands?.length?null:new Set(r.commands)}function Z(){return u.join(b(),"rapidkit","npm-bridge","modules-catalog.json")}async function gt(){let t=Z();if(!await d.pathExists(t))return null;try{let e=await d.readJson(t);if(e&&e.schema_version===1&&Array.isArray(e.modules))return e}catch{}return null}async function J(t){let e=Z();await d.ensureDir(u.dirname(e)),await d.writeJson(e,t,{spaces:2});}function H(t){try{return JSON.parse(t)}catch{return null}}async function It(t={}){let e=typeof t.ttlMs=="number"?t.ttlMs:18e5,r=Date.now(),n=await gt();if(n?.fetched_at&&r-n.fetched_at<e)return n;let o=["modules","list","--json-schema","1"];t.category&&o.push("--category",t.category),t.tag&&o.push("--tag",t.tag),t.detailed&&o.push("--detailed");let i=await E(o,{cwd:t.cwd,env:t.env});if(i.exitCode===0){let s=H(i.stdout);if(s&&s.schema_version===1&&Array.isArray(s.modules)){let c={...s,fetched_at:r};return await J(c),c}}let a=await E(["modules","list","--json"],{cwd:t.cwd,env:t.env});if(a.exitCode===0){let s=H(a.stdout);if(Array.isArray(s)){let c={schema_version:1,generated_at:new Date().toISOString(),filters:{category:t.category??null,tag:t.tag??null,detailed:!!t.detailed},stats:{total:s.length,returned:s.length,invalid:0},modules:s,source:"legacy-json",fetched_at:r};return await J(c),c}}return n||null}var Dt={pickSystemPython:$,ensureBridgeVenv:R,parseCoreCommandsFromHelp:q,tryRapidkit:X,checkRapidkitCoreAvailable:ut};export{j as a,ut as b,mt as c,kt as d,Rt as e,E as f,bt as g,At as h,It as i,Dt as j};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import p from'os';import r from'path';function a(o=process.platform){return o==="win32"?"windows":o==="linux"?"linux":o==="darwin"?"macos":"other"}function n(o=process.platform){return a(o)==="windows"}function u(o=process.platform){return n(o)}function l(o=process.platform){return n(o)?"python":"python3"}function g(o=process.platform){return n(o)?["python","py","python3"]:["python3","python"]}function h(o=14,t=10,s=process.platform){let i=[];if(n(s)){for(let e=o;e>=t;e-=1)i.push({command:"py",args:[`-3.${e}`,"--version"]});return i.push({command:"py",args:["-3","--version"]}),i.push({command:"python",args:["--version"]}),i}for(let e=o;e>=t;e-=1)i.push({command:`python3.${e}`,args:["--version"]});return i.push({command:"python3",args:["--version"]}),i.push({command:"python",args:["--version"]}),i}function P(o,t=process.platform){return n(t)?r.join(o,"Scripts","python.exe"):r.join(o,"bin","python")}function y(o,t=process.platform){return n(t)?r.join(o,"Scripts","rapidkit.exe"):r.join(o,"bin","rapidkit")}function S(o,t=process.platform){return n(t)?r.join(o,"Scripts","activate"):r.join(o,"bin","activate")}function x(o,t=process.platform){return n(t)?[r.join(o,"rapidkit.cmd"),r.join(o,".rapidkit","rapidkit.cmd")]:[r.join(o,"rapidkit"),r.join(o,".rapidkit","rapidkit")]}function j(o=process.env,t=process.platform){let s=o.XDG_CONFIG_HOME||o.APPDATA||r.join(p.homedir(),".config");return n(t)?r.join(s,"rapidkit"):r.join(p.homedir(),".rapidkit")}export{n as a,u as b,l as c,g as d,h as e,P as f,y as g,S as h,x as i,j};
|