@avleon/cli 0.0.44 → 0.0.46
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/dist/cli.js +49 -49
- package/dist/commands.js +10 -10
- package/dist/create.js +413 -263
- package/dist/serve.js +22 -16
- package/package.json +62 -51
- package/readme.md +66 -66
- package/stubs/app/app-controller.stub +11 -11
- package/stubs/app/app-minimal.stub +17 -17
- package/stubs/basic-controller.stub +7 -7
- package/stubs/config.stub +11 -11
- package/stubs/controllers/basic-controller.stub +12 -12
- package/stubs/controllers/orm-rest-controller.stub +52 -52
- package/stubs/controllers/rest-controller.stub +34 -34
- package/stubs/models/basic-model.stub +6 -6
- package/stubs/models/entity-model.stub +23 -23
- package/stubs/serve.stub +10 -10
- package/stubs/services/basic-service.stub +9 -8
- package/stubs/services/orm-rest-service.stub +73 -73
- package/stubs/services/rest-service.stub +71 -71
- package/.github/workflows/publish.yml +0 -69
- package/tsconfig.json +0 -16
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
import {Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn} from 'typeorm';
|
|
3
|
-
|
|
4
|
-
@Entity({name:"{Model}"})
|
|
5
|
-
export class {Model}{
|
|
6
|
-
|
|
7
|
-
@PrimaryGeneratedColumn()
|
|
8
|
-
id:number;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// your fields
|
|
12
|
-
|
|
13
|
-
// @Column()
|
|
14
|
-
// name:string
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
@CreateDateColumn()
|
|
18
|
-
createdAt: Date;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
@UpdateDateColumn()
|
|
22
|
-
updatedAt: Date;
|
|
23
|
-
}
|
|
1
|
+
|
|
2
|
+
import {Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn} from 'typeorm';
|
|
3
|
+
|
|
4
|
+
@Entity({name:"{Model}"})
|
|
5
|
+
export class {Model}{
|
|
6
|
+
|
|
7
|
+
@PrimaryGeneratedColumn()
|
|
8
|
+
id:number;
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
// your fields
|
|
12
|
+
|
|
13
|
+
// @Column()
|
|
14
|
+
// name:string
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@CreateDateColumn()
|
|
18
|
+
createdAt: Date;
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@UpdateDateColumn()
|
|
22
|
+
updatedAt: Date;
|
|
23
|
+
}
|
package/stubs/serve.stub
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Environment, inject } from "@avleon/core";
|
|
2
|
-
import app from "./app";
|
|
3
|
-
|
|
4
|
-
async function serve() {
|
|
5
|
-
const env = inject(Environment);
|
|
6
|
-
const port = env.get<number>("PORT") || 4000;
|
|
7
|
-
await app.run(port);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
serve();
|
|
1
|
+
import { Environment, inject } from "@avleon/core";
|
|
2
|
+
import app from "./app";
|
|
3
|
+
|
|
4
|
+
async function serve() {
|
|
5
|
+
const env = inject(Environment);
|
|
6
|
+
const port = env.get<number>("PORT") || 4000;
|
|
7
|
+
await app.run(port);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
serve();
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
1
|
+
import { AppService } from '@avleon/core';
|
|
2
|
+
|
|
3
|
+
@AppService
|
|
4
|
+
export class {Service} {
|
|
5
|
+
|
|
6
|
+
sayHello(){
|
|
7
|
+
return "Hello World!";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import { AppService, InjectRepository } from '@avleon/core';
|
|
2
|
-
import { Repository } from 'typeorm';
|
|
3
|
-
import { {Model} } from '../models/{model}.model';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
@AppService
|
|
7
|
-
export class {Service}Service{
|
|
8
|
-
|
|
9
|
-
constructor(
|
|
10
|
-
@InjectRepository({Model})
|
|
11
|
-
private readonly {model}Repository:Repository<{Model}>
|
|
12
|
-
){}
|
|
13
|
-
|
|
14
|
-
async findAll(options:any={}){
|
|
15
|
-
return this.{model}Repository.find(options);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async paginate(current:number = 1, options:any={}){
|
|
19
|
-
const take = 10;
|
|
20
|
-
const skip = current > 1 ? ( current -1 ) * 10 : 0;
|
|
21
|
-
const total = await this.{model}Repository.count(options);
|
|
22
|
-
const totalPage = Math.ceil(total / take);
|
|
23
|
-
const next = current < totalPage ? current + 1 : null;
|
|
24
|
-
const prev = current > 1 ? current - 1 : null;
|
|
25
|
-
const data = await this.{model}Repository.find({
|
|
26
|
-
...options,
|
|
27
|
-
take,
|
|
28
|
-
skip
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
total,
|
|
33
|
-
totalPage,
|
|
34
|
-
current,
|
|
35
|
-
next,
|
|
36
|
-
prev,
|
|
37
|
-
data
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async findByPk(id:number){
|
|
42
|
-
return this.{model}Repository.findOne({id});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async findBy(options:any){
|
|
46
|
-
return this.{model}Repository.findBy(options);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async findOneBy(options:any){
|
|
50
|
-
return this.{model}Repository.findOneBy(options);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
async findOne(id:number){
|
|
55
|
-
return this.{model}Repository.findOne({where:{id}}) ;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async create(createBody:any){
|
|
59
|
-
const newItem = this.{model}Repository.create();
|
|
60
|
-
return await this.{model}Repository.save();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async update(id:number, updateBody:any){
|
|
64
|
-
const isUpdate = await this.{model}Repository.update({id}, updateBody);
|
|
65
|
-
return isUpdate.affected > 0;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async delete(id:number){
|
|
69
|
-
const isDeleted = await this.{model}Repository.delete({id});
|
|
70
|
-
return isDeleted.affected > 0;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
}
|
|
1
|
+
import { AppService, InjectRepository } from '@avleon/core';
|
|
2
|
+
import { Repository } from 'typeorm';
|
|
3
|
+
import { {Model} } from '../models/{model}.model';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@AppService
|
|
7
|
+
export class {Service}Service{
|
|
8
|
+
|
|
9
|
+
constructor(
|
|
10
|
+
@InjectRepository({Model})
|
|
11
|
+
private readonly {model}Repository:Repository<{Model}>
|
|
12
|
+
){}
|
|
13
|
+
|
|
14
|
+
async findAll(options:any={}){
|
|
15
|
+
return this.{model}Repository.find(options);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async paginate(current:number = 1, options:any={}){
|
|
19
|
+
const take = 10;
|
|
20
|
+
const skip = current > 1 ? ( current -1 ) * 10 : 0;
|
|
21
|
+
const total = await this.{model}Repository.count(options);
|
|
22
|
+
const totalPage = Math.ceil(total / take);
|
|
23
|
+
const next = current < totalPage ? current + 1 : null;
|
|
24
|
+
const prev = current > 1 ? current - 1 : null;
|
|
25
|
+
const data = await this.{model}Repository.find({
|
|
26
|
+
...options,
|
|
27
|
+
take,
|
|
28
|
+
skip
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
total,
|
|
33
|
+
totalPage,
|
|
34
|
+
current,
|
|
35
|
+
next,
|
|
36
|
+
prev,
|
|
37
|
+
data
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async findByPk(id:number){
|
|
42
|
+
return this.{model}Repository.findOne({id});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async findBy(options:any){
|
|
46
|
+
return this.{model}Repository.findBy(options);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async findOneBy(options:any){
|
|
50
|
+
return this.{model}Repository.findOneBy(options);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
async findOne(id:number){
|
|
55
|
+
return this.{model}Repository.findOne({where:{id}}) ;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async create(createBody:any){
|
|
59
|
+
const newItem = this.{model}Repository.create();
|
|
60
|
+
return await this.{model}Repository.save();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async update(id:number, updateBody:any){
|
|
64
|
+
const isUpdate = await this.{model}Repository.update({id}, updateBody);
|
|
65
|
+
return isUpdate.affected > 0;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async delete(id:number){
|
|
69
|
+
const isDeleted = await this.{model}Repository.delete({id});
|
|
70
|
+
return isDeleted.affected > 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
}
|
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
import { AppService, Collection } from '@avleon/core';
|
|
2
|
-
import { {Model} } from '../models/{model}.model';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
@AppService
|
|
6
|
-
export class {Service}Service{
|
|
7
|
-
|
|
8
|
-
constructor(
|
|
9
|
-
private readonly {model}Collection:Collection.from<{Model}>([])
|
|
10
|
-
){}
|
|
11
|
-
|
|
12
|
-
async findAll(options:any={}){
|
|
13
|
-
return this.{model}Collection.find(options);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async paginate(current:number = 1, options:any={}){
|
|
17
|
-
const take = 10;
|
|
18
|
-
const skip = current > 1 ? ( current -1 ) * 10 : 0;
|
|
19
|
-
const total = await this.{model}Collection.count(options);
|
|
20
|
-
const totalPage = Math.ceil(total / take);
|
|
21
|
-
const next = current < totalPage ? current + 1 : null;
|
|
22
|
-
const prev = current > 1 ? current - 1 : null;
|
|
23
|
-
const data = await this.{model}Collection.find({
|
|
24
|
-
...options,
|
|
25
|
-
take,
|
|
26
|
-
skip
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
total,
|
|
31
|
-
totalPage,
|
|
32
|
-
current,
|
|
33
|
-
next,
|
|
34
|
-
prev,
|
|
35
|
-
data
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async findByPk(id:number){
|
|
40
|
-
return this.{model}Collection.findOne({id});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async findBy(options:any){
|
|
44
|
-
return this.{model}Collection.findBy(options);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async findOneBy(options:any){
|
|
48
|
-
return this.{model}Collection.findOneBy(options);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
async findOne(id:number){
|
|
53
|
-
return this.{model}Collection.findOne({where:{id}}) ;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async create(createBody:any){
|
|
57
|
-
const savedItem = await this.{model}Collection.save(createBody);
|
|
58
|
-
return savedItem;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async update(id:number, updateBody:any){
|
|
62
|
-
const isUpdate = await this.{model}Collection.update(id, updateBody);
|
|
63
|
-
return isUpdate;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async delete(id:number){
|
|
67
|
-
const isDeleted = await this.{model}Collection.delete(id);
|
|
68
|
-
return isDeleted > 0;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
}
|
|
1
|
+
import { AppService, Collection } from '@avleon/core';
|
|
2
|
+
import { {Model} } from '../models/{model}.model';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@AppService
|
|
6
|
+
export class {Service}Service{
|
|
7
|
+
|
|
8
|
+
constructor(
|
|
9
|
+
private readonly {model}Collection:Collection.from<{Model}>([])
|
|
10
|
+
){}
|
|
11
|
+
|
|
12
|
+
async findAll(options:any={}){
|
|
13
|
+
return this.{model}Collection.find(options);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async paginate(current:number = 1, options:any={}){
|
|
17
|
+
const take = 10;
|
|
18
|
+
const skip = current > 1 ? ( current -1 ) * 10 : 0;
|
|
19
|
+
const total = await this.{model}Collection.count(options);
|
|
20
|
+
const totalPage = Math.ceil(total / take);
|
|
21
|
+
const next = current < totalPage ? current + 1 : null;
|
|
22
|
+
const prev = current > 1 ? current - 1 : null;
|
|
23
|
+
const data = await this.{model}Collection.find({
|
|
24
|
+
...options,
|
|
25
|
+
take,
|
|
26
|
+
skip
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
total,
|
|
31
|
+
totalPage,
|
|
32
|
+
current,
|
|
33
|
+
next,
|
|
34
|
+
prev,
|
|
35
|
+
data
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async findByPk(id:number){
|
|
40
|
+
return this.{model}Collection.findOne({id});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async findBy(options:any){
|
|
44
|
+
return this.{model}Collection.findBy(options);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async findOneBy(options:any){
|
|
48
|
+
return this.{model}Collection.findOneBy(options);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
async findOne(id:number){
|
|
53
|
+
return this.{model}Collection.findOne({where:{id}}) ;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async create(createBody:any){
|
|
57
|
+
const savedItem = await this.{model}Collection.save(createBody);
|
|
58
|
+
return savedItem;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async update(id:number, updateBody:any){
|
|
62
|
+
const isUpdate = await this.{model}Collection.update(id, updateBody);
|
|
63
|
+
return isUpdate;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async delete(id:number){
|
|
67
|
+
const isDeleted = await this.{model}Collection.delete(id);
|
|
68
|
+
return isDeleted > 0;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
name: Publish to npm
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
on:
|
|
6
|
-
|
|
7
|
-
push:
|
|
8
|
-
|
|
9
|
-
tags:
|
|
10
|
-
|
|
11
|
-
- 'v*' # Trigger only when a tag like v1.0.0 is pushed
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
jobs:
|
|
16
|
-
|
|
17
|
-
publish:
|
|
18
|
-
|
|
19
|
-
runs-on: ubuntu-latest
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
steps:
|
|
24
|
-
|
|
25
|
-
- name: Checkout repository
|
|
26
|
-
|
|
27
|
-
uses: actions/checkout@v4
|
|
28
|
-
|
|
29
|
-
- name: Setup Node.js
|
|
30
|
-
|
|
31
|
-
uses: actions/setup-node@v4
|
|
32
|
-
|
|
33
|
-
with:
|
|
34
|
-
|
|
35
|
-
node-version: 20
|
|
36
|
-
|
|
37
|
-
registry-url: 'https://registry.npmjs.org'
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
- name: Install pnpm
|
|
42
|
-
|
|
43
|
-
uses: pnpm/action-setup@v4
|
|
44
|
-
|
|
45
|
-
with:
|
|
46
|
-
|
|
47
|
-
version: 9
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
- name: Install dependencies
|
|
52
|
-
|
|
53
|
-
run: pnpm install --frozen-lockfile
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
- name: Build package
|
|
57
|
-
|
|
58
|
-
run: pnpm run build
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
- name: Publish to npm
|
|
63
|
-
|
|
64
|
-
run: pnpm publish --access public --no-git-checks
|
|
65
|
-
|
|
66
|
-
env:
|
|
67
|
-
|
|
68
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
69
|
-
|
package/tsconfig.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "CommonJS",
|
|
5
|
-
"moduleResolution": "node",
|
|
6
|
-
"outDir": "./dist",
|
|
7
|
-
"rootDir": "./src",
|
|
8
|
-
"allowJs": true,
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"allowSyntheticDefaultImports": true,
|
|
11
|
-
"forceConsistentCasingInFileNames": true,
|
|
12
|
-
"skipLibCheck": true
|
|
13
|
-
},
|
|
14
|
-
"include": ["src/**/*", "src/stubs","scripts"],
|
|
15
|
-
"exclude": ["node_modules", "dist", "src/**/*.(spec|test).ts"]
|
|
16
|
-
}
|