create-aomex 0.0.27 → 0.0.28
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/package.json +2 -2
- package/templates/prisma/schema.prisma +6 -5
- package/templates/scripts/{deploy-production.sh → deploy.sh} +5 -3
- package/templates/src/commanders/hello.cmd.ts +36 -3
- package/templates/src/i18n/locales/zh-cn.ts +1 -1
- package/templates/src/routers/user.router.ts +4 -2
- package/templates/src/services/user.service.ts +3 -6
- package/templates/scripts/deploy-integration.sh +0 -14
- package/templates/src/commanders/schedule.cmd.ts +0 -31
package/package.json
CHANGED
package/templates/package.json
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"start": "node scripts/start.mjs",
|
|
11
|
-
"deploy:production": "sh scripts/deploy
|
|
12
|
-
"deploy:integration": "sh scripts/deploy
|
|
11
|
+
"deploy:production": "sh scripts/deploy.sh production",
|
|
12
|
+
"deploy:integration": "sh scripts/deploy.sh integration",
|
|
13
13
|
"prepare": "npx husky",
|
|
14
14
|
"preinstall": "npx only-allow {{packageManager}}"
|
|
15
15
|
},
|
|
@@ -8,10 +8,11 @@ generator client {
|
|
|
8
8
|
provider = "prisma-client-js"
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
model
|
|
11
|
+
model user {
|
|
12
12
|
id Int @id @default(autoincrement())
|
|
13
|
-
name String
|
|
14
|
-
age Int
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
name String @unique
|
|
14
|
+
age Int @default(17)
|
|
15
|
+
address String?
|
|
16
|
+
created_at DateTime @default(now()) @db.Timestamp(0)
|
|
17
|
+
updated_at DateTime @default(now()) @updatedAt() @db.Timestamp(0)
|
|
17
18
|
}
|
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
set -ex
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
env="$1"
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
sudo docker build --tag "{{projectName}}:$env" --file "Dockerfile.$env" .
|
|
8
|
+
|
|
9
|
+
cron_container_name="{{projectName}}-cron-$env"
|
|
8
10
|
container_exist=$(sudo docker ps | { grep $cron_container_name || :; })
|
|
9
11
|
if [ -n "$container_exist" ];
|
|
10
12
|
then
|
|
11
13
|
sudo docker exec it $cron_container_name /bin/sh -c "npx aomex cron:stop"
|
|
12
14
|
fi
|
|
13
15
|
|
|
14
|
-
sudo docker compose --file docker-compose
|
|
16
|
+
sudo docker compose --file "docker-compose-$env.yml" up -d --timeout=1
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { Commander, options } from '@aomex/console';
|
|
2
2
|
import { rule } from '@aomex/core';
|
|
3
|
+
import { cron } from '@aomex/cron';
|
|
4
|
+
import timers from 'node:timers/promises';
|
|
3
5
|
|
|
4
6
|
export const commander = new Commander();
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* 指令示例
|
|
10
|
+
*
|
|
11
|
+
* npx aomex hello
|
|
12
|
+
* npx aomex hello --user World
|
|
13
|
+
* npx aomex hello -u aomex.js
|
|
14
|
+
*/
|
|
9
15
|
commander.create('hello', {
|
|
10
16
|
mount: [
|
|
11
17
|
options(
|
|
@@ -22,3 +28,30 @@ commander.create('hello', {
|
|
|
22
28
|
console.log(`Hello ${user}`);
|
|
23
29
|
},
|
|
24
30
|
});
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 定时任务示例
|
|
34
|
+
*
|
|
35
|
+
* npx aomex cron:start 启动
|
|
36
|
+
* npx aomex cron:stop 结束
|
|
37
|
+
* npx aomex cron:stats 运行状态
|
|
38
|
+
* npx aomex cron:eject 查看列表
|
|
39
|
+
*/
|
|
40
|
+
commander.create('hello:cron', {
|
|
41
|
+
docs: {
|
|
42
|
+
summary: '执行 npx aomex -h 可以看到我',
|
|
43
|
+
description: '执行 npx aomex hello:cron -h 可以看到我',
|
|
44
|
+
},
|
|
45
|
+
mount: [
|
|
46
|
+
// cron({ second: '*/15' }),
|
|
47
|
+
cron({ minute: '*', args: ['--user', 'Boss'] }),
|
|
48
|
+
options({
|
|
49
|
+
user: rule.string().default('World'),
|
|
50
|
+
}),
|
|
51
|
+
],
|
|
52
|
+
action: async (ctx) => {
|
|
53
|
+
const { user } = ctx.options;
|
|
54
|
+
console.log(`Hello ${user}`);
|
|
55
|
+
await timers.setTimeout(5_000);
|
|
56
|
+
},
|
|
57
|
+
});
|
|
@@ -14,6 +14,7 @@ router.get('/', {
|
|
|
14
14
|
id: rule.int(),
|
|
15
15
|
name: rule.string(),
|
|
16
16
|
age: rule.int(),
|
|
17
|
+
address: rule.string().nullable(),
|
|
17
18
|
}),
|
|
18
19
|
}),
|
|
19
20
|
],
|
|
@@ -34,6 +35,7 @@ router.get('/:id', {
|
|
|
34
35
|
id: rule.int(),
|
|
35
36
|
name: rule.string(),
|
|
36
37
|
age: rule.int(),
|
|
38
|
+
address: rule.string().nullable(),
|
|
37
39
|
},
|
|
38
40
|
}),
|
|
39
41
|
response({
|
|
@@ -56,14 +58,14 @@ router.post('/', {
|
|
|
56
58
|
body({
|
|
57
59
|
name: rule.string(),
|
|
58
60
|
age: rule.number(),
|
|
61
|
+
address: rule.string().optional(),
|
|
59
62
|
}),
|
|
60
63
|
response({
|
|
61
64
|
statusCode: 201,
|
|
62
65
|
}),
|
|
63
66
|
],
|
|
64
67
|
action: async (ctx) => {
|
|
65
|
-
|
|
66
|
-
await services.user.createUser(name, age);
|
|
68
|
+
await services.user.createUser(ctx.body);
|
|
67
69
|
ctx.send(201, null);
|
|
68
70
|
},
|
|
69
71
|
});
|
|
@@ -4,7 +4,7 @@ import { Prisma } from '@prisma/client';
|
|
|
4
4
|
import { traceMethod } from '@aomex/async-trace';
|
|
5
5
|
|
|
6
6
|
export class UserService extends Service {
|
|
7
|
-
@traceMethod(
|
|
7
|
+
@traceMethod()
|
|
8
8
|
async findAll() {
|
|
9
9
|
return prisma.user.findMany({
|
|
10
10
|
orderBy: [
|
|
@@ -20,12 +20,9 @@ export class UserService extends Service {
|
|
|
20
20
|
return prisma.user.findUnique({ where: { id: userId } });
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
async createUser(
|
|
23
|
+
async createUser(data: Prisma.UserCreateArgs['data']) {
|
|
24
24
|
await prisma.user.create({
|
|
25
|
-
data:
|
|
26
|
-
name,
|
|
27
|
-
age,
|
|
28
|
-
},
|
|
25
|
+
data: data,
|
|
29
26
|
});
|
|
30
27
|
}
|
|
31
28
|
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env sh
|
|
2
|
-
|
|
3
|
-
set -ex
|
|
4
|
-
|
|
5
|
-
sudo docker build --tag {{projectName}}:integration --file Dockerfile.integration .
|
|
6
|
-
|
|
7
|
-
cron_container_name={{projectName}}-cron-integration
|
|
8
|
-
container_exist=$(sudo docker ps | { grep $cron_container_name || :; })
|
|
9
|
-
if [ -n "$container_exist" ];
|
|
10
|
-
then
|
|
11
|
-
sudo docker exec it $cron_container_name /bin/sh -c "npx aomex cron:stop"
|
|
12
|
-
fi
|
|
13
|
-
|
|
14
|
-
sudo docker compose --file docker-compose-integration.yml up -d --timeout=1
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Commander, options } from '@aomex/console';
|
|
2
|
-
import { rule } from '@aomex/core';
|
|
3
|
-
import { cron } from '@aomex/cron';
|
|
4
|
-
|
|
5
|
-
export const commander = new Commander();
|
|
6
|
-
|
|
7
|
-
commander.create('schedule', {
|
|
8
|
-
docs: {
|
|
9
|
-
summary: '执行 npx aomex -h 可以看到我',
|
|
10
|
-
description: '执行 npx aomex schedule -h 可以看到我',
|
|
11
|
-
},
|
|
12
|
-
mount: [
|
|
13
|
-
// cron({
|
|
14
|
-
// second: '*/15',
|
|
15
|
-
// }),
|
|
16
|
-
cron({
|
|
17
|
-
minute: '*/2',
|
|
18
|
-
args: ['--user', 'Boss'],
|
|
19
|
-
}),
|
|
20
|
-
options({
|
|
21
|
-
user: rule.string().default('World'),
|
|
22
|
-
}),
|
|
23
|
-
],
|
|
24
|
-
action: async (ctx) => {
|
|
25
|
-
const { user } = ctx.options;
|
|
26
|
-
console.log(`Hello ${user}`);
|
|
27
|
-
await new Promise((resolve) => {
|
|
28
|
-
setTimeout(resolve, 5_000);
|
|
29
|
-
});
|
|
30
|
-
},
|
|
31
|
-
});
|