rapidkit 0.11.2 โ 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +99 -408
- package/dist/index.js +508 -279
- package/dist/package.json +1 -1
- package/package.json +1 -1
- package/templates/generator.js +175 -0
- package/templates/kits/fastapi-standard/.rapidkit/__init__.py.j2 +1 -0
- package/templates/kits/fastapi-standard/.rapidkit/activate.j2 +24 -0
- package/templates/kits/fastapi-standard/.rapidkit/cli.py.j2 +257 -0
- package/templates/kits/fastapi-standard/.rapidkit/project.json.j2 +7 -0
- package/templates/kits/fastapi-standard/.rapidkit/rapidkit.j2 +98 -0
- package/templates/kits/fastapi-standard/Makefile.j2 +41 -0
- package/templates/kits/fastapi-standard/README.md.j2 +4 -4
- package/templates/kits/fastapi-standard/pyproject.toml.j2 +1 -0
- package/templates/kits/fastapi-standard/rapidkit.j2 +50 -0
- package/templates/kits/fastapi-standard/src/main.py.j2 +15 -12
- package/templates/kits/nestjs-standard/.env.example.j2 +16 -0
- package/templates/kits/nestjs-standard/.eslintrc.js.j2 +25 -0
- package/templates/kits/nestjs-standard/.gitignore.j2 +26 -0
- package/templates/kits/nestjs-standard/.node-version.j2 +1 -0
- package/templates/kits/nestjs-standard/.nvmrc.j2 +1 -0
- package/templates/kits/nestjs-standard/.prettierrc.j2 +7 -0
- package/templates/kits/nestjs-standard/.rapidkit/activate.j2 +25 -0
- package/templates/kits/nestjs-standard/.rapidkit/project.json.j2 +7 -0
- package/templates/kits/nestjs-standard/.rapidkit/rapidkit.j2 +227 -0
- package/templates/kits/nestjs-standard/README.md.j2 +97 -0
- package/templates/kits/nestjs-standard/jest.config.ts.j2 +21 -0
- package/templates/kits/nestjs-standard/nest-cli.json.j2 +10 -0
- package/templates/kits/nestjs-standard/package.json.j2 +75 -0
- package/templates/kits/nestjs-standard/rapidkit.j2 +5 -0
- package/templates/kits/nestjs-standard/src/app.controller.ts.j2 +12 -0
- package/templates/kits/nestjs-standard/src/app.module.ts.j2 +23 -0
- package/templates/kits/nestjs-standard/src/app.service.ts.j2 +11 -0
- package/templates/kits/nestjs-standard/src/config/configuration.ts.j2 +9 -0
- package/templates/kits/nestjs-standard/src/config/index.ts.j2 +2 -0
- package/templates/kits/nestjs-standard/src/config/validation.ts.j2 +11 -0
- package/templates/kits/nestjs-standard/src/examples/dto/create-note.dto.ts.j2 +11 -0
- package/templates/kits/nestjs-standard/src/examples/examples.controller.ts.j2 +24 -0
- package/templates/kits/nestjs-standard/src/examples/examples.module.ts.j2 +10 -0
- package/templates/kits/nestjs-standard/src/examples/examples.service.ts.j2 +33 -0
- package/templates/kits/nestjs-standard/src/main.ts.j2 +51 -0
- package/templates/kits/nestjs-standard/src/modules/index.ts.j2 +3 -0
- package/templates/kits/nestjs-standard/test/app.controller.spec.ts.j2 +22 -0
- package/templates/kits/nestjs-standard/test/app.e2e-spec.ts.j2 +48 -0
- package/templates/kits/nestjs-standard/test/examples.controller.spec.ts.j2 +28 -0
- package/templates/kits/nestjs-standard/test/jest-e2e.json.j2 +15 -0
- package/templates/kits/nestjs-standard/tsconfig.build.json.j2 +12 -0
- package/templates/kits/nestjs-standard/tsconfig.json.j2 +26 -0
package/dist/package.json
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* RapidKit Project Generator
|
|
4
|
+
* This script is called by the rapidkit CLI to generate projects
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const fs = require('fs').promises;
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const { execSync } = require('child_process');
|
|
10
|
+
|
|
11
|
+
const TEMPLATES_DIR = path.join(__dirname, 'templates');
|
|
12
|
+
|
|
13
|
+
async function generateProject(projectPath, template, useDefaults, skipGit, skipInstall) {
|
|
14
|
+
const projectName = path.basename(projectPath);
|
|
15
|
+
const templateDir = template === 'nestjs' ? 'nestjs-standard' : 'fastapi-standard';
|
|
16
|
+
const templatePath = path.join(TEMPLATES_DIR, templateDir);
|
|
17
|
+
|
|
18
|
+
// Check template exists
|
|
19
|
+
try {
|
|
20
|
+
await fs.access(templatePath);
|
|
21
|
+
} catch {
|
|
22
|
+
console.error('โ Template not found:', templateDir);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Create project directory
|
|
27
|
+
await fs.mkdir(projectPath, { recursive: true });
|
|
28
|
+
|
|
29
|
+
// Build context
|
|
30
|
+
const context = {
|
|
31
|
+
project_name: template === 'nestjs'
|
|
32
|
+
? projectName.replace(/_/g, '-').toLowerCase()
|
|
33
|
+
: projectName.replace(/-/g, '_').toLowerCase(),
|
|
34
|
+
author: process.env.USER || 'RapidKit User',
|
|
35
|
+
description: template === 'nestjs'
|
|
36
|
+
? 'NestJS application generated with RapidKit'
|
|
37
|
+
: 'FastAPI service generated with RapidKit',
|
|
38
|
+
app_version: '0.1.0',
|
|
39
|
+
license: 'MIT',
|
|
40
|
+
package_manager: 'npm',
|
|
41
|
+
created_at: new Date().toISOString(),
|
|
42
|
+
rapidkit_version: require('./config.json').rapidkit_version || '0.12.0',
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// Copy and render template files
|
|
46
|
+
await copyTemplateDir(templatePath, projectPath, context);
|
|
47
|
+
|
|
48
|
+
console.log('โ
Project files created!');
|
|
49
|
+
|
|
50
|
+
// Git initialization
|
|
51
|
+
if (!skipGit) {
|
|
52
|
+
try {
|
|
53
|
+
execSync('git init', { cwd: projectPath, stdio: 'pipe' });
|
|
54
|
+
execSync('git add .', { cwd: projectPath, stdio: 'pipe' });
|
|
55
|
+
const commitMsg = 'Initial commit: ' + (template === 'nestjs' ? 'NestJS' : 'FastAPI') + ' project via RapidKit';
|
|
56
|
+
execSync(`git commit -m "${commitMsg}"`, { cwd: projectPath, stdio: 'pipe' });
|
|
57
|
+
console.log('โ
Git repository initialized');
|
|
58
|
+
} catch (e) {
|
|
59
|
+
console.log('โ ๏ธ Could not initialize git');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Install dependencies
|
|
64
|
+
if (!skipInstall) {
|
|
65
|
+
if (template === 'nestjs') {
|
|
66
|
+
console.log('๐ฆ Installing dependencies...');
|
|
67
|
+
try {
|
|
68
|
+
execSync('npm install', { cwd: projectPath, stdio: 'inherit' });
|
|
69
|
+
console.log('โ
Dependencies installed');
|
|
70
|
+
} catch {
|
|
71
|
+
console.log('โ ๏ธ Could not install dependencies. Run npm install manually.');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Success message
|
|
77
|
+
const templateName = template === 'nestjs' ? 'NestJS' : 'FastAPI';
|
|
78
|
+
console.log('');
|
|
79
|
+
console.log('โจ ' + templateName + ' project created successfully!');
|
|
80
|
+
console.log('');
|
|
81
|
+
console.log('๐ Get started:');
|
|
82
|
+
console.log(' cd ' + projectName);
|
|
83
|
+
if (template === 'fastapi') {
|
|
84
|
+
console.log(' rapidkit init # poetry install');
|
|
85
|
+
console.log(' rapidkit dev # Start dev server');
|
|
86
|
+
} else {
|
|
87
|
+
if (skipInstall) {
|
|
88
|
+
console.log(' rapidkit init # npm install');
|
|
89
|
+
}
|
|
90
|
+
console.log(' cp .env.example .env');
|
|
91
|
+
console.log(' rapidkit dev # Start dev server');
|
|
92
|
+
}
|
|
93
|
+
console.log('');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function renderTemplate(content, context) {
|
|
97
|
+
let result = content;
|
|
98
|
+
|
|
99
|
+
for (const [key, value] of Object.entries(context)) {
|
|
100
|
+
// Simple variable replacement: {{ key }}
|
|
101
|
+
const simpleRegex = new RegExp(`\\{\\{\\s*${key}\\s*\\}\\}`, 'g');
|
|
102
|
+
result = result.replace(simpleRegex, String(value));
|
|
103
|
+
|
|
104
|
+
// With replace filter: {{ key | replace('a', 'b') }}
|
|
105
|
+
const replaceRegex = new RegExp(
|
|
106
|
+
`\\{\\{\\s*${key}\\s*\\|\\s*replace\\s*\\(\\s*['"]([^'"]+)['"]\\s*,\\s*['"]([^'"]*)['"]\\s*\\)\\s*\\}\\}`,
|
|
107
|
+
'g'
|
|
108
|
+
);
|
|
109
|
+
result = result.replace(replaceRegex, (match, from, to) => {
|
|
110
|
+
return String(value).replace(new RegExp(from, 'g'), to);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// With lower filter: {{ key | lower }}
|
|
114
|
+
const lowerRegex = new RegExp(`\\{\\{\\s*${key}\\s*\\|\\s*lower\\s*\\}\\}`, 'g');
|
|
115
|
+
result = result.replace(lowerRegex, String(value).toLowerCase());
|
|
116
|
+
|
|
117
|
+
// Combined: {{ key | replace('a', 'b') | lower }}
|
|
118
|
+
const combinedRegex = new RegExp(
|
|
119
|
+
`\\{\\{\\s*${key}\\s*\\|\\s*replace\\s*\\(\\s*['"]([^'"]+)['"]\\s*,\\s*['"]([^'"]*)['"]\\s*\\)\\s*\\|\\s*lower\\s*\\}\\}`,
|
|
120
|
+
'g'
|
|
121
|
+
);
|
|
122
|
+
result = result.replace(combinedRegex, (match, from, to) => {
|
|
123
|
+
return String(value).replace(new RegExp(from, 'g'), to).toLowerCase();
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function copyTemplateDir(src, dest, context) {
|
|
131
|
+
const entries = await fs.readdir(src, { withFileTypes: true });
|
|
132
|
+
|
|
133
|
+
for (const entry of entries) {
|
|
134
|
+
const srcPath = path.join(src, entry.name);
|
|
135
|
+
const destName = entry.name.replace(/\.j2$/, '');
|
|
136
|
+
const destPath = path.join(dest, destName);
|
|
137
|
+
|
|
138
|
+
if (entry.isDirectory()) {
|
|
139
|
+
await fs.mkdir(destPath, { recursive: true });
|
|
140
|
+
await copyTemplateDir(srcPath, destPath, context);
|
|
141
|
+
} else {
|
|
142
|
+
let content = await fs.readFile(srcPath, 'utf-8');
|
|
143
|
+
|
|
144
|
+
// Render template if it's a .j2 file
|
|
145
|
+
if (entry.name.endsWith('.j2')) {
|
|
146
|
+
content = renderTemplate(content, context);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
await fs.writeFile(destPath, content);
|
|
150
|
+
|
|
151
|
+
// Make scripts executable
|
|
152
|
+
if (destName === 'rapidkit' || (destName.endsWith('.py') && destPath.includes('.rapidkit'))) {
|
|
153
|
+
await fs.chmod(destPath, 0o755);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Main
|
|
160
|
+
const args = process.argv.slice(2);
|
|
161
|
+
const projectPath = args[0];
|
|
162
|
+
const template = args[1] || 'fastapi';
|
|
163
|
+
const useDefaults = args.includes('--yes');
|
|
164
|
+
const skipGit = args.includes('--skip-git');
|
|
165
|
+
const skipInstall = args.includes('--skip-install');
|
|
166
|
+
|
|
167
|
+
if (!projectPath) {
|
|
168
|
+
console.error('Usage: node generator.js <project-path> <template> [--yes] [--skip-git] [--skip-install]');
|
|
169
|
+
process.exit(1);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
generateProject(projectPath, template, useDefaults, skipGit, skipInstall).catch(err => {
|
|
173
|
+
console.error('Error:', err);
|
|
174
|
+
process.exit(1);
|
|
175
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# RapidKit local CLI module
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# RapidKit Environment Activation
|
|
3
|
+
# Usage: source .rapidkit/activate
|
|
4
|
+
|
|
5
|
+
# Get the directory where this script is located
|
|
6
|
+
RAPIDKIT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
7
|
+
PROJECT_ROOT="$(dirname "$RAPIDKIT_DIR")"
|
|
8
|
+
|
|
9
|
+
# Add project root to PATH (where rapidkit script lives)
|
|
10
|
+
if [[ ":$PATH:" != *":$PROJECT_ROOT:"* ]]; then
|
|
11
|
+
export PATH="$PROJECT_ROOT:$PATH"
|
|
12
|
+
echo "โ
RapidKit activated! You can now use 'rapidkit' commands directly."
|
|
13
|
+
else
|
|
14
|
+
echo "โน๏ธ RapidKit already activated."
|
|
15
|
+
fi
|
|
16
|
+
|
|
17
|
+
# Show available commands
|
|
18
|
+
echo ""
|
|
19
|
+
echo "๐ Available commands:"
|
|
20
|
+
echo " rapidkit dev - Start development server"
|
|
21
|
+
echo " rapidkit init - Install dependencies"
|
|
22
|
+
echo " rapidkit test - Run tests"
|
|
23
|
+
echo " rapidkit --help - Show all commands"
|
|
24
|
+
echo ""
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""RapidKit CLI wrapper (npm demo template)
|
|
3
|
+
|
|
4
|
+
This file provides local project commands for demo projects generated
|
|
5
|
+
via npx rapidkit --demo. It mimics the behavior of the full RapidKit
|
|
6
|
+
engine for dev, start, test, lint, and format commands.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import subprocess
|
|
10
|
+
import shutil
|
|
11
|
+
import sys
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
import socket
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _print_banner(emoji: str, message: str) -> None:
|
|
18
|
+
print(f"{emoji} {message}")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _run(*cmd: Any, cwd: Path | str | None = None, env: dict | None = None) -> int:
|
|
22
|
+
try:
|
|
23
|
+
run_env = None
|
|
24
|
+
if env is not None:
|
|
25
|
+
import os as _os
|
|
26
|
+
run_env = _os.environ.copy()
|
|
27
|
+
run_env.update(env)
|
|
28
|
+
|
|
29
|
+
proc = subprocess.run([str(c) for c in cmd], cwd=str(cwd) if cwd else None, env=run_env)
|
|
30
|
+
return proc.returncode
|
|
31
|
+
except KeyboardInterrupt:
|
|
32
|
+
print("\n๐ Command interrupted by user")
|
|
33
|
+
return 130
|
|
34
|
+
except Exception as exc:
|
|
35
|
+
print(f"โ Error running command: {exc}")
|
|
36
|
+
return 1
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _project_type(root: Path) -> str:
|
|
40
|
+
if (root / "pyproject.toml").exists():
|
|
41
|
+
return "python"
|
|
42
|
+
if (root / "package.json").exists():
|
|
43
|
+
return "node"
|
|
44
|
+
return "unknown"
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _python_module(module: str, *module_args: str) -> int:
|
|
48
|
+
return _run(sys.executable, "-m", module, *module_args)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _python_code_targets(root: Path) -> list[str]:
|
|
52
|
+
targets: list[str] = []
|
|
53
|
+
for name in ("src", "tests"):
|
|
54
|
+
if (root / name).exists():
|
|
55
|
+
targets.append(name)
|
|
56
|
+
return targets or ["src"]
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _venv_has_uvicorn(venv_path: Path) -> bool:
|
|
60
|
+
if (venv_path / "bin" / "uvicorn").exists():
|
|
61
|
+
return True
|
|
62
|
+
for p in venv_path.rglob("site-packages/*"):
|
|
63
|
+
name = p.name.lower()
|
|
64
|
+
if "uvicorn" in name or "fastapi" in name:
|
|
65
|
+
return True
|
|
66
|
+
return False
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def dev(port: int = 8000, host: str = "0.0.0.0", allow_global_runtime: bool = False) -> None:
|
|
70
|
+
"""Start development server with reload"""
|
|
71
|
+
_print_banner("๐", "Starting development server with hot reload...")
|
|
72
|
+
root = Path.cwd()
|
|
73
|
+
ptype = _project_type(root)
|
|
74
|
+
|
|
75
|
+
if ptype == "python":
|
|
76
|
+
venv_dir = root / ".venv"
|
|
77
|
+
_print_banner("๐", f"Working directory: {root}")
|
|
78
|
+
_print_banner("๐", f"Server will be available at: http://{host}:{port}")
|
|
79
|
+
|
|
80
|
+
if venv_dir.exists():
|
|
81
|
+
if not _venv_has_uvicorn(venv_dir):
|
|
82
|
+
print("โ Project .venv was found but uvicorn/fastapi doesn't appear installed.")
|
|
83
|
+
print("๐ก Run 'rapidkit init' to install dependencies.")
|
|
84
|
+
sys.exit(1)
|
|
85
|
+
else:
|
|
86
|
+
if not allow_global_runtime:
|
|
87
|
+
print("โ Project environment not bootstrapped (no .venv found).")
|
|
88
|
+
print("")
|
|
89
|
+
print("๐ก Initialize and install dependencies with:")
|
|
90
|
+
print("")
|
|
91
|
+
print(" rapidkit init")
|
|
92
|
+
print("")
|
|
93
|
+
print("If you intentionally want to use the system Python, run:")
|
|
94
|
+
print("")
|
|
95
|
+
print(" rapidkit dev --allow-global-runtime")
|
|
96
|
+
print("")
|
|
97
|
+
sys.exit(1)
|
|
98
|
+
|
|
99
|
+
if shutil.which("uvicorn") is None:
|
|
100
|
+
print("โ No uvicorn executable found on PATH and no .venv present.")
|
|
101
|
+
print("")
|
|
102
|
+
print("๐ก Install dependencies with: rapidkit init")
|
|
103
|
+
print("")
|
|
104
|
+
sys.exit(1)
|
|
105
|
+
print("โ ๏ธ Running with system/global Python runtime.")
|
|
106
|
+
|
|
107
|
+
rc = _run(sys.executable, "-m", "uvicorn", "src.main:app", "--reload", "--reload-dir", "src", "--host", host, "--port", str(port))
|
|
108
|
+
if rc != 0:
|
|
109
|
+
sys.exit(rc)
|
|
110
|
+
else:
|
|
111
|
+
print("โ Unknown project type. Ensure pyproject.toml exists.")
|
|
112
|
+
sys.exit(1)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def init() -> None:
|
|
116
|
+
"""Bootstrap project: install dependencies"""
|
|
117
|
+
_print_banner("๐", "Bootstrapping project (installing dependencies)")
|
|
118
|
+
root = Path.cwd()
|
|
119
|
+
ptype = _project_type(root)
|
|
120
|
+
|
|
121
|
+
if ptype == "python":
|
|
122
|
+
if shutil.which("poetry"):
|
|
123
|
+
rc = _run("poetry", "install")
|
|
124
|
+
if rc != 0:
|
|
125
|
+
print("โ Failed to install dependencies via poetry.")
|
|
126
|
+
sys.exit(rc)
|
|
127
|
+
print("โ
Dependencies installed successfully!")
|
|
128
|
+
else:
|
|
129
|
+
print("โ Poetry not found. Install it with: pip install poetry")
|
|
130
|
+
sys.exit(1)
|
|
131
|
+
else:
|
|
132
|
+
print("โ Unknown project type. Ensure pyproject.toml exists.")
|
|
133
|
+
sys.exit(1)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def start(port: int = 8000, host: str = "0.0.0.0", allow_global_runtime: bool = False) -> None:
|
|
137
|
+
"""Start production server"""
|
|
138
|
+
_print_banner("โก", "Starting production server...")
|
|
139
|
+
root = Path.cwd()
|
|
140
|
+
ptype = _project_type(root)
|
|
141
|
+
|
|
142
|
+
if ptype == "python":
|
|
143
|
+
venv_dir = root / ".venv"
|
|
144
|
+
if venv_dir.exists():
|
|
145
|
+
if not _venv_has_uvicorn(venv_dir):
|
|
146
|
+
print("โ Project .venv was found but uvicorn/fastapi doesn't appear installed.")
|
|
147
|
+
print("๐ก Run 'poetry install' to install dependencies.")
|
|
148
|
+
sys.exit(1)
|
|
149
|
+
else:
|
|
150
|
+
if not allow_global_runtime:
|
|
151
|
+
print("โ Project environment not bootstrapped (no .venv found).")
|
|
152
|
+
print("๐ก Run 'poetry install' to install dependencies.")
|
|
153
|
+
sys.exit(1)
|
|
154
|
+
|
|
155
|
+
rc = _run(sys.executable, "-m", "uvicorn", "src.main:app", "--host", host, "--port", str(port))
|
|
156
|
+
if rc != 0:
|
|
157
|
+
sys.exit(rc)
|
|
158
|
+
else:
|
|
159
|
+
print("โ Unknown project type.")
|
|
160
|
+
sys.exit(1)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def build() -> None:
|
|
164
|
+
"""Build project"""
|
|
165
|
+
_print_banner("๐ฆ", "Building project")
|
|
166
|
+
rc = _python_module("build")
|
|
167
|
+
if rc != 0:
|
|
168
|
+
sys.exit(rc)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def test() -> None:
|
|
172
|
+
"""Run tests"""
|
|
173
|
+
_print_banner("๐งช", "Running tests")
|
|
174
|
+
rc = _python_module("pytest", "-q")
|
|
175
|
+
if rc != 0:
|
|
176
|
+
sys.exit(rc)
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def lint() -> None:
|
|
180
|
+
"""Run linting"""
|
|
181
|
+
_print_banner("๐ง", "Running lint")
|
|
182
|
+
root = Path.cwd()
|
|
183
|
+
targets = _python_code_targets(root)
|
|
184
|
+
rc = _python_module("ruff", "check", *targets)
|
|
185
|
+
if rc == 0:
|
|
186
|
+
rc = _python_module("black", "--check", *targets)
|
|
187
|
+
if rc != 0:
|
|
188
|
+
sys.exit(rc)
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def format_code() -> None:
|
|
192
|
+
"""Format code"""
|
|
193
|
+
_print_banner("โจ", "Formatting")
|
|
194
|
+
root = Path.cwd()
|
|
195
|
+
targets = _python_code_targets(root)
|
|
196
|
+
rc = _python_module("ruff", "check", *targets, "--fix")
|
|
197
|
+
if rc == 0:
|
|
198
|
+
rc = _python_module("black", *targets)
|
|
199
|
+
if rc != 0:
|
|
200
|
+
sys.exit(rc)
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def help_cmd() -> None:
|
|
204
|
+
"""Show help"""
|
|
205
|
+
_print_banner("๐", "Project Commands")
|
|
206
|
+
print("Usage: rapidkit <command> [args...]\n")
|
|
207
|
+
print(" init ๐ฆ Initialize project (install deps)")
|
|
208
|
+
print(" dev ๐ Start development server")
|
|
209
|
+
print(" start โก Start production server")
|
|
210
|
+
print(" build ๐ฆ Build for production")
|
|
211
|
+
print(" test ๐งช Run tests")
|
|
212
|
+
print(" lint ๐ง Lint code")
|
|
213
|
+
print(" format โจ Format code")
|
|
214
|
+
print(" help ๐ Show help")
|
|
215
|
+
print("")
|
|
216
|
+
print("๐ก Note: This is a demo project. For full RapidKit features:")
|
|
217
|
+
print(" pipx install rapidkit")
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def main():
|
|
221
|
+
if len(sys.argv) < 2 or sys.argv[1] in ("-h", "--help", "help"):
|
|
222
|
+
help_cmd()
|
|
223
|
+
return
|
|
224
|
+
|
|
225
|
+
command = sys.argv[1]
|
|
226
|
+
args = sys.argv[2:]
|
|
227
|
+
|
|
228
|
+
commands = {
|
|
229
|
+
"init": init,
|
|
230
|
+
"dev": dev,
|
|
231
|
+
"start": start,
|
|
232
|
+
"build": build,
|
|
233
|
+
"test": test,
|
|
234
|
+
"lint": lint,
|
|
235
|
+
"format": format_code,
|
|
236
|
+
"help": help_cmd,
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if command not in commands:
|
|
240
|
+
print(f"โ Unknown command: {command}")
|
|
241
|
+
help_cmd()
|
|
242
|
+
sys.exit(1)
|
|
243
|
+
|
|
244
|
+
if command in ("dev", "start"):
|
|
245
|
+
import argparse as _arg
|
|
246
|
+
_parser = _arg.ArgumentParser(prog=f"rapidkit {command}")
|
|
247
|
+
_parser.add_argument("-p", "--port", dest="port", type=int, default=8000)
|
|
248
|
+
_parser.add_argument("--host", dest="host", default="0.0.0.0")
|
|
249
|
+
_parser.add_argument("--allow-global-runtime", action="store_true", dest="allow_global_runtime")
|
|
250
|
+
_ns, _extra = _parser.parse_known_args(args)
|
|
251
|
+
commands[command](port=_ns.port, host=_ns.host, allow_global_runtime=_ns.allow_global_runtime)
|
|
252
|
+
else:
|
|
253
|
+
commands[command]()
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
if __name__ == "__main__":
|
|
257
|
+
main()
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Local RapidKit project launcher (npm demo template)
|
|
3
|
+
# This script provides local project commands for demo projects.
|
|
4
|
+
|
|
5
|
+
set -euo pipefail
|
|
6
|
+
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
|
7
|
+
|
|
8
|
+
show_help() {
|
|
9
|
+
cat << 'EOF'
|
|
10
|
+
๐ RapidKit FastAPI Project Commands
|
|
11
|
+
|
|
12
|
+
Usage: rapidkit <command> [options]
|
|
13
|
+
|
|
14
|
+
Commands:
|
|
15
|
+
init ๐ฆ Initialize project (poetry install)
|
|
16
|
+
dev ๐ Start development server with hot reload
|
|
17
|
+
start โก Start production server
|
|
18
|
+
test ๐งช Run tests
|
|
19
|
+
lint ๐ง Lint code
|
|
20
|
+
format โจ Format code
|
|
21
|
+
help ๐ Show this help
|
|
22
|
+
|
|
23
|
+
Examples:
|
|
24
|
+
rapidkit init # Install dependencies
|
|
25
|
+
rapidkit dev # Start dev server
|
|
26
|
+
|
|
27
|
+
๐ก Note: Commands are run through Poetry.
|
|
28
|
+
EOF
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
# Handle help
|
|
32
|
+
case "${1:-}" in
|
|
33
|
+
help|--help|-h|"")
|
|
34
|
+
show_help
|
|
35
|
+
exit 0
|
|
36
|
+
;;
|
|
37
|
+
esac
|
|
38
|
+
|
|
39
|
+
# Detect project type
|
|
40
|
+
if [ -f "$ROOT_DIR/pyproject.toml" ]; then
|
|
41
|
+
PKG_TYPE="python"
|
|
42
|
+
elif [ -f "$ROOT_DIR/package.json" ]; then
|
|
43
|
+
PKG_TYPE="node"
|
|
44
|
+
else
|
|
45
|
+
PKG_TYPE="unknown"
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
VENV_PY="${ROOT_DIR}/.venv/bin/python"
|
|
49
|
+
VENV_POETRY="${ROOT_DIR}/.venv/bin/poetry"
|
|
50
|
+
|
|
51
|
+
case "$PKG_TYPE" in
|
|
52
|
+
python)
|
|
53
|
+
# prefer project-local poetry
|
|
54
|
+
if [ -x "$VENV_POETRY" ]; then
|
|
55
|
+
if [ "${1:-}" = "init" ]; then
|
|
56
|
+
exec "$VENV_POETRY" "install"
|
|
57
|
+
else
|
|
58
|
+
exec "$VENV_POETRY" "run" "$@"
|
|
59
|
+
fi
|
|
60
|
+
fi
|
|
61
|
+
|
|
62
|
+
# then prefer poetry on PATH
|
|
63
|
+
if command -v poetry >/dev/null 2>&1; then
|
|
64
|
+
if [ "${1:-}" = "init" ]; then
|
|
65
|
+
exec poetry "install"
|
|
66
|
+
else
|
|
67
|
+
exec poetry "run" "$@"
|
|
68
|
+
fi
|
|
69
|
+
fi
|
|
70
|
+
|
|
71
|
+
# If venv python exists, try installing poetry into it
|
|
72
|
+
if [ -x "$VENV_PY" ]; then
|
|
73
|
+
echo "โ ๏ธ Poetry not found. Installing poetry into project .venv..."
|
|
74
|
+
"$VENV_PY" -m pip install --upgrade pip >/dev/null 2>&1 || true
|
|
75
|
+
"$VENV_PY" -m pip install poetry >/dev/null 2>&1 || true
|
|
76
|
+
if [ -x "$VENV_POETRY" ]; then
|
|
77
|
+
if [ "${1:-}" = "init" ]; then
|
|
78
|
+
exec "$VENV_POETRY" "install"
|
|
79
|
+
else
|
|
80
|
+
exec "$VENV_POETRY" "run" "$@"
|
|
81
|
+
fi
|
|
82
|
+
else
|
|
83
|
+
echo "โ Failed to locate poetry after installation."
|
|
84
|
+
exit 1
|
|
85
|
+
fi
|
|
86
|
+
fi
|
|
87
|
+
|
|
88
|
+
echo "โ Poetry is not available and no project .venv exists."
|
|
89
|
+
echo "๐ก Run: 'poetry install' to bootstrap the project, or install poetry: 'pip install poetry'"
|
|
90
|
+
exit 127
|
|
91
|
+
;;
|
|
92
|
+
|
|
93
|
+
*)
|
|
94
|
+
echo "โ Could not detect project type (pyproject.toml missing)."
|
|
95
|
+
echo "๐ก This appears to be a demo project. Run 'poetry install' to set up."
|
|
96
|
+
exit 127
|
|
97
|
+
;;
|
|
98
|
+
esac
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# RapidKit Project Commands
|
|
2
|
+
# Usage: make <command>
|
|
3
|
+
|
|
4
|
+
.PHONY: init dev start build test lint format help
|
|
5
|
+
|
|
6
|
+
# Default target
|
|
7
|
+
help:
|
|
8
|
+
@echo "๐ RapidKit Commands"
|
|
9
|
+
@echo ""
|
|
10
|
+
@echo "Usage: make <command>"
|
|
11
|
+
@echo ""
|
|
12
|
+
@echo "Commands:"
|
|
13
|
+
@echo " init ๐ฆ Install dependencies (poetry install)"
|
|
14
|
+
@echo " dev ๐ฅ Start development server"
|
|
15
|
+
@echo " start โก Start production server"
|
|
16
|
+
@echo " build ๐ฆ Build for production"
|
|
17
|
+
@echo " test ๐งช Run tests"
|
|
18
|
+
@echo " lint ๐ง Run linting"
|
|
19
|
+
@echo " format โจ Format code"
|
|
20
|
+
@echo ""
|
|
21
|
+
|
|
22
|
+
init:
|
|
23
|
+
@poetry install
|
|
24
|
+
|
|
25
|
+
dev:
|
|
26
|
+
@poetry run dev
|
|
27
|
+
|
|
28
|
+
start:
|
|
29
|
+
@poetry run start
|
|
30
|
+
|
|
31
|
+
build:
|
|
32
|
+
@poetry run build
|
|
33
|
+
|
|
34
|
+
test:
|
|
35
|
+
@poetry run test
|
|
36
|
+
|
|
37
|
+
lint:
|
|
38
|
+
@poetry run lint
|
|
39
|
+
|
|
40
|
+
format:
|
|
41
|
+
@poetry run format
|
|
@@ -12,11 +12,11 @@ rapidkit dev
|
|
|
12
12
|
## Available commands
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
|
-
rapidkit init # ๐ง
|
|
15
|
+
rapidkit init # ๐ง Install dependencies
|
|
16
16
|
rapidkit dev # ๐ Start development server with hot reload
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
rapidkit start # โก Start production server
|
|
18
|
+
rapidkit test # ๐งช Run tests
|
|
19
|
+
rapidkit help # ๐ Show available commands
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
## Project layout
|