rapidkit 0.11.3 → 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.
Files changed (45) hide show
  1. package/README.md +99 -411
  2. package/dist/index.js +507 -640
  3. package/dist/package.json +1 -1
  4. package/package.json +1 -1
  5. package/templates/generator.js +175 -0
  6. package/templates/kits/fastapi-standard/.rapidkit/__init__.py.j2 +1 -0
  7. package/templates/kits/fastapi-standard/.rapidkit/activate.j2 +24 -0
  8. package/templates/kits/fastapi-standard/.rapidkit/cli.py.j2 +6 -4
  9. package/templates/kits/fastapi-standard/.rapidkit/project.json.j2 +3 -2
  10. package/templates/kits/fastapi-standard/.rapidkit/rapidkit.j2 +31 -0
  11. package/templates/kits/fastapi-standard/Makefile.j2 +41 -0
  12. package/templates/kits/fastapi-standard/pyproject.toml.j2 +1 -0
  13. package/templates/kits/fastapi-standard/rapidkit.j2 +50 -0
  14. package/templates/kits/nestjs-standard/.env.example.j2 +16 -0
  15. package/templates/kits/nestjs-standard/.eslintrc.js.j2 +25 -0
  16. package/templates/kits/nestjs-standard/.gitignore.j2 +26 -0
  17. package/templates/kits/nestjs-standard/.node-version.j2 +1 -0
  18. package/templates/kits/nestjs-standard/.nvmrc.j2 +1 -0
  19. package/templates/kits/nestjs-standard/.prettierrc.j2 +7 -0
  20. package/templates/kits/nestjs-standard/.rapidkit/activate.j2 +25 -0
  21. package/templates/kits/nestjs-standard/.rapidkit/project.json.j2 +7 -0
  22. package/templates/kits/nestjs-standard/.rapidkit/rapidkit.j2 +227 -0
  23. package/templates/kits/nestjs-standard/README.md.j2 +97 -0
  24. package/templates/kits/nestjs-standard/jest.config.ts.j2 +21 -0
  25. package/templates/kits/nestjs-standard/nest-cli.json.j2 +10 -0
  26. package/templates/kits/nestjs-standard/package.json.j2 +75 -0
  27. package/templates/kits/nestjs-standard/rapidkit.j2 +5 -0
  28. package/templates/kits/nestjs-standard/src/app.controller.ts.j2 +12 -0
  29. package/templates/kits/nestjs-standard/src/app.module.ts.j2 +23 -0
  30. package/templates/kits/nestjs-standard/src/app.service.ts.j2 +11 -0
  31. package/templates/kits/nestjs-standard/src/config/configuration.ts.j2 +9 -0
  32. package/templates/kits/nestjs-standard/src/config/index.ts.j2 +2 -0
  33. package/templates/kits/nestjs-standard/src/config/validation.ts.j2 +11 -0
  34. package/templates/kits/nestjs-standard/src/examples/dto/create-note.dto.ts.j2 +11 -0
  35. package/templates/kits/nestjs-standard/src/examples/examples.controller.ts.j2 +24 -0
  36. package/templates/kits/nestjs-standard/src/examples/examples.module.ts.j2 +10 -0
  37. package/templates/kits/nestjs-standard/src/examples/examples.service.ts.j2 +33 -0
  38. package/templates/kits/nestjs-standard/src/main.ts.j2 +51 -0
  39. package/templates/kits/nestjs-standard/src/modules/index.ts.j2 +3 -0
  40. package/templates/kits/nestjs-standard/test/app.controller.spec.ts.j2 +22 -0
  41. package/templates/kits/nestjs-standard/test/app.e2e-spec.ts.j2 +48 -0
  42. package/templates/kits/nestjs-standard/test/examples.controller.spec.ts.j2 +28 -0
  43. package/templates/kits/nestjs-standard/test/jest-e2e.json.j2 +15 -0
  44. package/templates/kits/nestjs-standard/tsconfig.build.json.j2 +12 -0
  45. package/templates/kits/nestjs-standard/tsconfig.json.j2 +26 -0
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rapidkit",
3
- "version": "0.11.3",
3
+ "version": "0.12.0",
4
4
  "type": "module",
5
5
  "description": "Create RapidKit projects with a single command - The official CLI for RapidKit framework",
6
6
  "keywords": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rapidkit",
3
- "version": "0.11.3",
3
+ "version": "0.12.0",
4
4
  "type": "module",
5
5
  "description": "Create RapidKit projects with a single command - The official CLI for RapidKit framework",
6
6
  "keywords": [
@@ -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 ""
@@ -74,11 +74,13 @@ def dev(port: int = 8000, host: str = "0.0.0.0", allow_global_runtime: bool = Fa
74
74
 
75
75
  if ptype == "python":
76
76
  venv_dir = root / ".venv"
77
+ _print_banner("📁", f"Working directory: {root}")
78
+ _print_banner("🌐", f"Server will be available at: http://{host}:{port}")
77
79
 
78
80
  if venv_dir.exists():
79
81
  if not _venv_has_uvicorn(venv_dir):
80
82
  print("❌ Project .venv was found but uvicorn/fastapi doesn't appear installed.")
81
- print("💡 Run 'poetry install' to install dependencies.")
83
+ print("💡 Run 'rapidkit init' to install dependencies.")
82
84
  sys.exit(1)
83
85
  else:
84
86
  if not allow_global_runtime:
@@ -86,7 +88,7 @@ def dev(port: int = 8000, host: str = "0.0.0.0", allow_global_runtime: bool = Fa
86
88
  print("")
87
89
  print("💡 Initialize and install dependencies with:")
88
90
  print("")
89
- print(" poetry install")
91
+ print(" rapidkit init")
90
92
  print("")
91
93
  print("If you intentionally want to use the system Python, run:")
92
94
  print("")
@@ -97,12 +99,12 @@ def dev(port: int = 8000, host: str = "0.0.0.0", allow_global_runtime: bool = Fa
97
99
  if shutil.which("uvicorn") is None:
98
100
  print("❌ No uvicorn executable found on PATH and no .venv present.")
99
101
  print("")
100
- print("💡 Install dependencies with: poetry install")
102
+ print("💡 Install dependencies with: rapidkit init")
101
103
  print("")
102
104
  sys.exit(1)
103
105
  print("⚠️ Running with system/global Python runtime.")
104
106
 
105
- rc = _run(sys.executable, "-m", "uvicorn", "src.main:app", "--reload", "--host", host, "--port", str(port))
107
+ rc = _run(sys.executable, "-m", "uvicorn", "src.main:app", "--reload", "--reload-dir", "src", "--host", host, "--port", str(port))
106
108
  if rc != 0:
107
109
  sys.exit(rc)
108
110
  else:
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "kit_name": "fastapi.standard",
3
3
  "profile": "fastapi/standard",
4
- "created_at": "{{ created_at | default(now) }}",
5
- "rapidkit_version": "npm-demo"
4
+ "project_name": "{{ project_name }}",
5
+ "created_at": "{{ created_at }}",
6
+ "rapidkit_version": "npm-{{ rapidkit_version }}"
6
7
  }
@@ -5,6 +5,37 @@
5
5
  set -euo pipefail
6
6
  ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
7
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
+
8
39
  # Detect project type
9
40
  if [ -f "$ROOT_DIR/pyproject.toml" ]; then
10
41
  PKG_TYPE="python"
@@ -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
@@ -7,6 +7,7 @@ license = "{{ license }}"
7
7
  packages = [{ include = "src" }]
8
8
 
9
9
  [tool.poetry.scripts]
10
+ rapidkit = ".rapidkit.cli:main"
10
11
  dev = "src.cli:dev"
11
12
  start = "src.cli:start"
12
13
  build = "src.cli:build"
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env bash
2
+ # RapidKit CLI - Local project commands
3
+ # This wrapper delegates to .rapidkit/cli.py with smart Python detection
4
+
5
+ set -euo pipefail
6
+
7
+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
8
+ CLI_PY="${SCRIPT_DIR}/.rapidkit/cli.py"
9
+
10
+ # Find the best Python to use
11
+ find_python() {
12
+ # 1. Project venv
13
+ if [ -x "${SCRIPT_DIR}/.venv/bin/python" ]; then
14
+ echo "${SCRIPT_DIR}/.venv/bin/python"
15
+ return 0
16
+ fi
17
+
18
+ # 2. Poetry's python
19
+ if command -v poetry >/dev/null 2>&1; then
20
+ POETRY_PY="$(poetry env info --executable 2>/dev/null || true)"
21
+ if [ -n "$POETRY_PY" ] && [ -x "$POETRY_PY" ]; then
22
+ echo "$POETRY_PY"
23
+ return 0
24
+ fi
25
+ fi
26
+
27
+ # 3. System python3
28
+ if command -v python3 >/dev/null 2>&1; then
29
+ echo "python3"
30
+ return 0
31
+ fi
32
+
33
+ # 4. System python
34
+ if command -v python >/dev/null 2>&1; then
35
+ echo "python"
36
+ return 0
37
+ fi
38
+
39
+ return 1
40
+ }
41
+
42
+ # Find Python
43
+ PYTHON_CMD="$(find_python)" || {
44
+ echo "❌ No Python interpreter found."
45
+ echo "💡 Install Python 3.11+ and try again."
46
+ exit 127
47
+ }
48
+
49
+ # Execute the CLI
50
+ exec "$PYTHON_CMD" "$CLI_PY" "$@"
@@ -0,0 +1,16 @@
1
+ # Application
2
+ APP_NAME={{ project_name | upper | replace('-', '_') }}
3
+ PORT=8000
4
+ HOST=0.0.0.0
5
+ NODE_ENV=development
6
+
7
+ # Security
8
+ JWT_SECRET=your-super-secret-jwt-key-change-in-production
9
+ JWT_EXPIRATION=1h
10
+
11
+ # Database (optional)
12
+ # DATABASE_URL=postgresql://user:password@localhost:5432/{{ project_name | replace('-', '_') }}
13
+
14
+ # Redis (optional)
15
+ # REDIS_HOST=localhost
16
+ # REDIS_PORT=6379
@@ -0,0 +1,25 @@
1
+ module.exports = {
2
+ parser: '@typescript-eslint/parser',
3
+ parserOptions: {
4
+ project: ['tsconfig.json'],
5
+ tsconfigRootDir: __dirname,
6
+ sourceType: 'module',
7
+ },
8
+ plugins: ['@typescript-eslint/eslint-plugin'],
9
+ extends: [
10
+ 'plugin:@typescript-eslint/recommended',
11
+ 'plugin:prettier/recommended',
12
+ ],
13
+ root: true,
14
+ env: {
15
+ node: true,
16
+ jest: true,
17
+ },
18
+ ignorePatterns: ['.eslintrc.js'],
19
+ rules: {
20
+ '@typescript-eslint/interface-name-prefix': 'off',
21
+ '@typescript-eslint/explicit-function-return-type': 'off',
22
+ '@typescript-eslint/explicit-module-boundary-types': 'off',
23
+ '@typescript-eslint/no-explicit-any': 'warn',
24
+ },
25
+ };
@@ -0,0 +1,26 @@
1
+ # Node artifacts
2
+ node_modules/
3
+ dist/
4
+ .tmp/
5
+ .env
6
+ .env.*
7
+ !.env.example
8
+
9
+ # Logs
10
+ logs/
11
+ *.log
12
+ npm-debug.log*
13
+ yarn-debug.log*
14
+ yarn-error.log*
15
+ pnpm-debug.log*
16
+
17
+ # OS
18
+ .DS_Store
19
+ Thumbs.db
20
+
21
+ # IDEs
22
+ .idea/
23
+ .vscode/
24
+
25
+ # Coverage
26
+ coverage/
@@ -0,0 +1,7 @@
1
+ {
2
+ "singleQuote": true,
3
+ "trailingComma": "all",
4
+ "printWidth": 100,
5
+ "tabWidth": 2,
6
+ "semi": true
7
+ }
@@ -0,0 +1,25 @@
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 build - Build for production"
23
+ echo " rapidkit test - Run tests"
24
+ echo " rapidkit --help - Show all commands"
25
+ echo ""
@@ -0,0 +1,7 @@
1
+ {
2
+ "kit_name": "nestjs.standard",
3
+ "profile": "nestjs/standard",
4
+ "project_name": "{{ project_name }}",
5
+ "created_at": "{{ created_at }}",
6
+ "rapidkit_version": "npm-{{ rapidkit_version }}"
7
+ }