@avleon/cli 0.0.25 → 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/cli.js +11 -54
- package/dist/controller.js +101 -84
- package/dist/create.js +58 -5
- 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 +6 -4
- package/stubs/app/app-controller.stub +11 -0
- package/stubs/app/app-minimal.stub +17 -0
- package/stubs/app/app-withdb.stub +0 -0
- package/stubs/basic-controller.stub +7 -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/dist/cli.js
CHANGED
|
@@ -42,7 +42,6 @@ exports.run = run;
|
|
|
42
42
|
const cli_table3_1 = __importDefault(require("cli-table3"));
|
|
43
43
|
const path_1 = __importDefault(require("path"));
|
|
44
44
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
45
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
46
45
|
const fs_1 = require("fs");
|
|
47
46
|
const prettier = __importStar(require("prettier"));
|
|
48
47
|
const controller_1 = require("./controller");
|
|
@@ -140,57 +139,6 @@ import {Entity, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn } fro
|
|
|
140
139
|
await promises_1.default.writeFile(path_1.default.join(process.cwd(), "./src/models/" + modelName.toLowerCase() + ".ts"), formatModel);
|
|
141
140
|
console.log("Model created succssessfully!");
|
|
142
141
|
}
|
|
143
|
-
async function createXApplication(fname) {
|
|
144
|
-
if ((0, fs_1.existsSync)(process.cwd() + fname)) {
|
|
145
|
-
throw new Error("Application already exists");
|
|
146
|
-
}
|
|
147
|
-
const projectPath = path_1.default.join(process.cwd(), fname);
|
|
148
|
-
const templateDir = path_1.default.resolve("D:\\projects\\node\\iqra\\packages\\cli\\src\\stubs");
|
|
149
|
-
//await fs.mkdir(projectPath);
|
|
150
|
-
//await fsExtra.copy(templateDir, projectPath + '/');
|
|
151
|
-
// Define project path
|
|
152
|
-
// const projectPath = path.resolve('new_test');
|
|
153
|
-
// Clone the repository and move the required folder
|
|
154
|
-
const cloneCommand = `
|
|
155
|
-
git clone -n --depth=1 --filter=tree:0 https://github.com/xtareq/iqra temp_repo &&
|
|
156
|
-
cd temp_repo &&
|
|
157
|
-
git sparse-checkout init --no-cone &&
|
|
158
|
-
git sparse-checkout set examples/iqra_test &&
|
|
159
|
-
git checkout &&
|
|
160
|
-
mv examples/iqra_test ${projectPath} &&
|
|
161
|
-
cd ..
|
|
162
|
-
`;
|
|
163
|
-
try {
|
|
164
|
-
// Execute the cloning and moving process
|
|
165
|
-
console.log("Cloning and setting up the repository...");
|
|
166
|
-
(0, child_process_1.exec)(cloneCommand, {});
|
|
167
|
-
// Check if the projectPath exists before proceeding
|
|
168
|
-
if (!fs_extra_1.default.existsSync(projectPath)) {
|
|
169
|
-
throw new Error(`Project path "${projectPath}" was not created.`);
|
|
170
|
-
}
|
|
171
|
-
// Remove the Git origin from the new project
|
|
172
|
-
console.log("Removing Git origin...");
|
|
173
|
-
(0, child_process_1.execSync)(`cd ${projectPath} && git remote remove origin`, {
|
|
174
|
-
stdio: "inherit",
|
|
175
|
-
});
|
|
176
|
-
// Clean up the temporary repository
|
|
177
|
-
console.log("Cleaning up temporary files...");
|
|
178
|
-
fs_extra_1.default.removeSync("./temp_repo");
|
|
179
|
-
console.log(`Project created successfully in ${projectPath}`);
|
|
180
|
-
}
|
|
181
|
-
catch (error) {
|
|
182
|
-
console.error("An error occurred:", error);
|
|
183
|
-
// Cleanup in case of failure
|
|
184
|
-
if (fs_extra_1.default.existsSync("./temp_repo")) {
|
|
185
|
-
console.log("Cleaning up temporary repository...");
|
|
186
|
-
fs_extra_1.default.removeSync("./temp_repo");
|
|
187
|
-
}
|
|
188
|
-
if (fs_extra_1.default.existsSync(projectPath)) {
|
|
189
|
-
console.log("Cleaning up project path...");
|
|
190
|
-
fs_extra_1.default.removeSync(projectPath);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
142
|
async function run() {
|
|
195
143
|
try {
|
|
196
144
|
const args = process.argv.slice(2);
|
|
@@ -207,12 +155,17 @@ async function run() {
|
|
|
207
155
|
}
|
|
208
156
|
else {
|
|
209
157
|
let force = false;
|
|
158
|
+
let minimal = false;
|
|
210
159
|
if (args.some((x) => x == "-f" || x == "--force")) {
|
|
211
160
|
force = true;
|
|
212
161
|
}
|
|
162
|
+
if (args.some((x) => x == "--mimimal")) {
|
|
163
|
+
minimal = true;
|
|
164
|
+
}
|
|
165
|
+
const flags = { minimal, force };
|
|
213
166
|
if (args[0] == "new") {
|
|
214
167
|
const fname = args[1];
|
|
215
|
-
await (0, create_1.createApplication)(fname);
|
|
168
|
+
await (0, create_1.createApplication)(fname, flags);
|
|
216
169
|
}
|
|
217
170
|
if (args[0] == "build") {
|
|
218
171
|
process.env.NODE_ENV = "production";
|
|
@@ -226,9 +179,13 @@ async function run() {
|
|
|
226
179
|
}
|
|
227
180
|
if (args[0] == "make:controller" || args[0] == "m:c") {
|
|
228
181
|
let resource = false;
|
|
182
|
+
let rest = false;
|
|
229
183
|
if (args.some((x) => x == "-r" || x == "--resource")) {
|
|
230
184
|
resource = true;
|
|
231
185
|
}
|
|
186
|
+
if (args.some((x) => x == "-r" || x == "--rest")) {
|
|
187
|
+
rest = true;
|
|
188
|
+
}
|
|
232
189
|
let model = null;
|
|
233
190
|
if (args.some((x) => x == "-m" || x == "--model")) {
|
|
234
191
|
const index = args.includes("-m")
|
|
@@ -240,7 +197,7 @@ async function run() {
|
|
|
240
197
|
const modelName = args[index + 1];
|
|
241
198
|
model = modelName;
|
|
242
199
|
}
|
|
243
|
-
await (0, controller_1.createController)(args[1], { force, resource, model });
|
|
200
|
+
await (0, controller_1.createController)(args[1], { force, resource, rest, model });
|
|
244
201
|
}
|
|
245
202
|
}
|
|
246
203
|
}
|
package/dist/controller.js
CHANGED
|
@@ -4,101 +4,118 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createController = createController;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
7
|
const fs_1 = require("fs");
|
|
9
|
-
const promises_1 = require("fs/promises");
|
|
10
8
|
const path_1 = __importDefault(require("path"));
|
|
11
|
-
const
|
|
9
|
+
const path_helper_1 = require("./helpers/path-helper");
|
|
10
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
11
|
+
const file_helper_1 = require("./helpers/file-helper");
|
|
12
12
|
function capitalize(str) {
|
|
13
13
|
if (!str)
|
|
14
14
|
return '';
|
|
15
15
|
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
|
|
16
16
|
}
|
|
17
|
-
async function createController(name, options = { force: false, resource: false, model: null }, p) {
|
|
18
|
-
var _a;
|
|
17
|
+
async function createController(name, options = { force: false, resource: false, rest: false, model: null }, p) {
|
|
19
18
|
if (!name) {
|
|
20
|
-
throw new Error("Controller name not found. use --name or
|
|
19
|
+
throw new Error("Controller name not found. use --name or npx avleon make:controller HomeController");
|
|
21
20
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
await (0, promises_1.mkdir)(controllerPath, {
|
|
26
|
-
recursive: true,
|
|
27
|
-
});
|
|
21
|
+
let stubPath = path_helper_1.pathHelper.stubPath('controllers/basic-controller.stub');
|
|
22
|
+
if (options.rest) {
|
|
23
|
+
stubPath = path_helper_1.pathHelper.stubPath('controllers/rest-controller.stub');
|
|
28
24
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
) === null || _a === void 0 ? void 0 : _a.join('-').toLowerCase()) || name.toLowerCase();
|
|
34
|
-
const controllerNameCap = controllerName.replace(/Controller/ig, '');
|
|
35
|
-
const controllerExists = (0, fs_1.existsSync)(`${controllerPath}/${name.toLowerCase()}.controller.ts`);
|
|
36
|
-
if (controllerExists && !options.force) {
|
|
37
|
-
console.log(chalk_1.default.bold(chalk_1.default.red("controller already exists!")), chalk_1.default.greenBright("Use -f or --force to overwrite.\r"));
|
|
38
|
-
return;
|
|
25
|
+
if (name.split("/").length > 1) {
|
|
26
|
+
if (!(0, fs_1.existsSync)(path_1.default.join('src/controllers/', name.split("/").splice(-1, 1).join("/")))) {
|
|
27
|
+
await promises_1.default.mkdir(path_1.default.join('src/controllers/', name.replace('/' + file_helper_1.fh.filenameFromPath(name), '')), { recursive: true });
|
|
28
|
+
}
|
|
39
29
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
//
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
-
//
|
|
30
|
+
const content = await promises_1.default.readFile(stubPath, 'utf8');
|
|
31
|
+
const names = (0, file_helper_1.resolveNames)(file_helper_1.fh.filenameFromPath(name), 'Controller');
|
|
32
|
+
const replacedContent = content
|
|
33
|
+
.replaceAll('{Controller}', names.className)
|
|
34
|
+
.replaceAll('{controller}', names.varName);
|
|
35
|
+
console.log('replce', content);
|
|
36
|
+
await promises_1.default.writeFile(path_1.default.join('src/controllers/', name + '.controller.ts'), replacedContent, 'utf8');
|
|
37
|
+
// const controllerPath = path.join(process.cwd(), "./src/controllers");
|
|
38
|
+
// const controllerFolderExists = existsSync(controllerPath);
|
|
39
|
+
// if (!controllerFolderExists) {
|
|
40
|
+
// await mkdir(controllerPath, {
|
|
41
|
+
// recursive: true,
|
|
42
|
+
// });
|
|
43
|
+
// }
|
|
44
|
+
// const controllerName = name.at(0).toUpperCase() + name.slice(1);
|
|
45
|
+
// const controllerNameLowerCase = name
|
|
46
|
+
// .replace(/Controller/ig, '')
|
|
47
|
+
// .match(/[A-Z]?[a-z]+|[0-9]+/g) // added ? to also capture single lowercase words
|
|
48
|
+
// ?.join('-')
|
|
49
|
+
// .toLowerCase() || name.toLowerCase();
|
|
50
|
+
// const controllerNameCap = controllerName.replace(/Controller/ig, '')
|
|
51
|
+
// const controllerExists = existsSync(`${controllerPath}/${name.toLowerCase()}.controller.ts`);
|
|
52
|
+
// if (controllerExists && !options.force) {
|
|
53
|
+
// console.log(
|
|
54
|
+
// chalk.bold(chalk.red("controller already exists!")),
|
|
55
|
+
// chalk.greenBright("Use -f or --force to overwrite.\r"),
|
|
56
|
+
// );
|
|
57
|
+
// return;
|
|
58
|
+
// }
|
|
59
|
+
// if (options.resource && !options.model) {
|
|
60
|
+
// console.log(
|
|
61
|
+
// chalk.bold(chalk.red("Model must be provide to generate rest controller!")),
|
|
62
|
+
// chalk.greenBright("Use -m Model or --model Model to .\r"),
|
|
63
|
+
// );
|
|
64
|
+
// return;
|
|
65
|
+
// }
|
|
66
|
+
// const restController = `
|
|
67
|
+
// import { ApiController, Collection, Get, Post, Put, Delete, Param, Body } from '@avleon/core';
|
|
68
|
+
// import { ${capitalize(options.model)} } from '../models/${capitalize(options.model)}'
|
|
69
|
+
// \t
|
|
70
|
+
// @ApiController("/${controllerNameLowerCase}s")
|
|
71
|
+
// export class ${controllerName}Controller {\n
|
|
72
|
+
// constructor(
|
|
73
|
+
// private readonly ${options.model.toLowerCase()}Repository = Collection.fromRepository(${capitalize(options.model)})
|
|
74
|
+
// ){}
|
|
75
|
+
// @Get()
|
|
76
|
+
// async findAll(){
|
|
77
|
+
// return "okay";
|
|
78
|
+
// }\n
|
|
79
|
+
// @Get('/:id')
|
|
80
|
+
// async findOne(@Param('id') id:number){
|
|
81
|
+
// return "okay";
|
|
82
|
+
// }\n
|
|
83
|
+
// @Post()
|
|
84
|
+
// async create(@Body() body:any){
|
|
85
|
+
// return true;
|
|
86
|
+
// }\n
|
|
87
|
+
// @Put('/:id')
|
|
88
|
+
// async update(@Param('id') id:number, @Body() body:any){
|
|
89
|
+
// return true;
|
|
90
|
+
// }\n
|
|
91
|
+
// @Delete('/:id')
|
|
92
|
+
// async delete(@Param('id') id:number){
|
|
93
|
+
// return true;
|
|
94
|
+
// }
|
|
95
|
+
// }
|
|
96
|
+
// `;
|
|
97
|
+
// const basicContorller = `import {ApiController, Get} from '@avleon/core'
|
|
98
|
+
// \n
|
|
99
|
+
// @ApiController("/${controllerNameLowerCase}")
|
|
100
|
+
// export class ${controllerName}{
|
|
101
|
+
// \n
|
|
102
|
+
// @Get()
|
|
103
|
+
// index(){
|
|
104
|
+
// return []
|
|
105
|
+
// }
|
|
51
106
|
// }
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return "okay";
|
|
66
|
-
}\n
|
|
67
|
-
@Get('/:id')
|
|
68
|
-
async findOne(@Param('id') id:number){
|
|
69
|
-
return "okay";
|
|
70
|
-
}\n
|
|
71
|
-
@Post()
|
|
72
|
-
async create(@Body() body:any){
|
|
73
|
-
return true;
|
|
74
|
-
}\n
|
|
75
|
-
@Put('/:id')
|
|
76
|
-
async update(@Param('id') id:number, @Body() body:any){
|
|
77
|
-
return true;
|
|
78
|
-
}\n
|
|
79
|
-
@Delete('/:id')
|
|
80
|
-
async delete(@Param('id') id:number){
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
`;
|
|
86
|
-
const basicContorller = `import {ApiController, Get} from '@avleon/core'
|
|
87
|
-
\n
|
|
88
|
-
@ApiController("/${controllerNameLowerCase}")
|
|
89
|
-
export class ${controllerName}{
|
|
90
|
-
\n
|
|
91
|
-
@Get()
|
|
92
|
-
index(){
|
|
93
|
-
return []
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
`;
|
|
97
|
-
const formatcontroller = await prettier_1.default.format(options.resource ? restController : basicContorller, {
|
|
98
|
-
singleQuote: true,
|
|
99
|
-
singleAttributePerLine: true,
|
|
100
|
-
parser: "typescript",
|
|
101
|
-
});
|
|
102
|
-
await (0, promises_1.writeFile)(path_1.default.join(process.cwd(), "./src/controllers/" + controllerName.toLowerCase().replace("controller", "") + ".controller" + ".ts"), formatcontroller);
|
|
107
|
+
// `;
|
|
108
|
+
// const formatcontroller = await prettier.format(
|
|
109
|
+
// options.resource ? restController : basicContorller,
|
|
110
|
+
// {
|
|
111
|
+
// singleQuote: true,
|
|
112
|
+
// singleAttributePerLine: true,
|
|
113
|
+
// parser: "typescript",
|
|
114
|
+
// },
|
|
115
|
+
// );
|
|
116
|
+
// await writeFile(
|
|
117
|
+
// path.join(process.cwd(), "./src/controllers/" + controllerName.toLowerCase().replace("controller", "") + ".controller" + ".ts"),
|
|
118
|
+
// formatcontroller,
|
|
119
|
+
// );
|
|
103
120
|
console.log("Controller created succssessfully!");
|
|
104
121
|
}
|
package/dist/create.js
CHANGED
|
@@ -41,8 +41,8 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
|
41
41
|
const paths_1 = require("./paths");
|
|
42
42
|
const prettier = __importStar(require("prettier"));
|
|
43
43
|
const win32_1 = __importDefault(require("path/win32"));
|
|
44
|
-
async function createApplication(fname) {
|
|
45
|
-
|
|
44
|
+
async function createApplication(fname, flags = {}) {
|
|
45
|
+
let appPaths = (0, paths_1.appPaths)(fname);
|
|
46
46
|
const dirs = Object.values(appPaths);
|
|
47
47
|
for (let i = 0; i < dirs.length; i++) {
|
|
48
48
|
await fs_extra_1.default.ensureDir(dirs[i]);
|
|
@@ -54,12 +54,21 @@ async function createApplication(fname) {
|
|
|
54
54
|
import {
|
|
55
55
|
Avleon
|
|
56
56
|
} from "@avleon/core";
|
|
57
|
+
import {HomeController} from './controllers/home.controller';
|
|
57
58
|
|
|
58
59
|
|
|
59
60
|
const app = Avleon.createApplication();
|
|
60
|
-
app.
|
|
61
|
-
|
|
61
|
+
app.useOpenApi({
|
|
62
|
+
info:{
|
|
63
|
+
title: '${fname} Api',
|
|
64
|
+
version: '0.0.1'
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
app.useControllers([HomeController]);
|
|
69
|
+
app.useStaticFiles();
|
|
62
70
|
|
|
71
|
+
export default app;
|
|
63
72
|
`;
|
|
64
73
|
const formatMainFunc = await prettier.format(mainFunc, {
|
|
65
74
|
singleQuote: true,
|
|
@@ -67,6 +76,22 @@ app.run();
|
|
|
67
76
|
parser: "typescript",
|
|
68
77
|
});
|
|
69
78
|
await fs_extra_1.default.writeFile(win32_1.default.join(appPaths.src, "app.ts"), formatMainFunc);
|
|
79
|
+
// create serve.ts
|
|
80
|
+
const serveFunc = `
|
|
81
|
+
import app from "./app";
|
|
82
|
+
|
|
83
|
+
async function serve(){
|
|
84
|
+
app.run();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
serve();
|
|
88
|
+
`;
|
|
89
|
+
const formatServeFunc = await prettier.format(serveFunc, {
|
|
90
|
+
singleQuote: true,
|
|
91
|
+
singleAttributePerLine: true,
|
|
92
|
+
parser: "typescript",
|
|
93
|
+
});
|
|
94
|
+
await fs_extra_1.default.writeFile(win32_1.default.join(appPaths.src, "serve.ts"), formatServeFunc);
|
|
70
95
|
// create package.json
|
|
71
96
|
const packageJson = `
|
|
72
97
|
{
|
|
@@ -75,7 +100,7 @@ app.run();
|
|
|
75
100
|
"description": "Basic avleon application",
|
|
76
101
|
"main": "index.js",
|
|
77
102
|
"scripts": {
|
|
78
|
-
"start:dev": "nodemon src/serve.ts",
|
|
103
|
+
"start:dev": "nodemon /src/serve.ts",
|
|
79
104
|
"start:debug": "nodemon --watch src --ext ts --exec node --inspect=0.0.0.0:9229 -r ts-node/register src/serve.ts",
|
|
80
105
|
"clean": "rimraf ./dist",
|
|
81
106
|
"build": "npm run clean & tsc --project ./tsconfig.build.json",
|
|
@@ -96,9 +121,22 @@ app.run();
|
|
|
96
121
|
"reflect-metadata": "^0.2.2"
|
|
97
122
|
},
|
|
98
123
|
"devDependencies": {
|
|
124
|
+
"@types/jest": "^29.5.14",
|
|
125
|
+
"jest": "^29.7.0",
|
|
126
|
+
"ts-jest": "^29.2.6",
|
|
99
127
|
"nodemon": "^3.1.7",
|
|
100
128
|
"ts-node": "^10.9.2",
|
|
101
129
|
"typescript": "^5.7.2"
|
|
130
|
+
},
|
|
131
|
+
"jest": {
|
|
132
|
+
"preset": "ts-jest",
|
|
133
|
+
"rootDir": "src",
|
|
134
|
+
"testRegex": ".*\\.spec\\.ts$",
|
|
135
|
+
"collectCoverageFrom": [
|
|
136
|
+
"**/*.(t|j)s"
|
|
137
|
+
],
|
|
138
|
+
"coverageDirectory": "../coverage",
|
|
139
|
+
"testEnvironment": "node"
|
|
102
140
|
}
|
|
103
141
|
|
|
104
142
|
}
|
|
@@ -124,6 +162,21 @@ app.run();
|
|
|
124
162
|
"exclude": ["node_modules", "dist"]
|
|
125
163
|
}`, { parser: "json" });
|
|
126
164
|
await fs_extra_1.default.writeFile(win32_1.default.join(appPaths.root, "tsconfig.json"), tsconfigJson);
|
|
165
|
+
// write e2e-test.json
|
|
166
|
+
const e2eJson = await prettier.format(`{
|
|
167
|
+
"moduleFileExtensions": [
|
|
168
|
+
"js",
|
|
169
|
+
"json",
|
|
170
|
+
"ts"
|
|
171
|
+
],
|
|
172
|
+
"rootDir": ".",
|
|
173
|
+
"testEnvironment": "node",
|
|
174
|
+
"testRegex": ".e2e-spec.ts$",
|
|
175
|
+
"transform": {
|
|
176
|
+
"^.+\\.(t|j)s$": "ts-jest"
|
|
177
|
+
}
|
|
178
|
+
}`, { parser: "json" });
|
|
179
|
+
await fs_extra_1.default.writeFile(win32_1.default.join(appPaths.root, "test/e2e-spec.json"), e2eJson);
|
|
127
180
|
await fs_extra_1.default.writeFile(win32_1.default.join(appPaths.root, ".gitignore"), `node_modules/\ndist/\n.env`);
|
|
128
181
|
// create basic service
|
|
129
182
|
// create basic controller
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fh = void 0;
|
|
4
|
+
exports.getLastPart = getLastPart;
|
|
5
|
+
exports.resolveNames = resolveNames;
|
|
6
|
+
const filenameFromPath = (fpath) => fpath.split('/')[fpath.split('/').length - 1];
|
|
7
|
+
function getLastPart(str, separator) {
|
|
8
|
+
if (!str.includes(separator))
|
|
9
|
+
return str;
|
|
10
|
+
const parts = str.split(separator);
|
|
11
|
+
return parts.at(-1);
|
|
12
|
+
}
|
|
13
|
+
function resolveNames(name, exclude) {
|
|
14
|
+
const parsedName = name.replace(exclude, '');
|
|
15
|
+
return {
|
|
16
|
+
className: parsedName.charAt(0).toUpperCase() + name.slice(1),
|
|
17
|
+
fileName: parsedName.toLowerCase(),
|
|
18
|
+
varName: parsedName.toLowerCase(),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
exports.fh = { filenameFromPath };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.pathHelper = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
// export const __filename = fileURLToPath(process.argv[1])
|
|
9
|
+
// export const __dirname = path.dirname(__filename)
|
|
10
|
+
/* */
|
|
11
|
+
exports.pathHelper = {
|
|
12
|
+
appSoucePath(p) {
|
|
13
|
+
return path_1.default.join(process.cwd(), p ? './src/' + p : './src/');
|
|
14
|
+
},
|
|
15
|
+
appTestPath(p) {
|
|
16
|
+
return path_1.default.join(process.cwd(), p ? './test/' + p : './test/');
|
|
17
|
+
},
|
|
18
|
+
stubPath(p) {
|
|
19
|
+
return path_1.default.join(__dirname, p ? '../../stubs/' + p : '../../stubs/');
|
|
20
|
+
},
|
|
21
|
+
};
|
package/dist/paths.js
CHANGED
|
@@ -3,13 +3,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.appPaths = void 0;
|
|
6
|
+
exports.appPaths = exports.appPathsMinimal = void 0;
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const appPathsMinimal = (rootPath) => {
|
|
9
|
+
const root = rootPath ? rootPath : node_path_1.default.join(process.cwd(), "./");
|
|
10
|
+
return {
|
|
11
|
+
root: root,
|
|
12
|
+
src: node_path_1.default.join(root, "src"),
|
|
13
|
+
public: node_path_1.default.join(root, "public"),
|
|
14
|
+
test: node_path_1.default.join(root, "test"),
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
exports.appPathsMinimal = appPathsMinimal;
|
|
8
18
|
const appPaths = (rootPath) => {
|
|
9
19
|
const root = rootPath ? rootPath : node_path_1.default.join(process.cwd(), "./");
|
|
10
20
|
return {
|
|
11
21
|
root: root,
|
|
12
22
|
src: node_path_1.default.join(root, "src"),
|
|
23
|
+
public: node_path_1.default.join(root, "public"),
|
|
13
24
|
test: node_path_1.default.join(root, "test"),
|
|
14
25
|
controllers: node_path_1.default.join(root, "src/controllers"),
|
|
15
26
|
models: node_path_1.default.join(root, "src/models"),
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avleon/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.27",
|
|
4
4
|
"bin": {
|
|
5
|
-
"avleon": "./dist/cli.js"
|
|
5
|
+
"avleon": "./dist/cli.js",
|
|
6
|
+
"av":"./dist/cli.js"
|
|
6
7
|
},
|
|
7
8
|
"description": "",
|
|
8
9
|
"main": "dist/index.js",
|
|
9
10
|
"types": "dist/index.d.ts",
|
|
10
11
|
"scripts": {
|
|
11
|
-
"build": "tsc",
|
|
12
|
+
"build": "rimraf dist & tsc",
|
|
12
13
|
"clean": "rm -rf ./dist",
|
|
13
14
|
"watch": "tsc-watch"
|
|
14
15
|
},
|
|
@@ -32,7 +33,8 @@
|
|
|
32
33
|
"cli-table3": "^0.6.5",
|
|
33
34
|
"fs-extra": "^11.2.0",
|
|
34
35
|
"lodash": "^4.17.21",
|
|
35
|
-
"prettier": "^3.3.3"
|
|
36
|
+
"prettier": "^3.3.3",
|
|
37
|
+
"rimraf": "^6.0.1"
|
|
36
38
|
},
|
|
37
39
|
"repository": {
|
|
38
40
|
"type": "git",
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Builder, AppConfig } from '@avleon/core';
|
|
2
|
+
import { HomeController } from './controllers/home.controller';
|
|
3
|
+
|
|
4
|
+
const builder = Builder.createAppBuilder();
|
|
5
|
+
|
|
6
|
+
const app = builder.build();
|
|
7
|
+
app.useOpenApi((config:AppConfig)=> config.openApi);
|
|
8
|
+
app.useControllers([HomeController]);
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
app.run();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Builder, AppConfig } from '@avleon/core';
|
|
2
|
+
const builder = Builder.createAppBuilder();
|
|
3
|
+
|
|
4
|
+
builder.services.addOpenApi();
|
|
5
|
+
builder.services.addServices();
|
|
6
|
+
builder.services.addAuthentication();
|
|
7
|
+
builder.servicse.addControllers();
|
|
8
|
+
const app = builder.build();
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
if(app.isDevelopment()){
|
|
13
|
+
app.useOpenApi((config:AppConfig)=> config.openApi);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
app.mapGet('/', () => "Hello World!");
|
|
17
|
+
export default app;
|
|
File without changes
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ApiController, Get, Post, Update, Delete, Param, Body, HttpResponse } from '@avleon/core';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
@ApiController('/{controller}s')
|
|
5
|
+
export class {Controller}{
|
|
6
|
+
|
|
7
|
+
@Get()
|
|
8
|
+
index(){
|
|
9
|
+
return HttpResponse.Ok("{Controller}");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@Get('/:id')
|
|
13
|
+
findOne(@Param('id') id:{pktype}){
|
|
14
|
+
return HttpResponse.Ok(`Item found with id:${id}`);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@Post()
|
|
18
|
+
create(@Body() body:{bodyType}){
|
|
19
|
+
return HttpResponse.Ok("Created");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@Update('/:id')
|
|
23
|
+
update(@Param('id') id:{pktype}, updateBody:{updateBodyType}){
|
|
24
|
+
return HttpResponse.Ok(`Item updated with id:${id}`)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@Delete('/:id')
|
|
28
|
+
delete(@Param('id') id:{pktype}){
|
|
29
|
+
return HttpResponse.Ok(`Item delted with id:${id}`)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
}
|
package/stubs/model.stub
ADDED
|
File without changes
|
|
@@ -0,0 +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
|
+
}
|
package/stubs/serve.stub
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AppService, Collection } from '@avleon/core';
|
|
2
|
+
|
|
3
|
+
@AppService
|
|
4
|
+
export class {Service}{
|
|
5
|
+
|
|
6
|
+
constructor(
|
|
7
|
+
private readonly {modelRepository}:Collection.fromRepository({Model})
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
findAll(options?:any){
|
|
11
|
+
if(options && options.page){
|
|
12
|
+
return this.{modelRepository}.paginate(options.page)
|
|
13
|
+
}
|
|
14
|
+
return this.{modelRepository}.find();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
findOne(id:{pktype}){
|
|
18
|
+
return this.{modelRepository}.findOne({where:{id}}) ;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
create(createBody:{createBodyType}){
|
|
22
|
+
const newItem = this.{modelRepository}.create();
|
|
23
|
+
return await this.{modelRepository}.save();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
update(id:{pktype}, updateBody:{updateBodyType}){
|
|
27
|
+
return this.{modelRepository}.update({id}, updateBody);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
delete(id:{pktype}){
|
|
31
|
+
return this.modelRepository.delete({id});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
3
|
+
"target": "ES2021",
|
|
4
4
|
"module": "CommonJS",
|
|
5
5
|
"moduleResolution": "node",
|
|
6
6
|
"outDir": "./dist",
|
|
@@ -10,6 +10,6 @@
|
|
|
10
10
|
"forceConsistentCasingInFileNames": true,
|
|
11
11
|
"skipLibCheck": true
|
|
12
12
|
},
|
|
13
|
-
"include": ["src/**/*"],
|
|
13
|
+
"include": ["src/**/*", "src/stubs"],
|
|
14
14
|
"exclude": ["node_modules", "dist"]
|
|
15
15
|
}
|