@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/dist/avcli.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
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.js
CHANGED
|
@@ -42,16 +42,18 @@ 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
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
49
47
|
const controller_1 = require("./controller");
|
|
50
48
|
const commands_1 = require("./commands");
|
|
51
49
|
const child_process_1 = require("child_process");
|
|
52
50
|
const create_1 = require("./create");
|
|
53
51
|
function iqraCli() { }
|
|
54
|
-
const listedCommands = commands_1.commandList
|
|
52
|
+
const listedCommands = commands_1.commandList
|
|
53
|
+
.flatMap((x) => x.Command)
|
|
54
|
+
.concat(commands_1.commandList.flatMap((x) => x.Alias.split(",")))
|
|
55
|
+
.flatMap((a) => a.trim())
|
|
56
|
+
.concat("build");
|
|
55
57
|
/**
|
|
56
58
|
* @description Displaying basic info
|
|
57
59
|
* @since v0.0.2
|
|
@@ -110,7 +112,7 @@ async function createModel(name, options = { force: false }) {
|
|
|
110
112
|
const modelName = name.at(0).toUpperCase() + name.slice(1);
|
|
111
113
|
const modelExists = (0, fs_1.existsSync)(path_1.default.join(process.cwd(), `./src/models/${modelName.toLowerCase()}.ts`));
|
|
112
114
|
if (modelExists && !options.force) {
|
|
113
|
-
console.log(
|
|
115
|
+
console.log("Model already exists!", "Use -f or --force to overwrite.\r");
|
|
114
116
|
return;
|
|
115
117
|
}
|
|
116
118
|
const model = `
|
|
@@ -137,55 +139,6 @@ import {Entity, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn } fro
|
|
|
137
139
|
await promises_1.default.writeFile(path_1.default.join(process.cwd(), "./src/models/" + modelName.toLowerCase() + ".ts"), formatModel);
|
|
138
140
|
console.log("Model created succssessfully!");
|
|
139
141
|
}
|
|
140
|
-
async function createXApplication(fname) {
|
|
141
|
-
if ((0, fs_1.existsSync)(process.cwd() + fname)) {
|
|
142
|
-
throw new Error("Application already exists");
|
|
143
|
-
}
|
|
144
|
-
const projectPath = path_1.default.join(process.cwd(), fname);
|
|
145
|
-
const templateDir = path_1.default.resolve("D:\\projects\\node\\iqra\\packages\\cli\\src\\stubs");
|
|
146
|
-
//await fs.mkdir(projectPath);
|
|
147
|
-
//await fsExtra.copy(templateDir, projectPath + '/');
|
|
148
|
-
// Define project path
|
|
149
|
-
// const projectPath = path.resolve('new_test');
|
|
150
|
-
// Clone the repository and move the required folder
|
|
151
|
-
const cloneCommand = `
|
|
152
|
-
git clone -n --depth=1 --filter=tree:0 https://github.com/xtareq/iqra temp_repo &&
|
|
153
|
-
cd temp_repo &&
|
|
154
|
-
git sparse-checkout init --no-cone &&
|
|
155
|
-
git sparse-checkout set examples/iqra_test &&
|
|
156
|
-
git checkout &&
|
|
157
|
-
mv examples/iqra_test ${projectPath} &&
|
|
158
|
-
cd ..
|
|
159
|
-
`;
|
|
160
|
-
try {
|
|
161
|
-
// Execute the cloning and moving process
|
|
162
|
-
console.log('Cloning and setting up the repository...');
|
|
163
|
-
(0, child_process_1.exec)(cloneCommand, {});
|
|
164
|
-
// Check if the projectPath exists before proceeding
|
|
165
|
-
if (!fs_extra_1.default.existsSync(projectPath)) {
|
|
166
|
-
throw new Error(`Project path "${projectPath}" was not created.`);
|
|
167
|
-
}
|
|
168
|
-
// Remove the Git origin from the new project
|
|
169
|
-
console.log('Removing Git origin...');
|
|
170
|
-
(0, child_process_1.execSync)(`cd ${projectPath} && git remote remove origin`, { stdio: 'inherit' });
|
|
171
|
-
// Clean up the temporary repository
|
|
172
|
-
console.log('Cleaning up temporary files...');
|
|
173
|
-
fs_extra_1.default.removeSync('./temp_repo');
|
|
174
|
-
console.log(`Project created successfully in ${projectPath}`);
|
|
175
|
-
}
|
|
176
|
-
catch (error) {
|
|
177
|
-
console.error('An error occurred:', error);
|
|
178
|
-
// Cleanup in case of failure
|
|
179
|
-
if (fs_extra_1.default.existsSync('./temp_repo')) {
|
|
180
|
-
console.log('Cleaning up temporary repository...');
|
|
181
|
-
fs_extra_1.default.removeSync('./temp_repo');
|
|
182
|
-
}
|
|
183
|
-
if (fs_extra_1.default.existsSync(projectPath)) {
|
|
184
|
-
console.log('Cleaning up project path...');
|
|
185
|
-
fs_extra_1.default.removeSync(projectPath);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
142
|
async function run() {
|
|
190
143
|
try {
|
|
191
144
|
const args = process.argv.slice(2);
|
|
@@ -202,21 +155,37 @@ async function run() {
|
|
|
202
155
|
}
|
|
203
156
|
else {
|
|
204
157
|
let force = false;
|
|
158
|
+
let minimal = false;
|
|
205
159
|
if (args.some((x) => x == "-f" || x == "--force")) {
|
|
206
160
|
force = true;
|
|
207
161
|
}
|
|
162
|
+
if (args.some((x) => x == "--mimimal")) {
|
|
163
|
+
minimal = true;
|
|
164
|
+
}
|
|
165
|
+
const flags = { minimal, force };
|
|
208
166
|
if (args[0] == "new") {
|
|
209
167
|
const fname = args[1];
|
|
210
|
-
await (0, create_1.createApplication)(fname);
|
|
168
|
+
await (0, create_1.createApplication)(fname, flags);
|
|
169
|
+
}
|
|
170
|
+
if (args[0] == "build") {
|
|
171
|
+
process.env.NODE_ENV = "production";
|
|
172
|
+
//const appPath =
|
|
173
|
+
(0, child_process_1.execSync)("rm -r ./dist");
|
|
174
|
+
(0, child_process_1.execSync)("npx tsc --project tsconfig.build.json");
|
|
175
|
+
console.log("Build successfully");
|
|
211
176
|
}
|
|
212
177
|
if (args[0] == "make:model") {
|
|
213
178
|
await createModel(args[1], { force });
|
|
214
179
|
}
|
|
215
180
|
if (args[0] == "make:controller" || args[0] == "m:c") {
|
|
216
181
|
let resource = false;
|
|
182
|
+
let rest = false;
|
|
217
183
|
if (args.some((x) => x == "-r" || x == "--resource")) {
|
|
218
184
|
resource = true;
|
|
219
185
|
}
|
|
186
|
+
if (args.some((x) => x == "-r" || x == "--rest")) {
|
|
187
|
+
rest = true;
|
|
188
|
+
}
|
|
220
189
|
let model = null;
|
|
221
190
|
if (args.some((x) => x == "-m" || x == "--model")) {
|
|
222
191
|
const index = args.includes("-m")
|
|
@@ -228,7 +197,7 @@ async function run() {
|
|
|
228
197
|
const modelName = args[index + 1];
|
|
229
198
|
model = modelName;
|
|
230
199
|
}
|
|
231
|
-
await (0, controller_1.createController)(args[1], { force, resource, model });
|
|
200
|
+
await (0, controller_1.createController)(args[1], { force, resource, rest, model });
|
|
232
201
|
}
|
|
233
202
|
}
|
|
234
203
|
}
|
package/dist/controller.js
CHANGED
|
@@ -1,116 +1,121 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
4
|
};
|
|
38
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
6
|
exports.createController = createController;
|
|
40
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
41
7
|
const fs_1 = require("fs");
|
|
42
|
-
const promises_1 = require("fs/promises");
|
|
43
8
|
const path_1 = __importDefault(require("path"));
|
|
44
|
-
const
|
|
45
|
-
|
|
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
|
+
function capitalize(str) {
|
|
13
|
+
if (!str)
|
|
14
|
+
return '';
|
|
15
|
+
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
|
|
16
|
+
}
|
|
17
|
+
async function createController(name, options = { force: false, resource: false, rest: false, model: null }, p) {
|
|
46
18
|
if (!name) {
|
|
47
|
-
throw new Error("Controller name not found. use --name or
|
|
48
|
-
}
|
|
49
|
-
const controllerPath = path_1.default.join(process.cwd(), "./src/controllers");
|
|
50
|
-
const controllerFolderExists = (0, fs_1.existsSync)(controllerPath);
|
|
51
|
-
if (!controllerFolderExists) {
|
|
52
|
-
await (0, promises_1.mkdir)(controllerPath, {
|
|
53
|
-
recursive: true,
|
|
54
|
-
});
|
|
19
|
+
throw new Error("Controller name not found. use --name or npx avleon make:controller HomeController");
|
|
55
20
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const controllerExists = (0, fs_1.existsSync)(`${controllerPath}/${name.toLowerCase()}.controller.ts`);
|
|
60
|
-
if (controllerExists && !options.force) {
|
|
61
|
-
console.log(chalk_1.default.bold(chalk_1.default.red("controller already exists!")), chalk_1.default.greenBright("Use -f or --force to overwrite.\r"));
|
|
62
|
-
return;
|
|
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');
|
|
63
24
|
}
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
Object.getOwnPropertyNames(file);
|
|
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 });
|
|
68
28
|
}
|
|
69
29
|
}
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
})
|
|
114
|
-
|
|
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
|
+
// }
|
|
106
|
+
// }
|
|
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
|
+
// );
|
|
115
120
|
console.log("Controller created succssessfully!");
|
|
116
121
|
}
|
package/dist/create.js
CHANGED
|
@@ -41,86 +41,102 @@ 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]);
|
|
49
49
|
}
|
|
50
50
|
await fs_extra_1.default.ensureDir(appPaths.root + "/public");
|
|
51
|
-
// copy
|
|
51
|
+
// copy
|
|
52
52
|
//
|
|
53
53
|
const mainFunc = `
|
|
54
54
|
import {
|
|
55
|
-
|
|
56
|
-
env
|
|
55
|
+
Avleon
|
|
57
56
|
} from "@avleon/core";
|
|
57
|
+
import {HomeController} from './controllers/home.controller';
|
|
58
58
|
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
// database: path.join(process.cwd(), "mydb.db"),
|
|
67
|
-
// entities: [Category, Product],
|
|
68
|
-
// synchronize: true,
|
|
69
|
-
// });
|
|
70
|
-
|
|
71
|
-
// build app
|
|
72
|
-
const app = builder.build();
|
|
73
|
-
|
|
74
|
-
app.useSwagger({
|
|
75
|
-
info: {
|
|
76
|
-
title: "${fname}",
|
|
77
|
-
description: "Your description here",
|
|
78
|
-
version: "0.0.1",
|
|
79
|
-
},
|
|
80
|
-
servers: [
|
|
81
|
-
{
|
|
82
|
-
url: "http://localhost:"+env.PORT,
|
|
83
|
-
description: "Development",
|
|
84
|
-
},
|
|
85
|
-
|
|
60
|
+
const app = Avleon.createApplication();
|
|
61
|
+
app.useOpenApi({
|
|
62
|
+
info:{
|
|
63
|
+
title: '${fname} Api',
|
|
64
|
+
version: '0.0.1'
|
|
65
|
+
}
|
|
86
66
|
});
|
|
87
67
|
|
|
68
|
+
app.useControllers([HomeController]);
|
|
69
|
+
app.useStaticFiles();
|
|
88
70
|
|
|
89
|
-
|
|
71
|
+
export default app;
|
|
72
|
+
`;
|
|
73
|
+
const formatMainFunc = await prettier.format(mainFunc, {
|
|
74
|
+
singleQuote: true,
|
|
75
|
+
singleAttributePerLine: true,
|
|
76
|
+
parser: "typescript",
|
|
77
|
+
});
|
|
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";
|
|
90
82
|
|
|
91
|
-
|
|
83
|
+
async function serve(){
|
|
84
|
+
app.run();
|
|
85
|
+
}
|
|
92
86
|
|
|
87
|
+
serve();
|
|
93
88
|
`;
|
|
94
|
-
const
|
|
89
|
+
const formatServeFunc = await prettier.format(serveFunc, {
|
|
95
90
|
singleQuote: true,
|
|
96
91
|
singleAttributePerLine: true,
|
|
97
92
|
parser: "typescript",
|
|
98
93
|
});
|
|
99
|
-
await fs_extra_1.default.writeFile(win32_1.default.join(appPaths.src,
|
|
94
|
+
await fs_extra_1.default.writeFile(win32_1.default.join(appPaths.src, "serve.ts"), formatServeFunc);
|
|
100
95
|
// create package.json
|
|
101
96
|
const packageJson = `
|
|
102
97
|
{
|
|
103
98
|
"name": "${fname}",
|
|
104
|
-
"version": "
|
|
105
|
-
"description": "",
|
|
99
|
+
"version": "0.0.0",
|
|
100
|
+
"description": "Basic avleon application",
|
|
106
101
|
"main": "index.js",
|
|
107
102
|
"scripts": {
|
|
108
|
-
"dev": "nodemon src/
|
|
109
|
-
"start": "node
|
|
110
|
-
"
|
|
103
|
+
"start:dev": "nodemon /src/serve.ts",
|
|
104
|
+
"start:debug": "nodemon --watch src --ext ts --exec node --inspect=0.0.0.0:9229 -r ts-node/register src/serve.ts",
|
|
105
|
+
"clean": "rimraf ./dist",
|
|
106
|
+
"build": "npm run clean & tsc --project ./tsconfig.build.json",
|
|
107
|
+
"start": "node dist/serve.js",
|
|
108
|
+
"test": "jest",
|
|
109
|
+
"test:watch": "jest --watch",
|
|
110
|
+
"test:cov": "jest --coverage",
|
|
111
|
+
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
|
112
|
+
"test:e2e": "jest --config ./test/e2e-spec.json"
|
|
111
113
|
},
|
|
112
|
-
"keywords": [],
|
|
113
|
-
"author": "",
|
|
114
|
+
"keywords": ["avleon","nodejs","typescript"],
|
|
114
115
|
"license": "ISC",
|
|
115
116
|
"dependencies": {
|
|
117
|
+
"@avleon/core": "^0.0.25",
|
|
118
|
+
"@avleon/cli": "^0.0.25",
|
|
116
119
|
"class-transformer": "^0.5.1",
|
|
117
120
|
"class-validator": "^0.14.1",
|
|
118
121
|
"reflect-metadata": "^0.2.2"
|
|
119
122
|
},
|
|
120
123
|
"devDependencies": {
|
|
124
|
+
"@types/jest": "^29.5.14",
|
|
125
|
+
"jest": "^29.7.0",
|
|
126
|
+
"ts-jest": "^29.2.6",
|
|
121
127
|
"nodemon": "^3.1.7",
|
|
122
128
|
"ts-node": "^10.9.2",
|
|
123
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"
|
|
124
140
|
}
|
|
125
141
|
|
|
126
142
|
}
|
|
@@ -128,7 +144,7 @@ app.listen(env.PORT);
|
|
|
128
144
|
const formattedPackageJson = await prettier.format(packageJson, {
|
|
129
145
|
parser: "json",
|
|
130
146
|
});
|
|
131
|
-
await fs_extra_1.default.writeFile(win32_1.default.join(appPaths.root,
|
|
147
|
+
await fs_extra_1.default.writeFile(win32_1.default.join(appPaths.root, "package.json"), formattedPackageJson);
|
|
132
148
|
const tsconfigJson = await prettier.format(`{
|
|
133
149
|
"compilerOptions": {
|
|
134
150
|
"target": "ES2017",
|
|
@@ -144,13 +160,29 @@ app.listen(env.PORT);
|
|
|
144
160
|
},
|
|
145
161
|
"include": ["src/**/*"],
|
|
146
162
|
"exclude": ["node_modules", "dist"]
|
|
147
|
-
}`, { parser:
|
|
148
|
-
await fs_extra_1.default.writeFile(win32_1.default.join(appPaths.root,
|
|
149
|
-
|
|
163
|
+
}`, { parser: "json" });
|
|
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);
|
|
180
|
+
await fs_extra_1.default.writeFile(win32_1.default.join(appPaths.root, ".gitignore"), `node_modules/\ndist/\n.env`);
|
|
150
181
|
// create basic service
|
|
151
182
|
// create basic controller
|
|
152
|
-
console.info("
|
|
153
|
-
console.log(`cd ${fname}&& pnpm install`);
|
|
154
|
-
|
|
155
|
-
|
|
183
|
+
console.info("App created successfully. Run the following command to get start.");
|
|
184
|
+
console.log(`cd ${fname} && pnpm install`);
|
|
185
|
+
console.log(`npm run start:dev`);
|
|
186
|
+
//execSync(`cd ${fname} && pnpm install && pnpm add @avleon/core`, { stdio: 'inherit' })
|
|
187
|
+
console.info("Enjoy :D");
|
|
156
188
|
}
|
|
@@ -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"),
|