create-aomex 0.0.80 → 0.0.82
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/package.json +1 -1
- package/templates/scripts/start.mjs +7 -1
- package/templates/src/cli.ts +3 -3
- package/templates/src/routers/user.router.ts +2 -2
- package/templates/src/services/cache.service.ts +1 -1
- package/templates/src/services/prisma.ts +1 -1
- package/templates/src/web.ts +11 -6
- package/templates/tsconfig.json +1 -9
- package/templates/prisma/migrations/20251130164417_create_table_user/migration.sql +0 -11
- package/templates/prisma/migrations/migration_lock.toml +0 -3
package/package.json
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { execSync, spawn } from 'node:child_process';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
2
4
|
import process from 'node:process';
|
|
3
5
|
|
|
4
6
|
execSync('docker compose -f docker-compose.yml up --wait', { stdio: 'inherit' });
|
|
@@ -6,7 +8,11 @@ const healthCheck = execSync('docker compose -f docker-compose.yml ps', { encodi
|
|
|
6
8
|
if (healthCheck.includes('unhealthy')) process.exit(1);
|
|
7
9
|
|
|
8
10
|
execSync('npx prisma generate', { stdio: 'inherit' });
|
|
9
|
-
|
|
11
|
+
if (existsSync(path.resolve('prisma', 'migrations'))) {
|
|
12
|
+
execSync('npx prisma migrate deploy', { stdio: 'inherit' });
|
|
13
|
+
} else if (existsSync(path.resolve('prisma', 'schema.prisma'))) {
|
|
14
|
+
execSync('npx prisma db push', { stdio: 'inherit' });
|
|
15
|
+
}
|
|
10
16
|
const api = spawn('node', ['--import', 'tsx/esm', '--watch', 'src/web.ts'], { stdio: 'inherit' });
|
|
11
17
|
const cron = spawn('npx', ['aomex', 'cron:start'], { stdio: 'inherit' });
|
|
12
18
|
|
package/templates/src/cli.ts
CHANGED
|
@@ -4,9 +4,9 @@ import { destroyServices } from '@aomex/common';
|
|
|
4
4
|
import { commanders, ConsoleApp } from '@aomex/console';
|
|
5
5
|
import { crons } from '@aomex/cron';
|
|
6
6
|
import { openapi } from '@aomex/openapi';
|
|
7
|
-
import { configs } from '
|
|
8
|
-
import { services } from '
|
|
9
|
-
import { logger } from '
|
|
7
|
+
import { configs } from '@/configs';
|
|
8
|
+
import { services } from '@/services';
|
|
9
|
+
import { logger } from '@/services/logger';
|
|
10
10
|
|
|
11
11
|
const app = new ConsoleApp({
|
|
12
12
|
language: 'zh_CN',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { rule } from '@aomex/common';
|
|
2
2
|
import { body, response, Router } from '@aomex/web';
|
|
3
|
-
import { services } from '
|
|
4
|
-
import { prismaInput, prismaOutput } from '
|
|
3
|
+
import { services } from '@/services';
|
|
4
|
+
import { prismaInput, prismaOutput } from '@/generated/aomex/prisma';
|
|
5
5
|
|
|
6
6
|
export const router = new Router({
|
|
7
7
|
prefix: '/users',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Service } from '@aomex/common';
|
|
2
2
|
import { Caching } from '@aomex/cache';
|
|
3
3
|
import { redisAdapter } from '@aomex/cache-redis-adapter';
|
|
4
|
-
import { configs } from '
|
|
4
|
+
import { configs } from '@/configs';
|
|
5
5
|
|
|
6
6
|
export const cache = new Caching(redisAdapter(configs.redis));
|
|
7
7
|
|
package/templates/src/web.ts
CHANGED
|
@@ -4,10 +4,10 @@ import { compress } from '@aomex/compress';
|
|
|
4
4
|
import { etag } from '@aomex/etag';
|
|
5
5
|
import { helmet } from '@aomex/helmet';
|
|
6
6
|
import { responseTime } from '@aomex/response-time';
|
|
7
|
-
import { swagger } from '
|
|
8
|
-
import { slowTrace } from '
|
|
9
|
-
import { httpLogger } from '
|
|
10
|
-
import { logger } from '
|
|
7
|
+
import { swagger } from '@/middleware/swagger.md';
|
|
8
|
+
import { slowTrace } from '@/middleware/slow-trace.md';
|
|
9
|
+
import { httpLogger } from '@/middleware/http-logger.md';
|
|
10
|
+
import { logger } from '@/services/logger';
|
|
11
11
|
import cluster from 'node:cluster';
|
|
12
12
|
import { cpus } from 'node:os';
|
|
13
13
|
|
|
@@ -38,11 +38,16 @@ if (cluster.isWorker) {
|
|
|
38
38
|
message: ctx.response.body,
|
|
39
39
|
};
|
|
40
40
|
});
|
|
41
|
-
app
|
|
41
|
+
app
|
|
42
|
+
.http({
|
|
43
|
+
// 对应 nginx 的 keepalive_timeout
|
|
44
|
+
keepAliveTimeout: 60_000,
|
|
45
|
+
})
|
|
46
|
+
.listen(process.env['PORT'] || 3000);
|
|
42
47
|
}
|
|
43
48
|
|
|
44
49
|
if (cluster.isPrimary) {
|
|
45
|
-
for (let i = cpus().length; i-- > 0; ) {
|
|
50
|
+
for (let i = Math.max(5, Math.min(2, cpus().length)); i-- > 0; ) {
|
|
46
51
|
cluster.fork();
|
|
47
52
|
}
|
|
48
53
|
|
package/templates/tsconfig.json
CHANGED
|
@@ -34,15 +34,7 @@
|
|
|
34
34
|
"resolveJsonModule": true,
|
|
35
35
|
"typeRoots": ["./typings", "node_modules/@types"],
|
|
36
36
|
"paths": {
|
|
37
|
-
"
|
|
38
|
-
"@configs/*": ["./src/configs/*"],
|
|
39
|
-
"@middleware/*": ["./src/middleware/*"],
|
|
40
|
-
"@services": ["./src/services/index.ts"],
|
|
41
|
-
"@services/*": ["./src/services/*"],
|
|
42
|
-
"@constants/*": ["./src/constants/*"],
|
|
43
|
-
"@models/*": ["./src/models/*"],
|
|
44
|
-
"@utils/*": ["./src/utils/*"],
|
|
45
|
-
"@generated/*": ["./src/generated/*"]
|
|
37
|
+
"@/*": ["./src/*"]
|
|
46
38
|
}
|
|
47
39
|
}
|
|
48
40
|
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
-- CreateTable
|
|
2
|
-
CREATE TABLE `user` (
|
|
3
|
-
`id` INTEGER NOT NULL AUTO_INCREMENT,
|
|
4
|
-
`name` VARCHAR(191) NOT NULL,
|
|
5
|
-
`age` INTEGER NOT NULL DEFAULT 17,
|
|
6
|
-
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
7
|
-
`updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
8
|
-
|
|
9
|
-
UNIQUE INDEX `user_name_key`(`name`),
|
|
10
|
-
PRIMARY KEY (`id`)
|
|
11
|
-
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|