@avleon/cli 0.0.46 → 0.4.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/LICENSE +21 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +10 -0
- package/dist/commands/build.d.ts +11 -0
- package/dist/commands/build.js +65 -0
- package/dist/commands/doctor.d.ts +10 -0
- package/dist/commands/doctor.js +96 -0
- package/dist/commands/new.d.ts +19 -0
- package/dist/commands/new.js +306 -0
- package/dist/commands/route-list.d.ts +19 -0
- package/dist/commands/route-list.js +160 -0
- package/dist/commands/serve.d.ts +17 -0
- package/dist/commands/serve.js +238 -0
- package/dist/commands/start.d.ts +10 -0
- package/dist/commands/start.js +43 -0
- package/dist/compiler.d.ts +24 -0
- package/dist/compiler.js +83 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.js +16 -0
- package/dist/generators/make.d.ts +24 -0
- package/dist/generators/make.js +157 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +40 -15
- package/dist/program.d.ts +22 -0
- package/dist/program.js +178 -0
- package/dist/utils/entry.d.ts +15 -0
- package/dist/utils/entry.js +55 -0
- package/dist/utils/env-types.d.ts +8 -0
- package/dist/utils/env-types.js +19 -0
- package/dist/utils/log.d.ts +25 -0
- package/dist/utils/log.js +39 -0
- package/dist/utils/names.d.ts +27 -0
- package/dist/utils/names.js +58 -0
- package/dist/utils/process.d.ts +18 -0
- package/dist/utils/process.js +84 -0
- package/dist/utils/project.d.ts +17 -0
- package/dist/utils/project.js +91 -0
- package/dist/utils/stubs.d.ts +15 -0
- package/dist/utils/stubs.js +52 -0
- package/dist/utils/tsconfig.d.ts +13 -0
- package/dist/utils/tsconfig.js +102 -0
- package/package.json +63 -62
- package/readme.md +155 -66
- package/stubs/config/config.stub +9 -0
- package/stubs/controllers/basic-controller.stub +9 -12
- package/stubs/controllers/resource-controller.stub +45 -0
- package/stubs/controllers/rest-controller.stub +29 -34
- package/stubs/dtos/dto.stub +11 -0
- package/stubs/middlewares/middleware.stub +9 -0
- package/stubs/models/basic-model.stub +4 -6
- package/stubs/models/entity-model.stub +16 -23
- package/stubs/project/app-minimal.stub +7 -0
- package/stubs/project/app.stub +8 -0
- package/stubs/project/env.stub +3 -0
- package/stubs/project/gitignore.stub +5 -0
- package/stubs/project/home.controller.spec.stub +19 -0
- package/stubs/project/home.controller.stub +12 -0
- package/stubs/project/home.service.stub +8 -0
- package/stubs/project/openapi.config.stub +15 -0
- package/stubs/project/readme.stub +26 -0
- package/stubs/project/serve.stub +10 -0
- package/stubs/project/tsconfig.build.stub +4 -0
- package/stubs/project/tsconfig.stub +18 -0
- package/stubs/project/vitest-e2e.config.stub +10 -0
- package/stubs/project/vitest.config.stub +17 -0
- package/stubs/services/basic-service.stub +8 -9
- package/stubs/services/orm-rest-service.stub +61 -73
- package/stubs/services/rest-service.stub +34 -71
- package/dist/av-cli.js +0 -60
- package/dist/avcli.js +0 -26
- package/dist/cli.interface.js +0 -2
- package/dist/cli.js +0 -358
- package/dist/commands.js +0 -55
- package/dist/controller.js +0 -92
- package/dist/create.js +0 -498
- package/dist/helpers/file-helper.js +0 -30
- package/dist/helpers/path-helper.js +0 -21
- package/dist/paths.js +0 -32
- package/dist/scripts/serve.js +0 -290
- package/dist/serve.js +0 -311
- package/dist/service.js +0 -73
- package/stubs/app/app-controller.stub +0 -11
- package/stubs/app/app-minimal.stub +0 -17
- package/stubs/app/app-withdb.stub +0 -0
- package/stubs/basic-controller.stub +0 -7
- package/stubs/config.stub +0 -11
- package/stubs/controllers/orm-rest-controller.stub +0 -52
- package/stubs/model.stub +0 -0
- package/stubs/serve.stub +0 -10
|
@@ -1,73 +1,61 @@
|
|
|
1
|
-
import { AppService
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
@AppService
|
|
7
|
-
export class {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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 } from '@avleon/core';
|
|
2
|
+
import { InjectRepository } from '@avleon/data';
|
|
3
|
+
import { Repository } from 'typeorm';
|
|
4
|
+
import { {Model} } from '{modelImport}';
|
|
5
|
+
|
|
6
|
+
@AppService
|
|
7
|
+
export class {ClassName} {
|
|
8
|
+
constructor(
|
|
9
|
+
@InjectRepository({Model})
|
|
10
|
+
private readonly {modelVar}Repository: Repository<{Model}>,
|
|
11
|
+
) {}
|
|
12
|
+
|
|
13
|
+
async findAll(options: any = {}) {
|
|
14
|
+
return this.{modelVar}Repository.find(options);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async paginate(current = 1, options: any = {}) {
|
|
18
|
+
const take = 10;
|
|
19
|
+
const skip = current > 1 ? (current - 1) * take : 0;
|
|
20
|
+
const total = await this.{modelVar}Repository.count(options);
|
|
21
|
+
const totalPage = Math.ceil(total / take);
|
|
22
|
+
|
|
23
|
+
const data = await this.{modelVar}Repository.find({ ...options, take, skip });
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
total,
|
|
27
|
+
totalPage,
|
|
28
|
+
current,
|
|
29
|
+
next: current < totalPage ? current + 1 : null,
|
|
30
|
+
prev: current > 1 ? current - 1 : null,
|
|
31
|
+
data,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async findByPk(id: number) {
|
|
36
|
+
return this.{modelVar}Repository.findOneBy({ id } as any);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async findBy(options: any) {
|
|
40
|
+
return this.{modelVar}Repository.findBy(options);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async findOneBy(options: any) {
|
|
44
|
+
return this.{modelVar}Repository.findOneBy(options);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async create(createBody: Partial<{Model}>) {
|
|
48
|
+
const newItem = this.{modelVar}Repository.create(createBody as any);
|
|
49
|
+
return this.{modelVar}Repository.save(newItem);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async update(id: number, updateBody: Partial<{Model}>) {
|
|
53
|
+
const result = await this.{modelVar}Repository.update({ id } as any, updateBody as any);
|
|
54
|
+
return (result.affected ?? 0) > 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async delete(id: number) {
|
|
58
|
+
const result = await this.{modelVar}Repository.delete({ id } as any);
|
|
59
|
+
return (result.affected ?? 0) > 0;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -1,71 +1,34 @@
|
|
|
1
|
-
import { AppService, Collection } from '@avleon/core';
|
|
2
|
-
import { {Model} } from '
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
async
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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 '{modelImport}';
|
|
3
|
+
|
|
4
|
+
@AppService
|
|
5
|
+
export class {ClassName} {
|
|
6
|
+
private readonly {modelVar}Collection = Collection.from<{Model}>([]);
|
|
7
|
+
|
|
8
|
+
async findAll() {
|
|
9
|
+
return this.{modelVar}Collection.find();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async paginate(page = 1, take = 10) {
|
|
13
|
+
const skip = page > 1 ? (page - 1) * take : 0;
|
|
14
|
+
return this.{modelVar}Collection.paginate({ take, skip });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async findByPk(id: number) {
|
|
18
|
+
return this.{modelVar}Collection.findOne((item) => item.id === id);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async create(createBody: Partial<{Model}>) {
|
|
22
|
+
return this.{modelVar}Collection.add(createBody);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async update(id: number, updateBody: Partial<{Model}>) {
|
|
26
|
+
this.{modelVar}Collection.update((item) => item.id === id, updateBody);
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async delete(id: number) {
|
|
31
|
+
this.{modelVar}Collection.delete((item) => item.id === id);
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
}
|
package/dist/av-cli.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.PathExtractor = PathExtractor;
|
|
5
|
-
function formatFileName(name) {
|
|
6
|
-
return name
|
|
7
|
-
.replace(/[_\s]+/g, "-")
|
|
8
|
-
.replace(/([a-z])([A-Z])/g, "$1-$2")
|
|
9
|
-
.replace(/((-|_|\.)+(Controller|Service|Model))|(Controller|Service|Model)/gi, "")
|
|
10
|
-
.toLowerCase();
|
|
11
|
-
}
|
|
12
|
-
function formatClassName(name) {
|
|
13
|
-
return name
|
|
14
|
-
.replace(/[_\s-]+/g, " ")
|
|
15
|
-
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
|
16
|
-
.toLowerCase()
|
|
17
|
-
.replace(/\b\w/g, (char) => char.toUpperCase())
|
|
18
|
-
.replace(/\s+/g, "");
|
|
19
|
-
}
|
|
20
|
-
function PathExtractor(givenPath, options) {
|
|
21
|
-
let pathSplits = givenPath.split("/");
|
|
22
|
-
let splitSize = pathSplits.length;
|
|
23
|
-
let hasSubDirectory = splitSize > 0;
|
|
24
|
-
let name = hasSubDirectory ? pathSplits[splitSize - 1] : pathSplits[0];
|
|
25
|
-
let className = formatClassName(name);
|
|
26
|
-
let fileType = "any";
|
|
27
|
-
let isRest = false;
|
|
28
|
-
let isForced = false;
|
|
29
|
-
if (options.includes("make:controller") || options.includes("m:c")) {
|
|
30
|
-
fileType = "controller";
|
|
31
|
-
className = name.toLowerCase().replace(/controller|Controller/g, "");
|
|
32
|
-
}
|
|
33
|
-
if (options.includes("make:model") || options.includes("m:m")) {
|
|
34
|
-
fileType = "model";
|
|
35
|
-
className = name.toLowerCase().replace(/controller|Controller/g, "");
|
|
36
|
-
}
|
|
37
|
-
if (options.includes("make:service") || options.includes("m:s")) {
|
|
38
|
-
fileType = "service";
|
|
39
|
-
className = name.toLowerCase().replace(/controller|Controller/g, "");
|
|
40
|
-
}
|
|
41
|
-
if (options.includes("make:util") || options.includes("m:u")) {
|
|
42
|
-
fileType = "util";
|
|
43
|
-
className = name.toLowerCase().replace(/controller|Controller/g, "");
|
|
44
|
-
}
|
|
45
|
-
if (options.includes("make:config")) {
|
|
46
|
-
fileType = "config";
|
|
47
|
-
className = name.toLowerCase().replace(/controller|Controller/g, "");
|
|
48
|
-
}
|
|
49
|
-
if (options.includes("--rest") || options.includes("-r")) {
|
|
50
|
-
isRest = true;
|
|
51
|
-
className = name.toLowerCase().replace(/controller|Controller/g, "");
|
|
52
|
-
}
|
|
53
|
-
if (options.includes("--force") || options.includes("-f")) {
|
|
54
|
-
isForced = true;
|
|
55
|
-
className = name.toLowerCase().replace(/controller|Controller/g, "");
|
|
56
|
-
}
|
|
57
|
-
let outputFileName = formatFileName(name);
|
|
58
|
-
let outputPath = givenPath + "." + fileType + ".ts";
|
|
59
|
-
return {};
|
|
60
|
-
}
|
package/dist/avcli.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AvCli = void 0;
|
|
4
|
-
const node_child_process_1 = require("node:child_process");
|
|
5
|
-
class AvCli {
|
|
6
|
-
constructor() { }
|
|
7
|
-
formatFileName() { }
|
|
8
|
-
async executeCommand(cmd) {
|
|
9
|
-
const { stdout, stderr } = (0, node_child_process_1.exec)(cmd, { encoding: "utf8" });
|
|
10
|
-
if (stderr) {
|
|
11
|
-
throw new Error("Can't execute command");
|
|
12
|
-
}
|
|
13
|
-
console.log(stdout);
|
|
14
|
-
}
|
|
15
|
-
displayHelp() { }
|
|
16
|
-
newProject() { }
|
|
17
|
-
makeModel() { }
|
|
18
|
-
makeController() { }
|
|
19
|
-
makeService() { }
|
|
20
|
-
makeConfig() { }
|
|
21
|
-
makeHelper() { }
|
|
22
|
-
makeRestController() { }
|
|
23
|
-
makeRestService() { }
|
|
24
|
-
run() { }
|
|
25
|
-
}
|
|
26
|
-
exports.AvCli = AvCli;
|
package/dist/cli.interface.js
DELETED