@avleon/cli 0.0.6 → 0.0.27
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/avcli.js +26 -0
- package/dist/cli.js +24 -55
- package/dist/controller.js +106 -101
- package/dist/create.js +82 -50
- package/dist/helpers/file-helper.js +21 -0
- package/dist/helpers/path-helper.js +21 -0
- package/dist/paths.js +12 -1
- package/package.json +16 -8
- package/pnpm-workspace.yaml +2 -0
- package/stubs/app/app-controller.stub +11 -0
- package/stubs/app/app-minimal.stub +17 -0
- package/stubs/config.stub +11 -0
- package/stubs/controllers/basic-controller.stub +12 -0
- package/stubs/controllers/rest-controller.stub +32 -0
- package/stubs/model.stub +0 -0
- package/stubs/models/basic-model.stub +6 -0
- package/stubs/models/entity-model.stub +23 -0
- package/stubs/serve.stub +10 -0
- package/stubs/services/basic-service.stub +8 -0
- package/stubs/services/rest-service.stub +34 -0
- package/tsconfig.json +2 -2
- package/src/av-cli.ts +0 -95
- package/src/cli.interface.ts +0 -55
- package/src/cli.ts +0 -241
- package/src/commands.ts +0 -56
- package/src/controller.ts +0 -106
- package/src/create.ts +0 -145
- package/src/index.ts +0 -1
- package/src/paths.ts +0 -29
- /package/{src/stubs/model.stub → stubs/app/app-withdb.stub} +0 -0
- /package/{src/stubs → stubs}/basic-controller.stub +0 -0
package/src/commands.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import chalk from "chalk";
|
|
2
|
-
export type CommandType = {
|
|
3
|
-
Command: string;
|
|
4
|
-
Alias: string;
|
|
5
|
-
Options: string;
|
|
6
|
-
Description: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const commandList: CommandType[] = [
|
|
10
|
-
{
|
|
11
|
-
Command: "new",
|
|
12
|
-
Alias: "",
|
|
13
|
-
Options: "--minimal -m, -d --database",
|
|
14
|
-
Description: "Create a new application"
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
Command: "make:model",
|
|
18
|
-
Alias: "m:m, mm",
|
|
19
|
-
Options: "-f --force",
|
|
20
|
-
Description:
|
|
21
|
-
"Create a new model. Use -f or --froce to overwrite if any model exists with name",
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
Command: "make:controller",
|
|
25
|
-
Alias: "m:c",
|
|
26
|
-
Options: `-f, --force for force create\n -r or --resource for resource controller`,
|
|
27
|
-
Description: `Create a new controller. Use -f or --force to overwrite existing controller. If you want to create a resource controller pass options -r or --resource.
|
|
28
|
-
You may also pass model by -m or --model.\n
|
|
29
|
-
${chalk.blueBright("Note:")} when using a resource contorller iqra will automaticall check for dtos related to model name. If -m is user then
|
|
30
|
-
it will check for dtos like UserCreateDto and UserUpdateDto. If dtos not found it will create automatically using
|
|
31
|
-
model properties.
|
|
32
|
-
`,
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
Command: "make:service",
|
|
36
|
-
Alias: "m:s",
|
|
37
|
-
Options: `-f, --force for force create\n -r or --resource for resource controller`,
|
|
38
|
-
Description: `Create a new controller. Use -f or --force to overwrite existing controller. If you want to create a resource controller pass options -r or --resource.
|
|
39
|
-
You may also pass model by -m or --model.\n
|
|
40
|
-
${chalk.blueBright("Note:")} when using a resource contorller iqra will automaticall check for dtos related to model name. If -m is user then
|
|
41
|
-
it will check for dtos like UserCreateDto and UserUpdateDto. If dtos not found it will create automatically using
|
|
42
|
-
model properties.
|
|
43
|
-
`,
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
Command: "make:resource",
|
|
47
|
-
Alias: "m:r",
|
|
48
|
-
Options: `-f, --force for force create\n -r or --resource for resource`,
|
|
49
|
-
Description: `Create a new resource. Use -f or --force to overwrite existing controller. If you want to create a resource controller pass options -r or --resource.
|
|
50
|
-
You may also pass model by -m or --model.\n
|
|
51
|
-
${chalk.blueBright("Note:")} when using a resource contorller iqra will automaticall check for dtos related to model name. If -m is user then
|
|
52
|
-
it will check for dtos like UserCreateDto and UserUpdateDto. If dtos not found it will create automatically using
|
|
53
|
-
model properties.
|
|
54
|
-
`,
|
|
55
|
-
},
|
|
56
|
-
];
|
package/src/controller.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import chalk from "chalk";
|
|
2
|
-
import { existsSync } from "fs";
|
|
3
|
-
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
4
|
-
import path from "path";
|
|
5
|
-
import prettier from "prettier";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
async function createController(
|
|
9
|
-
name: string,
|
|
10
|
-
options = { force: false, resource: false, model: null },
|
|
11
|
-
p?: string
|
|
12
|
-
) {
|
|
13
|
-
if (!name) {
|
|
14
|
-
throw new Error(
|
|
15
|
-
"Controller name not found. use --name or node artisan make:controller HomeController",
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
const controllerPath = path.join(process.cwd(), "./src/controllers");
|
|
19
|
-
const controllerFolderExists = existsSync(controllerPath);
|
|
20
|
-
if (!controllerFolderExists) {
|
|
21
|
-
await mkdir(controllerPath, {
|
|
22
|
-
recursive: true,
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const controllerName = name.at(0).toUpperCase() + name.slice(1);
|
|
27
|
-
const controllerNameLowerCase = name.replace(/Controller/ig, '').match(/[A-Z][a-z]+|[0-9]+/g).join("-").toLowerCase();
|
|
28
|
-
const controllerNameCap = controllerName.replace(/Controller/ig, '')
|
|
29
|
-
const controllerExists = existsSync(`${controllerPath}/${name.toLowerCase()}.controller.ts`);
|
|
30
|
-
|
|
31
|
-
if (controllerExists && !options.force) {
|
|
32
|
-
console.log(
|
|
33
|
-
chalk.bold(chalk.red("controller already exists!")),
|
|
34
|
-
chalk.greenBright("Use -f or --force to overwrite.\r"),
|
|
35
|
-
);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (options.model) {
|
|
40
|
-
const file = await import(
|
|
41
|
-
path.join(process.cwd(), "./src/models/" + options.model.toUpperCase() + ".ts")
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
if (file) {
|
|
45
|
-
Object.getOwnPropertyNames(file);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const restController = `
|
|
50
|
-
import { ApiController, Get, Post, Put, Delete, Param, Body } from '@avleon/core';
|
|
51
|
-
\t
|
|
52
|
-
@ApiController("/${controllerNameLowerCase}")
|
|
53
|
-
export class ${controllerName}{\n
|
|
54
|
-
@Get()
|
|
55
|
-
async findAll(){
|
|
56
|
-
return "okay";
|
|
57
|
-
}\n
|
|
58
|
-
@Get('/:id')
|
|
59
|
-
async findOne(@Param('id') id:number){
|
|
60
|
-
return "okay";
|
|
61
|
-
}\n
|
|
62
|
-
@Post()
|
|
63
|
-
async create(@Body() body:any){
|
|
64
|
-
return true;
|
|
65
|
-
}\n
|
|
66
|
-
@Put('/:id')
|
|
67
|
-
async update(@Param('id') id:number, @Body() body:any){
|
|
68
|
-
return true;
|
|
69
|
-
}\n
|
|
70
|
-
@Delete('/:id')
|
|
71
|
-
async delete(@Param('id') id:number){
|
|
72
|
-
return true;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
`;
|
|
77
|
-
|
|
78
|
-
const basicContorller = `import {ApiController, Get} from '@avleon/core'
|
|
79
|
-
\n
|
|
80
|
-
@ApiController("/${controllerNameLowerCase}")
|
|
81
|
-
export class ${controllerName}{
|
|
82
|
-
\n
|
|
83
|
-
@Get()
|
|
84
|
-
index(){
|
|
85
|
-
return []
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
`;
|
|
89
|
-
|
|
90
|
-
const formatcontroller = await prettier.format(
|
|
91
|
-
options.resource ? restController : basicContorller,
|
|
92
|
-
{
|
|
93
|
-
singleQuote: true,
|
|
94
|
-
singleAttributePerLine: true,
|
|
95
|
-
parser: "typescript",
|
|
96
|
-
},
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
await writeFile(
|
|
100
|
-
path.join(process.cwd(), "./src/controllers/" + controllerName.toLowerCase().replace("controller", "") + ".controller." + ".ts"),
|
|
101
|
-
formatcontroller,
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
console.log("Controller created succssessfully!");
|
|
105
|
-
}
|
|
106
|
-
export { createController };
|
package/src/create.ts
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import fs from 'fs-extra';
|
|
3
|
-
import { appPaths as getAppPaths } from './paths';
|
|
4
|
-
import * as prettier from 'prettier';
|
|
5
|
-
import path from 'path/win32';
|
|
6
|
-
import { execSync } from 'child_process';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
async function createApplication(fname: any) {
|
|
11
|
-
|
|
12
|
-
const appPaths = getAppPaths(fname);
|
|
13
|
-
const dirs = Object.values(appPaths);
|
|
14
|
-
for (let i = 0; i < dirs.length; i++) {
|
|
15
|
-
await fs.ensureDir(dirs[i]);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
await fs.ensureDir(appPaths.root + "/public");
|
|
19
|
-
// copy
|
|
20
|
-
//
|
|
21
|
-
const mainFunc = `
|
|
22
|
-
import {
|
|
23
|
-
Builder,
|
|
24
|
-
env
|
|
25
|
-
} from "@avleon/core";
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
// create builder
|
|
29
|
-
const builder = Builder.createAppBuilder();
|
|
30
|
-
|
|
31
|
-
// registering all services and dependencies here
|
|
32
|
-
// builder.addDataSource({
|
|
33
|
-
// type: "better-sqlite3",
|
|
34
|
-
// database: path.join(process.cwd(), "mydb.db"),
|
|
35
|
-
// entities: [Category, Product],
|
|
36
|
-
// synchronize: true,
|
|
37
|
-
// });
|
|
38
|
-
|
|
39
|
-
// build app
|
|
40
|
-
const app = builder.build();
|
|
41
|
-
|
|
42
|
-
app.useSwagger({
|
|
43
|
-
info: {
|
|
44
|
-
title: "${fname}",
|
|
45
|
-
description: "Your description here",
|
|
46
|
-
version: "0.0.1",
|
|
47
|
-
},
|
|
48
|
-
servers: [
|
|
49
|
-
{
|
|
50
|
-
url: "http://localhost:"+env.PORT,
|
|
51
|
-
description: "Development",
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
app.mapGet('/', ()=> "Welcome");
|
|
58
|
-
|
|
59
|
-
app.listen(env.PORT);
|
|
60
|
-
|
|
61
|
-
`
|
|
62
|
-
|
|
63
|
-
const formatMainFunc = await prettier.format(
|
|
64
|
-
mainFunc,
|
|
65
|
-
{
|
|
66
|
-
singleQuote: true,
|
|
67
|
-
singleAttributePerLine: true,
|
|
68
|
-
parser: "typescript",
|
|
69
|
-
},
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
await fs.writeFile(path.join(appPaths.src, 'app.ts'), formatMainFunc);
|
|
73
|
-
|
|
74
|
-
// create package.json
|
|
75
|
-
const packageJson = `
|
|
76
|
-
{
|
|
77
|
-
"name": "${fname}",
|
|
78
|
-
"version": "1.0.0",
|
|
79
|
-
"description": "",
|
|
80
|
-
"main": "index.js",
|
|
81
|
-
"scripts": {
|
|
82
|
-
"dev": "nodemon src/app.ts",
|
|
83
|
-
"start": "node dist/app.js",
|
|
84
|
-
"build": "rimraf dist && tsc"
|
|
85
|
-
},
|
|
86
|
-
"keywords": [],
|
|
87
|
-
"author": "",
|
|
88
|
-
"license": "ISC",
|
|
89
|
-
"dependencies": {
|
|
90
|
-
"class-transformer": "^0.5.1",
|
|
91
|
-
"class-validator": "^0.14.1",
|
|
92
|
-
"reflect-metadata": "^0.2.2"
|
|
93
|
-
},
|
|
94
|
-
"devDependencies": {
|
|
95
|
-
"nodemon": "^3.1.7",
|
|
96
|
-
"ts-node": "^10.9.2",
|
|
97
|
-
"typescript": "^5.7.2"
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
`
|
|
102
|
-
|
|
103
|
-
const formattedPackageJson = await prettier.format(
|
|
104
|
-
packageJson,
|
|
105
|
-
{
|
|
106
|
-
parser: "json",
|
|
107
|
-
},
|
|
108
|
-
);
|
|
109
|
-
await fs.writeFile(path.join(appPaths.root, 'package.json'), formattedPackageJson);
|
|
110
|
-
const tsconfigJson = await prettier.format(`{
|
|
111
|
-
"compilerOptions": {
|
|
112
|
-
"target": "ES2017",
|
|
113
|
-
"module": "CommonJS",
|
|
114
|
-
"moduleResolution": "node",
|
|
115
|
-
"experimentalDecorators": true,
|
|
116
|
-
"emitDecoratorMetadata": true,
|
|
117
|
-
"outDir": "./dist",
|
|
118
|
-
"esModuleInterop": true,
|
|
119
|
-
"allowSyntheticDefaultImports": true,
|
|
120
|
-
"forceConsistentCasingInFileNames": true,
|
|
121
|
-
"skipLibCheck": true
|
|
122
|
-
},
|
|
123
|
-
"include": ["src/**/*"],
|
|
124
|
-
"exclude": ["node_modules", "dist"]
|
|
125
|
-
}`, { parser: 'json' })
|
|
126
|
-
await fs.writeFile(path.join(appPaths.root, 'tsconfig.json'), tsconfigJson);
|
|
127
|
-
await fs.writeFile(path.join(appPaths.root, '.gitignore'), `node_modules/\ndist/\n.env`);
|
|
128
|
-
// create basic service
|
|
129
|
-
// create basic controller
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
console.info("Running pnpm install");
|
|
133
|
-
|
|
134
|
-
console.log(`cd ${fname}&& pnpm install`);
|
|
135
|
-
|
|
136
|
-
//execSync(`cd ${fname}&& pnpm install && pnpm add @avleon/core`, { stdio: 'inherit' })
|
|
137
|
-
|
|
138
|
-
console.info("App create successfully.");
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
export { createApplication }
|
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./cli";
|
package/src/paths.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
|
|
3
|
-
export type AppPaths = {
|
|
4
|
-
root: string,
|
|
5
|
-
src: string,
|
|
6
|
-
test: string,
|
|
7
|
-
controllers: string,
|
|
8
|
-
models: string,
|
|
9
|
-
services: string,
|
|
10
|
-
requests: string,
|
|
11
|
-
responses: string,
|
|
12
|
-
configs: string
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export const appPaths = (rootPath?: string): AppPaths => {
|
|
17
|
-
const root = rootPath ? rootPath : path.join(process.cwd(), "./");
|
|
18
|
-
return {
|
|
19
|
-
root: root,
|
|
20
|
-
src: path.join(root, "src"),
|
|
21
|
-
test: path.join(root, "test"),
|
|
22
|
-
controllers: path.join(root, "src/controllers"),
|
|
23
|
-
models: path.join(root, "src/models"),
|
|
24
|
-
services: path.join(root, "src/services"),
|
|
25
|
-
requests: path.join(root, "src/requests"),
|
|
26
|
-
responses: path.join(root, "src/responses"),
|
|
27
|
-
configs: path.join(root, "src/configs")
|
|
28
|
-
}
|
|
29
|
-
}
|
|
File without changes
|
|
File without changes
|