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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-aomex",
3
- "version": "0.0.80",
3
+ "version": "0.0.82",
4
4
  "repository": "git@github.com:aomex/create-aomex.git",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -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
- execSync('npx prisma migrate deploy', { stdio: 'inherit' });
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
 
@@ -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 '@configs';
8
- import { services } from '@services';
9
- import { logger } from '@services/logger';
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 '@services';
4
- import { prismaInput, prismaOutput } from '../generated/aomex/prisma';
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 '@configs';
4
+ import { configs } from '@/configs';
5
5
 
6
6
  export const cache = new Caching(redisAdapter(configs.redis));
7
7
 
@@ -1,4 +1,4 @@
1
- import { PrismaClient } from '../generated/prisma/client';
1
+ import { PrismaClient } from '@/generated/prisma/client';
2
2
  import * as runtime from '@prisma/client/runtime/client';
3
3
  import { PrismaMariaDb } from '@prisma/adapter-mariadb';
4
4
 
@@ -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 '@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';
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.listen(process.env['PORT'] || 3000);
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
 
@@ -34,15 +34,7 @@
34
34
  "resolveJsonModule": true,
35
35
  "typeRoots": ["./typings", "node_modules/@types"],
36
36
  "paths": {
37
- "@configs": ["./src/configs/index.ts"],
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;
@@ -1,3 +0,0 @@
1
- # Please do not edit this file manually
2
- # It should be added in your version-control system (e.g., Git)
3
- provider = "mysql"