rapidkit 0.12.6 โ 0.12.7
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
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 o from'chalk';import U from'inquirer';import l,{dirname,join}from'path';import {spawn}from'child_process';import {execa}from'execa';import w,{readFileSync,promises}from'fs';import {fileURLToPath}from'url';import ue from'os';import he from'validate-npm-package-name';import*as f from'fs-extra';import L from'ora';var V=class{debugEnabled=false;setDebug(t){this.debugEnabled=t;}debug(t,...i){this.debugEnabled&&console.log(o.gray(`[DEBUG] ${t}`),...i);}info(t,...i){console.log(o.blue(t),...i);}success(t,...i){console.log(o.green(t),...i);}warn(t,...i){console.log(o.yellow(t),...i);}error(t,...i){console.error(o.red(t),...i);}step(t,i,n){console.log(o.cyan(`
|
|
3
|
+
[${t}/${i}]`),o.white(n));}},d=new V;var se="rapidkit",ce=fileURLToPath(import.meta.url),pe=dirname(ce),le=join(pe,"..","package.json"),de=JSON.parse(readFileSync(le,"utf-8")),B=de.version;async function H(){try{d.debug("Checking for updates...");let{stdout:e}=await execa("npm",["view",se,"version"],{timeout:3e3}),t=e.trim();t&&t!==B?(console.log(o.yellow(`
|
|
4
|
+
\u26A0\uFE0F Update available: ${B} \u2192 ${t}`)),console.log(o.cyan(`Run: npm install -g rapidkit@latest
|
|
5
|
+
`))):d.debug("You are using the latest version");}catch{d.debug("Could not check for updates");}}function S(){return B}var fe=".rapidkitrc.json";async function J(){let e=l.join(ue.homedir(),fe);try{let t=await promises.readFile(e,"utf-8"),i=JSON.parse(t);return d.debug(`Loaded config from ${e}`),i}catch{return d.debug("No user config found, using defaults"),{}}}var P=class extends Error{constructor(i,n,r){super(i);this.code=n;this.details=r;this.name="RapidKitError",Error.captureStackTrace(this,this.constructor);}};var v=class extends P{constructor(t,i){super(`Invalid project name: "${t}"`,"INVALID_PROJECT_NAME",i);}};function M(e){let t=he(e);if(!t.validForNewPackages){let n=t.errors||[],r=t.warnings||[],a=[...n,...r];throw new v(e,`NPM validation failed: ${a.join(", ")}`)}if(!/^[a-z][a-z0-9_-]*$/.test(e))throw new v(e,"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(e.toLowerCase()))throw new v(e,`"${e}" is a reserved name. Please choose a different name.`);if(e.length<2)throw new v(e,"Name must be at least 2 characters long");if(e.length>214)throw new v(e,"Name must be less than 214 characters");return true}async function Y(e,t){let i=L("Creating RapidKit workspace...").start();try{await promises.mkdir(e,{recursive:!0}),await promises.mkdir(l.join(e,".rapidkit"),{recursive:!0});let n={workspace_name:t.name,author:t.author,rapidkit_version:S(),created_at:new Date().toISOString(),type:"workspace"};await promises.writeFile(l.join(e,".rapidkit","config.json"),JSON.stringify(n,null,2));let r=ke();await promises.writeFile(l.join(e,"rapidkit"),r),await promises.chmod(l.join(e,"rapidkit"),493);let a=$e(t.name);if(await promises.writeFile(l.join(e,"README.md"),a),await promises.writeFile(l.join(e,".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 ye(e),i.succeed("Workspace created!"),!t.skipGit){let s=L("Initializing git repository...").start();try{await execa("git",["init"],{cwd:e}),await execa("git",["add","."],{cwd:e}),await execa("git",["commit","-m","Initial commit: RapidKit workspace"],{cwd:e}),s.succeed("Git repository initialized");}catch{s.warn("Could not initialize git repository");}}console.log(`
|
|
21
|
+
${o.green("\u2728 RapidKit workspace created successfully!")}
|
|
22
22
|
|
|
23
|
-
${
|
|
24
|
-
${
|
|
23
|
+
${o.bold("\u{1F4C2} Workspace structure:")}
|
|
24
|
+
${e}/
|
|
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
|
+
${o.bold("\u{1F680} Get started:")}
|
|
32
|
+
${o.cyan(`cd ${t.name}`)}
|
|
33
|
+
${o.cyan('export PATH="$PWD:$PATH"')} ${o.gray("# Add rapidkit to PATH")}
|
|
34
|
+
${o.cyan("rapidkit create my-api --template fastapi")}
|
|
35
|
+
${o.cyan("cd my-api")}
|
|
36
|
+
${o.cyan("rapidkit dev")}
|
|
37
37
|
|
|
38
|
-
${
|
|
38
|
+
${o.bold("\u{1F4E6} Available templates:")}
|
|
39
39
|
fastapi - FastAPI + Python (default)
|
|
40
40
|
nestjs - NestJS + TypeScript
|
|
41
41
|
|
|
42
|
-
${
|
|
42
|
+
${o.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(n){throw i.fail("Failed to create workspace"),n}}function
|
|
47
|
+
${o.gray("Tip: Add workspace to PATH for easier access:")}
|
|
48
|
+
${o.cyan(`echo 'export PATH="${e}:$PATH"' >> ~/.bashrc`)}
|
|
49
|
+
`);}catch(n){throw i.fail("Failed to create workspace"),n}}function ke(){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${S()}"
|
|
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 $e(e){return `# ${e}
|
|
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 ye(e){let{fileURLToPath:t}=await import('url'),i=t(import.meta.url),n=l.dirname(i),r=l.resolve(n,".."),a=l.join(r,"templates","kits"),c=l.join(e,".rapidkit","templates"),{default:s}=await import('fs-extra');await s.copy(a,c);let m=l.join(r,"templates","generator.js"),h=l.join(e,".rapidkit","generator.js");await s.copy(m,h);}async function z(e,t){let i=t.template==="fastapi",n=i?"FastAPI":"NestJS",r=L(`Creating ${n} project...`).start();try{let{fileURLToPath:a}=await import('url'),c=a(import.meta.url),s=l.dirname(c),m=l.resolve(s,".."),h=i?"fastapi-standard":"nestjs-standard",y=l.join(m,"templates","kits",h);await promises.mkdir(e,{recursive:!0});let k={project_name:i?t.name.replace(/-/g,"_").toLowerCase():t.name.replace(/_/g,"-").toLowerCase(),author:t.author,description:t.description||`${n} application generated with RapidKit`,app_version:"0.1.0",license:"MIT",package_manager:t.package_manager||"npm",created_at:new Date().toISOString(),rapidkit_version:S()};await q(y,e,k);let R=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(l.join(e,".gitignore"),R),r.succeed(`${n} project created!`),!t.skipGit){let C=L("Initializing git repository...").start();try{await execa("git",["init"],{cwd:e}),await execa("git",["add","."],{cwd:e}),await execa("git",["commit","-m",`Initial commit: ${n} project via RapidKit`],{cwd:e}),C.succeed("Git repository initialized");}catch{C.warn("Could not initialize git repository");}}if(!t.skipInstall&&!i){let C=t.package_manager||"npm",D=L(`Installing dependencies with ${C}...`).start();try{await execa(C,["install"],{cwd:e}),D.succeed("Dependencies installed");}catch{D.warn(`Could not install dependencies. Run '${C} install' manually.`);}}let x=l.basename(e);console.log(i?`
|
|
521
|
+
${o.green("\u2728 FastAPI project created successfully!")}
|
|
522
522
|
|
|
523
|
-
${
|
|
524
|
-
${
|
|
523
|
+
${o.bold("\u{1F4C2} Project structure:")}
|
|
524
|
+
${e}/
|
|
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 @@ ${t}/
|
|
|
532
532
|
\u251C\u2500\u2500 pyproject.toml # Poetry configuration
|
|
533
533
|
\u2514\u2500\u2500 README.md
|
|
534
534
|
|
|
535
|
-
${
|
|
536
|
-
${
|
|
537
|
-
${
|
|
538
|
-
${
|
|
535
|
+
${o.bold("\u{1F680} Get started:")}
|
|
536
|
+
${o.cyan(`cd ${x}`)}
|
|
537
|
+
${o.cyan("rapidkit init")} ${o.gray("# Install dependencies")}
|
|
538
|
+
${o.cyan("rapidkit dev")} ${o.gray("# Start dev server")}
|
|
539
539
|
|
|
540
|
-
${
|
|
540
|
+
${o.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 @@ ${a.bold("\u{1F4DA} Available commands:")}
|
|
|
545
545
|
rapidkit lint # Lint code
|
|
546
546
|
rapidkit format # Format code
|
|
547
547
|
|
|
548
|
-
${
|
|
548
|
+
${o.gray("Alternative: use make commands (make dev, make test, ...)")}
|
|
549
549
|
`:`
|
|
550
|
-
${
|
|
550
|
+
${o.green("\u2728 NestJS project created successfully!")}
|
|
551
551
|
|
|
552
|
-
${
|
|
553
|
-
${
|
|
552
|
+
${o.bold("\u{1F4C2} Project structure:")}
|
|
553
|
+
${e}/
|
|
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 @@ ${t}/
|
|
|
561
561
|
\u251C\u2500\u2500 package.json # Dependencies
|
|
562
562
|
\u2514\u2500\u2500 README.md
|
|
563
563
|
|
|
564
|
-
${
|
|
565
|
-
${
|
|
566
|
-
${
|
|
567
|
-
`:""}${
|
|
568
|
-
${
|
|
564
|
+
${o.bold("\u{1F680} Get started:")}
|
|
565
|
+
${o.cyan(`cd ${x}`)}
|
|
566
|
+
${t.skipInstall?o.cyan("rapidkit init")+o.gray(" # npm install")+`
|
|
567
|
+
`:""}${o.cyan("cp .env.example .env")}
|
|
568
|
+
${o.cyan("rapidkit dev")} ${o.gray("# Start dev server")}
|
|
569
569
|
|
|
570
|
-
${
|
|
570
|
+
${o.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,14 +576,14 @@ ${a.bold("\u{1F4DA} Available commands:")}
|
|
|
576
576
|
rapidkit lint # Lint code
|
|
577
577
|
rapidkit format # Format code
|
|
578
578
|
|
|
579
|
-
${
|
|
579
|
+
${o.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(a){throw r.fail(`Failed to create ${n} project`),a}}async function q(e,t,i){let n=await promises.readdir(e,{withFileTypes:true});for(let r of n){let a=l.join(e,r.name),c=r.name.replace(/\.j2$/,""),s=l.join(t,c);if(r.isDirectory())await promises.mkdir(s,{recursive:true}),await q(a,s,i);else {let m=await promises.readFile(a,"utf-8");r.name.endsWith(".j2")&&(m=we(m,i)),await promises.writeFile(s,m),(c==="rapidkit"||c==="activate"||c.endsWith(".py")&&s.includes(".rapidkit"))&&await promises.chmod(s,493);}}}function we(e,t){let i=e;for(let[n,r]of Object.entries(t)){let a=new RegExp(`\\{\\{\\s*${n}\\s*\\}\\}`,"g");i=i.replace(a,String(r));let c=new RegExp(`\\{\\{\\s*${n}\\s*\\|\\s*replace\\s*\\(\\s*['"]([^'"]+)['"]\\s*,\\s*['"]([^'"]*)['"]\\s*\\)\\s*\\}\\}`,"g");i=i.replace(c,(h,y,k)=>String(r).replace(new RegExp(y,"g"),k));let s=new RegExp(`\\{\\{\\s*${n}\\s*\\|\\s*lower\\s*\\}\\}`,"g");i=i.replace(s,String(r).toLowerCase());let m=new RegExp(`\\{\\{\\s*${n}\\s*\\|\\s*replace\\s*\\(\\s*['"]([^'"]+)['"]\\s*,\\s*['"]([^'"]*)['"]\\s*\\)\\s*\\|\\s*lower\\s*\\}\\}`,"g");i=i.replace(m,(h,y,k)=>String(r).replace(new RegExp(y,"g"),k).toLowerCase());}return i}var W=["init","dev","start","build","test","lint","format","help","--help","-h"];function je(e){let t=e;for(;;){let i=l.join(t,".rapidkit","context.json");if(w.existsSync(i))return i;let n=l.dirname(t);if(n===t)break;t=n;}return null}function xe(e){let t=process.platform==="win32",i=e;for(;;){if(t){let c=l.join(i,"rapidkit.cmd"),s=l.join(i,".rapidkit","rapidkit.cmd");if(w.existsSync(c))return c;if(w.existsSync(s))return s}let n=l.join(i,"rapidkit"),r=l.join(i,".rapidkit","rapidkit");if(w.existsSync(n))return n;if(w.existsSync(r))return r;let a=l.dirname(i);if(a===i)break;i=a;}return null}(()=>{try{let e=process.cwd(),i=process.argv.slice(2)[0],n=je(e);if(n&&w.existsSync(n)){let r=w.readFileSync(n,"utf8");try{let a=JSON.parse(r),c=i==="shell"&&process.argv.slice(2)[1]==="activate",m=xe(e)&&i&&W.includes(i);a?.engine==="pip"&&!c&&!m&&i!=="init"&&(console.log(o.yellow(`
|
|
584
584
|
\u26A0\uFE0F This project uses the Python RapidKit engine (pip). The global npm RapidKit CLI will not operate on this project.
|
|
585
585
|
\u{1F4A1} To prepare this project run: 'rapidkit init' (it uses the project's Python toolchain)
|
|
586
|
-
`)),process.exit(0));}catch{}}}catch{}})();function
|
|
586
|
+
`)),process.exit(0));}catch{}}}catch{}})();function Q(e){let t=e;for(;;){let i=l.join(t,".rapidkit","context.json");if(w.existsSync(i))return i;let n=l.dirname(t);if(n===t)break;t=n;}return null}async function Ce(){let e=process.cwd(),t=Q(e),i=t?l.dirname(t):l.join(e,".rapidkit");if(t&&await f.pathExists(t))try{if((await f.readJson(t)).engine==="pip"){let R=process.argv.slice(2),x=R[0],D=process.platform==="win32"?[l.join(e,"rapidkit.cmd"),l.join(e,"rapidkit"),l.join(e,".rapidkit","rapidkit.cmd"),l.join(e,".rapidkit","rapidkit")]:[l.join(e,"rapidkit"),l.join(e,".rapidkit","rapidkit")],O=null;for(let g of D)if(await f.pathExists(g)){O=g;break}if(O&&x&&W.includes(x)){d.debug(`Delegating to local CLI (early detection): ${O} ${R.join(" ")}`);let g=spawn(O,R,{stdio:"inherit",cwd:e});return g.on("close",N=>process.exit(N??0)),g.on("error",N=>{d.error(`Failed to run local rapidkit: ${N.message}`),process.exit(1);}),!0}if(x==="shell"&&R[1]==="activate"){let g=`# RapidKit: activation snippet - eval "$(rapidkit shell activate)"
|
|
587
587
|
VENV='.venv'
|
|
588
588
|
if [ -f "$VENV/bin/activate" ]; then
|
|
589
589
|
. "$VENV/bin/activate"
|
|
@@ -592,45 +592,45 @@ elif [ -f "$VENV/bin/activate.fish" ]; then
|
|
|
592
592
|
fi
|
|
593
593
|
export RAPIDKIT_PROJECT_ROOT="$(pwd)"
|
|
594
594
|
export PATH="$(pwd)/.rapidkit:$(pwd):$PATH"
|
|
595
|
-
`;console.log(
|
|
595
|
+
`;console.log(o.green.bold(`
|
|
596
596
|
\u2705 Activation snippet \u2014 run the following to activate this project in your current shell:
|
|
597
|
-
`)),console.log(
|
|
597
|
+
`)),console.log(g),console.log(o.gray(`
|
|
598
598
|
\u{1F4A1} After activation you can run: rapidkit dev
|
|
599
|
-
`)),process.exit(0);}if(
|
|
599
|
+
`)),process.exit(0);}if(x!=="init"){let g=(await import('chalk')).default;console.log(g.yellow(`
|
|
600
600
|
\u26A0\uFE0F This project uses the Python RapidKit engine (pip). The global npm RapidKit CLI will not operate on this project.
|
|
601
601
|
\u{1F4A1} To prepare this project run: 'rapidkit init' (it uses the project's Python toolchain)
|
|
602
602
|
|
|
603
|
-
`)),process.exit(0);}let
|
|
603
|
+
`)),process.exit(0);}let Z=(await import('chalk')).default;console.log(Z.yellow(`
|
|
604
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:
|
|
605
|
+
`));let{spawnSync:ee}=await import('child_process'),te=[["python3",["-m","pip","install","rapidkit-core"]],["python",["-m","pip","install","rapidkit-core"]],["pip",["install","rapidkit-core"]]],I=!0;if(process.stdin.isTTY)try{I=!!(await U.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{I=!1;}else I=!1;if(!I){let g=(await import('chalk')).default;console.log(g.yellow(`
|
|
606
606
|
\u26A0\uFE0F Skipping automatic installation of the Python RapidKit CLI (rapidkit-core).
|
|
607
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
|
|
609
|
-
`)),
|
|
608
|
+
`)),process.exit(0);}let E={status:1};if(I)for(let[g,N]of te)try{if(console.log(o.gray(`Running: ${g} ${N.join(" ")}
|
|
609
|
+
`)),E=ee(g,N,{stdio:"inherit"}),E&&E.status===0)break}catch{}if(E&&E.status===0){let g=(await import('chalk')).default;console.log(g.green(`
|
|
610
610
|
\u2705 RapidKit Python CLI (rapidkit) installed successfully!
|
|
611
611
|
Please re-run your command.
|
|
612
|
-
`));}else {let
|
|
612
|
+
`));}else {let g=(await import('chalk')).default;console.log(g.red(`
|
|
613
613
|
\u274C Failed to install RapidKit Python CLI automatically.
|
|
614
614
|
\u{1F4A1} Manual install options:
|
|
615
615
|
python3 -m pip install rapidkit
|
|
616
616
|
python -m pip install rapidkit
|
|
617
617
|
pip install rapidkit
|
|
618
|
-
`));}process.exit(
|
|
618
|
+
`));}process.exit(E.status??1);}}catch{}let n=process.platform==="win32",r=n?[l.join(e,"rapidkit.cmd"),l.join(e,"rapidkit"),l.join(e,".rapidkit","rapidkit.cmd"),l.join(e,".rapidkit","rapidkit")]:[l.join(e,"rapidkit"),l.join(e,".rapidkit","rapidkit")],a=n?l.join(e,"rapidkit.cmd"):l.join(e,"rapidkit");for(let k of r)if(await f.pathExists(k)){a=k;break}let c=await f.pathExists(a),s=await f.pathExists(i);if(!c||!s)return false;let m=process.argv.slice(2),h=m[0];if(!h||!W.includes(h))return false;d.debug(`Delegating to local CLI: ./rapidkit ${m.join(" ")}`);let y=spawn(a,m,{stdio:"inherit",cwd:e});return y.on("close",k=>{process.exit(k??0);}),y.on("error",k=>{d.error(`Failed to run local rapidkit: ${k.message}`),process.exit(1);}),true}var j=null,K=false,F=new Command;F.name("rapidkit").description("Create RapidKit workspaces and projects").version(S());F.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(e,t)=>{try{t.debug&&(d.setDebug(!0),d.debug("Debug mode enabled"));let i=await J();d.debug("User config loaded",i),t.updateCheck!==!1&&await H(),console.log(o.blue.bold(`
|
|
619
619
|
\u{1F680} Welcome to RapidKit!
|
|
620
|
-
`)),
|
|
621
|
-
\u274C ${
|
|
622
|
-
`),process.exit(1)),
|
|
623
|
-
\u274C Directory "${
|
|
620
|
+
`)),e||(be(),process.exit(0));try{M(e);}catch(c){throw c instanceof P&&(d.error(`
|
|
621
|
+
\u274C ${c.message}`),c.details&&d.warn(`\u{1F4A1} ${c.details}
|
|
622
|
+
`),process.exit(1)),c}let n=l.resolve(process.cwd(),e);j=n,await f.pathExists(n)&&(d.error(`
|
|
623
|
+
\u274C Directory "${e}" already exists`),console.log(o.cyan(`
|
|
624
624
|
\u{1F4A1} Choose a different name or delete the existing directory.
|
|
625
|
-
`)),process.exit(1));let
|
|
626
|
-
\u274C Invalid template: ${
|
|
627
|
-
\u{1F4E6} Available templates: ${
|
|
628
|
-
`)),process.exit(1));}if(
|
|
625
|
+
`)),process.exit(1));let r=!!t.template;if(r){let c=t.template.toLowerCase(),s=["fastapi","nestjs"];s.includes(c)||(d.error(`
|
|
626
|
+
\u274C Invalid template: ${t.template}`),console.log(o.cyan(`
|
|
627
|
+
\u{1F4E6} Available templates: ${s.join(", ")}
|
|
628
|
+
`)),process.exit(1));}if(t.dryRun){console.log(o.cyan(`
|
|
629
629
|
\u{1F50D} Dry-run mode - showing what would be created:
|
|
630
|
-
`)),console.log(
|
|
631
|
-
`))):
|
|
632
|
-
\u274C ${i.message}`),i.details&&
|
|
633
|
-
\u274C An unexpected error occurred:`),console.error(i)),process.exit(1);}finally{
|
|
630
|
+
`)),console.log(o.white("\u{1F4C2} Path:"),n),console.log(o.white("\u{1F4E6} Type:"),r?`Project (${t.template})`:"Workspace"),console.log();return}let a;t.yes?(a={author:process.env.USER||"RapidKit User",description:r?`${t.template==="nestjs"?"NestJS":"FastAPI"} application generated with RapidKit`:void 0,package_manager:"npm"},console.log(o.gray(`Using default values (--yes flag)
|
|
631
|
+
`))):r?t.template.toLowerCase()==="fastapi"?a=await U.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"}]):a=await U.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"}]):a=await U.prompt([{type:"input",name:"author",message:"Author name:",default:process.env.USER||"RapidKit User"}]),r?await z(n,{name:e,template:t.template.toLowerCase(),author:a.author,description:a.description,package_manager:a.package_manager,skipGit:t.skipGit,skipInstall:t.skipInstall}):await Y(n,{name:e,author:a.author,skipGit:t.skipGit});}catch(i){i instanceof P?(d.error(`
|
|
632
|
+
\u274C ${i.message}`),i.details&&d.warn(`\u{1F4A1} ${i.details}`),d.debug("Error code:",i.code)):(d.error(`
|
|
633
|
+
\u274C An unexpected error occurred:`),console.error(i)),process.exit(1);}finally{j=null;}});F.command("shell <action>").description("Shell helpers (activate virtualenv in current shell)").action(async e=>{e!=="activate"&&(console.log(o.red(`Unknown shell command: ${e}`)),process.exit(1));let t=process.cwd();function i(c){let s=c;for(;;){let m=l.join(s,".rapidkit","context.json");if(w.existsSync(m))return m;let h=l.dirname(s);if(h===s)break;s=h;}return null}let n=i(t);function r(c){let s=c;for(;;){let m=l.join(s,".venv"),h=l.join(s,".rapidkit","activate");if(w.existsSync(h)||w.existsSync(m))return {venv:m,activateFile:h};let y=l.dirname(s);if(y===s)break;s=y;}return null}let a=r(t);if(!n&&!a&&(console.log(o.red("No RapidKit project found to activate")),process.exit(1)),a){let c=`# RapidKit: activation snippet - eval "$(rapidkit shell activate)"
|
|
634
634
|
VENV='.venv'
|
|
635
635
|
if [ -f "$VENV/bin/activate" ]; then
|
|
636
636
|
. "$VENV/bin/activate"
|
|
@@ -639,11 +639,11 @@ elif [ -f "$VENV/bin/activate.fish" ]; then
|
|
|
639
639
|
fi
|
|
640
640
|
export RAPIDKIT_PROJECT_ROOT="$(pwd)"
|
|
641
641
|
export PATH="$(pwd)/.rapidkit:$(pwd):$PATH"
|
|
642
|
-
`;console.log(
|
|
642
|
+
`;console.log(o.green.bold(`
|
|
643
643
|
\u2705 Activation snippet \u2014 run the following to activate this project in your current shell:
|
|
644
|
-
`)),console.log(
|
|
644
|
+
`)),console.log(c),console.log(o.gray(`
|
|
645
645
|
\u{1F4A1} After activation you can run: rapidkit dev
|
|
646
|
-
`)),process.exit(0);}try{(await f.readJson(n)).engine!=="pip"&&(console.log(
|
|
646
|
+
`)),process.exit(0);}try{(await f.readJson(n)).engine!=="pip"&&(console.log(o.yellow("This project is not a pip-based RapidKit project.")),process.exit(1)),console.log(`# RapidKit: activation snippet - eval "$(rapidkit shell activate)"
|
|
647
647
|
VENV='.venv'
|
|
648
648
|
if [ -f "$VENV/bin/activate" ]; then
|
|
649
649
|
. "$VENV/bin/activate"
|
|
@@ -652,7 +652,7 @@ elif [ -f "$VENV/bin/activate.fish" ]; then
|
|
|
652
652
|
fi
|
|
653
653
|
export RAPIDKIT_PROJECT_ROOT="$(pwd)"
|
|
654
654
|
export PATH="$(pwd)/.rapidkit:$(pwd):$PATH"
|
|
655
|
-
`),process.exit(0);}catch{console.log(
|
|
655
|
+
`),process.exit(0);}catch{console.log(o.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
656
|
VENV='.venv'
|
|
657
657
|
if [ -f "$VENV/bin/activate" ]; then
|
|
658
658
|
. "$VENV/bin/activate"
|
|
@@ -661,15 +661,15 @@ elif [ -f "$VENV/bin/activate.fish" ]; then
|
|
|
661
661
|
fi
|
|
662
662
|
export RAPIDKIT_PROJECT_ROOT="$(pwd)"
|
|
663
663
|
export PATH="$(pwd):$PATH"
|
|
664
|
-
`),process.exit(0);}});function
|
|
665
|
-
`)),console.log(
|
|
666
|
-
`)),console.log(
|
|
667
|
-
`)),console.log(
|
|
668
|
-
`)),console.log(
|
|
669
|
-
`));}process.on("SIGINT",async()=>{if(!
|
|
670
|
-
|
|
671
|
-
\u26A0\uFE0F Interrupted by user`)),
|
|
664
|
+
`),process.exit(0);}});function be(){console.log(o.white(`Usage: npx rapidkit <name> [options]
|
|
665
|
+
`)),console.log(o.bold("Create a workspace (recommended):")),console.log(o.cyan(" npx rapidkit my-workspace")),console.log(o.cyan(" cd my-workspace")),console.log(o.cyan(" rapidkit create my-api --template fastapi")),console.log(o.cyan(" cd my-api")),console.log(o.cyan(` rapidkit dev
|
|
666
|
+
`)),console.log(o.bold("Or create a project directly:")),console.log(o.cyan(" npx rapidkit my-project --template fastapi")),console.log(o.cyan(` npx rapidkit my-project --template nestjs
|
|
667
|
+
`)),console.log(o.bold("Options:")),console.log(o.gray(" -t, --template <template> Create project with template (fastapi, nestjs)")),console.log(o.gray(" -y, --yes Skip prompts and use defaults")),console.log(o.gray(" --skip-git Skip git initialization")),console.log(o.gray(" --skip-install Skip installing dependencies")),console.log(o.gray(" --debug Enable debug logging")),console.log(o.gray(` --dry-run Show what would be created
|
|
668
|
+
`)),console.log(o.bold("Templates:")),console.log(o.gray(" fastapi FastAPI + Python")),console.log(o.gray(` nestjs NestJS + TypeScript
|
|
669
|
+
`));}process.on("SIGINT",async()=>{if(!K){if(K=true,console.log(o.yellow(`
|
|
670
|
+
|
|
671
|
+
\u26A0\uFE0F Interrupted by user`)),j&&await f.pathExists(j)){console.log(o.gray("Cleaning up partial installation..."));try{await f.remove(j),console.log(o.green("\u2713 Cleanup complete"));}catch(e){d.debug("Cleanup failed:",e);}}process.exit(130);}});process.on("SIGTERM",async()=>{if(!K){if(K=true,d.debug("Received SIGTERM"),j&&await f.pathExists(j))try{await f.remove(j);}catch(e){d.debug("Cleanup failed:",e);}process.exit(143);}});Ce().then(async e=>{if(!e){let t=process.cwd();try{let i=Q(t);if(i&&await f.pathExists(i)){let n=await f.readJson(i),r=process.argv.slice(2)[0];if(n?.engine==="pip"&&r!=="init"){let a=(await import('chalk')).default;console.log(a.yellow(`
|
|
672
672
|
\u26A0\uFE0F This project uses the Python RapidKit engine (pip). The global npm RapidKit CLI will not operate on this project.
|
|
673
673
|
\u{1F4A1} To prepare this project run: 'rapidkit init' (it uses the project's Python toolchain)
|
|
674
674
|
|
|
675
|
-
`)),process.exit(0);}}}catch{}
|
|
675
|
+
`)),process.exit(0);}}}catch{}F.parse();}});
|
package/dist/package.json
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
REM RapidKit CLI - Local project commands (Windows)
|
|
3
|
+
REM This wrapper delegates to .rapidkit/cli.py with smart Python detection
|
|
4
|
+
|
|
5
|
+
setlocal enabledelayedexpansion
|
|
6
|
+
|
|
7
|
+
set "SCRIPT_DIR=%~dp0"
|
|
8
|
+
set "CLI_PY=%SCRIPT_DIR%.rapidkit\cli.py"
|
|
9
|
+
|
|
10
|
+
REM Find the best Python to use
|
|
11
|
+
|
|
12
|
+
REM 1. Project venv
|
|
13
|
+
if exist "%SCRIPT_DIR%.venv\Scripts\python.exe" (
|
|
14
|
+
set "PYTHON_CMD=%SCRIPT_DIR%.venv\Scripts\python.exe"
|
|
15
|
+
goto :run
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
REM 2. Poetry's python
|
|
19
|
+
where poetry >nul 2>&1
|
|
20
|
+
if %ERRORLEVEL% EQU 0 (
|
|
21
|
+
for /f "tokens=*" %%i in ('poetry env info --executable 2^>nul') do set "POETRY_PY=%%i"
|
|
22
|
+
if defined POETRY_PY (
|
|
23
|
+
if exist "!POETRY_PY!" (
|
|
24
|
+
set "PYTHON_CMD=!POETRY_PY!"
|
|
25
|
+
goto :run
|
|
26
|
+
)
|
|
27
|
+
)
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
REM 3. System python
|
|
31
|
+
where python >nul 2>&1
|
|
32
|
+
if %ERRORLEVEL% EQU 0 (
|
|
33
|
+
set "PYTHON_CMD=python"
|
|
34
|
+
goto :run
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
REM 4. py launcher (Windows Python Launcher)
|
|
38
|
+
where py >nul 2>&1
|
|
39
|
+
if %ERRORLEVEL% EQU 0 (
|
|
40
|
+
set "PYTHON_CMD=py -3"
|
|
41
|
+
goto :run
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
echo โ No Python interpreter found.
|
|
45
|
+
echo ๐ก Install Python 3.11+ and try again.
|
|
46
|
+
exit /b 127
|
|
47
|
+
|
|
48
|
+
:run
|
|
49
|
+
%PYTHON_CMD% "%CLI_PY%" %*
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
REM RapidKit CLI wrapper for NestJS projects (Windows)
|
|
3
|
+
REM This script provides local commands that mirror the full RapidKit engine.
|
|
4
|
+
|
|
5
|
+
setlocal enabledelayedexpansion
|
|
6
|
+
|
|
7
|
+
set "PROJECT_ROOT=%~dp0.."
|
|
8
|
+
cd /d "%PROJECT_ROOT%"
|
|
9
|
+
|
|
10
|
+
set "COMMAND=%~1"
|
|
11
|
+
if "%COMMAND%"=="" set "COMMAND=help"
|
|
12
|
+
|
|
13
|
+
set "PORT=8000"
|
|
14
|
+
set "HOST=0.0.0.0"
|
|
15
|
+
|
|
16
|
+
REM Parse remaining arguments for port/host
|
|
17
|
+
:parse_args
|
|
18
|
+
if "%~2"=="" goto :run_command
|
|
19
|
+
if "%~2"=="-p" (
|
|
20
|
+
set "PORT=%~3"
|
|
21
|
+
shift
|
|
22
|
+
shift
|
|
23
|
+
goto :parse_args
|
|
24
|
+
)
|
|
25
|
+
if "%~2"=="--port" (
|
|
26
|
+
set "PORT=%~3"
|
|
27
|
+
shift
|
|
28
|
+
shift
|
|
29
|
+
goto :parse_args
|
|
30
|
+
)
|
|
31
|
+
if "%~2"=="--host" (
|
|
32
|
+
set "HOST=%~3"
|
|
33
|
+
shift
|
|
34
|
+
shift
|
|
35
|
+
goto :parse_args
|
|
36
|
+
)
|
|
37
|
+
shift
|
|
38
|
+
goto :parse_args
|
|
39
|
+
|
|
40
|
+
:run_command
|
|
41
|
+
if /i "%COMMAND%"=="init" goto :cmd_init
|
|
42
|
+
if /i "%COMMAND%"=="dev" goto :cmd_dev
|
|
43
|
+
if /i "%COMMAND%"=="start" goto :cmd_start
|
|
44
|
+
if /i "%COMMAND%"=="build" goto :cmd_build
|
|
45
|
+
if /i "%COMMAND%"=="test" goto :cmd_test
|
|
46
|
+
if /i "%COMMAND%"=="lint" goto :cmd_lint
|
|
47
|
+
if /i "%COMMAND%"=="format" goto :cmd_format
|
|
48
|
+
if /i "%COMMAND%"=="help" goto :cmd_help
|
|
49
|
+
if /i "%COMMAND%"=="-h" goto :cmd_help
|
|
50
|
+
if /i "%COMMAND%"=="--help" goto :cmd_help
|
|
51
|
+
goto :cmd_unknown
|
|
52
|
+
|
|
53
|
+
:check_node
|
|
54
|
+
where node >nul 2>&1
|
|
55
|
+
if %ERRORLEVEL% NEQ 0 (
|
|
56
|
+
echo โ Node.js not found. Please install Node.js first.
|
|
57
|
+
exit /b 1
|
|
58
|
+
)
|
|
59
|
+
exit /b 0
|
|
60
|
+
|
|
61
|
+
:get_pkg_manager
|
|
62
|
+
where pnpm >nul 2>&1
|
|
63
|
+
if %ERRORLEVEL% EQU 0 (
|
|
64
|
+
set "PKG_MANAGER=pnpm"
|
|
65
|
+
) else (
|
|
66
|
+
set "PKG_MANAGER=npm"
|
|
67
|
+
)
|
|
68
|
+
exit /b 0
|
|
69
|
+
|
|
70
|
+
:cmd_init
|
|
71
|
+
echo ๐ฆ Bootstrapping NestJS project (installing dependencies)
|
|
72
|
+
call :check_node
|
|
73
|
+
if %ERRORLEVEL% NEQ 0 exit /b 1
|
|
74
|
+
call :get_pkg_manager
|
|
75
|
+
%PKG_MANAGER% install
|
|
76
|
+
echo โ
Dependencies installed successfully!
|
|
77
|
+
goto :eof
|
|
78
|
+
|
|
79
|
+
:cmd_dev
|
|
80
|
+
echo ๐ Starting NestJS development server with hot reload...
|
|
81
|
+
call :check_node
|
|
82
|
+
if %ERRORLEVEL% NEQ 0 exit /b 1
|
|
83
|
+
if not exist "node_modules" (
|
|
84
|
+
echo โ node_modules not found. Run 'rapidkit init' first.
|
|
85
|
+
exit /b 1
|
|
86
|
+
)
|
|
87
|
+
call :get_pkg_manager
|
|
88
|
+
set "PORT=%PORT%"
|
|
89
|
+
set "HOST=%HOST%"
|
|
90
|
+
%PKG_MANAGER% run start:dev
|
|
91
|
+
goto :eof
|
|
92
|
+
|
|
93
|
+
:cmd_start
|
|
94
|
+
echo โก Starting NestJS production server...
|
|
95
|
+
call :check_node
|
|
96
|
+
if %ERRORLEVEL% NEQ 0 exit /b 1
|
|
97
|
+
if not exist "node_modules" (
|
|
98
|
+
echo โ node_modules not found. Run 'rapidkit init' first.
|
|
99
|
+
exit /b 1
|
|
100
|
+
)
|
|
101
|
+
call :get_pkg_manager
|
|
102
|
+
set "PORT=%PORT%"
|
|
103
|
+
set "HOST=%HOST%"
|
|
104
|
+
%PKG_MANAGER% run start:prod
|
|
105
|
+
goto :eof
|
|
106
|
+
|
|
107
|
+
:cmd_build
|
|
108
|
+
echo ๐ฆ Building NestJS project...
|
|
109
|
+
call :check_node
|
|
110
|
+
if %ERRORLEVEL% NEQ 0 exit /b 1
|
|
111
|
+
call :get_pkg_manager
|
|
112
|
+
%PKG_MANAGER% run build
|
|
113
|
+
echo โ
Build completed!
|
|
114
|
+
goto :eof
|
|
115
|
+
|
|
116
|
+
:cmd_test
|
|
117
|
+
echo ๐งช Running tests...
|
|
118
|
+
call :check_node
|
|
119
|
+
if %ERRORLEVEL% NEQ 0 exit /b 1
|
|
120
|
+
call :get_pkg_manager
|
|
121
|
+
%PKG_MANAGER% run test
|
|
122
|
+
goto :eof
|
|
123
|
+
|
|
124
|
+
:cmd_lint
|
|
125
|
+
echo ๐ง Running ESLint...
|
|
126
|
+
call :check_node
|
|
127
|
+
if %ERRORLEVEL% NEQ 0 exit /b 1
|
|
128
|
+
call :get_pkg_manager
|
|
129
|
+
%PKG_MANAGER% run lint
|
|
130
|
+
goto :eof
|
|
131
|
+
|
|
132
|
+
:cmd_format
|
|
133
|
+
echo โจ Formatting code with Prettier...
|
|
134
|
+
call :check_node
|
|
135
|
+
if %ERRORLEVEL% NEQ 0 exit /b 1
|
|
136
|
+
call :get_pkg_manager
|
|
137
|
+
%PKG_MANAGER% run format
|
|
138
|
+
goto :eof
|
|
139
|
+
|
|
140
|
+
:cmd_help
|
|
141
|
+
echo ๐ RapidKit NestJS Project Commands
|
|
142
|
+
echo.
|
|
143
|
+
echo Usage: rapidkit ^<command^> [options]
|
|
144
|
+
echo.
|
|
145
|
+
echo Commands:
|
|
146
|
+
echo init ๐ฆ Initialize project (install dependencies)
|
|
147
|
+
echo dev ๐ Start development server with hot reload
|
|
148
|
+
echo start โก Start production server
|
|
149
|
+
echo build ๐ฆ Build for production
|
|
150
|
+
echo test ๐งช Run tests
|
|
151
|
+
echo lint ๐ง Lint code
|
|
152
|
+
echo format โจ Format code
|
|
153
|
+
echo help ๐ Show this help
|
|
154
|
+
echo.
|
|
155
|
+
echo Options for dev/start:
|
|
156
|
+
echo -p, --port ^<port^> Port number (default: 8000)
|
|
157
|
+
echo --host ^<host^> Host address (default: 0.0.0.0)
|
|
158
|
+
echo.
|
|
159
|
+
echo ๐ก Note: This is a demo project. For full RapidKit features:
|
|
160
|
+
echo pipx install rapidkit
|
|
161
|
+
goto :eof
|
|
162
|
+
|
|
163
|
+
:cmd_unknown
|
|
164
|
+
echo โ Unknown command: %COMMAND%
|
|
165
|
+
echo.
|
|
166
|
+
goto :cmd_help
|