rapidkit 0.16.3 → 0.16.4
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/dist/index.js +195 -167
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
[${
|
|
4
|
-
\u26A0\uFE0F Update available: ${
|
|
5
|
-
`))):
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
import v from'path';import {fileURLToPath}from'url';import m from'chalk';import {execa}from'execa';import {createRequire}from'module';import*as B from'os';import B__default from'os';import*as E from'fs-extra';import N,{promises}from'fs';import mt from'ora';import {Command,Option}from'commander';import Wt from'inquirer';import {spawn}from'child_process';import Te from'validate-npm-package-name';import li from'nunjucks';import mi from'crypto';var Re=Object.defineProperty;var et=(t,e)=>()=>(t&&(e=t(t=0)),e);var _t=(t,e)=>{for(var i in e)Re(t,i,{get:e[i],enumerable:true});};var $=et(()=>{});var Ct,g,ct=et(()=>{$();Ct=class{debugEnabled=false;setDebug(e){this.debugEnabled=e;}debug(e,...i){this.debugEnabled&&console.log(m.gray(`[DEBUG] ${e}`),...i);}info(e,...i){console.log(m.blue(e),...i);}success(e,...i){console.log(m.green(e),...i);}warn(e,...i){console.log(m.yellow(e),...i);}error(e,...i){console.error(m.red(e),...i);}step(e,i,r){console.log(m.cyan(`
|
|
3
|
+
[${e}/${i}]`),m.white(r));}},g=new Ct;});async function Yt(){try{g.debug("Checking for updates...");let{stdout:t}=await execa("npm",["view",Ce,"version"],{timeout:3e3}),e=t.trim();e&&e!==Et?(console.log(m.yellow(`
|
|
4
|
+
\u26A0\uFE0F Update available: ${Et} \u2192 ${e}`)),console.log(m.cyan(`Run: npm install -g rapidkit@latest
|
|
5
|
+
`))):g.debug("You are using the latest version");}catch{g.debug("Could not check for updates");}}function M(){return Et}var Ce,Ee,Ie,Et,pt=et(()=>{$();ct();Ce="rapidkit",Ee=createRequire(import.meta.url),Ie=Ee("../package.json"),Et=Ie?.version??"0.0.0";});var Ot={};_t(Ot,{__test__:()=>He,checkRapidkitCoreAvailable:()=>oe,getCachedCoreTopLevelCommands:()=>Tt,getCoreTopLevelCommands:()=>Be,resolveRapidkitPython:()=>nt,runCoreRapidkit:()=>V,runCoreRapidkitCapture:()=>Dt});function Nt(t){return t instanceof ot?t.code==="PYTHON_NOT_FOUND"?"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.":`RapidKit (npm) bridge error: ${t.message}`:`RapidKit (npm) failed to run the Python core engine: ${t instanceof Error?t.message:String(t)}`}function Ve(){let t=process.env.RAPIDKIT_CORE_PYTHON_PACKAGE;return t&&t.trim()?t.trim():"rapidkit-core"}function te(){let t=process.env.XDG_CACHE_HOME;return t&&t.trim()?t:v.join(B__default.homedir(),".cache")}function It(){return v.join(te(),"rapidkit","npm-bridge","venv")}function Xt(t){return process.platform==="win32"?v.join(t,"Scripts","python.exe"):v.join(t,"bin","python")}function Qt(t){return process.platform==="win32"?v.join(t,"Scripts","rapidkit.exe"):v.join(t,"bin","rapidkit")}function ee(){return v.join(te(),"rapidkit","npm-bridge","core-commands.json")}async function ie(t){let e=!!process.env.RAPIDKIT_DEBUG,i=r=>{e&&process.stderr.write(`[DEBUG] tryRapidkit(${t}): ${r}
|
|
6
|
+
`);};try{i("probing interpreter-specific rapidkit script");let n=((await execa(t,["-c","import sysconfig, os; print(os.path.join(sysconfig.get_path('scripts'), 'rapidkit'))"],{reject:!1,stdio:"pipe",timeout:2e3})).stdout??"").toString().trim();if(i(`script path: ${n}`),n)try{if(await E.pathExists(n)){i(`found script at ${n}; invoking --version --json`);let o=await execa(n,["--version","--json"],{reject:!1,stdio:"pipe",timeout:4e3});if(i(`script exitCode=${o.exitCode}`),o.exitCode===0){let a=(o.stdout??"").toString().trim();try{let s=JSON.parse(a),c=!!s&&typeof s=="object"&&s!==null&&"version"in s;if(i(`script JSON parse ok=${c}`),c)return !0}catch{i("script output not valid JSON");}}}}catch(o){i(`interpreter-specific script probe failed: ${String(o)}`);}}catch(r){i(`interpreter-specific script probe error: ${String(r)}`);}try{i('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:!1,stdio:"pipe",timeout:2e3});if(i(`import probe exitCode=${r.exitCode} stdout=${(r.stdout??"").toString().trim()}`),r.exitCode===0&&(r.stdout??"").toString().trim()==="1")return !0}catch(r){i(`import probe error: ${String(r)}`);}try{i("probing python -m rapidkit");let r=await execa(t,["-m","rapidkit","--version","--json"],{reject:!1,stdio:"pipe",timeout:8e3});if(i(`-m probe exitCode=${r.exitCode}`),r.exitCode===0)return !0}catch(r){i(`-m probe error: ${String(r)}`);}try{i("probing PATH for rapidkit executables");let r=(process.env.PATH??"").split(v.delimiter).filter(Boolean);for(let n of r){let o=v.join(n,process.platform==="win32"?"rapidkit.exe":"rapidkit");try{if(await E.pathExists(o)){i(`found candidate on PATH: ${o}; invoking --version --json`);let a=await execa(o,["--version","--json"],{reject:!1,stdio:"pipe",timeout:4e3});if(i(`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 !0}catch{i("candidate output not valid JSON, skipping");}}}}catch(a){i(`error probing candidate ${o}: ${String(a)}`);}}return i("no valid rapidkit found on PATH"),!1}catch(r){return i(`PATH probe error: ${String(r)}`),false}}async function St(t){let e=(t??"").toString().trim();if(!e)return false;try{let i=JSON.parse(e);return !!i&&typeof i=="object"&&i!==null&&"version"in i}catch{return false}}async function We(t){let e=process.platform==="win32",i=e?v.join(".venv","Scripts","rapidkit.exe"):v.join(".venv","bin","rapidkit"),r=e?v.join(".venv","Scripts","python.exe"):v.join(".venv","bin","python"),n=t;for(let o=0;o<25;o+=1){let a=v.join(n,i);if(await E.pathExists(a)){let d=await execa(a,["--version","--json"],{reject:false,stdio:"pipe",timeout:1500,cwd:n});if(d.exitCode===0&&await St(d.stdout))return {cmd:a,baseArgs:[]}}let s=v.join(n,r);if(await E.pathExists(s)){let d=await execa(s,["-m","rapidkit","--version","--json"],{reject:false,stdio:"pipe",timeout:1500,cwd:n});if(d.exitCode===0&&await St(d.stdout))return {cmd:s,baseArgs:["-m","rapidkit"]}}let c=v.dirname(n);if(c===n)break;n=c;}return null}async function Le(t){try{let e=v.join(t,".python-version");if(await E.pathExists(e)){let r=(await E.readFile(e,"utf-8")).trim();if(r)return r}}catch{}try{let e=v.join(t,".rapidkit-workspace");if(await E.pathExists(e)){let i=await E.readFile(e,"utf-8"),r=JSON.parse(i);if(r.pythonVersion)return r.pythonVersion}}catch{}return null}async function re(t){if(t&&t.trim())try{let o=await We(t);if(o){let a=v.dirname(o.cmd).includes(".venv")?v.dirname(v.dirname(v.dirname(o.cmd))):v.dirname(o.cmd),s=await Le(a);return s&&(process.env.PYENV_VERSION=s),o}}catch{}let e=await nt();if(e.kind==="venv"){let o=It(),a=Qt(o);return await E.pathExists(a)?{cmd:a,baseArgs:[]}:{cmd:e.pythonPath,baseArgs:["-m","rapidkit"]}}try{if((await execa(e.cmd,["-m","rapidkit","--version","--json"],{reject:!1,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:!1,stdio:"pipe",timeout:2e3})).stdout??"").toString().trim();if(a&&await E.pathExists(a))try{let s=await execa(a,["--version","--json"],{reject:!1,stdio:"pipe",timeout:4e3});if(s.exitCode===0&&await St(s.stdout))return {cmd:a,baseArgs:[]}}catch{}}catch{}let i=It(),r=await yt(e.cmd),n=Qt(i);return await E.pathExists(n)?{cmd:n,baseArgs:[]}:{cmd:r,baseArgs:["-m","rapidkit"]}}async function At(){for(let t of ["python3","python"])try{return await execa(t,["--version"],{reject:!1,stdio:"pipe",timeout:2e3}),t}catch{}return null}async function oe(){let t=!!process.env.RAPIDKIT_DEBUG,e=i=>{t&&process.stderr.write(`[DEBUG] checkRapidkitCore: ${i}
|
|
7
|
+
`);};for(let i of ["python3","python","python3.10","python3.11","python3.12"])try{e(`Method 1: trying ${i} import`);let r=await execa(i,["-c","import rapidkit_core; print(1)"],{reject:!1,stdio:"pipe",timeout:3e3});if(r.exitCode===0&&r.stdout?.trim()==="1")return e(`\u2713 Found via ${i} import`),!0}catch{continue}for(let i of ["python3","python"])try{e(`Method 2: trying ${i} -m pip show`);let r=await execa(i,["-m","pip","show","rapidkit-core"],{reject:!1,stdio:"pipe",timeout:3e3});if(r.exitCode===0&&r.stdout?.includes("Name: rapidkit-core"))return e(`\u2713 Found via ${i} -m pip show`),!0}catch{continue}for(let i of ["pip","pip3"])try{e(`Method 3: trying ${i} show`);let r=await execa(i,["show","rapidkit-core"],{reject:!1,stdio:"pipe",timeout:3e3});if(r.exitCode===0&&r.stdout?.includes("Name: rapidkit-core"))return e(`\u2713 Found via ${i} show`),!0}catch{continue}try{e("Method 4: checking pyenv versions");let i=await execa("pyenv",["versions","--bare"],{reject:!1,stdio:"pipe",timeout:3e3});if(i.exitCode===0&&i.stdout){let r=i.stdout.split(`
|
|
8
|
+
`).filter(n=>n.trim());e(`Found pyenv versions: ${r.join(", ")}`);for(let n of r){let o=process.env.PYENV_ROOT||v.join(B__default.homedir(),".pyenv"),a=v.join(o,"versions",n.trim(),"bin","pip");try{let s=await execa(a,["show","rapidkit-core"],{reject:!1,stdio:"pipe",timeout:3e3});if(s.exitCode===0&&s.stdout?.includes("Name: rapidkit-core"))return e(`\u2713 Found in pyenv ${n}`),!0}catch{try{let s=await execa("bash",["-c",`PYENV_VERSION=${n.trim()} pyenv exec pip show rapidkit-core`],{reject:!1,stdio:"pipe",timeout:3e3});if(s.exitCode===0&&s.stdout?.includes("Name: rapidkit-core"))return e(`\u2713 Found in pyenv ${n} via PYENV_VERSION`),!0}catch{continue}}}}}catch{e("pyenv not available");}for(let i of ["python3","python"])try{e(`Method 5: checking ${i} user site`);let r=await execa(i,["-m","site","--user-site"],{reject:!1,stdio:"pipe",timeout:3e3});if(r.exitCode===0&&r.stdout){let n=r.stdout.trim(),o=v.join(n,"rapidkit_core");if(await E.pathExists(o))return e("\u2713 Found in user site-packages"),!0}}catch{continue}try{e("Method 6: checking pipx");let i=await execa("pipx",["list"],{reject:!1,stdio:"pipe",timeout:3e3});if(i.exitCode===0&&i.stdout?.includes("rapidkit-core"))return e("\u2713 Found via pipx"),!0}catch{e("pipx not available");}try{if(e("Method 7: checking poetry"),(await execa("poetry",["show","rapidkit-core"],{reject:!1,stdio:"pipe",timeout:3e3})).exitCode===0)return e("\u2713 Found via poetry"),!0}catch{e("poetry check failed");}try{e("Method 8: checking conda");let i=await execa("conda",["list","rapidkit-core"],{reject:!1,stdio:"pipe",timeout:3e3});if(i.exitCode===0&&i.stdout?.includes("rapidkit-core"))return e("\u2713 Found via conda"),!0}catch{e("conda not available");}return e("\u2717 Not found in any environment"),false}async function yt(t){let e=It(),i=Xt(e);if(await E.pathExists(i))try{let o=await execa(i,["-c","import importlib.util; print(1 if importlib.util.find_spec('rapidkit') else 0)"],{reject:!1,stdio:"pipe",timeout:2e3});if(o.exitCode===0&&(o.stdout??"").toString().trim()==="1")return i;await E.remove(e);}catch{await E.remove(e);}let r={...process.env,PIP_DISABLE_PIP_VERSION_CHECK:"1",PIP_NO_PYTHON_VERSION_WARNING:"1"},n=async(o,a)=>{let s=await execa(o,a,{reject:false,stdio:["ignore","pipe","inherit"],env:r});if(s.exitCode===0)return;let c=(s.stdout??"").toString(),d=(s.stderr??"").toString(),p=[c,d].filter(Boolean).join(`
|
|
9
|
+
`),l=p?`${o} ${a.join(" ")}
|
|
10
|
+
${p}`:`${o} ${a.join(" ")}`;throw new Error(l)};try{await E.ensureDir(v.dirname(e)),await n(t,["-m","venv",e]);let o=Xt(e);if((await execa(o,["-m","pip","--version"],{reject:!1,stdio:"pipe",timeout:2e3})).exitCode!==0&&(await execa(o,["-m","ensurepip","--default-pip"],{reject:!1,stdio:["ignore","pipe","inherit"],env:r})).exitCode!==0)throw new Error(`Failed to install pip in virtual environment.
|
|
11
|
+
Your Python installation may be missing the ensurepip module.
|
|
12
|
+
On Debian/Ubuntu, install: sudo apt install python3-venv python3-pip`);return process.env.RAPIDKIT_BRIDGE_UPGRADE_PIP==="1"&&await n(o,["-m","pip","install","-U","pip"]),await n(o,["-m","pip","install","-U",Ve()]),o}catch(o){throw new ot("BRIDGE_VENV_BOOTSTRAP_FAILED",Nt(o))}}async function nt(){if(process.env.RAPIDKIT_BRIDGE_FORCE_VENV==="1"){let i=await At();if(!i)throw new ot("PYTHON_NOT_FOUND","No Python interpreter found (python3/python).");return {kind:"venv",pythonPath:await yt(i)}}for(let i of ["python3","python"])if(await ie(i))return {kind:"system",cmd:i};let t=await At();if(!t)throw new ot("PYTHON_NOT_FOUND","No Python interpreter found (python3/python).");return {kind:"venv",pythonPath:await yt(t)}}async function V(t,e){try{let i=await re(e?.cwd),r=i.cmd,n=[...i.baseArgs,...t],o=await execa(r,n,{cwd:e?.cwd,env:{...process.env,...e?.env},reject:!1,stdio:"inherit"});return typeof o.exitCode=="number"?o.exitCode:1}catch(i){return process.stderr.write(`${Nt(i)}
|
|
13
|
+
`),1}}async function Dt(t,e){try{let i=await re(e?.cwd),r=i.cmd,n=[...i.baseArgs,...t],o=await execa(r,n,{cwd:e?.cwd,env:{...process.env,...e?.env},reject:!1,stdio:"pipe"});return {exitCode:typeof o.exitCode=="number"?o.exitCode:1,stdout:(o.stdout??"").toString(),stderr:(o.stderr??"").toString()}}catch(i){return {exitCode:1,stdout:"",stderr:`${Nt(i)}
|
|
14
|
+
`}}}function ne(t){let e=new Set,i=t.split(`
|
|
15
|
+
`),r=false;for(let n of i){let o=n.replace(/\r$/,"");if(!r){/^\s*Commands:\s*$/i.test(o)&&(r=true);let c=o.match(/^\s*rapidkit\s+([a-z0-9_-]+)\b/i);if(c){let d=c[1].trim();d&&!d.startsWith("-")&&e.add(d);}continue}if(!o.trim())break;if(/^\s*(Options|Arguments|Usage|Commands)\s*:/i.test(o))continue;let a=o.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 ae(){let t=ee();if(!await E.pathExists(t))return null;try{let e=await E.readJson(t);if(e&&e.schema_version===1&&Array.isArray(e.commands))return e}catch{}return null}async function Ge(t){let e=ee();await E.ensureDir(v.dirname(e)),await E.writeJson(e,t,{spaces:2});}async function Ue(){let t=await Dt(["version","--json"],{cwd:process.cwd()});if(t.exitCode===0)try{let i=JSON.parse(t.stdout)?.version;return typeof i=="string"?i:void 0}catch{return}}async function Be(){let e=Date.now(),i=await ae(),r=await Ue(),n=!!i?.commands?.length;if(n&&e-i.fetched_at<864e5&&(!r||!i.rapidkit_version||i.rapidkit_version===r))return new Set(i.commands);let o=await Dt(["--help"],{cwd:process.cwd()});if(o.exitCode!==0)return n&&i?.commands?new Set(i.commands):new Set;let a=ne(o.stdout);if(a.size===0)return new Set;let s=Array.from(a).sort();return await Ge({schema_version:1,fetched_at:e,rapidkit_version:r,commands:s}),a}async function Tt(){let e=Date.now(),i=await ae();return !i||e-i.fetched_at>=864e5||!i.commands?.length?null:new Set(i.commands)}var ot,He,wt=et(()=>{$();ot=class extends Error{code;constructor(e,i){super(i),this.code=e;}};He={pickSystemPython:At,ensureBridgeVenv:yt,parseCoreCommandsFromHelp:ne,tryRapidkit:ie,checkRapidkitCoreAvailable:oe};});var pe={};_t(pe,{createNpmWorkspaceMarker:()=>Kt,isValidWorkspaceMarker:()=>ze,readWorkspaceMarker:()=>Ft,updateWorkspaceMetadata:()=>Ye,writeWorkspaceMarker:()=>vt});async function Ft(t){let e=v.join(t,".rapidkit-workspace");try{if(await E.pathExists(e))return await E.readJson(e)}catch{return null}return null}async function vt(t,e){let i=v.join(t,".rapidkit-workspace"),r=await Ft(t);r?.metadata&&(e.metadata={...r.metadata,...e.metadata}),await E.outputFile(i,JSON.stringify(e,null,2)+`
|
|
16
|
+
`,"utf-8");}async function Ye(t,e){let i=await Ft(t);return i?(i.metadata={...i.metadata,...e,vscode:e.vscode?{...i.metadata?.vscode,...e.vscode}:i.metadata?.vscode,npm:e.npm?{...i.metadata?.npm,...e.npm}:i.metadata?.npm,python:e.python?{...i.metadata?.python,...e.python}:i.metadata?.python},await vt(t,i),true):false}function Kt(t,e,i){return {signature:"RAPIDKIT_WORKSPACE",createdBy:"rapidkit-npm",version:e,createdAt:new Date().toISOString(),name:t,metadata:{npm:{packageVersion:e,installMethod:i,lastUsedAt:new Date().toISOString()}}}}function ze(t){if(!t||typeof t!="object")return false;let e=t;return e.signature==="RAPIDKIT_WORKSPACE"&&typeof e.createdBy=="string"&&typeof e.version=="string"&&typeof e.createdAt=="string"&&typeof e.name=="string"}var Mt=et(()=>{$();});var H={};_t(H,{createProject:()=>ii,createWorkspace:()=>Qe,listWorkspaces:()=>oi,registerProjectInWorkspace:()=>Xe,registerWorkspace:()=>de,syncWorkspaceProjects:()=>qe});async function de(t,e){try{let i=process.env.XDG_CONFIG_HOME||process.env.APPDATA||v.join(B__default.homedir(),".config"),r=process.platform==="win32"?v.join(i,"rapidkit"):v.join(B__default.homedir(),".rapidkit"),n=v.join(r,"workspaces.json");await promises.mkdir(r,{recursive:!0});let o={workspaces:[]};try{let s=await promises.readFile(n,"utf8"),c=JSON.parse(s);c&&Array.isArray(c.workspaces)&&(o=c);}catch{}o.workspaces.some(s=>s.path===t)||(o.workspaces.push({name:e,path:t,mode:"full",projects:[]}),await promises.writeFile(n,JSON.stringify(o,null,2)));}catch{console.warn(m.gray("Note: Could not register workspace in shared registry"));}}async function qe(t,e=false){try{let i=process.env.XDG_CONFIG_HOME||process.env.APPDATA||v.join(B__default.homedir(),".config"),r=process.platform==="win32"?v.join(i,"rapidkit"):v.join(B__default.homedir(),".rapidkit"),n=v.join(r,"workspaces.json"),o={workspaces:[]};try{let p=await promises.readFile(n,"utf8"),l=JSON.parse(p);l&&Array.isArray(l.workspaces)&&(o=l);}catch{e||console.log("\u26A0\uFE0F Workspace registry not found");return}let a=o.workspaces.find(p=>p.path===t);if(!a){e||console.log("\u26A0\uFE0F Workspace not registered in registry");return}Array.isArray(a.projects)||(a.projects=[]);let s=await promises.readdir(t,{withFileTypes:!0}),c=0,d=0;for(let p of s)if(p.isDirectory()&&!p.name.startsWith(".")){let l=v.join(t,p.name),u=v.join(l,".rapidkit","context.json"),k=v.join(l,".rapidkit","project.json");try{let f=!1;try{await promises.access(u),f=!0;}catch{await promises.access(k),f=!0;}f&&(a.projects.some(I=>I.path===l||I.name===p.name)?d++:(a.projects.push({name:p.name,path:l}),c++,e||console.log(`\u2714 Added: ${p.name}`)));}catch{}}c>0?(await promises.writeFile(n,JSON.stringify(o,null,2)),e||console.log(`
|
|
17
|
+
\u2705 Synced ${c} project(s) to registry`)):e||console.log(`
|
|
18
|
+
\u2705 All projects already registered (${d} found)`);}catch(i){e||console.error("\u274C Failed to sync projects:",i.message);}}async function Xe(t,e,i){try{let r=process.env.XDG_CONFIG_HOME||process.env.APPDATA||v.join(B__default.homedir(),".config"),n=process.platform==="win32"?v.join(r,"rapidkit"):v.join(B__default.homedir(),".rapidkit"),o=v.join(n,"workspaces.json");console.log(`[REGISTRY DEBUG] Registry file: ${o}`);let a={workspaces:[]};try{let d=await promises.readFile(o,"utf8"),p=JSON.parse(d);p&&Array.isArray(p.workspaces)&&(a=p),console.log(`[REGISTRY DEBUG] Registry loaded, ${a.workspaces.length} workspaces`);}catch{console.log("[REGISTRY DEBUG] Registry doesn't exist, returning");return}let s=a.workspaces.find(d=>d.path===t);if(!s){console.log("[REGISTRY DEBUG] Workspace not found in registry, returning");return}console.log(`[REGISTRY DEBUG] Workspace found: ${s.name}`),Array.isArray(s.projects)||(s.projects=[]),s.projects.some(d=>d.path===i||d.name===e)?console.log("[REGISTRY DEBUG] Project already exists in registry"):(console.log("[REGISTRY DEBUG] Adding project to registry"),s.projects.push({name:e,path:i}),await promises.writeFile(o,JSON.stringify(a,null,2)),console.log("[REGISTRY DEBUG] Registry updated successfully"));}catch(r){console.log(`[REGISTRY DEBUG] Error: ${r}`);}}async function Qe(t,e){let i=mt("Creating RapidKit workspace...").start();try{await promises.mkdir(t,{recursive:!0}),await promises.mkdir(v.join(t,".rapidkit"),{recursive:!0});let r={workspace_name:e.name,author:e.author,rapidkit_version:M(),created_at:new Date().toISOString(),type:"workspace"};await promises.writeFile(v.join(t,".rapidkit","config.json"),JSON.stringify(r,null,2));let n=Ze();await promises.writeFile(v.join(t,"rapidkit"),n),await promises.chmod(v.join(t,"rapidkit"),493);let o=ti(e.name);if(await promises.writeFile(v.join(t,"README.md"),o),await promises.writeFile(v.join(t,".gitignore"),`# RapidKit workspace
|
|
9
19
|
.env
|
|
10
20
|
.env.*
|
|
11
21
|
!.env.example
|
|
@@ -20,37 +30,37 @@ Thumbs.db
|
|
|
20
30
|
|
|
21
31
|
# Logs
|
|
22
32
|
*.log
|
|
23
|
-
`),await promises.writeFile(
|
|
24
|
-
${
|
|
33
|
+
`),await promises.writeFile(v.join(t,".rapidkit-workspace"),JSON.stringify({signature:"RAPIDKIT_WORKSPACE",createdBy:"rapidkit-npm",version:M(),createdAt:new Date().toISOString(),name:e.name},null,2)),await ei(t),i.succeed("Workspace created!"),!e.skipGit){let s=mt("Initializing git repository...").start();try{await execa("git",["init"],{cwd:t}),await execa("git",["add","."],{cwd:t}),await execa("git",["commit","-m","Initial commit: RapidKit workspace"],{cwd:t}),s.succeed("Git repository initialized");}catch{s.warn("Could not initialize git repository");}}await de(t,e.name),console.log(`
|
|
34
|
+
${m.green("\u2728 RapidKit workspace created successfully!")}
|
|
25
35
|
|
|
26
|
-
${
|
|
27
|
-
${
|
|
36
|
+
${m.bold("\u{1F4C2} Workspace structure:")}
|
|
37
|
+
${t}/
|
|
28
38
|
\u251C\u2500\u2500 rapidkit # Local CLI wrapper
|
|
29
39
|
\u251C\u2500\u2500 .rapidkit/ # Workspace configuration
|
|
30
40
|
\u2502 \u251C\u2500\u2500 config.json # Workspace settings
|
|
31
41
|
\u2502 \u2514\u2500\u2500 templates/ # Project templates
|
|
32
42
|
\u2514\u2500\u2500 README.md
|
|
33
43
|
|
|
34
|
-
${
|
|
35
|
-
${
|
|
36
|
-
${
|
|
37
|
-
${
|
|
38
|
-
${
|
|
39
|
-
${
|
|
44
|
+
${m.bold("\u{1F680} Get started:")}
|
|
45
|
+
${m.cyan(`cd ${e.name}`)}
|
|
46
|
+
${m.cyan("npx rapidkit my-api --template fastapi")}
|
|
47
|
+
${m.cyan("cd my-api")}
|
|
48
|
+
${m.cyan("npx rapidkit init")}
|
|
49
|
+
${m.cyan("npx rapidkit dev")}
|
|
40
50
|
|
|
41
|
-
${
|
|
51
|
+
${m.bold("\u{1F4E6} Available templates:")}
|
|
42
52
|
fastapi - FastAPI + Python (default)
|
|
43
53
|
nestjs - NestJS + TypeScript
|
|
44
54
|
|
|
45
|
-
${
|
|
55
|
+
${m.bold("\u{1F4DA} Commands:")}
|
|
46
56
|
npx rapidkit <name> --template <type> Create a new project
|
|
47
57
|
npx rapidkit init Install dependencies
|
|
48
58
|
npx rapidkit dev Start dev server
|
|
49
59
|
npx rapidkit help Show all commands
|
|
50
60
|
|
|
51
|
-
${
|
|
52
|
-
${
|
|
53
|
-
`);}catch(r){throw i.fail("Failed to create workspace"),r}}function
|
|
61
|
+
${m.gray("Alternative: ./rapidkit dev, make dev")}
|
|
62
|
+
${m.gray("\u{1F4A1} Tip: Install globally (npm i -g rapidkit) to use without npx")}
|
|
63
|
+
`);}catch(r){throw i.fail("Failed to create workspace"),r}}function Ze(){return `#!/usr/bin/env bash
|
|
54
64
|
#
|
|
55
65
|
# RapidKit CLI - Local workspace commands
|
|
56
66
|
# This script provides rapidkit commands within the workspace
|
|
@@ -386,7 +396,7 @@ main() {
|
|
|
386
396
|
print_help
|
|
387
397
|
;;
|
|
388
398
|
version|-v|--version)
|
|
389
|
-
echo "RapidKit CLI (npm workspace) v${
|
|
399
|
+
echo "RapidKit CLI (npm workspace) v${M()}"
|
|
390
400
|
;;
|
|
391
401
|
*)
|
|
392
402
|
echo -e "\${RED}\u274C Unknown command: $cmd\${NC}"
|
|
@@ -398,7 +408,7 @@ main() {
|
|
|
398
408
|
}
|
|
399
409
|
|
|
400
410
|
main "$@"
|
|
401
|
-
`}function
|
|
411
|
+
`}function ti(t){return `# ${t}
|
|
402
412
|
|
|
403
413
|
RapidKit workspace for building API projects.
|
|
404
414
|
|
|
@@ -446,7 +456,7 @@ npx rapidkit dev # Start dev server
|
|
|
446
456
|
|
|
447
457
|
- [RapidKit Documentation](https://rapidkit.dev)
|
|
448
458
|
- [GitHub Repository](https://github.com/Baziar/rapidkit)
|
|
449
|
-
`}async function
|
|
459
|
+
`}async function ei(t){let{fileURLToPath:e}=await import('url'),i=e(import.meta.url),r=v.dirname(i),n=v.resolve(r,".."),o=v.join(n,"templates","kits"),a=v.join(t,".rapidkit","templates"),{default:s}=await import('fs-extra');await s.copy(o,a);let c=v.join(n,"templates","generator.js"),d=v.join(t,".rapidkit","generator.js");await s.copy(c,d);}async function ii(t,e){let i=e.template==="fastapi",r=i?"FastAPI":"NestJS",n=mt(`Creating ${r} project...`).start();try{let{fileURLToPath:o}=await import('url'),a=o(import.meta.url),s=v.dirname(a),c=v.resolve(s,".."),d=i?"fastapi-standard":"nestjs-standard",p=v.join(c,"templates","kits",d);await promises.mkdir(t,{recursive:!0});let l={project_name:i?e.name.replace(/-/g,"_").toLowerCase():e.name.replace(/_/g,"-").toLowerCase(),author:e.author,description:e.description||`${r} application generated with RapidKit`,app_version:"0.1.0",license:"MIT",package_manager:e.package_manager||"npm",created_at:new Date().toISOString(),rapidkit_version:M()};await le(p,t,l);let u=i?`# Python
|
|
450
460
|
__pycache__/
|
|
451
461
|
*.py[cod]
|
|
452
462
|
*$py.class
|
|
@@ -514,11 +524,11 @@ Thumbs.db
|
|
|
514
524
|
|
|
515
525
|
# Coverage
|
|
516
526
|
coverage/
|
|
517
|
-
`;if(await promises.writeFile(
|
|
518
|
-
${
|
|
527
|
+
`;if(await promises.writeFile(v.join(t,".gitignore"),u),n.succeed(`${r} project created!`),!e.skipGit){let f=mt("Initializing git repository...").start();try{await execa("git",["init"],{cwd:t}),await execa("git",["add","."],{cwd:t}),await execa("git",["commit","-m",`Initial commit: ${r} project via RapidKit`],{cwd:t}),f.succeed("Git repository initialized");}catch{f.warn("Could not initialize git repository");}}if(!e.skipInstall&&!i){let f=e.package_manager||"npm",w=mt(`Installing dependencies with ${f}...`).start();try{await execa(f,["install"],{cwd:t}),w.succeed("Dependencies installed");}catch{w.warn(`Could not install dependencies. Run '${f} install' manually.`);}}let k=v.basename(t);console.log(i?`
|
|
528
|
+
${m.green("\u2728 FastAPI project created successfully!")}
|
|
519
529
|
|
|
520
|
-
${
|
|
521
|
-
${
|
|
530
|
+
${m.bold("\u{1F4C2} Project structure:")}
|
|
531
|
+
${t}/
|
|
522
532
|
\u251C\u2500\u2500 .rapidkit/ # RapidKit CLI module
|
|
523
533
|
\u251C\u2500\u2500 src/
|
|
524
534
|
\u2502 \u251C\u2500\u2500 main.py # FastAPI application
|
|
@@ -529,12 +539,12 @@ ${e}/
|
|
|
529
539
|
\u251C\u2500\u2500 pyproject.toml # Poetry configuration
|
|
530
540
|
\u2514\u2500\u2500 README.md
|
|
531
541
|
|
|
532
|
-
${
|
|
533
|
-
${
|
|
534
|
-
${
|
|
535
|
-
${
|
|
542
|
+
${m.bold("\u{1F680} Get started:")}
|
|
543
|
+
${m.cyan(`cd ${k}`)}
|
|
544
|
+
${m.cyan("npx rapidkit init")} ${m.gray("# Install dependencies")}
|
|
545
|
+
${m.cyan("npx rapidkit dev")} ${m.gray("# Start dev server")}
|
|
536
546
|
|
|
537
|
-
${
|
|
547
|
+
${m.bold("\u{1F4DA} Available commands:")}
|
|
538
548
|
npx rapidkit init # Install dependencies (poetry install)
|
|
539
549
|
npx rapidkit dev # Start dev server with hot reload
|
|
540
550
|
npx rapidkit start # Start production server
|
|
@@ -542,13 +552,13 @@ ${l.bold("\u{1F4DA} Available commands:")}
|
|
|
542
552
|
npx rapidkit lint # Lint code
|
|
543
553
|
npx rapidkit format # Format code
|
|
544
554
|
|
|
545
|
-
${
|
|
546
|
-
${
|
|
555
|
+
${m.gray("Alternative: make dev, ./rapidkit dev, poetry run dev")}
|
|
556
|
+
${m.gray("\u{1F4A1} Tip: Install globally (npm i -g rapidkit) to use without npx")}
|
|
547
557
|
`:`
|
|
548
|
-
${
|
|
558
|
+
${m.green("\u2728 NestJS project created successfully!")}
|
|
549
559
|
|
|
550
|
-
${
|
|
551
|
-
${
|
|
560
|
+
${m.bold("\u{1F4C2} Project structure:")}
|
|
561
|
+
${t}/
|
|
552
562
|
\u251C\u2500\u2500 .rapidkit/ # RapidKit CLI module
|
|
553
563
|
\u251C\u2500\u2500 src/
|
|
554
564
|
\u2502 \u251C\u2500\u2500 main.ts # Application entry point
|
|
@@ -559,13 +569,13 @@ ${e}/
|
|
|
559
569
|
\u251C\u2500\u2500 package.json # Dependencies
|
|
560
570
|
\u2514\u2500\u2500 README.md
|
|
561
571
|
|
|
562
|
-
${
|
|
563
|
-
${
|
|
564
|
-
${
|
|
565
|
-
`:""}${
|
|
566
|
-
${
|
|
572
|
+
${m.bold("\u{1F680} Get started:")}
|
|
573
|
+
${m.cyan(`cd ${k}`)}
|
|
574
|
+
${e.skipInstall?m.cyan("npx rapidkit init")+m.gray(" # npm install")+`
|
|
575
|
+
`:""}${m.cyan("cp .env.example .env")}
|
|
576
|
+
${m.cyan("npx rapidkit dev")} ${m.gray("# Start dev server")}
|
|
567
577
|
|
|
568
|
-
${
|
|
578
|
+
${m.bold("\u{1F4DA} Available commands:")}
|
|
569
579
|
npx rapidkit init # Install dependencies
|
|
570
580
|
npx rapidkit dev # Start dev server with hot reload
|
|
571
581
|
npx rapidkit start # Start production server
|
|
@@ -574,48 +584,43 @@ ${l.bold("\u{1F4DA} Available commands:")}
|
|
|
574
584
|
npx rapidkit lint # Lint code
|
|
575
585
|
npx rapidkit format # Format code
|
|
576
586
|
|
|
577
|
-
${
|
|
587
|
+
${m.bold("\u{1F310} API endpoints:")}
|
|
578
588
|
http://localhost:8000/health # Health check
|
|
579
589
|
http://localhost:8000/docs # Swagger docs
|
|
580
590
|
http://localhost:8000/examples/notes # Example API
|
|
581
591
|
|
|
582
|
-
${
|
|
583
|
-
`);}catch(o){throw n.fail(`Failed to create ${r} project`),o}}async function
|
|
592
|
+
${m.gray("\u{1F4A1} Tip: Install globally (npm i -g rapidkit) to use without npx")}
|
|
593
|
+
`);}catch(o){throw n.fail(`Failed to create ${r} project`),o}}async function le(t,e,i){let r=await promises.readdir(t,{withFileTypes:true});for(let n of r){let o=v.join(t,n.name),a=n.name.replace(/\.j2$/,""),s=v.join(e,a);if(n.isDirectory())await promises.mkdir(s,{recursive:true}),await le(o,s,i);else {let c=await promises.readFile(o,"utf-8");n.name.endsWith(".j2")&&(c=ri(c,i)),await promises.writeFile(s,c),(a==="rapidkit"||a==="activate"||a.endsWith(".py")&&s.includes(".rapidkit"))&&await promises.chmod(s,493);}}}function ri(t,e){let i=t;for(let[r,n]of Object.entries(e)){let o=new RegExp(`\\{\\{\\s*${r}\\s*\\}\\}`,"g");i=i.replace(o,String(n));let a=new RegExp(`\\{\\{\\s*${r}\\s*\\|\\s*replace\\s*\\(\\s*['"]([^'"]+)['"]\\s*,\\s*['"]([^'"]*)['"]\\s*\\)\\s*\\}\\}`,"g");i=i.replace(a,(d,p,l)=>String(n).replace(new RegExp(p,"g"),l));let s=new RegExp(`\\{\\{\\s*${r}\\s*\\|\\s*lower\\s*\\}\\}`,"g");i=i.replace(s,String(n).toLowerCase());let c=new RegExp(`\\{\\{\\s*${r}\\s*\\|\\s*replace\\s*\\(\\s*['"]([^'"]+)['"]\\s*,\\s*['"]([^'"]*)['"]\\s*\\)\\s*\\|\\s*lower\\s*\\}\\}`,"g");i=i.replace(c,(d,p,l)=>String(n).replace(new RegExp(p,"g"),l).toLowerCase());}return i}async function oi(){let t=process.env.XDG_CONFIG_HOME||process.env.APPDATA||v.join(B__default.homedir(),".config"),e=process.platform==="win32"?v.join(t,"rapidkit"):v.join(B__default.homedir(),".rapidkit"),i=v.join(e,"workspaces.json");if(!await promises.stat(i).catch(()=>null)){console.log(m.yellow(`
|
|
584
594
|
\u26A0\uFE0F No workspaces registered yet.
|
|
585
|
-
`)),console.log(
|
|
586
|
-
`));return}try{let r=await promises.readFile(i,"utf8"),n=JSON.parse(r);if(!n.workspaces||n.workspaces.length===0){console.log(
|
|
595
|
+
`)),console.log(m.gray(`Create a workspace with: npx rapidkit <workspace-name>
|
|
596
|
+
`));return}try{let r=await promises.readFile(i,"utf8"),n=JSON.parse(r);if(!n.workspaces||n.workspaces.length===0){console.log(m.yellow(`
|
|
587
597
|
\u26A0\uFE0F No workspaces registered yet.
|
|
588
|
-
`));return}console.log(
|
|
598
|
+
`));return}console.log(m.bold(`
|
|
589
599
|
\u{1F4E6} Registered RapidKit Workspaces:
|
|
590
|
-
`));for(let o of n.workspaces)console.log(
|
|
591
|
-
`));}catch(r){console.error(
|
|
592
|
-
\u274C Failed to read workspace registry`)),console.error(
|
|
600
|
+
`));for(let o of n.workspaces)console.log(m.cyan(` ${o.name}`)),console.log(m.gray(` Path: ${o.path}`)),console.log(m.gray(` Projects: ${o.projects?.length||0}`)),await promises.stat(o.path).catch(()=>null)||console.log(m.red(" \u26A0\uFE0F Path not found")),console.log();console.log(m.gray(`Total: ${n.workspaces.length} workspace(s)
|
|
601
|
+
`));}catch(r){console.error(m.red(`
|
|
602
|
+
\u274C Failed to read workspace registry`)),console.error(m.gray(String(r)));}}var J=et(()=>{$();pt();});$();ct();pt();$();ct();var De=".rapidkitrc.json";async function dt(){let t=v.join(B__default.homedir(),De);try{let e=await promises.readFile(t,"utf-8"),i=JSON.parse(e);return g.debug(`Loaded config from ${t}`),i}catch{return g.debug("No user config found, using defaults"),{}}}function ft(t){return process.env.RAPIDKIT_DEV_PATH||t.testRapidKitPath||void 0}$();$();var F=class extends Error{constructor(i,r,n){super(i);this.code=r;this.details=n;this.name="RapidKitError",Error.captureStackTrace(this,this.constructor);}},it=class extends F{constructor(e,i){let r=i?`Python ${e}+ required, found ${i}`:`Python ${e}+ not found`;super(r,"PYTHON_NOT_FOUND","Please install Python from https://www.python.org/downloads/");}},lt=class extends F{constructor(){super("Poetry is not installed","POETRY_NOT_FOUND","Install Poetry from https://python-poetry.org/docs/#installation");}},ut=class extends F{constructor(){super("pipx is not installed","PIPX_NOT_FOUND","Install pipx from https://pypa.github.io/pipx/installation/");}},ht=class extends F{constructor(e){super(`Directory "${e}" already exists`,"DIRECTORY_EXISTS","Please choose a different name or remove the existing directory");}},U=class extends F{constructor(e,i){super(`Invalid project name: "${e}"`,"INVALID_PROJECT_NAME",i);}},A=class extends F{constructor(e,i){let r=`Installation failed at: ${e}`,n=`${i.message}
|
|
593
603
|
|
|
594
604
|
Troubleshooting:
|
|
595
605
|
- Check your internet connection
|
|
596
606
|
- Verify Python/Poetry installation
|
|
597
|
-
- Try running with --debug flag for more details`;super(r,"INSTALLATION_ERROR",n);}},
|
|
607
|
+
- Try running with --debug flag for more details`;super(r,"INSTALLATION_ERROR",n);}},rt=class extends F{constructor(){super("RapidKit Python package is not yet available on PyPI","RAPIDKIT_NOT_AVAILABLE",`Available options:
|
|
598
608
|
1. Install Python 3.10+ and retry the same command
|
|
599
609
|
2. Use the core workflow: npx rapidkit create workspace <name>
|
|
600
610
|
3. Offline fallback (limited): npx rapidkit create project fastapi.standard <name> --output .
|
|
601
611
|
|
|
602
|
-
Legacy: set RAPIDKIT_SHOW_LEGACY=1 to reveal template-mode flags in help.`);}};function
|
|
603
|
-
`);};try{i("probing interpreter-specific rapidkit script");let n=((await execa(e,["-c","import sysconfig, os; print(os.path.join(sysconfig.get_path('scripts'), 'rapidkit'))"],{reject:!1,stdio:"pipe",timeout:2e3})).stdout??"").toString().trim();if(i(`script path: ${n}`),n)try{if(await P.pathExists(n)){i(`found script at ${n}; invoking --version --json`);let o=await execa(n,["--version","--json"],{reject:!1,stdio:"pipe",timeout:4e3});if(i(`script exitCode=${o.exitCode}`),o.exitCode===0){let s=(o.stdout??"").toString().trim();try{let a=JSON.parse(s),c=!!a&&typeof a=="object"&&a!==null&&"version"in a;if(i(`script JSON parse ok=${c}`),c)return !0}catch{i("script output not valid JSON");}}}}catch(o){i(`interpreter-specific script probe failed: ${String(o)}`);}}catch(r){i(`interpreter-specific script probe error: ${String(r)}`);}try{i('probing importlib.find_spec("rapidkit")');let r=await execa(e,["-c","import importlib.util; print(1 if importlib.util.find_spec('rapidkit') else 0)"],{reject:!1,stdio:"pipe",timeout:2e3});if(i(`import probe exitCode=${r.exitCode} stdout=${(r.stdout??"").toString().trim()}`),r.exitCode===0&&(r.stdout??"").toString().trim()==="1")return !0}catch(r){i(`import probe error: ${String(r)}`);}try{i("probing python -m rapidkit");let r=await execa(e,["-m","rapidkit","--version","--json"],{reject:!1,stdio:"pipe",timeout:8e3});if(i(`-m probe exitCode=${r.exitCode}`),r.exitCode===0)return !0}catch(r){i(`-m probe error: ${String(r)}`);}try{i("probing PATH for rapidkit executables");let r=(process.env.PATH??"").split(h.delimiter).filter(Boolean);for(let n of r){let o=h.join(n,process.platform==="win32"?"rapidkit.exe":"rapidkit");try{if(await P.pathExists(o)){i(`found candidate on PATH: ${o}; invoking --version --json`);let s=await execa(o,["--version","--json"],{reject:!1,stdio:"pipe",timeout:4e3});if(i(`candidate exitCode=${s.exitCode}`),s.exitCode===0){let a=(s.stdout??"").toString().trim();try{let c=JSON.parse(a);if(c&&typeof c=="object"&&c!==null&&"version"in c)return !0}catch{i("candidate output not valid JSON, skipping");}}}}catch(s){i(`error probing candidate ${o}: ${String(s)}`);}}return i("no valid rapidkit found on PATH"),!1}catch(r){return i(`PATH probe error: ${String(r)}`),false}}async function _e(e){let t=(e??"").toString().trim();if(!t)return false;try{let i=JSON.parse(t);return !!i&&typeof i=="object"&&i!==null&&"version"in i}catch{return false}}async function At(e){let t=process.platform==="win32",i=t?h.join(".venv","Scripts","rapidkit.exe"):h.join(".venv","bin","rapidkit"),r=t?h.join(".venv","Scripts","python.exe"):h.join(".venv","bin","python"),n=e;for(let o=0;o<25;o+=1){let s=h.join(n,i);if(await P.pathExists(s)){let p=await execa(s,["--version","--json"],{reject:false,stdio:"pipe",timeout:1500,cwd:n});if(p.exitCode===0&&await _e(p.stdout))return {cmd:s,baseArgs:[]}}let a=h.join(n,r);if(await P.pathExists(a)){let p=await execa(a,["-m","rapidkit","--version","--json"],{reject:false,stdio:"pipe",timeout:1500,cwd:n});if(p.exitCode===0&&await _e(p.stdout))return {cmd:a,baseArgs:["-m","rapidkit"]}}let c=h.dirname(n);if(c===n)break;n=c;}return null}async function Nt(e){if(e&&e.trim())try{let o=await At(e);if(o)return o}catch{}let t=await de();if(t.kind==="venv"){let o=Re(),s=Ue(o);return await P.pathExists(s)?{cmd:s,baseArgs:[]}:{cmd:t.pythonPath,baseArgs:["-m","rapidkit"]}}try{if((await execa(t.cmd,["-m","rapidkit","--version","--json"],{reject:!1,stdio:"pipe",timeout:4e3})).exitCode===0)return {cmd:t.cmd,baseArgs:["-m","rapidkit"]}}catch{}try{let s=((await execa(t.cmd,["-c","import sysconfig, os; print(os.path.join(sysconfig.get_path('scripts'), 'rapidkit'))"],{reject:!1,stdio:"pipe",timeout:2e3})).stdout??"").toString().trim();if(s&&await P.pathExists(s))try{let a=await execa(s,["--version","--json"],{reject:!1,stdio:"pipe",timeout:4e3});if(a.exitCode===0&&await _e(a.stdout))return {cmd:s,baseArgs:[]}}catch{}}catch{}let i=Re(),r=await be(t.cmd),n=Ue(i);return await P.pathExists(n)?{cmd:n,baseArgs:[]}:{cmd:r,baseArgs:["-m","rapidkit"]}}async function Be(){for(let e of ["python3","python"])try{return await execa(e,["--version"],{reject:!1,stdio:"pipe",timeout:2e3}),e}catch{}return null}async function be(e){let t=Re(),i=Ge(t);if(await P.pathExists(i))try{let o=await execa(i,["-c","import importlib.util; print(1 if importlib.util.find_spec('rapidkit') else 0)"],{reject:!1,stdio:"pipe",timeout:2e3});if(o.exitCode===0&&(o.stdout??"").toString().trim()==="1")return i;await P.remove(t);}catch{await P.remove(t);}let r={...process.env,PIP_DISABLE_PIP_VERSION_CHECK:"1",PIP_NO_PYTHON_VERSION_WARNING:"1"},n=async(o,s)=>{let a=await execa(o,s,{reject:false,stdio:["ignore","pipe","inherit"],env:r});if(a.exitCode===0)return;let c=(a.stdout??"").toString(),p=(a.stderr??"").toString(),d=[c,p].filter(Boolean).join(`
|
|
604
|
-
`),m=d?`${o} ${s.join(" ")}
|
|
605
|
-
${d}`:`${o} ${s.join(" ")}`;throw new Error(m)};try{await P.ensureDir(h.dirname(t)),await n(e,["-m","venv",t]);let o=Ge(t);if((await execa(o,["-m","pip","--version"],{reject:!1,stdio:"pipe",timeout:2e3})).exitCode!==0&&(await execa(o,["-m","ensurepip","--default-pip"],{reject:!1,stdio:["ignore","pipe","inherit"],env:r})).exitCode!==0)throw new Error(`Failed to install pip in virtual environment.
|
|
606
|
-
Your Python installation may be missing the ensurepip module.
|
|
607
|
-
On Debian/Ubuntu, install: sudo apt install python3-venv python3-pip`);return process.env.RAPIDKIT_BRIDGE_UPGRADE_PIP==="1"&&await n(o,["-m","pip","install","-U","pip"]),await n(o,["-m","pip","install","-U",Et()]),o}catch(o){throw new Z("BRIDGE_VENV_BOOTSTRAP_FAILED",He(o))}}async function de(){if(process.env.RAPIDKIT_BRIDGE_FORCE_VENV==="1"){let i=await Be();if(!i)throw new Z("PYTHON_NOT_FOUND","No Python interpreter found (python3/python).");return {kind:"venv",pythonPath:await be(i)}}for(let i of ["python3","python"])if(await St(i))return {kind:"system",cmd:i};let e=await Be();if(!e)throw new Z("PYTHON_NOT_FOUND","No Python interpreter found (python3/python).");return {kind:"venv",pythonPath:await be(e)}}async function K(e,t){try{let i=await Nt(t?.cwd),r=i.cmd,n=[...i.baseArgs,...e],o=await execa(r,n,{cwd:t?.cwd,env:{...process.env,...t?.env},reject:!1,stdio:"inherit"});return typeof o.exitCode=="number"?o.exitCode:1}catch(i){return process.stderr.write(`${He(i)}
|
|
608
|
-
`),1}}async function Dt(){let e=It();if(!await P.pathExists(e))return null;try{let t=await P.readJson(e);if(t&&t.schema_version===1&&Array.isArray(t.commands))return t}catch{}return null}async function Ye(){let t=Date.now(),i=await Dt();return !i||t-i.fetched_at>=864e5||!i.commands?.length?null:new Set(i.commands)}w();var Tt=["version","project","create","init","dev","start","build","test","lint","format","add","list","info","upgrade","diff","doctor","license","reconcile","rollback","uninstall","checkpoint","optimize","snapshot","frameworks","modules","merge"],ze=new Set(Tt);w();ne();ae();w();function Pe(){return process.platform==="win32"?"python":"python3"}Ie();async function tt(e,t,i){let r=Ee(t,F(),i);await fe(e,r);}async function it(e){await P.outputFile(h.join(e,".gitignore"),`.venv/
|
|
612
|
+
Legacy: set RAPIDKIT_SHOW_LEGACY=1 to reveal template-mode flags in help.`);}};function zt(t){let e=Te(t);if(!e.validForNewPackages){let r=e.errors||[],n=e.warnings||[],o=[...r,...n];throw new U(t,`NPM validation failed: ${o.join(", ")}`)}if(!/^[a-z][a-z0-9_-]*$/.test(t))throw new U(t,"Must start with a lowercase letter and contain only lowercase letters, numbers, hyphens, and underscores");if(["test","tests","src","dist","build","lib","python","pip","poetry","node","npm","rapidkit","rapidkit"].includes(t.toLowerCase()))throw new U(t,`"${t}" is a reserved name. Please choose a different name.`);if(t.length<2)throw new U(t,"Name must be at least 2 characters long");if(t.length>214)throw new U(t,"Name must be less than 214 characters");return true}$();function Fe(t){return typeof t=="object"&&t!==null}async function Ke(t,e,i,r=8e3){try{let n=await execa(t,e,{cwd:i,timeout:r,reject:!1,stdio:"pipe"});return {ok:n.exitCode===0,exitCode:n.exitCode,stdout:n.stdout,stderr:n.stderr}}catch(n){return {ok:false,exitCode:void 0,stdout:"",stderr:n instanceof Error?n.message:String(n)}}}async function Me(t,e){let i=["-m","rapidkit",...t],r=["python3","python"];for(let n of r){let o=await Ke(n,i,e?.cwd,e?.timeoutMs);if(!o.ok)continue;let a=(o.stdout??"").trim();try{let s=JSON.parse(a);return Fe(s)?{ok:!0,command:n,exitCode:o.exitCode,stdout:o.stdout,stderr:o.stderr,data:s}:{ok:!1,command:n,exitCode:o.exitCode,stdout:o.stdout,stderr:o.stderr}}catch{return {ok:false,command:n,exitCode:o.exitCode,stdout:o.stdout,stderr:o.stderr}}}return {ok:false}}async function qt(t,e){let i=await Me(["project","detect","--path",t,"--json"],e);return !i.ok||!i.data||i.data.schema_version!==1?{ok:false,command:i.command,exitCode:i.exitCode,stdout:i.stdout,stderr:i.stderr}:i}wt();$();var Je=["version","project","create","init","dev","start","build","test","lint","format","add","list","info","upgrade","diff","doctor","license","reconcile","rollback","uninstall","checkpoint","optimize","snapshot","frameworks","modules","merge"],se=new Set(Je);$();ct();pt();$();function kt(){return process.platform==="win32"?"python":"python3"}Mt();async function ge(t,e,i,r){let n=Kt(e,M(),i);r&&(n.metadata||(n.metadata={}),n.metadata.python={version:r}),await vt(t,n);}async function fe(t){await E.outputFile(v.join(t,".gitignore"),`.venv/
|
|
609
613
|
__pycache__/
|
|
610
614
|
*.pyc
|
|
611
615
|
.env
|
|
612
616
|
.rapidkit-workspace/
|
|
613
617
|
|
|
614
|
-
`,"utf-8");}
|
|
618
|
+
`,"utf-8");}async function ue(t){try{let{stdout:e}=await execa(t,["--version"],{timeout:3e3}),i=e.match(/Python (\d+\.\d+\.\d+)/);if(i)return i[1]}catch{}return null}async function ni(t,e){try{await promises.writeFile(v.join(t,".python-version"),`${e}
|
|
619
|
+
`,"utf-8"),g.debug(`Created .python-version with ${e}`);}catch(i){g.warn(`Failed to create .python-version: ${i}`);}}function gt(){let t=v.join(B.homedir(),".local","bin"),i=(process.env.PATH||"").split(v.delimiter).filter(Boolean);i.includes(t)||(process.env.PATH=[t,...i].join(v.delimiter));}async function xt(t,e){gt(),t.start("Checking pipx installation");try{return await execa("pipx",["--version"]),t.succeed("pipx found"),{kind:"binary"}}catch{}let i=kt();try{return await execa(i,["-m","pipx","--version"]),t.succeed("pipx found"),{kind:"python-module",pythonCmd:i}}catch{}if(e)throw new ut;let{installPipx:r}=await Wt.prompt([{type:"confirm",name:"installPipx",message:"pipx is not installed. Install it now (user install via python -m pip)?",default:true}]);if(!r)throw new ut;t.start("Installing pipx (user install)");try{try{await execa(i,["-m","pip","install","--user","--upgrade","pip"]);}catch{}await execa(i,["-m","pip","install","--user","--upgrade","pipx"]);}catch(n){let o=n,a=String(o?.stderr||o?.shortMessage||o?.message||"");throw new A("Install pipx with python -m pip",n instanceof Error?n:new Error(a))}t.succeed("pipx installed"),gt();try{return await execa(i,["-m","pipx","--version"]),{kind:"python-module",pythonCmd:i}}catch(n){let o=n,a=String(o?.stderr||o?.shortMessage||o?.message||"pipx not runnable after install");throw new A("Verify pipx after install",new Error(`${a}
|
|
615
620
|
|
|
616
|
-
Try reopening your terminal or run: python3 -m pipx ensurepath`))}}async function
|
|
621
|
+
Try reopening your terminal or run: python3 -m pipx ensurepath`))}}async function st(t,e){return t.kind==="binary"?execa("pipx",e):execa(t.pythonCmd,["-m","pipx",...e])}async function ai(t,e){gt(),t.start("Checking Poetry installation");try{await execa("poetry",["--version"]),t.succeed("Poetry found");return}catch{}if(e)throw new lt;let{installPoetry:i}=await Wt.prompt([{type:"confirm",name:"installPoetry",message:"Poetry is not installed. Install it now using pipx?",default:true}]);if(!i)throw new lt;let r=await xt(t,e);t.start("Installing Poetry with pipx");try{await st(r,["install","poetry"]);}catch(n){let o=n,a=String(o?.stderr||o?.shortMessage||o?.message||"");if(/already\s+installed|already\s+seems\s+to\s+be\s+installed|exists/i.test(a))try{await st(r,["upgrade","poetry"]);}catch{}else throw new A("Install Poetry with pipx",n instanceof Error?n:new Error(a))}t.succeed("Poetry installed"),gt();try{await execa("poetry",["--version"]);}catch(n){let o=n,a=String(o?.stderr||o?.shortMessage||o?.message||"Poetry not found on PATH");throw new A("Verify Poetry after pipx install",new Error(`${a}
|
|
617
622
|
|
|
618
|
-
Poetry may be installed but not on PATH yet. Try reopening your terminal or run: pipx ensurepath`))}}function
|
|
623
|
+
Poetry may be installed but not on PATH yet. Try reopening your terminal or run: pipx ensurepath`))}}function si(t){let e=t==="poetry";return `#!/usr/bin/env sh
|
|
619
624
|
set -eu
|
|
620
625
|
|
|
621
626
|
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
|
@@ -625,16 +630,16 @@ if [ -x "$VENV_RAPIDKIT" ]; then
|
|
|
625
630
|
exec "$VENV_RAPIDKIT" "$@"
|
|
626
631
|
fi
|
|
627
632
|
|
|
628
|
-
${
|
|
633
|
+
${e?`if command -v poetry >/dev/null 2>&1 && [ -f "$SCRIPT_DIR/pyproject.toml" ]; then
|
|
629
634
|
exec poetry run rapidkit "$@"
|
|
630
635
|
fi
|
|
631
636
|
|
|
632
637
|
`:""}echo "RapidKit launcher could not find a local Python CLI." 1>&2
|
|
633
638
|
echo "- If you used venv: ensure .venv exists (or re-run the installer)." 1>&2
|
|
634
|
-
${
|
|
639
|
+
${e?`echo "- If you used Poetry: run 'poetry install' and retry, or activate the env." 1>&2
|
|
635
640
|
`:""}echo "Tip: you can also run: ./.venv/bin/rapidkit --help" 1>&2
|
|
636
641
|
exit 1
|
|
637
|
-
`}function
|
|
642
|
+
`}function ci(t){return `@echo off
|
|
638
643
|
setlocal
|
|
639
644
|
|
|
640
645
|
set "SCRIPT_DIR=%~dp0"
|
|
@@ -644,7 +649,7 @@ if exist "%SCRIPT_DIR%\\.venv\\Scripts\\rapidkit.exe" (
|
|
|
644
649
|
exit /b %ERRORLEVEL%
|
|
645
650
|
)
|
|
646
651
|
|
|
647
|
-
${
|
|
652
|
+
${t==="poetry"?`where poetry >nul 2>nul
|
|
648
653
|
if %ERRORLEVEL%==0 if exist "%SCRIPT_DIR%\\pyproject.toml" (
|
|
649
654
|
poetry run rapidkit %*
|
|
650
655
|
exit /b %ERRORLEVEL%
|
|
@@ -653,28 +658,48 @@ if %ERRORLEVEL%==0 if exist "%SCRIPT_DIR%\\pyproject.toml" (
|
|
|
653
658
|
`:""}echo RapidKit launcher could not find a local Python CLI. 1>&2
|
|
654
659
|
echo Tip: run .venv\\Scripts\\rapidkit.exe --help 1>&2
|
|
655
660
|
exit /b 1
|
|
656
|
-
`}async function
|
|
661
|
+
`}async function he(t,e){await E.outputFile(v.join(t,"rapidkit"),si(e),{encoding:"utf-8",mode:493}),await E.outputFile(v.join(t,"rapidkit.cmd"),ci(e),"utf-8");}async function ye(t,e){let{skipGit:i=false,testMode:r=false,demoMode:n=false,dryRun:o=false,yes:a=false,userConfig:s={},installMethod:c}=e,d=t||"rapidkit",p=v.resolve(process.cwd(),d);if(await E.pathExists(p))throw new ht(d);if(o){await di(p,d,n,s);return}if(n){await pi(p,d,i);return}let l=a?{pythonVersion:s.pythonVersion||"3.10",installMethod:c||s.defaultInstallMethod||"poetry"}:await Wt.prompt([{type:"list",name:"pythonVersion",message:"Select Python version for RapidKit:",choices:["3.10","3.11","3.12"],default:s.pythonVersion||"3.10"},{type:"list",name:"installMethod",message:"How would you like to install RapidKit?",choices:[{name:"\u{1F3AF} Poetry (Recommended - includes virtual env)",value:"poetry"},{name:"\u{1F4E6} pip with venv (Standard)",value:"venv"},{name:"\u{1F527} pipx (Global isolated install)",value:"pipx"}],default:s.defaultInstallMethod||"poetry"}]);g.step(1,3,"Setting up RapidKit environment");let u=mt("Creating directory").start();try{await E.ensureDir(p),u.succeed("Directory created"),u.start("Detecting Python version");let k=null,f=await we(l.pythonVersion);if(f)k=await ue(f),k?(g.info(`Detected Python ${k}`),u.succeed(`Python ${k} detected`)):u.warn("Could not detect exact Python version");else {let w=kt();k=await ue(w),k?u.succeed(`Python ${k} detected`):u.warn("Could not detect Python version, proceeding with defaults");}if(await ge(p,d,l.installMethod,k||void 0),k&&await ni(p,k),await fe(p),l.installMethod==="poetry")try{await ke(p,l.pythonVersion,u,r,s,a);}catch(w){let I=w?.details||w?.message||String(w);if(I.includes("pyenv")||I.includes("exit status 127")||I.includes("returned non-zero exit status 127")){u.warn("Poetry encountered Python discovery issues, trying venv method"),g.debug(`Poetry error (attempting venv fallback): ${I}`);try{await Vt(p,l.pythonVersion,u,r,s),l.installMethod="venv";}catch(G){throw G}}else throw w}else l.installMethod==="venv"?await Vt(p,l.pythonVersion,u,r,s):await ve(p,u,r,s,a);if(await he(p,l.installMethod),await xe(p,l.installMethod),u.succeed("RapidKit environment ready!"),!e.skipGit){u.start("Initializing git repository");try{await execa("git",["init"],{cwd:p}),await execa("git",["add","."],{cwd:p}),await execa("git",["commit","-m","Initial commit: RapidKit environment"],{cwd:p}),u.succeed("Git repository initialized");}catch{u.warn("Could not initialize git repository");}}try{let{registerWorkspace:w}=await Promise.resolve().then(()=>(J(),H));await w(p,d);}catch{console.warn(m.gray("Note: Could not register workspace in shared registry"));}if(console.log(m.green(`
|
|
657
662
|
\u2728 RapidKit environment created successfully!
|
|
658
|
-
`)),console.log(
|
|
659
|
-
`)),console.log(
|
|
660
|
-
\u{1F4A1} For more information, check the README.md file.`)),console.log(
|
|
661
|
-
\u{1F4DA} RapidKit commands:`)),console.log(
|
|
662
|
-
`));}catch(
|
|
663
|
-
\u274C Error:`),
|
|
664
|
-
package-mode = false`)
|
|
663
|
+
`)),console.log(m.cyan("\u{1F4C2} Location:"),m.white(p)),console.log(m.cyan(`\u{1F680} Get started:
|
|
664
|
+
`)),console.log(m.white(` cd ${d}`)),l.installMethod==="poetry"){let w="source $(poetry env info --path)/bin/activate";try{gt();let{stdout:I}=await execa("poetry",["--version"]),W=I.match(/Poetry.*?(\d+)\.(\d+)/);W&&(parseInt(W[1])>=2?w="source $(poetry env info --path)/bin/activate":w="poetry shell");}catch{}console.log(m.white(` ${w} # Or: poetry run rapidkit`)),console.log(m.white(" rapidkit create # Interactive mode")),console.log(m.white(" cd <project-name> && rapidkit init && rapidkit dev"));}else l.installMethod==="venv"?(console.log(m.white(" source .venv/bin/activate # On Windows: .venv\\Scripts\\activate")),console.log(m.white(" rapidkit create # Interactive mode")),console.log(m.white(" cd <project-name> && rapidkit init && rapidkit dev"))):(console.log(m.white(" rapidkit create # Interactive mode")),console.log(m.white(" cd <project-name> && rapidkit init && rapidkit dev")));console.log(m.white(`
|
|
665
|
+
\u{1F4A1} For more information, check the README.md file.`)),console.log(m.cyan(`
|
|
666
|
+
\u{1F4DA} RapidKit commands:`)),console.log(m.white(" rapidkit create - Create a new project (interactive)")),console.log(m.white(" rapidkit dev - Run development server")),console.log(m.white(" rapidkit add module <name> - Add a module (e.g., settings)")),console.log(m.white(" rapidkit list - List available kits")),console.log(m.white(" rapidkit modules - List available modules")),console.log(m.white(` rapidkit --help - Show all commands
|
|
667
|
+
`));}catch(k){u.fail("Failed to create RapidKit environment"),console.error(m.red(`
|
|
668
|
+
\u274C Error:`),k);try{await E.remove(p);}catch{}throw k}}async function we(t){let e=[];try{let{stdout:i}=await execa("pyenv",["root"]),r=i.trim();e.push(v.join(r,"versions",`${t}.*`,"bin","python"));let[n,o]=t.split(".");e.push(v.join(r,"versions",`${n}.${o}.*`,"bin","python"));}catch{}e.push(`python${t}`,`python3.${t.split(".")[1]}`,"python3","python"),e.push(`/usr/bin/python${t}`,"/usr/bin/python3",`/usr/local/bin/python${t}`,"/usr/local/bin/python3");for(let i of e)try{let r=i;if(i.includes("*")){if(r=(await execa("sh",["-c",`ls -d ${i} 2>/dev/null | head -1`])).stdout.trim(),!r)continue;r=v.join(r.split("/").slice(0,-1).join("/"),"../bin/python");}let{stdout:n}=await execa(r,["--version"],{timeout:2e3}),o=n.match(/Python (\d+\.\d+)/)?.[1];if(o&&parseFloat(o)>=parseFloat(t))return await execa(r,["-c","import sys; sys.exit(0)"],{timeout:2e3}),r}catch{continue}return null}async function ke(t,e,i,r,n,o=false){await ai(i,o),i.start("Finding Python interpreter");let a=await we(e);a?(g.debug(`Found working Python: ${a}`),i.succeed("Python found")):i.warn("Could not verify Python path, proceeding with default"),i.start("Initializing Poetry project"),await execa("poetry",["init","--no-interaction","--python",`^${e}`],{cwd:t}),i.succeed("Poetry project initialized");let s=v.join(t,"pyproject.toml"),d=await promises.readFile(s,"utf-8");d.includes("[tool.poetry]")?d=d.replace("[tool.poetry]",`[tool.poetry]
|
|
669
|
+
package-mode = false`):d.includes("[project]")&&(d.includes("[build-system]")?d=d.replace("[build-system]",`
|
|
670
|
+
[tool.poetry]
|
|
671
|
+
package-mode = false
|
|
672
|
+
|
|
673
|
+
[build-system]`):d+=`
|
|
674
|
+
|
|
675
|
+
[tool.poetry]
|
|
676
|
+
package-mode = false
|
|
677
|
+
`),await promises.writeFile(s,d,"utf-8"),i.start("Configuring Poetry");try{if(await execa("poetry",["config","virtualenvs.in-project","true","--local"],{cwd:t}),a)try{await execa("poetry",["env","use",a],{cwd:t}),g.debug(`Poetry configured to use: ${a}`);}catch(p){g.debug(`Could not set Poetry env to ${a}: ${p}`);}i.succeed("Poetry configured");}catch{i.warn("Could not configure Poetry virtualenvs.in-project");}i.start("Creating virtualenv");try{await execa("poetry",["install","--no-root"],{cwd:t,timeout:3e4}),i.succeed("Virtualenv created");}catch(p){g.debug(`Failed to create virtualenv: ${p}`),i.warn("Could not create virtualenv, proceeding with add command");}if(i.start("Installing RapidKit"),r){let p=ft(n||{});if(!p)throw new A("Test mode installation",new Error("No local RapidKit path configured. Set RAPIDKIT_DEV_PATH environment variable."));g.debug(`Installing from local path: ${p}`),i.text="Installing RapidKit from local path (test mode)",await execa("poetry",["add",p],{cwd:t});}else {i.text="Installing RapidKit from PyPI";let p=false,l=null;for(let u=1;u<=3;u++)try{await execa("poetry",["add","rapidkit-core"],{cwd:t,timeout:6e4*u}),p=!0;break}catch(k){l=k,g.debug(`Poetry add attempt ${u} failed: ${k}`),u<3&&(i.text=`Retrying installation (attempt ${u+1}/3)`,await new Promise(f=>setTimeout(f,2e3)));}if(!p){let u=l?.stderr||l?.message||"Unknown error";throw g.debug(`All Poetry install attempts failed. Last error: ${u}`),u.includes("Could not find")||u.includes("No matching distribution")?new rt:new A("Install rapidkit-core with Poetry",new Error(`Failed to install rapidkit-core after 3 attempts.
|
|
678
|
+
Error: ${u}
|
|
679
|
+
|
|
680
|
+
Possible solutions:
|
|
681
|
+
1. Check your internet connection
|
|
682
|
+
2. Try installing manually: cd ${v.basename(t)} && poetry add rapidkit-core
|
|
683
|
+
3. Use venv method instead: npx rapidkit ${v.basename(t)} --install-method=venv`))}}i.succeed("RapidKit installed in project virtualenv");try{let{checkRapidkitCoreAvailable:p}=await Promise.resolve().then(()=>(wt(),Ot));if(!await p()&&!r){i.start("Installing RapidKit globally with pipx for CLI access");let u=await xt(i,o);try{await st(u,["install","rapidkit-core"]),i.succeed("RapidKit installed globally");}catch(k){i.warn("Could not install globally (non-fatal, project virtualenv has RapidKit)"),g.debug(`pipx install failed: ${k}`);}}}catch(p){g.debug(`Global install check skipped: ${p}`);}}async function Vt(t,e,i,r,n,o=false){i.start(`Checking Python ${e}`);let a=kt();try{let{stdout:c}=await execa(a,["--version"]),d=c.match(/Python (\d+\.\d+)/)?.[1];if(d&&parseFloat(d)<parseFloat(e))throw new it(e,d);i.succeed(`Python ${d} found`);}catch(c){throw c instanceof it?c:new it(e)}i.start("Creating virtual environment");try{await execa(a,["-m","venv",".venv"],{cwd:t}),i.succeed("Virtual environment created");}catch(c){if(i.fail("Failed to create virtual environment"),(p=>typeof p=="object"&&p!==null&&"stdout"in p&&typeof p.stdout=="string")(c)&&c.stdout.includes("ensurepip is not")){let p=c.stdout.match(/apt install (python[\d.]+-venv)/),l=p?p[1]:"python3-venv";throw new A("Python venv module not available",new Error(`Virtual environment creation failed.
|
|
665
684
|
|
|
666
685
|
On Debian/Ubuntu systems, install the venv package:
|
|
667
|
-
sudo apt install ${
|
|
686
|
+
sudo apt install ${l}
|
|
668
687
|
|
|
669
688
|
Or use Poetry instead (recommended):
|
|
670
|
-
npx rapidkit ${
|
|
671
|
-
|
|
689
|
+
npx rapidkit ${v.basename(t)} --yes`))}throw new A("Virtual environment creation",c instanceof Error?c:new Error(String(c)))}i.start("Installing RapidKit");let s=v.join(t,".venv",process.platform==="win32"?"Scripts":"bin",process.platform==="win32"?"python.exe":"python");if(await execa(s,["-m","pip","install","--upgrade","pip"],{cwd:t}),r){let c=ft(n||{});if(!c)throw new A("Test mode installation",new Error("No local RapidKit path configured. Set RAPIDKIT_DEV_PATH environment variable."));g.debug(`Installing from local path: ${c}`),i.text="Installing RapidKit from local path (test mode)",await execa(s,["-m","pip","install","-e",c],{cwd:t});}else {i.text="Installing RapidKit from PyPI";let c=false,d=null;for(let p=1;p<=3;p++)try{await execa(s,["-m","pip","install","rapidkit-core"],{cwd:t,timeout:6e4*p}),c=!0;break}catch(l){d=l,g.debug(`pip install attempt ${p} failed: ${l}`),p<3&&(i.text=`Retrying installation (attempt ${p+1}/3)`,await new Promise(u=>setTimeout(u,2e3)));}if(!c){let p=d?.stderr||d?.message||"Unknown error";throw g.debug(`All pip install attempts failed. Last error: ${p}`),p.includes("Could not find")||p.includes("No matching distribution")?new rt:new A("Install rapidkit-core with pip",new Error(`Failed to install rapidkit-core after 3 attempts.
|
|
690
|
+
Error: ${p}
|
|
691
|
+
|
|
692
|
+
Possible solutions:
|
|
693
|
+
1. Check your internet connection
|
|
694
|
+
2. Try installing manually: cd ${v.basename(t)} && .venv/bin/python -m pip install rapidkit-core
|
|
695
|
+
3. Use Poetry instead: npx rapidkit ${v.basename(t)} --install-method=poetry`))}}i.succeed("RapidKit installed in project virtualenv");try{let{checkRapidkitCoreAvailable:c}=await Promise.resolve().then(()=>(wt(),Ot));if(!await c()&&!r){i.start("Installing RapidKit globally with pipx for CLI access");let p=await xt(i,o);try{await st(p,["install","rapidkit-core"]),i.succeed("RapidKit installed globally");}catch(l){i.warn("Could not install globally (non-fatal, project virtualenv has RapidKit)"),g.debug(`pipx install failed: ${l}`);}}}catch(c){g.debug(`Global install check skipped: ${c}`);}}async function ve(t,e,i,r,n=false){let o=await xt(e,n);if(e.start("Installing RapidKit globally with pipx"),i){let a=ft(r||{});if(!a)throw new A("Test mode installation",new Error("No local RapidKit path configured. Set RAPIDKIT_DEV_PATH environment variable."));g.debug(`Installing from local path: ${a}`),e.text="Installing RapidKit from local path (test mode)",await st(o,["install","-e",a]);}else {e.text="Installing RapidKit from PyPI";try{await st(o,["install","rapidkit-core"]);}catch{throw new rt}}e.succeed("RapidKit installed globally"),await E.outputFile(v.join(t,".rapidkit-global"),`RapidKit installed globally with pipx
|
|
696
|
+
`,"utf-8");}async function Q(t,e){let{skipGit:i=false,testMode:r=false,userConfig:n={},yes:o=false,installMethod:a,pythonVersion:s="3.10"}=e||{},c=a||n.defaultInstallMethod||"poetry";await ge(t,v.basename(t),c),await fe(t);let d=mt("Registering workspace").start();try{c==="poetry"?await ke(t,s,d,r,n,o):c==="venv"?await Vt(t,s,d,r,n):await ve(t,d,r,n,o),await he(t,c),await xe(t,c),d.succeed("Workspace registered");try{let{registerWorkspace:p}=await Promise.resolve().then(()=>(J(),H));await p(t,v.basename(t));}catch{}if(!i){d.start("Initializing git repository");try{await execa("git",["init"],{cwd:t}),await execa("git",["add","."],{cwd:t}),await execa("git",["commit","-m","Initial commit: RapidKit workspace"],{cwd:t}),d.succeed("Git repository initialized");}catch{d.warn("Could not initialize git repository");}}}catch(p){throw d.fail("Failed to register workspace"),p}}async function xe(t,e){let n=`# RapidKit Workspace
|
|
672
697
|
|
|
673
698
|
This directory contains a RapidKit development environment.
|
|
674
699
|
|
|
675
700
|
## Installation Method
|
|
676
701
|
|
|
677
|
-
**${
|
|
702
|
+
**${e==="poetry"?"Poetry":e==="venv"?"Python venv + pip":"pipx (global)"}**
|
|
678
703
|
|
|
679
704
|
## Getting Started
|
|
680
705
|
|
|
@@ -683,10 +708,10 @@ This directory contains a RapidKit development environment.
|
|
|
683
708
|
This workspace includes a local launcher script so you can run the Python Core CLI without activating the environment:
|
|
684
709
|
|
|
685
710
|
\`\`\`bash
|
|
686
|
-
${
|
|
711
|
+
${e==="poetry"?`# No activation needed (recommended):
|
|
687
712
|
./rapidkit --help
|
|
688
713
|
# or:
|
|
689
|
-
poetry run rapidkit --help`:
|
|
714
|
+
poetry run rapidkit --help`:e==="venv"?`# No activation needed (recommended):
|
|
690
715
|
./rapidkit --help
|
|
691
716
|
# or direct:
|
|
692
717
|
./.venv/bin/rapidkit --help`:`# Optional: use the local launcher
|
|
@@ -697,8 +722,8 @@ poetry run rapidkit --help`:t==="venv"?`# No activation needed (recommended):
|
|
|
697
722
|
### 1. Activate Environment
|
|
698
723
|
|
|
699
724
|
\`\`\`bash
|
|
700
|
-
${
|
|
701
|
-
# Or simply use: poetry run rapidkit <command>`:
|
|
725
|
+
${e==="poetry"?`source $(poetry env info --path)/bin/activate
|
|
726
|
+
# Or simply use: poetry run rapidkit <command>`:e==="venv"?"source .venv/bin/activate # On Windows: .venv\\Scripts\\activate":"N/A (globally installed)"}
|
|
702
727
|
\`\`\`
|
|
703
728
|
|
|
704
729
|
### 2. Create Your First Project
|
|
@@ -765,8 +790,8 @@ For full documentation, visit: [RapidKit Docs](https://getrapidkit.com) *(or app
|
|
|
765
790
|
## Workspace Structure
|
|
766
791
|
|
|
767
792
|
\`\`\`
|
|
768
|
-
${
|
|
769
|
-
${
|
|
793
|
+
${e==="venv"?".venv/ # Python virtual environment":""}
|
|
794
|
+
${e==="poetry"?"pyproject.toml # Poetry configuration":""}
|
|
770
795
|
my-project/ # Your RapidKit projects go here
|
|
771
796
|
README.md # This file
|
|
772
797
|
\`\`\`
|
|
@@ -779,7 +804,7 @@ If you encounter issues:
|
|
|
779
804
|
2. Check RapidKit installation: \`rapidkit --version\`
|
|
780
805
|
3. Run diagnostics: \`rapidkit doctor\`
|
|
781
806
|
4. Visit RapidKit documentation or GitHub issues
|
|
782
|
-
`;await promises.writeFile(
|
|
807
|
+
`;await promises.writeFile(v.join(t,"README.md"),n,"utf-8");}async function pi(t,e,i){let r=mt("Creating demo workspace").start();try{await E.ensureDir(t),r.succeed("Directory created"),r.start("Setting up demo kit generator");let n=JSON.stringify({name:`${e}-workspace`,version:"1.0.0",private:!0,description:"RapidKit demo workspace",scripts:{generate:"node generate-demo.js"}},null,2);await promises.writeFile(v.join(t,"package.json"),n,"utf-8"),await promises.writeFile(v.join(t,"generate-demo.js"),`#!/usr/bin/env node
|
|
783
808
|
/**
|
|
784
809
|
* Demo Kit Generator - Create FastAPI demo projects
|
|
785
810
|
*
|
|
@@ -1175,7 +1200,7 @@ venv/
|
|
|
1175
1200
|
}
|
|
1176
1201
|
|
|
1177
1202
|
main().catch(console.error);
|
|
1178
|
-
`,"utf-8");try{await execa("chmod",["+x",
|
|
1203
|
+
`,"utf-8");try{await execa("chmod",["+x",v.join(t,"generate-demo.js")]);}catch{}let a=`# RapidKit Demo Workspace
|
|
1179
1204
|
|
|
1180
1205
|
Welcome to your RapidKit demo workspace! This environment lets you generate FastAPI demo projects using bundled RapidKit templates, without needing to install Python RapidKit.
|
|
1181
1206
|
|
|
@@ -1246,7 +1271,7 @@ pipx install rapidkit
|
|
|
1246
1271
|
## \u{1F6E0}\uFE0F Workspace Structure
|
|
1247
1272
|
|
|
1248
1273
|
\`\`\`
|
|
1249
|
-
${
|
|
1274
|
+
${e}/
|
|
1250
1275
|
\u251C\u2500\u2500 generate-demo.js # Demo project generator
|
|
1251
1276
|
\u251C\u2500\u2500 README.md # This file
|
|
1252
1277
|
\u2514\u2500\u2500 my-api/ # Your generated projects go here
|
|
@@ -1262,7 +1287,7 @@ ${t}/
|
|
|
1262
1287
|
---
|
|
1263
1288
|
|
|
1264
1289
|
**Generated with RapidKit** | [GitHub](https://github.com/getrapidkit/rapidkit-npm)
|
|
1265
|
-
`;if(await promises.writeFile(
|
|
1290
|
+
`;if(await promises.writeFile(v.join(t,"README.md"),a,"utf-8"),r.succeed("Demo workspace setup complete"),!i){r.start("Initializing git repository");try{await execa("git",["init"],{cwd:t}),await E.outputFile(v.join(t,".gitignore"),`# Dependencies
|
|
1266
1291
|
node_modules/
|
|
1267
1292
|
|
|
1268
1293
|
# Generated projects
|
|
@@ -1275,19 +1300,19 @@ __pycache__/
|
|
|
1275
1300
|
*.pyc
|
|
1276
1301
|
.venv/
|
|
1277
1302
|
.env
|
|
1278
|
-
`,"utf-8"),await execa("git",["add","."],{cwd:
|
|
1303
|
+
`,"utf-8"),await execa("git",["add","."],{cwd:t}),await execa("git",["commit","-m","Initial commit: Demo workspace"],{cwd:t}),r.succeed("Git repository initialized");}catch{r.warn("Could not initialize git repository");}}console.log(m.green(`
|
|
1279
1304
|
\u2728 Demo workspace created successfully!
|
|
1280
|
-
`)),console.log(
|
|
1281
|
-
`)),console.log(
|
|
1305
|
+
`)),console.log(m.cyan("\u{1F4C2} Location:"),m.white(t)),console.log(m.cyan(`\u{1F680} Get started:
|
|
1306
|
+
`)),console.log(m.white(` cd ${e}`)),console.log(m.white(" node generate-demo.js my-api")),console.log(m.white(" cd my-api")),console.log(m.white(" rapidkit init")),console.log(m.white(" rapidkit dev")),console.log(),console.log(m.yellow("\u{1F4A1} Note:"),"This is a demo workspace. For full RapidKit features:"),console.log(m.cyan(" pipx install rapidkit")),console.log();}catch(n){throw r.fail("Failed to create demo workspace"),n}}async function di(t,e,i,r){console.log(m.cyan(`
|
|
1282
1307
|
\u{1F50D} Dry-run mode - showing what would be created:
|
|
1283
|
-
`)),console.log(
|
|
1284
|
-
\u{1F4DD} Files to create:`)),console.log(
|
|
1285
|
-
\u{1F3AF} Capabilities:`)),console.log(
|
|
1286
|
-
\u2699\uFE0F Configuration:`)),console.log(
|
|
1287
|
-
\u{1F4DD} Files to create:`)),console.log(
|
|
1288
|
-
\u{1F3AF} Next steps after creation:`)),console.log(
|
|
1308
|
+
`)),console.log(m.white("\u{1F4C2} Project path:"),t),console.log(m.white("\u{1F4E6} Project type:"),i?"Demo workspace":"Full RapidKit environment"),i?(console.log(m.white(`
|
|
1309
|
+
\u{1F4DD} Files to create:`)),console.log(m.gray(" - package.json")),console.log(m.gray(" - generate-demo.js (project generator)")),console.log(m.gray(" - README.md")),console.log(m.gray(" - .gitignore")),console.log(m.white(`
|
|
1310
|
+
\u{1F3AF} Capabilities:`)),console.log(m.gray(" - Generate multiple FastAPI demo projects")),console.log(m.gray(" - No Python RapidKit installation required")),console.log(m.gray(" - Bundled templates included"))):(console.log(m.white(`
|
|
1311
|
+
\u2699\uFE0F Configuration:`)),console.log(m.gray(` - Python version: ${r.pythonVersion||"3.10"}`)),console.log(m.gray(` - Install method: ${r.defaultInstallMethod||"poetry"}`)),console.log(m.gray(` - Git initialization: ${r.skipGit?"No":"Yes"}`)),console.log(m.white(`
|
|
1312
|
+
\u{1F4DD} Files to create:`)),console.log(m.gray(" - pyproject.toml (Poetry) or .venv/ (venv)")),console.log(m.gray(" - README.md")),console.log(m.gray(" - .gitignore")),console.log(m.white(`
|
|
1313
|
+
\u{1F3AF} Next steps after creation:`)),console.log(m.gray(" 1. Install RapidKit Python package")),console.log(m.gray(" 2. Create projects with rapidkit CLI")),console.log(m.gray(" 3. Add modules and customize"))),console.log(m.white(`
|
|
1289
1314
|
\u{1F4A1} To proceed with actual creation, run without --dry-run flag
|
|
1290
|
-
`));}
|
|
1315
|
+
`));}$();pt();var gi=fileURLToPath(import.meta.url),fi=v.dirname(gi);function hi(t=32){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",i=mi.randomBytes(t),r="";for(let n=0;n<t;n++)r+=e[i[n]%e.length];return r}async function je(t,e){let r=(e.template||"fastapi")==="fastapi",n=r?"FastAPI":"NestJS",o=mt(`Generating ${n} project...`).start();try{let a=v.resolve(fi,".."),s=r?"fastapi-standard":"nestjs-standard",c=v.join(a,"templates","kits",s),d=li.configure(c,{autoescape:!1,trimBlocks:!0,lstripBlocks:!0});d.addFilter("generate_secret",function(f,w=32){return hi(w)});let p={project_name:e.project_name,author:e.author||"RapidKit User",description:e.description||(r?"FastAPI service generated with RapidKit":"NestJS application generated with RapidKit"),app_version:e.app_version||"0.1.0",license:e.license||"MIT",package_manager:e.package_manager||"npm",created_at:new Date().toISOString(),rapidkit_version:M()},l;r?l=["src/main.py.j2","src/__init__.py.j2","src/cli.py.j2","src/routing/__init__.py.j2","src/routing/health.py.j2","src/modules/__init__.py.j2","tests/__init__.py.j2","README.md.j2","pyproject.toml.j2","Makefile.j2",".rapidkit/__init__.py.j2",".rapidkit/project.json.j2",".rapidkit/cli.py.j2",".rapidkit/rapidkit.j2",".rapidkit/activate.j2","rapidkit.j2","rapidkit.cmd.j2"]:l=["src/main.ts.j2","src/app.module.ts.j2","src/app.controller.ts.j2","src/app.service.ts.j2","src/config/configuration.ts.j2","src/config/validation.ts.j2","src/config/index.ts.j2","src/modules/index.ts.j2","src/examples/examples.module.ts.j2","src/examples/examples.controller.ts.j2","src/examples/examples.service.ts.j2","src/examples/dto/create-note.dto.ts.j2","test/app.controller.spec.ts.j2","test/examples.controller.spec.ts.j2","test/app.e2e-spec.ts.j2","test/jest-e2e.json.j2","package.json.j2","tsconfig.json.j2","tsconfig.build.json.j2","nest-cli.json.j2","jest.config.ts.j2","eslint.config.cjs.j2",".env.example.j2","docker-compose.yml.j2","Dockerfile.j2","README.md.j2",".rapidkit/project.json.j2",".rapidkit/rapidkit.j2",".rapidkit/rapidkit.cmd.j2",".rapidkit/activate.j2","rapidkit.j2","rapidkit.cmd.j2"];for(let f of l){let w=v.join(c,f);try{await promises.access(w);}catch{continue}let I=await promises.readFile(w,"utf-8"),W=d.renderString(I,p),G=f.replace(/\.j2$/,""),Pt=v.join(t,G);await promises.mkdir(v.dirname(Pt),{recursive:!0}),await promises.writeFile(Pt,W),(G.endsWith(".rapidkit/rapidkit")||G.endsWith(".rapidkit/cli.py")||G.endsWith(".rapidkit/activate")||G==="rapidkit")&&await promises.chmod(Pt,493);}if(r){let f=v.join(c,".rapidkit","context.json"),w=v.join(t,".rapidkit","context.json");try{await promises.mkdir(v.join(t,".rapidkit"),{recursive:!0}),await promises.copyFile(f,w);}catch{await promises.mkdir(v.join(t,".rapidkit"),{recursive:!0});let W=e.engine||"pip";await promises.writeFile(w,JSON.stringify({engine:W,created_by:"rapidkit-npm-fallback"},null,2));}}let u=r?`# Python
|
|
1291
1316
|
__pycache__/
|
|
1292
1317
|
*.py[cod]
|
|
1293
1318
|
*$py.class
|
|
@@ -1355,16 +1380,16 @@ Thumbs.db
|
|
|
1355
1380
|
|
|
1356
1381
|
# Coverage
|
|
1357
1382
|
coverage/
|
|
1358
|
-
`;if(await promises.writeFile(
|
|
1359
|
-
${
|
|
1360
|
-
${
|
|
1361
|
-
${
|
|
1362
|
-
${
|
|
1383
|
+
`;if(await promises.writeFile(v.join(t,".gitignore"),u),o.succeed(`${n} project generated!`),!e.skipGit){let f=mt("Initializing git repository...").start();try{await execa("git",["init"],{cwd:t}),await execa("git",["add","."],{cwd:t}),await execa("git",["commit","-m",`Initial commit: ${n} project via RapidKit`],{cwd:t}),f.succeed("Git repository initialized");}catch{f.warn("Could not initialize git repository");}}if(!r&&!e.skipInstall){let f=e.package_manager||"npm",w=mt(`Installing dependencies with ${f}...`).start();try{await execa(f,f==="yarn"?["install"]:f==="pnpm"?["install"]:["install"],{cwd:t}),w.succeed("Dependencies installed");}catch{w.warn(`Could not install dependencies. Run '${f} install' manually.`);}}let k=v.basename(t);console.log(`
|
|
1384
|
+
${m.yellow("\u26A0\uFE0F Limited offline mode:")} This project was created using basic templates.
|
|
1385
|
+
${m.gray("For full kit features, install Python 3.10+ and rapidkit-core:")}
|
|
1386
|
+
${m.cyan(" sudo apt install python3 python3-pip python3-venv")}
|
|
1387
|
+
${m.cyan(" pip install rapidkit-core")}
|
|
1363
1388
|
`),console.log(r?`
|
|
1364
|
-
${
|
|
1389
|
+
${m.green("\u2728 FastAPI project created successfully!")}
|
|
1365
1390
|
|
|
1366
|
-
${
|
|
1367
|
-
${
|
|
1391
|
+
${m.bold("\u{1F4C2} Project structure:")}
|
|
1392
|
+
${t}/
|
|
1368
1393
|
\u251C\u2500\u2500 .rapidkit/ # RapidKit CLI module
|
|
1369
1394
|
\u251C\u2500\u2500 src/
|
|
1370
1395
|
\u2502 \u251C\u2500\u2500 main.py # FastAPI application
|
|
@@ -1375,12 +1400,12 @@ ${e}/
|
|
|
1375
1400
|
\u251C\u2500\u2500 pyproject.toml # Poetry configuration
|
|
1376
1401
|
\u2514\u2500\u2500 README.md
|
|
1377
1402
|
|
|
1378
|
-
${
|
|
1379
|
-
${
|
|
1380
|
-
${
|
|
1381
|
-
${
|
|
1403
|
+
${m.bold("\u{1F680} Get started:")}
|
|
1404
|
+
${m.cyan(`cd ${k}`)}
|
|
1405
|
+
${m.cyan("npx rapidkit init")} ${m.gray("# Install dependencies")}
|
|
1406
|
+
${m.cyan("npx rapidkit dev")} ${m.gray("# Start dev server")}
|
|
1382
1407
|
|
|
1383
|
-
${
|
|
1408
|
+
${m.bold("\u{1F4DA} Available commands:")}
|
|
1384
1409
|
npx rapidkit init # Install dependencies (poetry install)
|
|
1385
1410
|
npx rapidkit dev # Start dev server with hot reload
|
|
1386
1411
|
npx rapidkit start # Start production server
|
|
@@ -1388,13 +1413,13 @@ ${l.bold("\u{1F4DA} Available commands:")}
|
|
|
1388
1413
|
npx rapidkit lint # Lint code
|
|
1389
1414
|
npx rapidkit format # Format code
|
|
1390
1415
|
|
|
1391
|
-
${
|
|
1392
|
-
${
|
|
1416
|
+
${m.gray("Alternative: make dev, ./rapidkit dev, poetry run dev")}
|
|
1417
|
+
${m.gray("\u{1F4A1} Tip: Install globally (npm i -g rapidkit) to use without npx")}
|
|
1393
1418
|
`:`
|
|
1394
|
-
${
|
|
1419
|
+
${m.green("\u2728 NestJS project created successfully!")}
|
|
1395
1420
|
|
|
1396
|
-
${
|
|
1397
|
-
${
|
|
1421
|
+
${m.bold("\u{1F4C2} Project structure:")}
|
|
1422
|
+
${t}/
|
|
1398
1423
|
\u251C\u2500\u2500 .rapidkit/ # RapidKit CLI module
|
|
1399
1424
|
\u251C\u2500\u2500 src/
|
|
1400
1425
|
\u2502 \u251C\u2500\u2500 main.ts # Application entry point
|
|
@@ -1405,13 +1430,13 @@ ${e}/
|
|
|
1405
1430
|
\u251C\u2500\u2500 package.json # Dependencies
|
|
1406
1431
|
\u2514\u2500\u2500 README.md
|
|
1407
1432
|
|
|
1408
|
-
${
|
|
1409
|
-
${
|
|
1410
|
-
${
|
|
1411
|
-
${
|
|
1412
|
-
${
|
|
1433
|
+
${m.bold("\u{1F680} Get started:")}
|
|
1434
|
+
${m.cyan(`cd ${k}`)}
|
|
1435
|
+
${m.cyan("npx rapidkit init")} ${m.gray("# Install dependencies")}
|
|
1436
|
+
${m.cyan("cp .env.example .env")}
|
|
1437
|
+
${m.cyan("npx rapidkit dev")} ${m.gray("# Start dev server")}
|
|
1413
1438
|
|
|
1414
|
-
${
|
|
1439
|
+
${m.bold("\u{1F4DA} Available commands:")}
|
|
1415
1440
|
npx rapidkit init # Install dependencies
|
|
1416
1441
|
npx rapidkit dev # Start dev server with hot reload
|
|
1417
1442
|
npx rapidkit start # Start production server
|
|
@@ -1420,29 +1445,30 @@ ${l.bold("\u{1F4DA} Available commands:")}
|
|
|
1420
1445
|
npx rapidkit lint # Lint code
|
|
1421
1446
|
npx rapidkit format # Format code
|
|
1422
1447
|
|
|
1423
|
-
${
|
|
1448
|
+
${m.bold("\u{1F310} API endpoints:")}
|
|
1424
1449
|
http://localhost:8000/health # Health check
|
|
1425
1450
|
http://localhost:8000/docs # Swagger docs
|
|
1426
1451
|
http://localhost:8000/examples/notes # Example API
|
|
1427
1452
|
|
|
1428
|
-
${
|
|
1429
|
-
${
|
|
1430
|
-
`);}catch(
|
|
1431
|
-
Reason: ${
|
|
1453
|
+
${m.gray("Alternative: npm run start:dev, ./rapidkit dev")}
|
|
1454
|
+
${m.gray("\u{1F4A1} Tip: Install globally (npm i -g rapidkit) to use without npx")}
|
|
1455
|
+
`);}catch(a){throw o.fail(`Failed to generate ${n} project`),a}}function Ut(t){if(!t||typeof t!="object")return null;let e=t.code;return e==="PYTHON_NOT_FOUND"||e==="BRIDGE_VENV_BOOTSTRAP_FAILED"?e:null}function wi(t){let e=t.trim().toLowerCase();return e?e.startsWith("fastapi")?"fastapi":e.startsWith("nestjs")?"nestjs":null:null}function ki(t,e){let i=t.indexOf(e);if(i>=0&&i+1<t.length)return t[i+1];let r=t.find(n=>n.startsWith(`${e}=`));if(r)return r.slice(e.length+1)}async function Bt(t,e){if(t.includes("--json"))return process.stderr.write("RapidKit (npm) offline fallback does not support --json for `create` commands.\nInstall Python 3.10+ and retry the same command.\n"),1;if(t[0]!=="create")return 1;if(t[1]!=="project")return process.stderr.write(`RapidKit (npm) could not run the Python core engine for \`create\`.
|
|
1456
|
+
Reason: ${e}.
|
|
1432
1457
|
Install Python 3.10+ to use the interactive wizard and full kit catalog.
|
|
1433
|
-
`),1;let n=
|
|
1458
|
+
`),1;let n=t[2],o=t[3];if(!n||!o)return process.stderr.write(`Usage: rapidkit create project <kit> <name> [--output <dir>]
|
|
1434
1459
|
Tip: offline fallback supports only fastapi* and nestjs* kits.
|
|
1435
|
-
`),1;let
|
|
1436
|
-
Reason: ${
|
|
1460
|
+
`),1;let a=wi(n);if(!a)return process.stderr.write(`RapidKit (npm) could not run the Python core engine to create this kit.
|
|
1461
|
+
Reason: ${e}.
|
|
1437
1462
|
Requested kit: ${n}
|
|
1438
1463
|
Offline fallback only supports: fastapi.standard, nestjs.standard (and their shorthands).
|
|
1439
1464
|
Install Python 3.10+ to access all kits.
|
|
1440
|
-
`),1;let
|
|
1441
|
-
`),1;let
|
|
1442
|
-
`),1}}async function
|
|
1443
|
-
`),
|
|
1444
|
-
`),1)}
|
|
1445
|
-
`),1)}
|
|
1465
|
+
`),1;let s=ki(t,"--output")||process.cwd(),c=v.resolve(s,o),d=t.includes("--skip-git")||t.includes("--no-git"),p=t.includes("--skip-install");try{if(await E.ensureDir(v.dirname(c)),await E.pathExists(c))return process.stderr.write(`\u274C Directory "${c}" already exists
|
|
1466
|
+
`),1;let l="pip",u=bt(process.cwd());if(u)try{let{readWorkspaceMarker:k}=await Promise.resolve().then(()=>(Mt(),pe)),f=await k(u);f?.metadata?.npm?.installMethod&&(l=f.metadata.npm.installMethod,console.log(`[DEBUG] Detected workspace engine: ${l}`));}catch(k){console.log("[DEBUG] Failed to read workspace marker:",k);}else console.log("[DEBUG] No workspace found, using default engine: pip");if(await E.ensureDir(c),await je(c,{project_name:o,template:a,skipGit:d,skipInstall:p,engine:l}),u){let{syncWorkspaceProjects:k}=await Promise.resolve().then(()=>(J(),H));await k(u,!0);}return 0}catch(l){return process.stderr.write(`RapidKit (npm) offline fallback failed: ${l?.message??l}
|
|
1467
|
+
`),1}}async function vi(t){let e=new Set(["--yes","-y","--skip-git","--skip-install","--debug","--dry-run","--no-update-check","--create-workspace","--no-workspace"]);try{if(t[0]==="create"&&t[1]==="project"){let i=t.includes("--create-workspace"),r=t.includes("--no-workspace"),n=t.includes("--yes")||t.includes("-y"),o=t.includes("--skip-git")||t.includes("--no-git");if(!!!$t(process.cwd())){if(i)await Q(process.cwd(),{skipGit:o,yes:n,userConfig:await dt()});else if(!r)if(n)await Q(process.cwd(),{skipGit:o,yes:!0,userConfig:await dt()});else {let{createWs:c}=await Wt.prompt([{type:"confirm",name:"createWs",message:"This project will be created outside a RapidKit workspace. Create and register a workspace here?",default:!0}]);c&&await Q(process.cwd(),{skipGit:o,yes:!1,userConfig:await dt()});}}let s=t.filter(c=>{let d=c.split("=")[0];return !e.has(c)&&!e.has(d)});try{await nt();let c=await V(s,{cwd:process.cwd()});if(c===0){let d=bt(process.cwd());if(d){try{let l=t[3];if(l){let u=t.indexOf("--output"),k=u>=0?t[u+1]:".",f=v.resolve(process.cwd(),k,l),w=v.join(d,".python-version"),I=v.join(f,".python-version");if(N.existsSync(w)&&N.existsSync(f)){let W=N.readFileSync(w,"utf-8");N.writeFileSync(I,W.trim()+`
|
|
1468
|
+
`),g.debug(`Synced Python version ${W.trim()} from workspace to ${l}`);}}}catch(l){g.debug("Could not sync Python version from workspace:",l);}let{syncWorkspaceProjects:p}=await Promise.resolve().then(()=>(J(),H));await p(d,!0);}}return c}catch(c){let d=Ut(c);return d?await Bt(s,d):(process.stderr.write(`RapidKit (npm) failed to run the Python core engine: ${c?.message??c}
|
|
1469
|
+
`),1)}}if(t[0]==="create"&&t[1]!=="project")try{await nt();let i=await V(t,{cwd:process.cwd()});if(i===0){let r=bt(process.cwd());if(r){let{syncWorkspaceProjects:n}=await Promise.resolve().then(()=>(J(),H));await n(r,!0);}}return i}catch(i){let r=Ut(i);return r?await Bt(t,r):(process.stderr.write(`RapidKit (npm) failed to run the Python core engine: ${i?.message??i}
|
|
1470
|
+
`),1)}return await nt(),await V(t,{cwd:process.cwd()})}catch(i){let r=Ut(i);return r?await Bt(t,r):(process.stderr.write(`RapidKit (npm) failed to run the Python core engine: ${i?.message??i}
|
|
1471
|
+
`),1)}}var be=["init","dev","start","build","test","lint","format","create","help","--help","-h"];function xi(t){let e=t;for(;;){let i=v.join(e,".rapidkit","context.json");if(N.existsSync(i))return i;let r=v.dirname(e);if(r===e)break;e=r;}return null}function $t(t){let e=t;for(;;){let i=v.join(e,".rapidkit-workspace");if(N.existsSync(i))return i;let r=v.dirname(e);if(r===e)break;e=r;}return null}function bt(t){let e=t;for(;;){let i=v.join(e,".rapidkit-workspace");if(N.existsSync(i))return e;let r=v.dirname(e);if(r===e)break;e=r;}return null}async function ji(){let t=process.cwd(),e=process.argv.slice(2);if(e[0]==="create")return false;try{let c=e[0],d=!c||c==="--help"||c==="-h"||c==="help";if($t(t)&&d){let l=await V(c?["--help"]:[],{cwd:t});process.exit(l);}}catch{}try{let c=e[0],d=c==="shell"&&e[1]==="activate",p=c==="create",l=await qt(t,{cwd:t,timeoutMs:1200});if(l.ok&&l.data?.isRapidkitProject&&l.data.engine==="python"&&!d&&!p){let u=await V(process.argv.slice(2),{cwd:t});process.exit(u);}}catch{}let i=xi(t),r=process.platform==="win32",n=r?[v.join(t,"rapidkit.cmd"),v.join(t,"rapidkit"),v.join(t,".rapidkit","rapidkit.cmd"),v.join(t,".rapidkit","rapidkit")]:[v.join(t,"rapidkit"),v.join(t,".rapidkit","rapidkit")],o=null;for(let c of n)if(await E.pathExists(c)){o=c;break}let a=e[0],s=a==="create";if(o&&a&&be.includes(a)&&!s){g.debug(`Delegating to local CLI: ${o} ${e.join(" ")}`);let c=spawn(o,e,{stdio:"inherit",cwd:t,shell:r});return c.on("close",d=>{process.exit(d??0);}),c.on("error",d=>{g.error(`Failed to run local rapidkit: ${d.message}`),process.exit(1);}),true}if(i&&await E.pathExists(i))try{if((await E.readJson(i)).engine==="pip"){let d=e[0],l=process.platform==="win32"?[v.join(t,"rapidkit.cmd"),v.join(t,"rapidkit"),v.join(t,".rapidkit","rapidkit.cmd"),v.join(t,".rapidkit","rapidkit")]:[v.join(t,"rapidkit"),v.join(t,".rapidkit","rapidkit")],u=null;for(let f of l)if(await E.pathExists(f)){u=f;break}if(u&&d&&be.includes(d)){g.debug(`Delegating to local CLI (early detection): ${u} ${e.join(" ")}`);let f=spawn(u,e,{stdio:"inherit",cwd:t});return f.on("close",w=>process.exit(w??0)),f.on("error",w=>{g.error(`Failed to run local rapidkit: ${w.message}`),process.exit(1);}),!0}if(d==="shell"&&e[1]==="activate"){let f=`# RapidKit: activation snippet - eval "$(rapidkit shell activate)"
|
|
1446
1472
|
VENV='.venv'
|
|
1447
1473
|
if [ -f "$VENV/bin/activate" ]; then
|
|
1448
1474
|
. "$VENV/bin/activate"
|
|
@@ -1451,37 +1477,39 @@ elif [ -f "$VENV/bin/activate.fish" ]; then
|
|
|
1451
1477
|
fi
|
|
1452
1478
|
export RAPIDKIT_PROJECT_ROOT="$(pwd)"
|
|
1453
1479
|
export PATH="$(pwd)/.rapidkit:$(pwd):$PATH"
|
|
1454
|
-
`;console.log(
|
|
1480
|
+
`;console.log(m.green.bold(`
|
|
1455
1481
|
\u2705 Activation snippet \u2014 run the following to activate this project in your current shell:
|
|
1456
|
-
`)),console.log(f),console.log(
|
|
1482
|
+
`)),console.log(f),console.log(m.gray(`
|
|
1457
1483
|
\u{1F4A1} After activation you can run: rapidkit dev
|
|
1458
|
-
`)),process.exit(0);}let
|
|
1484
|
+
`)),process.exit(0);}let k=await V(e,{cwd:t});process.exit(k);}}catch{}return false}var Y=null,Rt=false,tt=new Command;async function bi(t){if(t.length===0)return false;let e=t[0],i=t[1];if(e==="shell"&&i==="activate"||e==="workspace")return false;if(t.includes("--tui"))return true;if(e==="--help"||e==="-h"||e==="help"||e==="--version"||e==="-V"||t.includes("--template")||t.includes("-t"))return false;let r=new Set(["--yes","-y","--skip-git","--skip-install","--debug","--dry-run","--no-update-check","--create-workspace","--no-workspace"]);if(t.some(o=>r.has(o)))return false;let n=await Tt();return n?n.has(e):!!(se.has(e)||t.length>1)}tt.name("rapidkit").description("Create RapidKit workspaces and projects").version(M());tt.addHelpText("beforeAll",`RapidKit
|
|
1459
1485
|
|
|
1460
1486
|
Global CLI
|
|
1461
1487
|
Create RapidKit workspaces and projects
|
|
1462
1488
|
|
|
1463
1489
|
Global Engine Commands
|
|
1464
1490
|
Access engine-level commands when inside a RapidKit workspace or via the core bridge
|
|
1465
|
-
`);
|
|
1491
|
+
`);tt.addHelpText("afterAll",`
|
|
1466
1492
|
Project Commands
|
|
1467
1493
|
rapidkit create
|
|
1468
1494
|
rapidkit init
|
|
1469
1495
|
rapidkit dev
|
|
1470
1496
|
|
|
1471
1497
|
Use "rapidkit help <command>" for more information.
|
|
1472
|
-
`);
|
|
1498
|
+
`);tt.argument("[name]","Name of the workspace or project directory").addOption(new Option("-t, --template <template>","Legacy: create a project with template (fastapi, nestjs) instead of a workspace").hideHelp()).option("-y, --yes","Skip prompts and use defaults").addOption(new Option("--skip-git","Skip git initialization").hideHelp()).addOption(new Option("--skip-install","Legacy: skip installing dependencies (template mode)").hideHelp()).option("--debug","Enable debug logging").addOption(new Option("--dry-run","Show what would be created without creating it").hideHelp()).addOption(new Option("--install-method <method>","Installation method: poetry, venv, or pipx").choices(["poetry","venv","pipx"]).hideHelp()).addOption(new Option("--create-workspace","When creating a project outside a workspace: create and register a workspace in the current directory").hideHelp()).addOption(new Option("--no-workspace","When creating a project outside a workspace: do not create a workspace").hideHelp()).option("--no-update-check","Skip checking for updates").action(async(t,e)=>{try{e.debug&&(g.setDebug(!0),g.debug("Debug mode enabled"));let i=await dt();g.debug("User config loaded",i),e.updateCheck!==!1&&await Yt(),console.log(m.blue.bold(`
|
|
1473
1499
|
\u{1F680} Welcome to RapidKit!
|
|
1474
|
-
`)),
|
|
1475
|
-
\u274C ${o.message}`),o.details&&
|
|
1476
|
-
`),process.exit(1)),o}let r=
|
|
1477
|
-
\u274C Directory "${
|
|
1500
|
+
`)),t||(Ri(),process.exit(0));try{zt(t);}catch(o){throw o instanceof F&&(g.error(`
|
|
1501
|
+
\u274C ${o.message}`),o.details&&g.warn(`\u{1F4A1} ${o.details}
|
|
1502
|
+
`),process.exit(1)),o}let r=v.resolve(process.cwd(),t);Y=r,await E.pathExists(r)&&(g.error(`
|
|
1503
|
+
\u274C Directory "${t}" already exists`),console.log(m.cyan(`
|
|
1478
1504
|
\u{1F4A1} Choose a different name or delete the existing directory.
|
|
1479
|
-
`)),process.exit(1));let n=!!
|
|
1505
|
+
`)),process.exit(1));let n=!!e.template;if(e.dryRun){console.log(m.cyan(`
|
|
1480
1506
|
\u{1F50D} Dry-run mode - showing what would be created:
|
|
1481
|
-
`)),console.log(
|
|
1482
|
-
`)),n){let o=String(
|
|
1483
|
-
|
|
1484
|
-
|
|
1507
|
+
`)),console.log(m.white("\u{1F4C2} Path:"),r),console.log(m.white("\u{1F4E6} Type:"),n?`Project (${e.template})`:"Workspace"),console.log();return}if(!e.yes&&!n?await Wt.prompt([{type:"input",name:"author",message:"Author name:",default:process.env.USER||"RapidKit User"}]):e.yes&&console.log(m.gray(`Using default values (--yes flag)
|
|
1508
|
+
`)),n){let o=String(e.template||"").trim(),a=o.toLowerCase(),s=a==="fastapi"?"fastapi.standard":a==="nestjs"?"nestjs.standard":o;if(!!!$t(process.cwd())){if(e.createWorkspace)await Q(process.cwd(),{skipGit:e.skipGit,yes:e.yes,userConfig:i});else if(!e.noWorkspace)if(e.yes)await Q(process.cwd(),{skipGit:e.skipGit,yes:!0,userConfig:i});else {let{createWs:u}=await Wt.prompt([{type:"confirm",name:"createWs",message:"This project will be created outside a RapidKit workspace. Create and register a workspace here?",default:!0}]);u&&await Q(process.cwd(),{skipGit:e.skipGit,yes:!1,userConfig:i});}}let d=["create","project",s,t,"--output",process.cwd(),"--install-essentials"],p=await V(d,{cwd:process.cwd()});p!==0&&process.exit(p);let l=$t(process.cwd());if(l){let u=v.dirname(l),k=v.join(u,".python-version"),f=v.join(r,".python-version");try{if(await E.pathExists(k)){let w=N.readFileSync(k,"utf-8");N.writeFileSync(f,w.trim()+`
|
|
1509
|
+
`),g.debug(`Synced Python version ${w.trim()} from workspace to project`);}}catch(w){g.debug("Could not sync Python version from workspace:",w);}}if(!e.skipInstall){let u=await V(["init",r],{cwd:process.cwd()});if(u!==0&&process.exit(u),l){let k=v.dirname(l),f=v.join(k,".python-version"),w=v.join(r,".python-version");try{if(await E.pathExists(f)){let I=N.readFileSync(f,"utf-8");N.writeFileSync(w,I.trim()+`
|
|
1510
|
+
`),g.debug(`Re-synced Python version ${I.trim()} after init`);}}catch(I){g.debug("Could not re-sync Python version after init:",I);}}}}else await ye(t,{skipGit:e.skipGit,dryRun:e.dryRun,yes:e.yes,userConfig:i,installMethod:e.installMethod});}catch(i){i instanceof F?(g.error(`
|
|
1511
|
+
\u274C ${i.message}`),i.details&&g.warn(`\u{1F4A1} ${i.details}`),g.debug("Error code:",i.code)):(g.error(`
|
|
1512
|
+
\u274C An unexpected error occurred:`),console.error(i)),process.exit(1);}finally{Y=null;}});tt.command("shell <action>").description("Shell helpers (activate virtualenv in current shell)").action(async t=>{t!=="activate"&&(console.log(m.red(`Unknown shell command: ${t}`)),process.exit(1));let e=process.cwd();function i(a){let s=a;for(;;){let c=v.join(s,".rapidkit","context.json");if(N.existsSync(c))return c;let d=v.dirname(s);if(d===s)break;s=d;}return null}let r=i(e);function n(a){let s=a;for(;;){let c=v.join(s,".venv"),d=v.join(s,".rapidkit","activate");if(N.existsSync(d)||N.existsSync(c))return {venv:c,activateFile:d};let p=v.dirname(s);if(p===s)break;s=p;}return null}let o=n(e);if(!r&&!o&&(console.log(m.red("No RapidKit project found to activate")),process.exit(1)),o){let a=`# RapidKit: activation snippet - eval "$(rapidkit shell activate)"
|
|
1485
1513
|
VENV='.venv'
|
|
1486
1514
|
if [ -f "$VENV/bin/activate" ]; then
|
|
1487
1515
|
. "$VENV/bin/activate"
|
|
@@ -1490,11 +1518,11 @@ elif [ -f "$VENV/bin/activate.fish" ]; then
|
|
|
1490
1518
|
fi
|
|
1491
1519
|
export RAPIDKIT_PROJECT_ROOT="$(pwd)"
|
|
1492
1520
|
export PATH="$(pwd)/.rapidkit:$(pwd):$PATH"
|
|
1493
|
-
`;console.log(
|
|
1521
|
+
`;console.log(m.green.bold(`
|
|
1494
1522
|
\u2705 Activation snippet \u2014 run the following to activate this project in your current shell:
|
|
1495
|
-
`)),console.log(
|
|
1523
|
+
`)),console.log(a),console.log(m.gray(`
|
|
1496
1524
|
\u{1F4A1} After activation you can run: rapidkit dev
|
|
1497
|
-
`)),process.exit(0);}try{(await
|
|
1525
|
+
`)),process.exit(0);}try{(await E.readJson(r)).engine!=="pip"&&(console.log(m.yellow("This project is not a pip-based RapidKit project.")),process.exit(1)),console.log(`# RapidKit: activation snippet - eval "$(rapidkit shell activate)"
|
|
1498
1526
|
VENV='.venv'
|
|
1499
1527
|
if [ -f "$VENV/bin/activate" ]; then
|
|
1500
1528
|
. "$VENV/bin/activate"
|
|
@@ -1503,7 +1531,7 @@ elif [ -f "$VENV/bin/activate.fish" ]; then
|
|
|
1503
1531
|
fi
|
|
1504
1532
|
export RAPIDKIT_PROJECT_ROOT="$(pwd)"
|
|
1505
1533
|
export PATH="$(pwd)/.rapidkit:$(pwd):$PATH"
|
|
1506
|
-
`),process.exit(0);}catch{console.log(
|
|
1534
|
+
`),process.exit(0);}catch{console.log(m.yellow("Could not read project context but found a venv or activation file \u2014 printing activation snippet")),console.log(`# RapidKit: activation snippet - eval "$(rapidkit shell activate)"
|
|
1507
1535
|
VENV='.venv'
|
|
1508
1536
|
if [ -f "$VENV/bin/activate" ]; then
|
|
1509
1537
|
. "$VENV/bin/activate"
|
|
@@ -1512,13 +1540,13 @@ elif [ -f "$VENV/bin/activate.fish" ]; then
|
|
|
1512
1540
|
fi
|
|
1513
1541
|
export RAPIDKIT_PROJECT_ROOT="$(pwd)"
|
|
1514
1542
|
export PATH="$(pwd):$PATH"
|
|
1515
|
-
`),process.exit(0);}});
|
|
1516
|
-
`)),console.log(
|
|
1517
|
-
`)),console.log(
|
|
1518
|
-
`)),console.log(
|
|
1519
|
-
`)),console.log(
|
|
1520
|
-
`));}process.on("SIGINT",async()=>{if(!
|
|
1521
|
-
|
|
1522
|
-
\u26A0\uFE0F Interrupted by user`)),
|
|
1523
|
-
`),
|
|
1524
|
-
`),i){let r=await
|
|
1543
|
+
`),process.exit(0);}});tt.command("workspace <action>").description("Manage RapidKit workspaces (list, sync)").action(async t=>{if(t==="list"){let{listWorkspaces:e}=await Promise.resolve().then(()=>(J(),H));await e();}else if(t==="sync"){let e=bt(process.cwd());e||(console.log(m.red("\u274C Not inside a RapidKit workspace")),console.log(m.gray("\u{1F4A1} Run this command from within a workspace directory")),process.exit(1));let{syncWorkspaceProjects:i}=await Promise.resolve().then(()=>(J(),H));console.log(m.cyan(`\u{1F4C2} Scanning workspace: ${v.basename(e)}`)),await i(e);}else console.log(m.red(`Unknown workspace action: ${t}`)),console.log(m.gray("Available: list, sync")),process.exit(1);});function Ri(){console.log(m.white(`Usage:
|
|
1544
|
+
`)),console.log(m.cyan(" npx rapidkit <workspace-name> [options]")),console.log(m.cyan(` npx rapidkit create <...>
|
|
1545
|
+
`)),console.log(m.bold("Recommended workflow:")),console.log(m.cyan(" npx rapidkit my-workspace")),console.log(m.cyan(" cd my-workspace")),console.log(m.cyan(" npx rapidkit create project fastapi.standard my-api --output .")),console.log(m.cyan(" cd my-api")),console.log(m.cyan(` npx rapidkit init && npx rapidkit dev
|
|
1546
|
+
`)),console.log(m.bold("Options (workspace creation):")),console.log(m.gray(" -y, --yes Skip prompts and use defaults")),console.log(m.gray(" --skip-git Skip git initialization")),console.log(m.gray(" --debug Enable debug logging")),console.log(m.gray(" --dry-run Show what would be created")),console.log(m.gray(" --create-workspace When creating a project outside a workspace: create and register a workspace in the current directory")),console.log(m.gray(" --no-workspace When creating a project outside a workspace: do not create a workspace")),console.log(m.gray(` --no-update-check Skip checking for updates
|
|
1547
|
+
`)),console.log(m.gray(`Tip: set RAPIDKIT_SHOW_LEGACY=1 to show legacy template flags in help.
|
|
1548
|
+
`));}process.on("SIGINT",async()=>{if(!Rt){if(Rt=true,console.log(m.yellow(`
|
|
1549
|
+
|
|
1550
|
+
\u26A0\uFE0F Interrupted by user`)),Y&&await E.pathExists(Y)){console.log(m.gray("Cleaning up partial installation..."));try{await E.remove(Y),console.log(m.green("\u2713 Cleanup complete"));}catch(t){g.debug("Cleanup failed:",t);}}process.exit(130);}});process.on("SIGTERM",async()=>{if(!Rt){if(Rt=true,g.debug("Received SIGTERM"),Y&&await E.pathExists(Y))try{await E.remove(Y);}catch(t){g.debug("Cleanup failed:",t);}process.exit(143);}});ji().then(async t=>{if(!t){let e=process.argv.slice(2);if(process.env.RAPIDKIT_NPM_DEBUG_ARGS==="1"&&process.stderr.write(`[rapidkit-npm] argv=${JSON.stringify(e)}
|
|
1551
|
+
`),e[0]==="create"){let r=await vi(e);process.exit(r);}let i=await bi(e);if(process.env.RAPIDKIT_NPM_DEBUG_ARGS==="1"&&process.stderr.write(`[rapidkit-npm] shouldForwardToCore=${i}
|
|
1552
|
+
`),i){let r=await V(e,{cwd:process.cwd()});process.exit(r);}tt.parse();}});export{vi as handleCreateOrFallback};
|
package/dist/package.json
CHANGED