rapidkit 0.12.2 → 0.12.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/README.md
CHANGED
|
@@ -98,9 +98,11 @@ rapidkit format # Format code
|
|
|
98
98
|
rapidkit --help # Show all commands
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
> **Note:** The global `rapidkit` command automatically detects when you're inside a RapidKit project and delegates to the local CLI. No need for `./rapidkit` prefix or `source .rapidkit/activate`.
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
### Alternative: Direct Commands
|
|
104
|
+
|
|
105
|
+
You can also run commands directly:
|
|
104
106
|
|
|
105
107
|
```bash
|
|
106
108
|
./rapidkit dev # Using the wrapper script
|
|
@@ -193,6 +195,8 @@ MIT
|
|
|
193
195
|
|
|
194
196
|
---
|
|
195
197
|
|
|
196
|
-
**v0.12.
|
|
198
|
+
**v0.12.4** - Friendly shell activation UX with green headers and robust fallback logic
|
|
199
|
+
|
|
200
|
+
**v0.12.2** - Simplified CLI: `rapidkit init` now handles environment activation automatically
|
|
197
201
|
|
|
198
202
|
**v0.12.0** - Added NestJS template, workspace mode, and unified CLI
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {Command}from'commander';import
|
|
3
|
-
[${
|
|
4
|
-
\u26A0\uFE0F Update available: ${
|
|
5
|
-
`))):
|
|
2
|
+
import {Command}from'commander';import a from'chalk';import O from'inquirer';import g,{dirname,join}from'path';import {spawn}from'child_process';import {execa}from'execa';import v,{readFileSync,promises}from'fs';import {fileURLToPath}from'url';import me from'os';import ue from'validate-npm-package-name';import*as f from'fs-extra';import A from'ora';var F=class{debugEnabled=false;setDebug(e){this.debugEnabled=e;}debug(e,...i){this.debugEnabled&&console.log(a.gray(`[DEBUG] ${e}`),...i);}info(e,...i){console.log(a.blue(e),...i);}success(e,...i){console.log(a.green(e),...i);}warn(e,...i){console.log(a.yellow(e),...i);}error(e,...i){console.error(a.red(e),...i);}step(e,i,n){console.log(a.cyan(`
|
|
3
|
+
[${e}/${i}]`),a.white(n));}},l=new F;var oe="rapidkit",re=fileURLToPath(import.meta.url),se=dirname(re),ce=join(se,"..","package.json"),pe=JSON.parse(readFileSync(ce,"utf-8")),V=pe.version;async function H(){try{l.debug("Checking for updates...");let{stdout:t}=await execa("npm",["view",oe,"version"],{timeout:3e3}),e=t.trim();e&&e!==V?(console.log(a.yellow(`
|
|
4
|
+
\u26A0\uFE0F Update available: ${V} \u2192 ${e}`)),console.log(a.cyan(`Run: npm install -g rapidkit@latest
|
|
5
|
+
`))):l.debug("You are using the latest version");}catch{l.debug("Could not check for updates");}}function N(){return V}var ge=".rapidkitrc.json";async function J(){let t=g.join(me.homedir(),ge);try{let e=await promises.readFile(t,"utf-8"),i=JSON.parse(e);return l.debug(`Loaded config from ${t}`),i}catch{return l.debug("No user config found, using defaults"),{}}}var P=class extends Error{constructor(i,n,o){super(i);this.code=n;this.details=o;this.name="RapidKitError",Error.captureStackTrace(this,this.constructor);}};var j=class extends P{constructor(e,i){super(`Invalid project name: "${e}"`,"INVALID_PROJECT_NAME",i);}};function W(t){let e=ue(t);if(!e.validForNewPackages){let n=e.errors||[],o=e.warnings||[],c=[...n,...o];throw new j(t,`NPM validation failed: ${c.join(", ")}`)}if(!/^[a-z][a-z0-9_-]*$/.test(t))throw new j(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 j(t,`"${t}" is a reserved name. Please choose a different name.`);if(t.length<2)throw new j(t,"Name must be at least 2 characters long");if(t.length>214)throw new j(t,"Name must be less than 214 characters");return true}async function M(t,e){let i=A("Creating RapidKit workspace...").start();try{await promises.mkdir(t,{recursive:!0}),await promises.mkdir(g.join(t,".rapidkit"),{recursive:!0});let n={workspace_name:e.name,author:e.author,rapidkit_version:N(),created_at:new Date().toISOString(),type:"workspace"};await promises.writeFile(g.join(t,".rapidkit","config.json"),JSON.stringify(n,null,2));let o=he();await promises.writeFile(g.join(t,"rapidkit"),o),await promises.chmod(g.join(t,"rapidkit"),493);let c=fe(e.name);if(await promises.writeFile(g.join(t,"README.md"),c),await promises.writeFile(g.join(t,".gitignore"),`# RapidKit workspace
|
|
6
6
|
.env
|
|
7
7
|
.env.*
|
|
8
8
|
!.env.example
|
|
@@ -17,36 +17,36 @@ Thumbs.db
|
|
|
17
17
|
|
|
18
18
|
# Logs
|
|
19
19
|
*.log
|
|
20
|
-
`),await
|
|
21
|
-
${
|
|
20
|
+
`),await $e(t),i.succeed("Workspace created!"),!e.skipGit){let r=A("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}),r.succeed("Git repository initialized");}catch{r.warn("Could not initialize git repository");}}console.log(`
|
|
21
|
+
${a.green("\u2728 RapidKit workspace created successfully!")}
|
|
22
22
|
|
|
23
|
-
${
|
|
24
|
-
${
|
|
23
|
+
${a.bold("\u{1F4C2} Workspace structure:")}
|
|
24
|
+
${t}/
|
|
25
25
|
\u251C\u2500\u2500 rapidkit # Local CLI (add to PATH or use ./rapidkit)
|
|
26
26
|
\u251C\u2500\u2500 .rapidkit/ # Workspace configuration
|
|
27
27
|
\u2502 \u251C\u2500\u2500 config.json # Workspace settings
|
|
28
28
|
\u2502 \u2514\u2500\u2500 templates/ # Project templates
|
|
29
29
|
\u2514\u2500\u2500 README.md
|
|
30
30
|
|
|
31
|
-
${
|
|
32
|
-
${
|
|
33
|
-
${
|
|
34
|
-
${
|
|
35
|
-
${
|
|
36
|
-
${
|
|
31
|
+
${a.bold("\u{1F680} Get started:")}
|
|
32
|
+
${a.cyan(`cd ${e.name}`)}
|
|
33
|
+
${a.cyan('export PATH="$PWD:$PATH"')} ${a.gray("# Add rapidkit to PATH")}
|
|
34
|
+
${a.cyan("rapidkit create my-api --template fastapi")}
|
|
35
|
+
${a.cyan("cd my-api")}
|
|
36
|
+
${a.cyan("rapidkit dev")}
|
|
37
37
|
|
|
38
|
-
${
|
|
38
|
+
${a.bold("\u{1F4E6} Available templates:")}
|
|
39
39
|
fastapi - FastAPI + Python (default)
|
|
40
40
|
nestjs - NestJS + TypeScript
|
|
41
41
|
|
|
42
|
-
${
|
|
42
|
+
${a.bold("\u{1F4DA} Commands:")}
|
|
43
43
|
rapidkit create <name> Create a new project
|
|
44
44
|
rapidkit create --help Show create options
|
|
45
45
|
rapidkit help Show all commands
|
|
46
46
|
|
|
47
|
-
${
|
|
48
|
-
${
|
|
49
|
-
`);}catch(
|
|
47
|
+
${a.gray("Tip: Add workspace to PATH for easier access:")}
|
|
48
|
+
${a.cyan(`echo 'export PATH="${t}:$PATH"' >> ~/.bashrc`)}
|
|
49
|
+
`);}catch(n){throw i.fail("Failed to create workspace"),n}}function he(){return `#!/usr/bin/env bash
|
|
50
50
|
#
|
|
51
51
|
# RapidKit CLI - Local workspace commands
|
|
52
52
|
# This script provides rapidkit commands within the workspace
|
|
@@ -382,7 +382,7 @@ main() {
|
|
|
382
382
|
print_help
|
|
383
383
|
;;
|
|
384
384
|
version|-v|--version)
|
|
385
|
-
echo "RapidKit CLI (npm workspace) v${
|
|
385
|
+
echo "RapidKit CLI (npm workspace) v${N()}"
|
|
386
386
|
;;
|
|
387
387
|
*)
|
|
388
388
|
echo -e "\${RED}\u274C Unknown command: $cmd\${NC}"
|
|
@@ -394,7 +394,7 @@ main() {
|
|
|
394
394
|
}
|
|
395
395
|
|
|
396
396
|
main "$@"
|
|
397
|
-
`}function
|
|
397
|
+
`}function fe(t){return `# ${t}
|
|
398
398
|
|
|
399
399
|
RapidKit workspace for building API projects.
|
|
400
400
|
|
|
@@ -449,7 +449,7 @@ rapidkit dev # Start dev server
|
|
|
449
449
|
|
|
450
450
|
- [RapidKit Documentation](https://rapidkit.dev)
|
|
451
451
|
- [GitHub Repository](https://github.com/Baziar/rapidkit)
|
|
452
|
-
`}async function
|
|
452
|
+
`}async function $e(t){let{fileURLToPath:e}=await import('url'),i=e(import.meta.url),n=g.dirname(i),o=g.resolve(n,".."),c=g.join(o,"templates","kits"),p=g.join(t,".rapidkit","templates"),{default:r}=await import('fs-extra');await r.copy(c,p);let d=g.join(o,"templates","generator.js"),$=g.join(t,".rapidkit","generator.js");await r.copy(d,$);}async function Y(t,e){let i=e.template==="fastapi",n=i?"FastAPI":"NestJS",o=A(`Creating ${n} project...`).start();try{let{fileURLToPath:c}=await import('url'),p=c(import.meta.url),r=g.dirname(p),d=g.resolve(r,".."),$=i?"fastapi-standard":"nestjs-standard",h=g.join(d,"templates","kits",$);await promises.mkdir(t,{recursive:!0});let w={project_name:i?e.name.replace(/-/g,"_").toLowerCase():e.name.replace(/_/g,"-").toLowerCase(),author:e.author,description:e.description||`${n} application generated with RapidKit`,app_version:"0.1.0",license:"MIT",package_manager:e.package_manager||"npm",created_at:new Date().toISOString(),rapidkit_version:N()};await z(h,t,w);let _=i?`# Python
|
|
453
453
|
__pycache__/
|
|
454
454
|
*.py[cod]
|
|
455
455
|
*$py.class
|
|
@@ -517,11 +517,11 @@ Thumbs.db
|
|
|
517
517
|
|
|
518
518
|
# Coverage
|
|
519
519
|
coverage/
|
|
520
|
-
`;if(await promises.writeFile(
|
|
521
|
-
${
|
|
520
|
+
`;if(await promises.writeFile(g.join(t,".gitignore"),_),o.succeed(`${n} project created!`),!e.skipGit){let k=A("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}),k.succeed("Git repository initialized");}catch{k.warn("Could not initialize git repository");}}if(!e.skipInstall&&!i){let k=e.package_manager||"npm",D=A(`Installing dependencies with ${k}...`).start();try{await execa(k,["install"],{cwd:t}),D.succeed("Dependencies installed");}catch{D.warn(`Could not install dependencies. Run '${k} install' manually.`);}}let L=g.basename(t);console.log(i?`
|
|
521
|
+
${a.green("\u2728 FastAPI project created successfully!")}
|
|
522
522
|
|
|
523
|
-
${
|
|
524
|
-
${
|
|
523
|
+
${a.bold("\u{1F4C2} Project structure:")}
|
|
524
|
+
${t}/
|
|
525
525
|
\u251C\u2500\u2500 .rapidkit/ # RapidKit CLI module
|
|
526
526
|
\u251C\u2500\u2500 src/
|
|
527
527
|
\u2502 \u251C\u2500\u2500 main.py # FastAPI application
|
|
@@ -532,12 +532,12 @@ ${e}/
|
|
|
532
532
|
\u251C\u2500\u2500 pyproject.toml # Poetry configuration
|
|
533
533
|
\u2514\u2500\u2500 README.md
|
|
534
534
|
|
|
535
|
-
${
|
|
536
|
-
${
|
|
537
|
-
${
|
|
538
|
-
${
|
|
535
|
+
${a.bold("\u{1F680} Get started:")}
|
|
536
|
+
${a.cyan(`cd ${L}`)}
|
|
537
|
+
${a.cyan("rapidkit init")} ${a.gray("# Install dependencies")}
|
|
538
|
+
${a.cyan("rapidkit dev")} ${a.gray("# Start dev server")}
|
|
539
539
|
|
|
540
|
-
${
|
|
540
|
+
${a.bold("\u{1F4DA} Available commands:")}
|
|
541
541
|
rapidkit init # Install dependencies (poetry install)
|
|
542
542
|
rapidkit dev # Start dev server with hot reload
|
|
543
543
|
rapidkit start # Start production server
|
|
@@ -545,12 +545,12 @@ ${r.bold("\u{1F4DA} Available commands:")}
|
|
|
545
545
|
rapidkit lint # Lint code
|
|
546
546
|
rapidkit format # Format code
|
|
547
547
|
|
|
548
|
-
${
|
|
548
|
+
${a.gray("Alternative: use make commands (make dev, make test, ...)")}
|
|
549
549
|
`:`
|
|
550
|
-
${
|
|
550
|
+
${a.green("\u2728 NestJS project created successfully!")}
|
|
551
551
|
|
|
552
|
-
${
|
|
553
|
-
${
|
|
552
|
+
${a.bold("\u{1F4C2} Project structure:")}
|
|
553
|
+
${t}/
|
|
554
554
|
\u251C\u2500\u2500 .rapidkit/ # RapidKit CLI module
|
|
555
555
|
\u251C\u2500\u2500 src/
|
|
556
556
|
\u2502 \u251C\u2500\u2500 main.ts # Application entry point
|
|
@@ -561,13 +561,13 @@ ${e}/
|
|
|
561
561
|
\u251C\u2500\u2500 package.json # Dependencies
|
|
562
562
|
\u2514\u2500\u2500 README.md
|
|
563
563
|
|
|
564
|
-
${
|
|
565
|
-
${
|
|
566
|
-
${
|
|
567
|
-
`:""}${
|
|
568
|
-
${
|
|
564
|
+
${a.bold("\u{1F680} Get started:")}
|
|
565
|
+
${a.cyan(`cd ${L}`)}
|
|
566
|
+
${e.skipInstall?a.cyan("rapidkit init")+a.gray(" # npm install")+`
|
|
567
|
+
`:""}${a.cyan("cp .env.example .env")}
|
|
568
|
+
${a.cyan("rapidkit dev")} ${a.gray("# Start dev server")}
|
|
569
569
|
|
|
570
|
-
${
|
|
570
|
+
${a.bold("\u{1F4DA} Available commands:")}
|
|
571
571
|
rapidkit init # Install dependencies
|
|
572
572
|
rapidkit dev # Start dev server with hot reload
|
|
573
573
|
rapidkit start # Start production server
|
|
@@ -576,30 +576,100 @@ ${r.bold("\u{1F4DA} Available commands:")}
|
|
|
576
576
|
rapidkit lint # Lint code
|
|
577
577
|
rapidkit format # Format code
|
|
578
578
|
|
|
579
|
-
${
|
|
579
|
+
${a.bold("\u{1F310} API endpoints:")}
|
|
580
580
|
http://localhost:8000/health # Health check
|
|
581
581
|
http://localhost:8000/docs # Swagger docs
|
|
582
582
|
http://localhost:8000/examples/notes # Example API
|
|
583
|
-
`);}catch(
|
|
583
|
+
`);}catch(c){throw o.fail(`Failed to create ${n} project`),c}}async function z(t,e,i){let n=await promises.readdir(t,{withFileTypes:true});for(let o of n){let c=g.join(t,o.name),p=o.name.replace(/\.j2$/,""),r=g.join(e,p);if(o.isDirectory())await promises.mkdir(r,{recursive:true}),await z(c,r,i);else {let d=await promises.readFile(c,"utf-8");o.name.endsWith(".j2")&&(d=ye(d,i)),await promises.writeFile(r,d),(p==="rapidkit"||p==="activate"||p.endsWith(".py")&&r.includes(".rapidkit"))&&await promises.chmod(r,493);}}}function ye(t,e){let i=t;for(let[n,o]of Object.entries(e)){let c=new RegExp(`\\{\\{\\s*${n}\\s*\\}\\}`,"g");i=i.replace(c,String(o));let p=new RegExp(`\\{\\{\\s*${n}\\s*\\|\\s*replace\\s*\\(\\s*['"]([^'"]+)['"]\\s*,\\s*['"]([^'"]*)['"]\\s*\\)\\s*\\}\\}`,"g");i=i.replace(p,($,h,w)=>String(o).replace(new RegExp(h,"g"),w));let r=new RegExp(`\\{\\{\\s*${n}\\s*\\|\\s*lower\\s*\\}\\}`,"g");i=i.replace(r,String(o).toLowerCase());let d=new RegExp(`\\{\\{\\s*${n}\\s*\\|\\s*replace\\s*\\(\\s*['"]([^'"]+)['"]\\s*,\\s*['"]([^'"]*)['"]\\s*\\)\\s*\\|\\s*lower\\s*\\}\\}`,"g");i=i.replace(d,($,h,w)=>String(o).replace(new RegExp(h,"g"),w).toLowerCase());}return i}var B=["init","dev","start","build","test","lint","format","help","--help","-h"];function we(t){let e=t;for(;;){let i=g.join(e,".rapidkit","context.json");if(v.existsSync(i))return i;let n=g.dirname(e);if(n===e)break;e=n;}return null}function ve(t){let e=t;for(;;){let i=g.join(e,"rapidkit"),n=g.join(e,".rapidkit","rapidkit");if(v.existsSync(i))return i;if(v.existsSync(n))return n;let o=g.dirname(e);if(o===e)break;e=o;}return null}(()=>{try{let t=process.cwd(),i=process.argv.slice(2)[0],n=we(t);if(n&&v.existsSync(n)){let o=v.readFileSync(n,"utf8");try{let c=JSON.parse(o),p=i==="shell"&&process.argv.slice(2)[1]==="activate",d=ve(t)&&i&&B.includes(i);c?.engine==="pip"&&!p&&!d&&i!=="init"&&(console.log(a.yellow(`
|
|
584
|
+
\u26A0\uFE0F This project uses the Python RapidKit engine (pip). The global npm RapidKit CLI will not operate on this project.
|
|
585
|
+
\u{1F4A1} To prepare this project run: 'rapidkit init' (it uses the project's Python toolchain)
|
|
586
|
+
`)),process.exit(0));}catch{}}}catch{}})();function X(t){let e=t;for(;;){let i=g.join(e,".rapidkit","context.json");if(v.existsSync(i))return i;let n=g.dirname(e);if(n===e)break;e=n;}return null}async function je(){let t=process.cwd(),e=X(t),i=e?g.dirname(e):g.join(t,".rapidkit");if(e&&await f.pathExists(e))try{if((await f.readJson(e)).engine==="pip"){let w=process.argv.slice(2),_=w[0],L=[g.join(t,"rapidkit"),g.join(t,".rapidkit","rapidkit")],k=null;for(let m of L)if(await f.pathExists(m)){k=m;break}if(k&&_&&B.includes(_)){l.debug(`Delegating to local CLI (early detection): ${k} ${w.join(" ")}`);let m=spawn(k,w,{stdio:"inherit",cwd:t});return m.on("close",E=>process.exit(E??0)),m.on("error",E=>{l.error(`Failed to run local rapidkit: ${E.message}`),process.exit(1);}),!0}if(_==="shell"&&w[1]==="activate"){let m=`# RapidKit: activation snippet - eval "$(rapidkit shell activate)"
|
|
587
|
+
VENV='.venv'
|
|
588
|
+
if [ -f "$VENV/bin/activate" ]; then
|
|
589
|
+
. "$VENV/bin/activate"
|
|
590
|
+
elif [ -f "$VENV/bin/activate.fish" ]; then
|
|
591
|
+
source "$VENV/bin/activate.fish"
|
|
592
|
+
fi
|
|
593
|
+
export RAPIDKIT_PROJECT_ROOT="$(pwd)"
|
|
594
|
+
export PATH="$(pwd)/.rapidkit:$(pwd):$PATH"
|
|
595
|
+
`;console.log(a.green.bold(`
|
|
596
|
+
\u2705 Activation snippet \u2014 run the following to activate this project in your current shell:
|
|
597
|
+
`)),console.log(m),console.log(a.gray(`
|
|
598
|
+
\u{1F4A1} After activation you can run: rapidkit dev
|
|
599
|
+
`)),process.exit(0);}if(_!=="init"){let m=(await import('chalk')).default;console.log(m.yellow(`
|
|
600
|
+
\u26A0\uFE0F This project uses the Python RapidKit engine (pip). The global npm RapidKit CLI will not operate on this project.
|
|
601
|
+
\u{1F4A1} To prepare this project run: 'rapidkit init' (it uses the project's Python toolchain)
|
|
602
|
+
|
|
603
|
+
`)),process.exit(0);}let D=(await import('chalk')).default;console.log(D.yellow(`
|
|
604
|
+
\u26A0\uFE0F This project was created with the Python engine (pip). RapidKit (npm) will try to install the Python CLI for you...
|
|
605
|
+
`));let{spawnSync:Q}=await import('child_process'),Z=[["python3",["-m","pip","install","rapidkit-core"]],["python",["-m","pip","install","rapidkit-core"]],["pip",["install","rapidkit-core"]]],S=!0;if(process.stdin.isTTY)try{S=!!(await O.prompt([{type:"confirm",name:"confirm",message:"This project needs the Python RapidKit CLI (rapidkit). Do you want to try installing it now using pip?",default:!0}])).confirm;}catch{S=!1;}else S=!1;if(!S){let m=(await import('chalk')).default;console.log(m.yellow(`
|
|
606
|
+
\u26A0\uFE0F Skipping automatic installation of the Python RapidKit CLI (rapidkit-core).
|
|
607
|
+
\u{1F4A1} To continue, either run 'rapidkit init' locally after installing rapidkit-core: \`python3 -m pip install rapidkit-core\`
|
|
608
|
+
`)),process.exit(0);}let R={status:1};if(S)for(let[m,E]of Z)try{if(console.log(a.gray(`Running: ${m} ${E.join(" ")}
|
|
609
|
+
`)),R=Q(m,E,{stdio:"inherit"}),R&&R.status===0)break}catch{}if(R&&R.status===0){let m=(await import('chalk')).default;console.log(m.green(`
|
|
610
|
+
\u2705 RapidKit Python CLI (rapidkit) installed successfully!
|
|
611
|
+
Please re-run your command.
|
|
612
|
+
`));}else {let m=(await import('chalk')).default;console.log(m.red(`
|
|
613
|
+
\u274C Failed to install RapidKit Python CLI automatically.
|
|
614
|
+
\u{1F4A1} Manual install options:
|
|
615
|
+
python3 -m pip install rapidkit
|
|
616
|
+
python -m pip install rapidkit
|
|
617
|
+
pip install rapidkit
|
|
618
|
+
`));}process.exit(R.status??1);}}catch{}let n=[g.join(t,"rapidkit"),g.join(t,".rapidkit","rapidkit")],o=g.join(t,"rapidkit");for(let h of n)if(await f.pathExists(h)){o=h;break}let c=await f.pathExists(o),p=await f.pathExists(i);if(!c||!p)return false;let r=process.argv.slice(2),d=r[0];if(!d||!B.includes(d))return false;l.debug(`Delegating to local CLI: ./rapidkit ${r.join(" ")}`);let $=spawn(o,r,{stdio:"inherit",cwd:t});return $.on("close",h=>{process.exit(h??0);}),$.on("error",h=>{l.error(`Failed to run local rapidkit: ${h.message}`),process.exit(1);}),true}var x=null,U=false,K=new Command;K.name("rapidkit").description("Create RapidKit workspaces and projects").version(N());K.argument("[name]","Name of the workspace or project directory").option("-t, --template <template>","Create project with template (fastapi, nestjs) instead of workspace").option("-y, --yes","Skip prompts and use defaults").option("--skip-git","Skip git initialization").option("--skip-install","Skip installing dependencies").option("--debug","Enable debug logging").option("--dry-run","Show what would be created without creating it").option("--no-update-check","Skip checking for updates").action(async(t,e)=>{try{e.debug&&(l.setDebug(!0),l.debug("Debug mode enabled"));let i=await J();l.debug("User config loaded",i),e.updateCheck!==!1&&await H(),console.log(a.blue.bold(`
|
|
584
619
|
\u{1F680} Welcome to RapidKit!
|
|
585
|
-
`)),
|
|
586
|
-
\u274C ${p.message}`),p.details&&
|
|
587
|
-
`),process.exit(1)),p}let
|
|
588
|
-
\u274C Directory "${
|
|
620
|
+
`)),t||(xe(),process.exit(0));try{W(t);}catch(p){throw p instanceof P&&(l.error(`
|
|
621
|
+
\u274C ${p.message}`),p.details&&l.warn(`\u{1F4A1} ${p.details}
|
|
622
|
+
`),process.exit(1)),p}let n=g.resolve(process.cwd(),t);x=n,await f.pathExists(n)&&(l.error(`
|
|
623
|
+
\u274C Directory "${t}" already exists`),console.log(a.cyan(`
|
|
589
624
|
\u{1F4A1} Choose a different name or delete the existing directory.
|
|
590
|
-
`)),process.exit(1));let
|
|
591
|
-
\u274C Invalid template: ${
|
|
592
|
-
\u{1F4E6} Available templates: ${
|
|
593
|
-
`)),process.exit(1));}if(
|
|
625
|
+
`)),process.exit(1));let o=!!e.template;if(o){let p=e.template.toLowerCase(),r=["fastapi","nestjs"];r.includes(p)||(l.error(`
|
|
626
|
+
\u274C Invalid template: ${e.template}`),console.log(a.cyan(`
|
|
627
|
+
\u{1F4E6} Available templates: ${r.join(", ")}
|
|
628
|
+
`)),process.exit(1));}if(e.dryRun){console.log(a.cyan(`
|
|
594
629
|
\u{1F50D} Dry-run mode - showing what would be created:
|
|
595
|
-
`)),console.log(
|
|
596
|
-
`))):
|
|
597
|
-
\u274C ${i.message}`),i.details&&
|
|
598
|
-
\u274C An unexpected error occurred:`),console.error(i)),process.exit(1);}finally{
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
630
|
+
`)),console.log(a.white("\u{1F4C2} Path:"),n),console.log(a.white("\u{1F4E6} Type:"),o?`Project (${e.template})`:"Workspace"),console.log();return}let c;e.yes?(c={author:process.env.USER||"RapidKit User",description:o?`${e.template==="nestjs"?"NestJS":"FastAPI"} application generated with RapidKit`:void 0,package_manager:"npm"},console.log(a.gray(`Using default values (--yes flag)
|
|
631
|
+
`))):o?e.template.toLowerCase()==="fastapi"?c=await O.prompt([{type:"input",name:"author",message:"Author name:",default:process.env.USER||"RapidKit User"},{type:"input",name:"description",message:"Project description:",default:"FastAPI service generated with RapidKit"}]):c=await O.prompt([{type:"input",name:"author",message:"Author name:",default:process.env.USER||"RapidKit User"},{type:"input",name:"description",message:"Project description:",default:"NestJS application generated with RapidKit"},{type:"list",name:"package_manager",message:"Package manager:",choices:["npm","yarn","pnpm"],default:"npm"}]):c=await O.prompt([{type:"input",name:"author",message:"Author name:",default:process.env.USER||"RapidKit User"}]),o?await Y(n,{name:t,template:e.template.toLowerCase(),author:c.author,description:c.description,package_manager:c.package_manager,skipGit:e.skipGit,skipInstall:e.skipInstall}):await M(n,{name:t,author:c.author,skipGit:e.skipGit});}catch(i){i instanceof P?(l.error(`
|
|
632
|
+
\u274C ${i.message}`),i.details&&l.warn(`\u{1F4A1} ${i.details}`),l.debug("Error code:",i.code)):(l.error(`
|
|
633
|
+
\u274C An unexpected error occurred:`),console.error(i)),process.exit(1);}finally{x=null;}});K.command("shell <action>").description("Shell helpers (activate virtualenv in current shell)").action(async t=>{t!=="activate"&&(console.log(a.red(`Unknown shell command: ${t}`)),process.exit(1));let e=process.cwd();function i(p){let r=p;for(;;){let d=g.join(r,".rapidkit","context.json");if(v.existsSync(d))return d;let $=g.dirname(r);if($===r)break;r=$;}return null}let n=i(e);function o(p){let r=p;for(;;){let d=g.join(r,".venv"),$=g.join(r,".rapidkit","activate");if(v.existsSync($)||v.existsSync(d))return {venv:d,activateFile:$};let h=g.dirname(r);if(h===r)break;r=h;}return null}let c=o(e);if(!n&&!c&&(console.log(a.red("No RapidKit project found to activate")),process.exit(1)),c){let p=`# RapidKit: activation snippet - eval "$(rapidkit shell activate)"
|
|
634
|
+
VENV='.venv'
|
|
635
|
+
if [ -f "$VENV/bin/activate" ]; then
|
|
636
|
+
. "$VENV/bin/activate"
|
|
637
|
+
elif [ -f "$VENV/bin/activate.fish" ]; then
|
|
638
|
+
source "$VENV/bin/activate.fish"
|
|
639
|
+
fi
|
|
640
|
+
export RAPIDKIT_PROJECT_ROOT="$(pwd)"
|
|
641
|
+
export PATH="$(pwd)/.rapidkit:$(pwd):$PATH"
|
|
642
|
+
`;console.log(a.green.bold(`
|
|
643
|
+
\u2705 Activation snippet \u2014 run the following to activate this project in your current shell:
|
|
644
|
+
`)),console.log(p),console.log(a.gray(`
|
|
645
|
+
\u{1F4A1} After activation you can run: rapidkit dev
|
|
646
|
+
`)),process.exit(0);}try{(await f.readJson(n)).engine!=="pip"&&(console.log(a.yellow("This project is not a pip-based RapidKit project.")),process.exit(1)),console.log(`# RapidKit: activation snippet - eval "$(rapidkit shell activate)"
|
|
647
|
+
VENV='.venv'
|
|
648
|
+
if [ -f "$VENV/bin/activate" ]; then
|
|
649
|
+
. "$VENV/bin/activate"
|
|
650
|
+
elif [ -f "$VENV/bin/activate.fish" ]; then
|
|
651
|
+
source "$VENV/bin/activate.fish"
|
|
652
|
+
fi
|
|
653
|
+
export RAPIDKIT_PROJECT_ROOT="$(pwd)"
|
|
654
|
+
export PATH="$(pwd)/.rapidkit:$(pwd):$PATH"
|
|
655
|
+
`),process.exit(0);}catch{console.log(a.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)"
|
|
656
|
+
VENV='.venv'
|
|
657
|
+
if [ -f "$VENV/bin/activate" ]; then
|
|
658
|
+
. "$VENV/bin/activate"
|
|
659
|
+
elif [ -f "$VENV/bin/activate.fish" ]; then
|
|
660
|
+
source "$VENV/bin/activate.fish"
|
|
661
|
+
fi
|
|
662
|
+
export RAPIDKIT_PROJECT_ROOT="$(pwd)"
|
|
663
|
+
export PATH="$(pwd):$PATH"
|
|
664
|
+
`),process.exit(0);}});function xe(){console.log(a.white(`Usage: npx rapidkit <name> [options]
|
|
665
|
+
`)),console.log(a.bold("Create a workspace (recommended):")),console.log(a.cyan(" npx rapidkit my-workspace")),console.log(a.cyan(" cd my-workspace")),console.log(a.cyan(" rapidkit create my-api --template fastapi")),console.log(a.cyan(" cd my-api")),console.log(a.cyan(` rapidkit dev
|
|
666
|
+
`)),console.log(a.bold("Or create a project directly:")),console.log(a.cyan(" npx rapidkit my-project --template fastapi")),console.log(a.cyan(` npx rapidkit my-project --template nestjs
|
|
667
|
+
`)),console.log(a.bold("Options:")),console.log(a.gray(" -t, --template <template> Create project with template (fastapi, nestjs)")),console.log(a.gray(" -y, --yes Skip prompts and use defaults")),console.log(a.gray(" --skip-git Skip git initialization")),console.log(a.gray(" --skip-install Skip installing dependencies")),console.log(a.gray(" --debug Enable debug logging")),console.log(a.gray(` --dry-run Show what would be created
|
|
668
|
+
`)),console.log(a.bold("Templates:")),console.log(a.gray(" fastapi FastAPI + Python")),console.log(a.gray(` nestjs NestJS + TypeScript
|
|
669
|
+
`));}process.on("SIGINT",async()=>{if(!U){if(U=true,console.log(a.yellow(`
|
|
670
|
+
|
|
671
|
+
\u26A0\uFE0F Interrupted by user`)),x&&await f.pathExists(x)){console.log(a.gray("Cleaning up partial installation..."));try{await f.remove(x),console.log(a.green("\u2713 Cleanup complete"));}catch(t){l.debug("Cleanup failed:",t);}}process.exit(130);}});process.on("SIGTERM",async()=>{if(!U){if(U=true,l.debug("Received SIGTERM"),x&&await f.pathExists(x))try{await f.remove(x);}catch(t){l.debug("Cleanup failed:",t);}process.exit(143);}});je().then(async t=>{if(!t){let e=process.cwd();try{let i=X(e);if(i&&await f.pathExists(i)){let n=await f.readJson(i),o=process.argv.slice(2)[0];if(n?.engine==="pip"&&o!=="init"){let c=(await import('chalk')).default;console.log(c.yellow(`
|
|
672
|
+
\u26A0\uFE0F This project uses the Python RapidKit engine (pip). The global npm RapidKit CLI will not operate on this project.
|
|
673
|
+
\u{1F4A1} To prepare this project run: 'rapidkit init' (it uses the project's Python toolchain)
|
|
674
|
+
|
|
675
|
+
`)),process.exit(0);}}}catch{}K.parse();}});
|
package/dist/package.json
CHANGED
package/package.json
CHANGED