@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.
Files changed (89) hide show
  1. package/LICENSE +21 -0
  2. package/dist/bin.d.ts +2 -0
  3. package/dist/bin.js +10 -0
  4. package/dist/commands/build.d.ts +11 -0
  5. package/dist/commands/build.js +65 -0
  6. package/dist/commands/doctor.d.ts +10 -0
  7. package/dist/commands/doctor.js +96 -0
  8. package/dist/commands/new.d.ts +19 -0
  9. package/dist/commands/new.js +306 -0
  10. package/dist/commands/route-list.d.ts +19 -0
  11. package/dist/commands/route-list.js +160 -0
  12. package/dist/commands/serve.d.ts +17 -0
  13. package/dist/commands/serve.js +238 -0
  14. package/dist/commands/start.d.ts +10 -0
  15. package/dist/commands/start.js +43 -0
  16. package/dist/compiler.d.ts +24 -0
  17. package/dist/compiler.js +83 -0
  18. package/dist/errors.d.ts +8 -0
  19. package/dist/errors.js +16 -0
  20. package/dist/generators/make.d.ts +24 -0
  21. package/dist/generators/make.js +157 -0
  22. package/dist/index.d.ts +17 -0
  23. package/dist/index.js +40 -15
  24. package/dist/program.d.ts +22 -0
  25. package/dist/program.js +178 -0
  26. package/dist/utils/entry.d.ts +15 -0
  27. package/dist/utils/entry.js +55 -0
  28. package/dist/utils/env-types.d.ts +8 -0
  29. package/dist/utils/env-types.js +19 -0
  30. package/dist/utils/log.d.ts +25 -0
  31. package/dist/utils/log.js +39 -0
  32. package/dist/utils/names.d.ts +27 -0
  33. package/dist/utils/names.js +58 -0
  34. package/dist/utils/process.d.ts +18 -0
  35. package/dist/utils/process.js +84 -0
  36. package/dist/utils/project.d.ts +17 -0
  37. package/dist/utils/project.js +91 -0
  38. package/dist/utils/stubs.d.ts +15 -0
  39. package/dist/utils/stubs.js +52 -0
  40. package/dist/utils/tsconfig.d.ts +13 -0
  41. package/dist/utils/tsconfig.js +102 -0
  42. package/package.json +63 -62
  43. package/readme.md +155 -66
  44. package/stubs/config/config.stub +9 -0
  45. package/stubs/controllers/basic-controller.stub +9 -12
  46. package/stubs/controllers/resource-controller.stub +45 -0
  47. package/stubs/controllers/rest-controller.stub +29 -34
  48. package/stubs/dtos/dto.stub +11 -0
  49. package/stubs/middlewares/middleware.stub +9 -0
  50. package/stubs/models/basic-model.stub +4 -6
  51. package/stubs/models/entity-model.stub +16 -23
  52. package/stubs/project/app-minimal.stub +7 -0
  53. package/stubs/project/app.stub +8 -0
  54. package/stubs/project/env.stub +3 -0
  55. package/stubs/project/gitignore.stub +5 -0
  56. package/stubs/project/home.controller.spec.stub +19 -0
  57. package/stubs/project/home.controller.stub +12 -0
  58. package/stubs/project/home.service.stub +8 -0
  59. package/stubs/project/openapi.config.stub +15 -0
  60. package/stubs/project/readme.stub +26 -0
  61. package/stubs/project/serve.stub +10 -0
  62. package/stubs/project/tsconfig.build.stub +4 -0
  63. package/stubs/project/tsconfig.stub +18 -0
  64. package/stubs/project/vitest-e2e.config.stub +10 -0
  65. package/stubs/project/vitest.config.stub +17 -0
  66. package/stubs/services/basic-service.stub +8 -9
  67. package/stubs/services/orm-rest-service.stub +61 -73
  68. package/stubs/services/rest-service.stub +34 -71
  69. package/dist/av-cli.js +0 -60
  70. package/dist/avcli.js +0 -26
  71. package/dist/cli.interface.js +0 -2
  72. package/dist/cli.js +0 -358
  73. package/dist/commands.js +0 -55
  74. package/dist/controller.js +0 -92
  75. package/dist/create.js +0 -498
  76. package/dist/helpers/file-helper.js +0 -30
  77. package/dist/helpers/path-helper.js +0 -21
  78. package/dist/paths.js +0 -32
  79. package/dist/scripts/serve.js +0 -290
  80. package/dist/serve.js +0 -311
  81. package/dist/service.js +0 -73
  82. package/stubs/app/app-controller.stub +0 -11
  83. package/stubs/app/app-minimal.stub +0 -17
  84. package/stubs/app/app-withdb.stub +0 -0
  85. package/stubs/basic-controller.stub +0 -7
  86. package/stubs/config.stub +0 -11
  87. package/stubs/controllers/orm-rest-controller.stub +0 -52
  88. package/stubs/model.stub +0 -0
  89. package/stubs/serve.stub +0 -10
@@ -1,73 +1,61 @@
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 } 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 '../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 '{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;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });