create-dp-koa 1.0.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 +50 -0
- package/index.mjs +97 -0
- package/package.json +33 -0
- package/template/.env.development +9 -0
- package/template/.env.production +12 -0
- package/template/.github/workflows/ci-cd.yml +182 -0
- package/template/.trae/documents/controller_development_plan.md +386 -0
- package/template/.trae/skills/00-backend-core.skill.md +50 -0
- package/template/.trae/skills/01-backend-skill-router.skill.md +55 -0
- package/template/.trae/skills/10-backend-api.skill.md +54 -0
- package/template/.trae/skills/11-backend-controller-recipes.skill.md +107 -0
- package/template/.trae/skills/20-backend-repository.skill.md +25 -0
- package/template/.trae/skills/21-backend-service.skill.md +135 -0
- package/template/.trae/skills/25-backend-comments-and-doc.skill.md +97 -0
- package/template/.trae/skills/30-backend-validation.skill.md +320 -0
- package/template/.trae/skills/40-backend-error-logging.skill.md +21 -0
- package/template/.trae/skills/50-backend-bootstrap-lifecycle.skill.md +90 -0
- package/template/.trae/skills/60-backend-router-registration.skill.md +71 -0
- package/template/.trae/skills/70-backend-middleware.skill.md +98 -0
- package/template/.trae/skills/80-backend-utils-and-libs.skill.md +90 -0
- package/template/.trae/skills/85-backend-plugins.rule.md +64 -0
- package/template/.trae/skills/90-backend-testing.skill.md +29 -0
- package/template/.trae/skills/README.md +49 -0
- package/template/.vscode/launch.json +38 -0
- package/template/.vscode/settings.json +1 -0
- package/template/Dockerfile +36 -0
- package/template/README.md +229 -0
- package/template/docker-compose.yml +135 -0
- package/template/docs/API_DOCUMENTATION.md +837 -0
- package/template/docs/ARCHITECTURE_REFACTOR.md +109 -0
- package/template/docs/CACHE_MIGRATION_GUIDE.md +142 -0
- package/template/docs/DEPLOYMENT_GUIDE.md +1062 -0
- package/template/docs/DEVELOPMENT_GUIDE.md +1097 -0
- package/template/docs/DOCUMENTATION_CLEANUP_REPORT.md +166 -0
- package/template/docs/DOCUMENTATION_COMPLETION_REPORT.md +223 -0
- package/template/docs/DOCUMENTATION_INDEX.md +294 -0
- package/template/docs/DOCUMENTATION_STRUCTURE.md +221 -0
- package/template/docs/ENTERPRISE_ANNOTATION_SYSTEM_GUIDE.md +2069 -0
- package/template/docs/ENTERPRISE_DATABASE_ARCHITECTURE.md +318 -0
- package/template/docs/ENTERPRISE_DEPLOYMENT_GUIDE.md +547 -0
- package/template/docs/ENTERPRISE_ERROR_HANDLING_GUIDE.md +357 -0
- package/template/docs/ENTERPRISE_LOGGING_SYSTEM_GUIDE.md +494 -0
- package/template/docs/ENVIRONMENT_CONFIG_EXAMPLE.md +69 -0
- package/template/docs/FINAL_IMPLEMENTATION_SUMMARY.md +206 -0
- package/template/docs/HEALTH_CHECK_ROUTE_FIX.md +134 -0
- package/template/docs/IMPLEMENTATION_CHECKLIST.md +204 -0
- package/template/docs/INSTALLATION_GUIDE.md +611 -0
- package/template/docs/INTERCEPTOR_TESTING_REPORT.md +226 -0
- package/template/docs/INTERCEPTOR_TESTING_SCRIPTS.md +143 -0
- package/template/docs/LOGGING_OPTIMIZATION_GUIDE.md +126 -0
- package/template/docs/MEMORY_DATABASE_GUIDE.md +212 -0
- package/template/docs/NEW_ROUTER_INTEGRATION_GUIDE.md +345 -0
- package/template/docs/NEW_ROUTER_INTEGRATION_SUMMARY.md +259 -0
- package/template/docs/NEW_ROUTER_USAGE_GUIDE.md +364 -0
- package/template/docs/QUICK_START.md +268 -0
- package/template/docs/ROUTE_SLASH_COMPATIBILITY_FIX.md +191 -0
- package/template/docs/SERVICE_INTERCEPTOR_GUIDE.md +243 -0
- package/template/docs/SERVICE_LAYER_INDEX.md +205 -0
- package/template/docs/SERVICE_PATTERN_GUIDE.md +270 -0
- package/template/docs/SERVICE_RETURN_VALUE_SPECIFICATION.md +466 -0
- package/template/docs/SWAGGER_DEBUG_MODE_GUIDE.md +80 -0
- package/template/docs/SWAGGER_INTEGRATION_GUIDE.md +416 -0
- package/template/docs/TRANSACTION_MANAGER_USAGE.md +360 -0
- package/template/docs/TROUBLESHOOTING.md +869 -0
- package/template/env.production.example +62 -0
- package/template/jest.config.js +34 -0
- package/template/package-lock.json +13240 -0
- package/template/package.json +119 -0
- package/template/patches/typeorm+0.3.25.patch +22 -0
- package/template/scripts/sync-template.mjs +84 -0
- package/template/scripts/test-annotation-system.sh +48 -0
- package/template/scripts/test-core-functionality.sh +28 -0
- package/template/src/annotations/decorators/ConfigManagement.ts +9 -0
- package/template/src/annotations/decorators/DistributedTracing.ts +9 -0
- package/template/src/annotations/decorators/EnterprisePerformance.ts +9 -0
- package/template/src/annotations/decorators/PerformanceMonitor.ts +32 -0
- package/template/src/annotations/decorators/SecurityAudit.ts +9 -0
- package/template/src/annotations/index.ts +50 -0
- package/template/src/annotations/processors/ConfigManagementProcessor.ts +369 -0
- package/template/src/annotations/processors/DistributedTracingProcessor.ts +288 -0
- package/template/src/annotations/processors/EnterprisePerformanceProcessor.ts +189 -0
- package/template/src/annotations/processors/PerformanceMonitorProcessor.ts +101 -0
- package/template/src/annotations/processors/SecurityAuditProcessor.ts +345 -0
- package/template/src/annotations/processors/SwaggerProcessor.ts +612 -0
- package/template/src/annotations/processors/index.ts +10 -0
- package/template/src/app.ts +123 -0
- package/template/src/controllers/base.controller.ts +41 -0
- package/template/src/controllers/cacheManagement.controller.ts +131 -0
- package/template/src/controllers/captcha.controller.ts +57 -0
- package/template/src/controllers/demo/AnnotationDemoController.ts +118 -0
- package/template/src/controllers/example/EnterpriseExampleController.ts +297 -0
- package/template/src/controllers/example/ExampleController.ts +110 -0
- package/template/src/controllers/example/NewAnnotationExampleController.ts +159 -0
- package/template/src/controllers/example/SwaggerExampleController.ts +205 -0
- package/template/src/controllers/example/TransactionExample.controller.ts +336 -0
- package/template/src/controllers/health.controller.ts +235 -0
- package/template/src/controllers/home/register.controller.ts +58 -0
- package/template/src/controllers/home/ytGoods.controller.ts +92 -0
- package/template/src/controllers/home/ytShop.controller.ts +135 -0
- package/template/src/controllers/home/ytUser.controller.ts +89 -0
- package/template/src/controllers/logManagement.controller.ts +396 -0
- package/template/src/controllers/public/emailSend.controller.ts +65 -0
- package/template/src/controllers/public/ytUserAuth.controller.ts +174 -0
- package/template/src/controllers/testData.controller.ts +253 -0
- package/template/src/dto/controller/example/NewAnnotationExampleController.dto.ts +73 -0
- package/template/src/dto/controller/home/emailSend.controller.dto.ts +40 -0
- package/template/src/dto/controller/home/register.controller.dto.ts +45 -0
- package/template/src/dto/controller/home/ytGoods.controller.dto.ts +55 -0
- package/template/src/dto/controller/home/ytShop.controller.dto.ts +69 -0
- package/template/src/dto/controller/home/ytUser.controller.dto.ts +44 -0
- package/template/src/dto/controller/public/ytUserAuth.controller.dto.ts +63 -0
- package/template/src/dto/goods.dto.ts +212 -0
- package/template/src/dto/service/ytService.dto.ts +13 -0
- package/template/src/dto/user.dto.ts +177 -0
- package/template/src/entity/base.entity.ts +13 -0
- package/template/src/entity/columnTypes.ts +13 -0
- package/template/src/entity/goodsImagesUnlockKey.entity.ts +33 -0
- package/template/src/entity/goodsUnlocker.entity.ts +34 -0
- package/template/src/entity/index.ts +15 -0
- package/template/src/entity/shop.entity.ts +52 -0
- package/template/src/entity/shopUser.entity.ts +41 -0
- package/template/src/entity/ytGoods.entity.ts +94 -0
- package/template/src/entity/ytUser.entity.ts +96 -0
- package/template/src/examples/InterceptorExampleRunner.ts +284 -0
- package/template/src/examples/ServiceInterceptorExample.ts +214 -0
- package/template/src/examples/SwaggerProcessorExample.ts +169 -0
- package/template/src/examples/TransactionManagerDemo.ts +377 -0
- package/template/src/examples/cacheExamples.ts +155 -0
- package/template/src/framework/decorator/controller.ts +311 -0
- package/template/src/framework/decorator/processor/AnnotationDecorators.ts +100 -0
- package/template/src/framework/decorator/processor/AnnotationProcessor.ts +156 -0
- package/template/src/framework/decorator/processor/AnnotationProcessorConfig.ts +45 -0
- package/template/src/framework/decorator/processor/AnnotationRegistry.ts +117 -0
- package/template/src/framework/decorator/processor/AnnotationSystemInitializer.ts +95 -0
- package/template/src/framework/decorator/processor/ProcessorManager.ts +76 -0
- package/template/src/framework/decorator/processor/processors/CustomProcessors.ts +126 -0
- package/template/src/framework/decorator/processor/processors/DefaultProcessors.ts +207 -0
- package/template/src/framework/decorator/refactored/DecoratorFactory.ts +99 -0
- package/template/src/framework/decorator/refactored/DecoratorMetadataManager.ts +125 -0
- package/template/src/framework/decorator/refactored/DecoratorValidator.ts +128 -0
- package/template/src/framework/decorator/refactored/TypeSafeDecorators.ts +139 -0
- package/template/src/framework/decorator/refactored/index.ts +98 -0
- package/template/src/framework/decorator/swagger.ts +150 -0
- package/template/src/framework/interceptors/AdvancedServiceCallInterceptor.ts +375 -0
- package/template/src/framework/interceptors/ServiceCallInterceptor.ts +348 -0
- package/template/src/framework/interceptors/index.ts +19 -0
- package/template/src/framework/plugins/registry.ts +63 -0
- package/template/src/framework/plugins/types.ts +15 -0
- package/template/src/framework/types/ServiceResult.ts +151 -0
- package/template/src/framework/types/index.ts +16 -0
- package/template/src/framework/utils/CacheManager.ts +430 -0
- package/template/src/framework/utils/CacheService.ts +248 -0
- package/template/src/framework/utils/DtoValidator.ts +164 -0
- package/template/src/framework/utils/MigrationHelper.ts +179 -0
- package/template/src/framework/utils/MigrationManager.ts +256 -0
- package/template/src/framework/utils/NewRouter.ts +207 -0
- package/template/src/framework/utils/TransactionManager.ts +172 -0
- package/template/src/framework/utils/bootstrap.ts +445 -0
- package/template/src/framework/utils/cache.ts +269 -0
- package/template/src/framework/utils/databaseConfig.ts +148 -0
- package/template/src/framework/utils/db.ts +39 -0
- package/template/src/framework/utils/dbMonitor.ts +106 -0
- package/template/src/framework/utils/dynamicSwagger.ts +410 -0
- package/template/src/framework/utils/function.ts +61 -0
- package/template/src/framework/utils/gracefulShutdown.ts +131 -0
- package/template/src/framework/utils/logger.ts +388 -0
- package/template/src/framework/utils/metrics.ts +182 -0
- package/template/src/framework/utils/router.ts +417 -0
- package/template/src/framework/utils/swagger.ts +184 -0
- package/template/src/framework/utils/testDb.ts +19 -0
- package/template/src/framework/utils/token.ts +23 -0
- package/template/src/framework/utils/transform.ts +17 -0
- package/template/src/libs/aokEmailSender.ts +42 -0
- package/template/src/libs/captcha.ts +37 -0
- package/template/src/libs/cos.ts +45 -0
- package/template/src/libs/mCache.ts +7 -0
- package/template/src/libs/serviceValidate.ts +3 -0
- package/template/src/libs/tecentSms.ts +51 -0
- package/template/src/middlewares/a.middleware.ts +6 -0
- package/template/src/middlewares/error.middleware.ts +14 -0
- package/template/src/middlewares/logging.middleware.ts +187 -0
- package/template/src/middlewares/static.middleware.ts +79 -0
- package/template/src/middlewares/swagger.middleware.ts +70 -0
- package/template/src/middlewares/token.middleware.ts +32 -0
- package/template/src/migrations/1700000000000-InitialDatabaseStructure.ts +172 -0
- package/template/src/migrations/index.ts +6 -0
- package/template/src/plugins/weboffice/core/context.ts +47 -0
- package/template/src/plugins/weboffice/core/errors.ts +51 -0
- package/template/src/plugins/weboffice/core/types.ts +63 -0
- package/template/src/plugins/weboffice/core/utils.ts +7 -0
- package/template/src/plugins/weboffice/entities/index.ts +3 -0
- package/template/src/plugins/weboffice/entities/webofficeFile.entity.ts +28 -0
- package/template/src/plugins/weboffice/entities/webofficeFileVersion.entity.ts +29 -0
- package/template/src/plugins/weboffice/http/routes.ts +179 -0
- package/template/src/plugins/weboffice/index.ts +23 -0
- package/template/src/plugins/weboffice/services/webofficeCallback.service.ts +274 -0
- package/template/src/repository/UserRepository.ts +122 -0
- package/template/src/repository/base/BaseRepository.ts +124 -0
- package/template/src/repository/interfaces/IBaseRepository.ts +67 -0
- package/template/src/routers/index.ts +49 -0
- package/template/src/service/base.service.ts +116 -0
- package/template/src/service/paramValidateTest.service.ts +139 -0
- package/template/src/service/ytGoods.service.ts +42 -0
- package/template/src/service/ytShop.service.ts +90 -0
- package/template/src/service/ytUser.service.ts +451 -0
- package/template/src/test/swaggerParameterTest.ts +90 -0
- package/template/src/utils/testDataInitializer.ts +296 -0
- package/template/static/output.json +15203 -0
- package/template/test/controllers/controllers.test.ts +173 -0
- package/template/test/controllers/example/ExampleController.test.ts +222 -0
- package/template/test/controllers/example/NewAnnotationExampleController.test.ts +200 -0
- package/template/test/framework/TransactionManagerDemo.test.ts +363 -0
- package/template/test/framework/annotation/AnnotationDecorators.test.ts +222 -0
- package/template/test/framework/annotation/AnnotationExecutor.test.ts +246 -0
- package/template/test/framework/annotation/AnnotationProcessor.test.ts +179 -0
- package/template/test/framework/annotation/CustomProcessors.test.ts +313 -0
- package/template/test/framework/annotation/DefaultProcessors.test.ts +371 -0
- package/template/test/framework/annotation/NewRouter.test.ts +272 -0
- package/template/test/framework/annotation/ProcessorManager.test.ts +248 -0
- package/template/test/framework/annotation/setup.ts +26 -0
- package/template/test/framework/cache.test.ts +101 -0
- package/template/test/framework/databaseConfig.test.ts +142 -0
- package/template/test/integration/integration.test.ts +153 -0
- package/template/test/plugins/weboffice/http.routes.int.test.ts +61 -0
- package/template/test/service/business.test.ts +87 -0
- package/template/test/service/paramValidateTest.service.test.ts +184 -0
- package/template/test/service/ytUser.service.test.ts +566 -0
- package/template/test/setup.ts +20 -0
- package/template/test/setupAfterEnv.ts +14 -0
- package/template/test/utils/testHelpers.ts +220 -0
- package/template/test_output.txt +0 -0
- package/template/tsconfig.build.json +17 -0
- package/template/tsconfig.json +31 -0
- package/template/webpack.config.js +71 -0
- package/template/yarn.lock +7354 -0
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# create-dp-koa
|
|
2
|
+
|
|
3
|
+
通过官方模板快速创建 [DP-Koa Framework](https://gitee.com/rajan_admin/dp-koa-framework) 项目。
|
|
4
|
+
|
|
5
|
+
## 要求
|
|
6
|
+
|
|
7
|
+
- Node.js >= 18
|
|
8
|
+
|
|
9
|
+
## 使用
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm create dp-koa@latest
|
|
13
|
+
# 或
|
|
14
|
+
npx create-dp-koa@latest <目录名>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
按提示输入项目名称,或直接在命令行传入目录名。
|
|
18
|
+
|
|
19
|
+
进入项目后:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
cd <目录名>
|
|
23
|
+
npm install
|
|
24
|
+
cp env.production.example .env
|
|
25
|
+
npm run dev
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## 源码与维护
|
|
29
|
+
|
|
30
|
+
框架源码仓库(SSH):
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
git clone git@gitee.com:rajan_admin/dp-koa-framework.git
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
若 npm 包名为作用域包(例如 `@your-org/create-dp-koa`),请使用:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm create @your-org/dp-koa@latest
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
具体以包发布说明为准。
|
|
43
|
+
|
|
44
|
+
## 维护者发版
|
|
45
|
+
|
|
46
|
+
在仓库根目录:
|
|
47
|
+
|
|
48
|
+
1. 合并并推送代码到远程。
|
|
49
|
+
2. 更新模板:`node scripts/sync-template.mjs`
|
|
50
|
+
3. 在 `packages/create-dp-koa` 下提升 `version`,执行 `npm publish`(`prepublishOnly` 会再次同步模板;若已手动同步可保持一致)。
|
package/index.mjs
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { cp, readFile, readdir, stat, writeFile } from 'fs/promises';
|
|
3
|
+
import { dirname, join, resolve } from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import prompts from 'prompts';
|
|
6
|
+
|
|
7
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const TEMPLATE_DIR = join(__dirname, 'template');
|
|
9
|
+
|
|
10
|
+
function toPackageName(input) {
|
|
11
|
+
const s = String(input || '')
|
|
12
|
+
.trim()
|
|
13
|
+
.toLowerCase()
|
|
14
|
+
.replace(/\s+/g, '-')
|
|
15
|
+
.replace(/[^a-z0-9._-]/g, '-')
|
|
16
|
+
.replace(/-+/g, '-')
|
|
17
|
+
.replace(/^-+|-+$/g, '');
|
|
18
|
+
return s || 'my-app';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function pathExists(p) {
|
|
22
|
+
try {
|
|
23
|
+
await stat(p);
|
|
24
|
+
return true;
|
|
25
|
+
} catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function assertTargetDirAllowed(targetDir) {
|
|
31
|
+
if (!(await pathExists(targetDir))) return;
|
|
32
|
+
const st = await stat(targetDir);
|
|
33
|
+
if (!st.isDirectory()) {
|
|
34
|
+
console.error(`错误: 目标路径已存在且不是目录: ${targetDir}`);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
const entries = await readdir(targetDir);
|
|
38
|
+
if (entries.length > 0) {
|
|
39
|
+
console.error(`错误: 目标目录已存在且非空: ${targetDir}`);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function main() {
|
|
45
|
+
let projectName = process.argv[2];
|
|
46
|
+
|
|
47
|
+
if (!projectName) {
|
|
48
|
+
const res = await prompts(
|
|
49
|
+
{
|
|
50
|
+
type: 'text',
|
|
51
|
+
name: 'name',
|
|
52
|
+
message: '项目名称(将作为目录名与 package.json 的 name)',
|
|
53
|
+
initial: 'my-dp-koa-app',
|
|
54
|
+
},
|
|
55
|
+
{ onCancel: () => process.exit(0) }
|
|
56
|
+
);
|
|
57
|
+
projectName = res.name;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const pkgName = toPackageName(projectName);
|
|
61
|
+
const cwd = process.cwd();
|
|
62
|
+
const targetDir = resolve(cwd, projectName);
|
|
63
|
+
|
|
64
|
+
if (!(await pathExists(TEMPLATE_DIR))) {
|
|
65
|
+
console.error(
|
|
66
|
+
`错误: 未找到模板目录。请在仓库根执行: node scripts/sync-template.mjs`
|
|
67
|
+
);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
await assertTargetDirAllowed(targetDir);
|
|
72
|
+
|
|
73
|
+
await cp(TEMPLATE_DIR, targetDir, { recursive: true });
|
|
74
|
+
|
|
75
|
+
const pkgPath = join(targetDir, 'package.json');
|
|
76
|
+
if (await pathExists(pkgPath)) {
|
|
77
|
+
const raw = await readFile(pkgPath, 'utf8');
|
|
78
|
+
const json = JSON.parse(raw);
|
|
79
|
+
json.name = pkgName;
|
|
80
|
+
await writeFile(pkgPath, `${JSON.stringify(json, null, 2)}\n`, 'utf8');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
console.log();
|
|
84
|
+
console.log(`已创建项目: ${targetDir}`);
|
|
85
|
+
console.log();
|
|
86
|
+
console.log('接下来执行:');
|
|
87
|
+
console.log(` cd ${projectName}`);
|
|
88
|
+
console.log(' npm install');
|
|
89
|
+
console.log(' cp env.production.example .env # 按需配置环境变量');
|
|
90
|
+
console.log(' npm run dev');
|
|
91
|
+
console.log();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
main().catch((err) => {
|
|
95
|
+
console.error(err);
|
|
96
|
+
process.exit(1);
|
|
97
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-dp-koa",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Scaffold a DP-Koa framework project from the official template",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"create-dp-koa": "./index.mjs"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"index.mjs",
|
|
11
|
+
"template"
|
|
12
|
+
],
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=18"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"prepublishOnly": "node ../../scripts/sync-template.mjs"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"prompts": "^2.4.2"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"koa",
|
|
24
|
+
"scaffold",
|
|
25
|
+
"dp-koa",
|
|
26
|
+
"create-app"
|
|
27
|
+
],
|
|
28
|
+
"license": "ISC",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git@gitee.com:rajan_admin/dp-koa-framework.git"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
host=127.0.0.1
|
|
2
|
+
port=3011
|
|
3
|
+
jwt_secret=eT4*fL8#uW9$mW4.pE5?yZ6`jB2[dE9.
|
|
4
|
+
db_enable=1
|
|
5
|
+
db_memory=0 # 关闭内存数据库
|
|
6
|
+
db_type=mysql
|
|
7
|
+
db_host=localhost
|
|
8
|
+
db_port=3306
|
|
9
|
+
db_username=ytfx
|
|
10
|
+
db_password=LDrMzwBMGEwkaYYM
|
|
11
|
+
db_database=ytfx
|
|
12
|
+
aok_email_api_key=330b853af20ef6762f259545ef7b4c17
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
name: Enterprise CI/CD Pipeline
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main, develop ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ main ]
|
|
8
|
+
|
|
9
|
+
env:
|
|
10
|
+
NODE_VERSION: '18'
|
|
11
|
+
REGISTRY: ghcr.io
|
|
12
|
+
IMAGE_NAME: ${{ github.repository }}
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
# 代码质量检查
|
|
16
|
+
quality-check:
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
steps:
|
|
19
|
+
- name: Checkout code
|
|
20
|
+
uses: actions/checkout@v4
|
|
21
|
+
|
|
22
|
+
- name: Setup Node.js
|
|
23
|
+
uses: actions/setup-node@v4
|
|
24
|
+
with:
|
|
25
|
+
node-version: ${{ env.NODE_VERSION }}
|
|
26
|
+
cache: 'npm'
|
|
27
|
+
|
|
28
|
+
- name: Install dependencies
|
|
29
|
+
run: npm ci
|
|
30
|
+
|
|
31
|
+
- name: Lint code
|
|
32
|
+
run: npm run lint
|
|
33
|
+
|
|
34
|
+
- name: Type check
|
|
35
|
+
run: npm run type-check
|
|
36
|
+
|
|
37
|
+
- name: Security audit
|
|
38
|
+
run: npm audit --audit-level=moderate
|
|
39
|
+
|
|
40
|
+
# 测试
|
|
41
|
+
test:
|
|
42
|
+
runs-on: ubuntu-latest
|
|
43
|
+
services:
|
|
44
|
+
mysql:
|
|
45
|
+
image: mysql:8.0
|
|
46
|
+
env:
|
|
47
|
+
MYSQL_ROOT_PASSWORD: root
|
|
48
|
+
MYSQL_DATABASE: test_db
|
|
49
|
+
ports:
|
|
50
|
+
- 3306:3306
|
|
51
|
+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
|
|
52
|
+
|
|
53
|
+
steps:
|
|
54
|
+
- name: Checkout code
|
|
55
|
+
uses: actions/checkout@v4
|
|
56
|
+
|
|
57
|
+
- name: Setup Node.js
|
|
58
|
+
uses: actions/setup-node@v4
|
|
59
|
+
with:
|
|
60
|
+
node-version: ${{ env.NODE_VERSION }}
|
|
61
|
+
cache: 'npm'
|
|
62
|
+
|
|
63
|
+
- name: Install dependencies
|
|
64
|
+
run: npm ci
|
|
65
|
+
|
|
66
|
+
- name: Run tests
|
|
67
|
+
run: npm run test:coverage
|
|
68
|
+
env:
|
|
69
|
+
DB_HOST: localhost
|
|
70
|
+
DB_PORT: 3306
|
|
71
|
+
DB_USERNAME: root
|
|
72
|
+
DB_PASSWORD: root
|
|
73
|
+
DB_DATABASE: test_db
|
|
74
|
+
|
|
75
|
+
- name: Upload coverage to Codecov
|
|
76
|
+
uses: codecov/codecov-action@v3
|
|
77
|
+
with:
|
|
78
|
+
file: ./coverage/lcov.info
|
|
79
|
+
flags: unittests
|
|
80
|
+
name: codecov-umbrella
|
|
81
|
+
|
|
82
|
+
# 构建Docker镜像
|
|
83
|
+
build:
|
|
84
|
+
runs-on: ubuntu-latest
|
|
85
|
+
needs: [quality-check, test]
|
|
86
|
+
if: github.event_name == 'push'
|
|
87
|
+
|
|
88
|
+
steps:
|
|
89
|
+
- name: Checkout code
|
|
90
|
+
uses: actions/checkout@v4
|
|
91
|
+
|
|
92
|
+
- name: Set up Docker Buildx
|
|
93
|
+
uses: docker/setup-buildx-action@v3
|
|
94
|
+
|
|
95
|
+
- name: Log in to Container Registry
|
|
96
|
+
uses: docker/login-action@v3
|
|
97
|
+
with:
|
|
98
|
+
registry: ${{ env.REGISTRY }}
|
|
99
|
+
username: ${{ github.actor }}
|
|
100
|
+
password: ${{ secrets.GITHUB_TOKEN }}
|
|
101
|
+
|
|
102
|
+
- name: Extract metadata
|
|
103
|
+
id: meta
|
|
104
|
+
uses: docker/metadata-action@v5
|
|
105
|
+
with:
|
|
106
|
+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
|
107
|
+
tags: |
|
|
108
|
+
type=ref,event=branch
|
|
109
|
+
type=ref,event=pr
|
|
110
|
+
type=sha,prefix={{branch}}-
|
|
111
|
+
type=raw,value=latest,enable={{is_default_branch}}
|
|
112
|
+
|
|
113
|
+
- name: Build and push Docker image
|
|
114
|
+
uses: docker/build-push-action@v5
|
|
115
|
+
with:
|
|
116
|
+
context: .
|
|
117
|
+
push: true
|
|
118
|
+
tags: ${{ steps.meta.outputs.tags }}
|
|
119
|
+
labels: ${{ steps.meta.outputs.labels }}
|
|
120
|
+
cache-from: type=gha
|
|
121
|
+
cache-to: type=gha,mode=max
|
|
122
|
+
|
|
123
|
+
# 安全扫描
|
|
124
|
+
security-scan:
|
|
125
|
+
runs-on: ubuntu-latest
|
|
126
|
+
needs: build
|
|
127
|
+
if: github.event_name == 'push'
|
|
128
|
+
|
|
129
|
+
steps:
|
|
130
|
+
- name: Run Trivy vulnerability scanner
|
|
131
|
+
uses: aquasecurity/trivy-action@master
|
|
132
|
+
with:
|
|
133
|
+
image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
|
|
134
|
+
format: 'sarif'
|
|
135
|
+
output: 'trivy-results.sarif'
|
|
136
|
+
|
|
137
|
+
- name: Upload Trivy scan results to GitHub Security tab
|
|
138
|
+
uses: github/codeql-action/upload-sarif@v2
|
|
139
|
+
with:
|
|
140
|
+
sarif_file: 'trivy-results.sarif'
|
|
141
|
+
|
|
142
|
+
# 部署到测试环境
|
|
143
|
+
deploy-staging:
|
|
144
|
+
runs-on: ubuntu-latest
|
|
145
|
+
needs: [build, security-scan]
|
|
146
|
+
if: github.ref == 'refs/heads/develop'
|
|
147
|
+
environment: staging
|
|
148
|
+
|
|
149
|
+
steps:
|
|
150
|
+
- name: Deploy to staging
|
|
151
|
+
run: |
|
|
152
|
+
echo "Deploying to staging environment..."
|
|
153
|
+
# 这里添加实际的部署脚本
|
|
154
|
+
|
|
155
|
+
# 部署到生产环境
|
|
156
|
+
deploy-production:
|
|
157
|
+
runs-on: ubuntu-latest
|
|
158
|
+
needs: [build, security-scan]
|
|
159
|
+
if: github.ref == 'refs/heads/main'
|
|
160
|
+
environment: production
|
|
161
|
+
|
|
162
|
+
steps:
|
|
163
|
+
- name: Deploy to production
|
|
164
|
+
run: |
|
|
165
|
+
echo "Deploying to production environment..."
|
|
166
|
+
# 这里添加实际的部署脚本
|
|
167
|
+
|
|
168
|
+
# 性能测试
|
|
169
|
+
performance-test:
|
|
170
|
+
runs-on: ubuntu-latest
|
|
171
|
+
needs: deploy-staging
|
|
172
|
+
if: github.ref == 'refs/heads/develop'
|
|
173
|
+
|
|
174
|
+
steps:
|
|
175
|
+
- name: Checkout code
|
|
176
|
+
uses: actions/checkout@v4
|
|
177
|
+
|
|
178
|
+
- name: Run performance tests
|
|
179
|
+
run: |
|
|
180
|
+
npm install -g artillery
|
|
181
|
+
artillery run tests/performance/load-test.yml
|
|
182
|
+
|