express-hale
Version:
๐ Interactive Express.js scaffold CLI with comprehensive error handling, TypeScript/JavaScript, database integrations, Git Flow, and development tools
553 lines (463 loc) โข 15.3 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConfigTemplates = void 0;
const base_renderer_1 = require("./base-renderer");
class ConfigTemplates extends base_renderer_1.BaseRenderer {
renderNodemonConfig() {
return JSON.stringify({
watch: ['src'],
ext: 'ts,js,json',
ignore: ['src/**/*.spec.ts', 'src/**/*.test.ts'],
exec: 'ts-node src/index.ts',
env: {
NODE_ENV: 'development',
},
delay: 1000,
}, null, 2);
}
renderEnvFile(config) {
let content = `# Server Configuration
PORT=3000
NODE_ENV=development
`;
if (config.databases.includes('mysql')) {
content += `# MySQL Configuration
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=your_password
MYSQL_DATABASE=your_database
`;
}
if (config.databases.includes('mongodb')) {
content += `# MongoDB Configuration
MONGODB_URI=mongodb://localhost:27017/your_database
`;
}
if (config.databases.includes('redis')) {
content += `# Redis Configuration
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=your_redis_password
`;
}
content += `# JWT Secret (generate a strong secret in production)
JWT_SECRET=your_jwt_secret_key
# API Configuration
API_VERSION=v1
API_BASE_URL=http://localhost:3000`;
return content;
}
renderEnvExampleFile(config) {
return this.renderEnvFile(config).replace(/=.+$/gm, '=');
}
renderTsConfig() {
return JSON.stringify({
compilerOptions: {
target: 'ES2020',
module: 'commonjs',
lib: ['ES2020'],
outDir: './dist',
rootDir: './src',
strict: true,
esModuleInterop: true,
skipLibCheck: true,
forceConsistentCasingInFileNames: true,
declaration: true,
sourceMap: true,
resolveJsonModule: true,
moduleResolution: 'node',
},
include: ['src/**/*'],
exclude: ['node_modules', 'dist', '**/*.test.ts'],
}, null, 2);
}
renderEslintConfig(config) {
if (config.language === 'typescript') {
return `const js = require('@eslint/js');
const tseslint = require('@typescript-eslint/eslint-plugin');
const tsparser = require('@typescript-eslint/parser');${config.prettier ? "\nconst prettier = require('eslint-plugin-prettier');\nconst prettierConfig = require('eslint-config-prettier');" : ''}
module.exports = [
js.configs.recommended,
{
files: ['**/*.ts', '**/*.tsx'],
languageOptions: {
parser: tsparser,
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
globals: {
console: 'readonly',
process: 'readonly',
Buffer: 'readonly',
__dirname: 'readonly',
__filename: 'readonly',
exports: 'writable',
module: 'writable',
require: 'readonly',
global: 'readonly',
setTimeout: 'readonly',
clearTimeout: 'readonly',
setInterval: 'readonly',
clearInterval: 'readonly',
},
},
plugins: {
'@typescript-eslint': tseslint${config.prettier ? ",\n 'prettier': prettier" : ''}
},
rules: {
...tseslint.configs.recommended.rules,
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'warn'${config.prettier ? ",\n 'prettier/prettier': 'error'" : ''}
},
}${config.prettier ? ',\n prettierConfig' : ''}
];`;
}
else {
return `const js = require('@eslint/js');${config.prettier ? "\nconst prettier = require('eslint-plugin-prettier');\nconst prettierConfig = require('eslint-config-prettier');" : ''}
module.exports = [
js.configs.recommended,
{
files: ['**/*.js', '**/*.mjs'],
languageOptions: {
ecmaVersion: 2020,
sourceType: 'module',
globals: {
console: 'readonly',
process: 'readonly',
Buffer: 'readonly',
__dirname: 'readonly',
__filename: 'readonly',
exports: 'writable',
module: 'writable',
require: 'readonly',
global: 'readonly',
setTimeout: 'readonly',
clearTimeout: 'readonly',
setInterval: 'readonly',
clearInterval: 'readonly',
},
}${config.prettier ? ",\n plugins: {\n 'prettier': prettier\n }" : ''},
rules: {
'no-unused-vars': 'error',
'no-console': 'off'${config.prettier ? ",\n 'prettier/prettier': 'error'" : ''}
},
}${config.prettier ? ',\n prettierConfig' : ''}
];`;
}
}
renderPrettierConfig() {
return JSON.stringify({
semi: true,
trailingComma: 'es5',
singleQuote: true,
printWidth: 80,
tabWidth: 2,
useTabs: false,
}, null, 2);
}
renderJestConfig(config) {
if (config.language === 'typescript') {
return `module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
roots: ['<rootDir>/src', '<rootDir>/tests'],
testMatch: ['**/__tests__/**/*.ts', '**/?(*.)+(spec|test).ts'],
transform: {
'^.+\\.ts$': 'ts-jest'
},
collectCoverageFrom: [
'src/**/*.ts',
'!src/**/*.d.ts'
],
coverageDirectory: 'coverage',
coverageReporters: ['text', 'lcov', 'html']
};`;
}
else {
return `module.exports = {
testEnvironment: 'node',
roots: ['<rootDir>/src', '<rootDir>/tests'],
testMatch: ['**/__tests__/**/*.js', '**/?(*.)+(spec|test).js'],
collectCoverageFrom: [
'src/**/*.js'
],
coverageDirectory: 'coverage',
coverageReporters: ['text', 'lcov', 'html']
};`;
}
}
renderReadme(projectName, config) {
const features = [];
// Add language feature
features.push(`- ๐ **${config.language === 'typescript' ? 'TypeScript' : 'JavaScript'}** ๆฏๆ`);
// Add database features
if (config.databases.includes('mysql'))
features.push('- ๐๏ธ **MySQL** ๆฐๆฎๅบ้ๆ');
if (config.databases.includes('mongodb'))
features.push('- ๐ **MongoDB** ๆฐๆฎๅบ้ๆ');
if (config.databases.includes('redis'))
features.push('- ๐ด **Redis** ็ผๅญ้ๆ');
// Add development tools
if (config.eslint)
features.push('- ๐ **ESLint** ไปฃ็ ๆฃๆฅ');
if (config.prettier)
features.push('- ๐
**Prettier** ไปฃ็ ๆ ผๅผๅ');
if (config.testing === 'jest')
features.push('- ๐งช **Jest** ๅๅ
ๆต่ฏ');
if (config.docker)
features.push('- ๐ณ **Docker** ๅฎนๅจๅๆฏๆ');
if (config.gitFlow)
features.push('- ๐ **Git Flow** ๅทฅไฝๆต');
// Add built-in features
features.push('- ๐ก๏ธ **ๅฎๅ
จไธญ้ดไปถ** (Helmet, CORS)');
features.push('- ๐ **่ฏทๆฑๆฅๅฟ** ๅฝฉ่ฒๅฏ่งๅๆพ็คบ');
features.push('- โก **ๅผๆญฅ้่ฏฏๅค็** ๅฎๆด็้่ฏฏๅค็ๆบๅถ');
features.push('- ๐ **ไผ้
ๅ
ณ้ญ** ่ฟ็จไฟกๅทๅค็');
features.push('- ๐ **ๅฅๅบทๆฃๆฅ** ๅ
็ฝฎๅฅๅบทๆฃๆฅ็ซฏ็น');
features.push('- ๐ฏ **้่ฏฏ็ๆง** ็ไบง็ฏๅข้่ฏฏ่ฟฝ่ธช');
return `# ${projectName}
> ๐ ๅบไบ Express.js ็็ฐไปฃๅ Web ๅบ็จ็จๅบ๏ผไฝฟ็จ express-hale CLI ็ๆ
## โจ ็นๆง
${features.join('\n')}
## ๐ ๏ธ ๆๆฏๆ
- **ๆกๆถ**: Express.js
- **่ฏญ่จ**: ${config.language === 'typescript' ? 'TypeScript' : 'JavaScript'}
${config.databases.length > 0 ? `- **ๆฐๆฎๅบ**: ${config.databases.map(db => db.charAt(0).toUpperCase() + db.slice(1)).join(', ')}` : ''}
- **ๅผๅๅทฅๅ
ท**: ${[
config.eslint && 'ESLint',
config.prettier && 'Prettier',
config.testing === 'jest' && 'Jest',
'Nodemon'
].filter(Boolean).join(', ')}
${config.docker ? '- **ๅฎนๅจๅ**: Docker & Docker Compose' : ''}
## ๐ ๅฟซ้ๅผๅง
### ๅฎ่ฃ
ไพ่ต
\`\`\`bash
npm install
\`\`\`
### ็ฏๅข้
็ฝฎ
ๅคๅถ็ฏๅขๅ้ๆจกๆฟๆไปถ๏ผ
\`\`\`bash
cp .env.example .env
\`\`\`
็ผ่พ \`.env\` ๆไปถ๏ผ้
็ฝฎไฝ ็็ฏๅขๅ้ใ
### ๅผๅๆจกๅผ
\`\`\`bash
npm run dev
\`\`\`
ๅบ็จๅฐๅจ [http://localhost:3000](http://localhost:3000) ๅฏๅจ
### ็ไบงๆจกๅผ
${config.language === 'typescript' ? `\`\`\`bash
# ๆๅปบ้กน็ฎ
npm run build
# ๅฏๅจ็ไบงๆๅก
npm start
\`\`\`` : `\`\`\`bash
npm start
\`\`\``}
## ๐ ้กน็ฎ็ปๆ
\`\`\`
${projectName}/
โโโ src/
โ โโโ config/ # ๆฐๆฎๅบ้
็ฝฎ
โ โโโ middleware/ # ไธญ้ดไปถ
โ โโโ routes/ # ่ทฏ็ฑๅฎไน
โ โโโ utils/ # ๅทฅๅ
ทๅฝๆฐ
โ โโโ index.${config.language === 'typescript' ? 'ts' : 'js'} # ๅบ็จๅ
ฅๅฃ
โโโ tests/ # ๆต่ฏๆไปถ
${config.docker ? 'โโโ docker-compose.yml # Docker ็ผๆๆไปถ\nโโโ Dockerfile # Docker ้ๅ้
็ฝฎ' : ''}
โโโ .env.example # ็ฏๅขๅ้ๆจกๆฟ
โโโ package.json # ้กน็ฎ้
็ฝฎ
${config.language === 'typescript' ? 'โโโ tsconfig.json # TypeScript ้
็ฝฎ' : ''}
${config.eslint ? 'โโโ eslint.config.js # ESLint ้
็ฝฎ' : ''}
${config.prettier ? 'โโโ .prettierrc # Prettier ้
็ฝฎ' : ''}
${config.testing === 'jest' ? 'โโโ jest.config.js # Jest ้
็ฝฎ' : ''}
${config.gitFlow ? 'โโโ GIT_FLOW.md # Git Flow ๅทฅไฝๆต่ฏดๆ' : ''}
\`\`\`
## ๐ง ๅฏ็จ่ๆฌ
- \`npm run dev\` - ๅฏๅจๅผๅๆๅกๅจ
${config.language === 'typescript' ? '- `npm run build` - ๆๅปบ็ไบง็ๆฌ' : ''}
- \`npm start\` - ๅฏๅจ็ไบงๆๅกๅจ
${config.testing === 'jest' ? '- `npm test` - ่ฟ่กๆต่ฏ' : ''}
${config.eslint ? '- `npm run lint` - ไปฃ็ ๆฃๆฅ' : ''}
${config.prettier ? '- `npm run format` - ไปฃ็ ๆ ผๅผๅ' : ''}
## ๐ API ็ซฏ็น
### ๅฅๅบทๆฃๆฅ
- **GET** \`/health\` - ๅบ็จๅฅๅบท็ถๆๆฃๆฅ
### ็คบไพ API
- **GET** \`/api/users\` - ่ทๅ็จๆทๅ่กจ
- **POST** \`/api/users\` - ๅๅปบๆฐ็จๆท
- **GET** \`/api/error-test\` - ้่ฏฏๅค็ๆต่ฏ
## ๐ ่ฏทๆฑๆฅๅฟ
ๅบ็จๅ
็ฝฎไบๅฝฉ่ฒๅฏ่งๅ็่ฏทๆฑๆฅๅฟ็ณป็ป๏ผ
\`\`\`
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐ HTTP REQUEST LOG
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โฐ Time: 2025/08/10 20:48:08
โ ๐ Method: GET
โ ๐ Path: /health
โ ๐ Status: 200
โ โก Duration: 1ms
โ ๐ฆ Size: 156 bytes
โ ๐ Client: ::1
โ ๐ง Agent: PostmanRuntime/7.45.0
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
\`\`\`
## ๐ก๏ธ ๅฎๅ
จ็นๆง
- **Helmet**: ่ฎพ็ฝฎๅ็ง HTTP ๅคดๆฅไฟๆคๅบ็จ
- **CORS**: ่ทจๅ่ตๆบๅ
ฑไบซ้
็ฝฎ
- **่ฏทๆฑๅคงๅฐ้ๅถ**: ้ฒๆญขๅคงๅ่ฏทๆฑๆปๅป
- **้่ฏฏๅค็**: ็ไบง็ฏๅขไธ้่ๆๆ้่ฏฏไฟกๆฏ
## ๐ ้่ฏฏๅค็
ๅบ็จๅ
ๅซๅฎๆด็้่ฏฏๅค็ๆบๅถ๏ผ
- **ๅผๆญฅ้่ฏฏๅ
่ฃ
ๅจ**: ่ชๅจๆ่ทๅผๆญฅ่ทฏ็ฑไธญ็้่ฏฏ
- **ๅ
จๅฑ้่ฏฏๅค็ๅจ**: ็ปไธ็้่ฏฏๅๅบๆ ผๅผ
- **404 ๅค็ๅจ**: ไผ้
ๅค็ๆชๆพๅฐ็่ทฏ็ฑ
- **้่ฏฏ็ๆง**: ็ไบง็ฏๅข้่ฏฏ่ฟฝ่ธชๅๆฅๅ
${config.databases.length > 0 ? `## ๐๏ธ ๆฐๆฎๅบ้
็ฝฎ
${config.databases.includes('mysql') ? `### MySQL
\`\`\`bash
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=your_password
MYSQL_DATABASE=your_database
\`\`\`
` : ''}${config.databases.includes('mongodb') ? `### MongoDB
\`\`\`bash
MONGODB_URI=mongodb://localhost:27017/your_database
\`\`\`
` : ''}${config.databases.includes('redis') ? `### Redis
\`\`\`bash
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=your_redis_password
\`\`\`
` : ''}` : ''}${config.docker ? `## ๐ณ Docker ๆฏๆ
### ไฝฟ็จ Docker Compose
\`\`\`bash
# ๅฏๅจๆๆๆๅก
docker-compose up -d
# ๆฅ็ๆฅๅฟ
docker-compose logs -f
# ๅๆญขๆๅก
docker-compose down
\`\`\`
### ๅ็ฌไฝฟ็จ Docker
\`\`\`bash
# ๆๅปบ้ๅ
docker build -t ${projectName.toLowerCase()} .
# ่ฟ่กๅฎนๅจ
docker run -p 3000:3000 ${projectName.toLowerCase()}
\`\`\`
` : ''}${config.gitFlow ? `## ๐ Git Flow ๅทฅไฝๆต
ๆฌ้กน็ฎไฝฟ็จ Git Flow ๅทฅไฝๆต่ฟ่ก็ๆฌ็ฎก็ใ่ฏฆ็ป่ฏดๆ่ฏทๆฅ็ [GIT_FLOW.md](./GIT_FLOW.md)ใ
### ๅฟซ้ๅฝไปค
\`\`\`bash
# ๅผๅงๆฐๅ่ฝ
npm run git:feature <feature-name>
# ๅฎๆๅ่ฝๅผๅ
npm run git:feature:finish <feature-name>
# ๅผๅงๅๅธ
npm run git:release <version>
# ๅฎๆๅๅธ
npm run git:release:finish <version>
\`\`\`
` : ''}## ๐ค ่ดก็ฎ
1. Fork ๆฌไปๅบ
2. ๅๅปบไฝ ็็นๆงๅๆฏ (\`git checkout -b feature/AmazingFeature\`)
3. ๆไบคไฝ ็ไฟฎๆน (\`git commit -m 'Add some AmazingFeature'\`)
4. ๆจ้ๅฐๅๆฏ (\`git push origin feature/AmazingFeature\`)
5. ๆๅผไธไธช Pull Request
## ๐ ่ฎธๅฏ่ฏ
ๆฌ้กน็ฎๅบไบ MIT ่ฎธๅฏ่ฏ - ๆฅ็ [LICENSE](LICENSE) ๆไปถไบ่งฃ่ฏฆๆ
## ๐ ่ด่ฐข
- [Express.js](https://expressjs.com/) - ๅฟซ้ใๅผๆพใๆ็ฎ็ Web ๆกๆถ
- [express-hale](https://www.npmjs.com/package/express-hale) - ็ฐไปฃๅ็ Express.js ้กน็ฎ็ๆๅจ
---
โญ ๅฆๆ่ฟไธช้กน็ฎๅฏนไฝ ๆๅธฎๅฉ๏ผ่ฏท็ปๅฎไธไธชๆๆ ๏ผ`;
}
renderGitignore() {
return `# Dependencies
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Coverage directory used by tools like istanbul
coverage/
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage
.grunt
# Bower dependency directory
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript output
dist/
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
.env.local
.env.production
# parcel-bundler cache
.cache
.parcel-cache
# Next.js build output
.next
# Nuxt.js build / generate output
.nuxt
# Gatsby files
.cache/
public
# Storybook build outputs
.out
.storybook-out
# Temporary folders
tmp/
temp/
# Logs
logs
*.log
# Editor directories and files
.vscode/
.idea/
*.swp
*.swo
*~
# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db`;
}
}
exports.ConfigTemplates = ConfigTemplates;
//# sourceMappingURL=config-templates.js.map