@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
package/dist/cli.js
DELETED
|
@@ -1,358 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
-
var ownKeys = function(o) {
|
|
21
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
-
var ar = [];
|
|
23
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
-
return ar;
|
|
25
|
-
};
|
|
26
|
-
return ownKeys(o);
|
|
27
|
-
};
|
|
28
|
-
return function (mod) {
|
|
29
|
-
if (mod && mod.__esModule) return mod;
|
|
30
|
-
var result = {};
|
|
31
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
-
__setModuleDefault(result, mod);
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
})();
|
|
36
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
-
};
|
|
39
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
exports.iqraCli = iqraCli;
|
|
41
|
-
exports.run = run;
|
|
42
|
-
const cli_table3_1 = __importDefault(require("cli-table3"));
|
|
43
|
-
const path_1 = __importDefault(require("path"));
|
|
44
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
45
|
-
const fs_1 = require("fs");
|
|
46
|
-
const prettier = __importStar(require("prettier"));
|
|
47
|
-
const controller_1 = require("./controller");
|
|
48
|
-
const commands_1 = require("./commands");
|
|
49
|
-
const child_process_1 = require("child_process");
|
|
50
|
-
const create_1 = require("./create");
|
|
51
|
-
const service_1 = require("./service");
|
|
52
|
-
const lodash_1 = require("lodash");
|
|
53
|
-
function iqraCli() { }
|
|
54
|
-
const listedCommands = commands_1.commandList
|
|
55
|
-
.flatMap((x) => x.Command)
|
|
56
|
-
.concat(commands_1.commandList.flatMap((x) => x.Alias.split(",")))
|
|
57
|
-
.flatMap((a) => a.trim())
|
|
58
|
-
.concat("build");
|
|
59
|
-
/**
|
|
60
|
-
* @description Displaying basic info
|
|
61
|
-
* @since v0.0.2
|
|
62
|
-
* */
|
|
63
|
-
async function printLogo() {
|
|
64
|
-
try {
|
|
65
|
-
const packageInfo = await promises_1.default.readFile(path_1.default.join(__dirname, "../package.json"), "utf8");
|
|
66
|
-
const parsedPackInfo = JSON.parse(packageInfo);
|
|
67
|
-
console.log(`Name: Avleon CLI`, "\r");
|
|
68
|
-
console.log(`Version: ${parsedPackInfo.version}`, "\r");
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
throw new Error("Can't read packag info");
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
async function displayCommandList(info = { logo: true, all: false }) {
|
|
75
|
-
if (info.logo) {
|
|
76
|
-
await printLogo();
|
|
77
|
-
}
|
|
78
|
-
console.log("Available commandList:");
|
|
79
|
-
if (info.all) {
|
|
80
|
-
const table = new cli_table3_1.default({
|
|
81
|
-
head: ["Command", "Alias", "Available Options", "Description"],
|
|
82
|
-
colWidths: [20, 10, 30, 50],
|
|
83
|
-
wrapOnWordBoundary: true,
|
|
84
|
-
wordWrap: true,
|
|
85
|
-
});
|
|
86
|
-
commands_1.commandList.forEach((c) => {
|
|
87
|
-
table.push([c.Command, c.Alias, c.Options, c.Description]);
|
|
88
|
-
});
|
|
89
|
-
console.log(table.toString());
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
const table = new cli_table3_1.default({
|
|
93
|
-
head: ["Command", "Alias", "Available Options"],
|
|
94
|
-
colWidths: [20, 10, 50],
|
|
95
|
-
wrapOnWordBoundary: true,
|
|
96
|
-
wordWrap: true,
|
|
97
|
-
});
|
|
98
|
-
commands_1.commandList.forEach((c) => {
|
|
99
|
-
table.push([c.Command, c.Alias, c.Options]);
|
|
100
|
-
});
|
|
101
|
-
console.log(table.toString());
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
async function createModel(name, options = { force: false, orm: false }) {
|
|
105
|
-
if (!name) {
|
|
106
|
-
throw new Error("Model name not found . use --name or node artisan make:model ModelName");
|
|
107
|
-
}
|
|
108
|
-
const modelFolderExists = (0, fs_1.existsSync)(path_1.default.join(process.cwd(), "./src/models"));
|
|
109
|
-
if (!modelFolderExists) {
|
|
110
|
-
await promises_1.default.mkdir(path_1.default.join(process.cwd(), "./src/models"), {
|
|
111
|
-
recursive: true,
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
const modelName = name.at(0).toUpperCase() + name.slice(1);
|
|
115
|
-
const modelExists = (0, fs_1.existsSync)(path_1.default.join(process.cwd(), `./src/models/${modelName.toLowerCase()}.ts`));
|
|
116
|
-
if (modelExists && !options.force) {
|
|
117
|
-
console.log("Model already exists!", "Use -f or --force to overwrite.\r");
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
const basicModel = `
|
|
121
|
-
\t
|
|
122
|
-
export class ${modelName}{
|
|
123
|
-
id:number;
|
|
124
|
-
name: string;
|
|
125
|
-
}
|
|
126
|
-
`;
|
|
127
|
-
const ormModel = `
|
|
128
|
-
import {Entity, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn } from 'typeorm';
|
|
129
|
-
\t
|
|
130
|
-
@Entity({name:'${modelName}'})
|
|
131
|
-
export class ${modelName}{
|
|
132
|
-
|
|
133
|
-
@PrimaryGeneratedColumn()
|
|
134
|
-
id:number;
|
|
135
|
-
|
|
136
|
-
@CreateDateColumn()
|
|
137
|
-
createdAt: Date;
|
|
138
|
-
|
|
139
|
-
@UpdateDateColumn()
|
|
140
|
-
updatedAt: Date;
|
|
141
|
-
}
|
|
142
|
-
`;
|
|
143
|
-
const formatModel = await prettier.format(options.orm ? ormModel : basicModel, {
|
|
144
|
-
singleQuote: true,
|
|
145
|
-
singleAttributePerLine: true,
|
|
146
|
-
parser: "typescript",
|
|
147
|
-
});
|
|
148
|
-
await promises_1.default.writeFile(path_1.default.join(process.cwd(), "./src/models/" + modelName.toLowerCase() + ".ts"), formatModel);
|
|
149
|
-
console.log("Model created succssessfully!");
|
|
150
|
-
}
|
|
151
|
-
async function createMiddleware(name, options = { force: false }) {
|
|
152
|
-
if (!name) {
|
|
153
|
-
throw new Error("Model name not found . use --name or node artisan make:model ModelName");
|
|
154
|
-
}
|
|
155
|
-
const modelName = name.at(0).toUpperCase() + name.slice(1);
|
|
156
|
-
const modelExists = (0, fs_1.existsSync)(path_1.default.join(process.cwd(), `./src/middlewares/${modelName.toLowerCase()}.middleware.ts`));
|
|
157
|
-
if (modelExists && !options.force) {
|
|
158
|
-
console.log("Middleware already exists!", "Use -f or --force to overwrite.\r");
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
const modelFolderExists = (0, fs_1.existsSync)(path_1.default.join(process.cwd(), "./src/middlewares"));
|
|
162
|
-
if (!modelFolderExists) {
|
|
163
|
-
await promises_1.default.mkdir(path_1.default.join(process.cwd(), "./src/middleware"), {
|
|
164
|
-
recursive: true,
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
const basicMiddleware = `
|
|
168
|
-
\t
|
|
169
|
-
import { Middleware, IMiddleware } from '@avleon/core';
|
|
170
|
-
|
|
171
|
-
@Middleware
|
|
172
|
-
export class ${modelName}Middleware implements IMiddleware{
|
|
173
|
-
|
|
174
|
-
invoke(req:IRequest){
|
|
175
|
-
// your logic goes here
|
|
176
|
-
return req;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
`;
|
|
181
|
-
const formatModel = await prettier.format(basicMiddleware, {
|
|
182
|
-
singleQuote: true,
|
|
183
|
-
singleAttributePerLine: true,
|
|
184
|
-
parser: "typescript",
|
|
185
|
-
});
|
|
186
|
-
await promises_1.default.writeFile(path_1.default.join(process.cwd(), "./src/middlewares/" + modelName.toLowerCase() + ".ts"), formatModel);
|
|
187
|
-
console.log("Middleware created succssessfully!");
|
|
188
|
-
}
|
|
189
|
-
async function createConfig(name, options = { force: false }) {
|
|
190
|
-
if (!name) {
|
|
191
|
-
throw new Error("Config name not found . use --name or node artisan make:config JwtConfig");
|
|
192
|
-
}
|
|
193
|
-
const modelName = name.at(0).toUpperCase() + name.slice(1);
|
|
194
|
-
const modelClassName = (0, lodash_1.capitalize)(modelName).endsWith('Config') ? (0, lodash_1.capitalize)(modelName) : (0, lodash_1.capitalize)(modelName) + "Config";
|
|
195
|
-
const modelExists = (0, fs_1.existsSync)(path_1.default.join(process.cwd(), `./src/config/${modelName.toLowerCase()}.ts`));
|
|
196
|
-
if (modelExists && !options.force) {
|
|
197
|
-
console.log("Config already exists!", "Use -f or --force to overwrite.\r");
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
const modelFolderExists = (0, fs_1.existsSync)(path_1.default.join(process.cwd(), "./src/config"));
|
|
201
|
-
if (!modelFolderExists) {
|
|
202
|
-
await promises_1.default.mkdir(path_1.default.join(process.cwd(), "./src/config"), {
|
|
203
|
-
recursive: true,
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
const basicMiddleware = `
|
|
207
|
-
\t
|
|
208
|
-
import { AppConfig, IConfig } from '@avleon/core';
|
|
209
|
-
|
|
210
|
-
@AppConfig
|
|
211
|
-
export class ${modelClassName} implements IConfig<T>{
|
|
212
|
-
|
|
213
|
-
config(env: Environment){
|
|
214
|
-
// config must return config
|
|
215
|
-
return {
|
|
216
|
-
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
`;
|
|
222
|
-
const formatModel = await prettier.format(basicMiddleware, {
|
|
223
|
-
singleQuote: true,
|
|
224
|
-
singleAttributePerLine: true,
|
|
225
|
-
parser: "typescript",
|
|
226
|
-
});
|
|
227
|
-
await promises_1.default.writeFile(path_1.default.join(process.cwd(), "./src/config/" + modelName.toLowerCase() + ".ts"), formatModel);
|
|
228
|
-
console.log("Config created succssessfully!");
|
|
229
|
-
}
|
|
230
|
-
async function run() {
|
|
231
|
-
try {
|
|
232
|
-
const args = process.argv.slice(2);
|
|
233
|
-
if (args[0] == "serve") {
|
|
234
|
-
require('./serve');
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
if (args.length < 1) {
|
|
238
|
-
await displayCommandList({ logo: true, all: false });
|
|
239
|
-
}
|
|
240
|
-
else {
|
|
241
|
-
const cmdList = commands_1.commandList
|
|
242
|
-
.flatMap((x) => x.Command)
|
|
243
|
-
.concat(...commands_1.commandList.flatMap((f) => f.Alias.split(",").map((s) => s.trim())));
|
|
244
|
-
if (!listedCommands.includes(args[0].trim())) {
|
|
245
|
-
console.error("Invalid command");
|
|
246
|
-
await displayCommandList({ logo: false, all: false });
|
|
247
|
-
}
|
|
248
|
-
else {
|
|
249
|
-
let force = false;
|
|
250
|
-
let minimal = false;
|
|
251
|
-
if (args.some((x) => x == "-f" || x == "--force")) {
|
|
252
|
-
force = true;
|
|
253
|
-
}
|
|
254
|
-
if (args.some((x) => x == "--mimimal")) {
|
|
255
|
-
minimal = true;
|
|
256
|
-
}
|
|
257
|
-
const flags = { minimal, force };
|
|
258
|
-
if (args[0] == "new") {
|
|
259
|
-
if (args[1] == undefined) {
|
|
260
|
-
throw new Error('Please provide a project name. Ex avleon new example_api');
|
|
261
|
-
}
|
|
262
|
-
const fname = args[1];
|
|
263
|
-
await (0, create_1.createApplication)(fname, flags);
|
|
264
|
-
}
|
|
265
|
-
if (args[0] == "build") {
|
|
266
|
-
process.env.NODE_ENV = "production";
|
|
267
|
-
//const appPath =
|
|
268
|
-
(0, child_process_1.execSync)("rm -r ./dist");
|
|
269
|
-
(0, child_process_1.execSync)("npx tsc --project tsconfig.build.json");
|
|
270
|
-
console.log("Build successfully");
|
|
271
|
-
}
|
|
272
|
-
if (args[0] == "make:model") {
|
|
273
|
-
const orm = args.some((x) => x == "--orm");
|
|
274
|
-
await createModel(args[1], { force, orm });
|
|
275
|
-
}
|
|
276
|
-
if (args[0] == "make:config" || args[0] == "m:cfg") {
|
|
277
|
-
await createConfig(args[1], { force });
|
|
278
|
-
}
|
|
279
|
-
if (args[0] == "make:middleware" || args[0] == "m:mdlr") {
|
|
280
|
-
await createMiddleware(args[1], { force });
|
|
281
|
-
}
|
|
282
|
-
if (args[0] == "make:controller" || args[0] == "m:c") {
|
|
283
|
-
let resource = false;
|
|
284
|
-
let rest = false;
|
|
285
|
-
let prefix = true;
|
|
286
|
-
let root = null;
|
|
287
|
-
if (args.some((x) => x == "-r" || x == "--resource")) {
|
|
288
|
-
resource = true;
|
|
289
|
-
}
|
|
290
|
-
if (args.some((x) => x == "-r" || x == "--rest")) {
|
|
291
|
-
rest = true;
|
|
292
|
-
}
|
|
293
|
-
if (args.some((x) => x == "--base-path")) {
|
|
294
|
-
prefix = false;
|
|
295
|
-
}
|
|
296
|
-
let model = null;
|
|
297
|
-
if (args.some((x) => x == "-m" || x == "--model")) {
|
|
298
|
-
const index = args.includes("-m")
|
|
299
|
-
? args.indexOf("-m")
|
|
300
|
-
: args.indexOf("--model");
|
|
301
|
-
if (args[index + 1] == undefined) {
|
|
302
|
-
throw new Error("Model not defined");
|
|
303
|
-
}
|
|
304
|
-
const modelName = args[index + 1];
|
|
305
|
-
model = modelName;
|
|
306
|
-
}
|
|
307
|
-
if (args.some((x) => x == "-rt" || x == "--root")) {
|
|
308
|
-
const index = args.includes("-rt")
|
|
309
|
-
? args.indexOf("-rt")
|
|
310
|
-
: args.indexOf("--root");
|
|
311
|
-
if (args[index + 1] == undefined) {
|
|
312
|
-
throw new Error("Root Path not defined");
|
|
313
|
-
}
|
|
314
|
-
const rootPath = args[index + 1];
|
|
315
|
-
root = rootPath;
|
|
316
|
-
}
|
|
317
|
-
await (0, controller_1.createController)(args[1], { force, resource, prefix, rest, model, root });
|
|
318
|
-
}
|
|
319
|
-
if (args[0] == "make:service" || args[0] == "m:s") {
|
|
320
|
-
let resource = false;
|
|
321
|
-
let rest = false;
|
|
322
|
-
let prefix = true;
|
|
323
|
-
let root = null;
|
|
324
|
-
if (args.some((x) => x == "-r" || x == "--resource" || x == '--rest')) {
|
|
325
|
-
resource = true;
|
|
326
|
-
rest = true;
|
|
327
|
-
}
|
|
328
|
-
let model = null;
|
|
329
|
-
if (args.some((x) => x == "-m" || x == "--model")) {
|
|
330
|
-
const index = args.includes("-m")
|
|
331
|
-
? args.indexOf("-m")
|
|
332
|
-
: args.indexOf("--model");
|
|
333
|
-
if (args[index + 1] == undefined) {
|
|
334
|
-
throw new Error("Model not defined");
|
|
335
|
-
}
|
|
336
|
-
const modelName = args[index + 1];
|
|
337
|
-
model = modelName;
|
|
338
|
-
}
|
|
339
|
-
if (args.some((x) => x == "-rt" || x == "--root")) {
|
|
340
|
-
const index = args.includes("-rt")
|
|
341
|
-
? args.indexOf("-rt")
|
|
342
|
-
: args.indexOf("--root");
|
|
343
|
-
if (args[index + 1] == undefined) {
|
|
344
|
-
throw new Error("Root Path not defined");
|
|
345
|
-
}
|
|
346
|
-
const rootPath = args[index + 1];
|
|
347
|
-
root = rootPath;
|
|
348
|
-
}
|
|
349
|
-
await (0, service_1.createService)(args[1], { force, resource, prefix, rest, model, root });
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
catch (error) {
|
|
355
|
-
console.log("CLI ERROR:", error);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
run();
|
package/dist/commands.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
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.commandList = void 0;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
exports.commandList = [
|
|
9
|
-
{
|
|
10
|
-
Command: "new",
|
|
11
|
-
Alias: "",
|
|
12
|
-
Options: "--minimal -m, -d --database",
|
|
13
|
-
Description: "Create a new application"
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
Command: "make:model",
|
|
17
|
-
Alias: "m:m",
|
|
18
|
-
Options: "-f --force, --orm",
|
|
19
|
-
Description: "Create a new model. Use -f or --froce to overwrite if any model exists with name",
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
Command: "make:controller",
|
|
23
|
-
Alias: "m:c",
|
|
24
|
-
Options: `-f, --force for force create\n -r or --resource for resource controller`,
|
|
25
|
-
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.
|
|
26
|
-
You may also pass model by -m or --model.\n
|
|
27
|
-
${chalk_1.default.blueBright("Note:")} when using a resource contorller iqra will automaticall check for dtos related to model name. If -m is user then
|
|
28
|
-
it will check for dtos like UserCreateDto and UserUpdateDto. If dtos not found it will create automatically using
|
|
29
|
-
model properties.
|
|
30
|
-
`,
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
Command: "make:service",
|
|
34
|
-
Alias: "m:s",
|
|
35
|
-
Options: `-f, --force for force create\n -r or --resource for resource controller, --dtos`,
|
|
36
|
-
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.
|
|
37
|
-
You may also pass model by -m or --model.\n
|
|
38
|
-
${chalk_1.default.blueBright("Note:")} when using a resource contorller iqra will automaticall check for dtos related to model name. If -m is user then
|
|
39
|
-
it will check for dtos like UserCreateDto and UserUpdateDto. If dtos not found it will create automatically using
|
|
40
|
-
model properties.
|
|
41
|
-
`,
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
Command: "make:config",
|
|
45
|
-
Alias: "m:cnf",
|
|
46
|
-
Options: "-f --force",
|
|
47
|
-
Description: "Create a new config. Use -f or --froce to overwrite if any config exists with name",
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
Command: "make:middleware",
|
|
51
|
-
Alias: "m:mlwr",
|
|
52
|
-
Options: "-f --force",
|
|
53
|
-
Description: "Create a new middleware. Use -f or --froce to overwrite if any config exists with name",
|
|
54
|
-
},
|
|
55
|
-
];
|
package/dist/controller.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
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.createController = createController;
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
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
|
-
const lodash_1 = require("lodash");
|
|
13
|
-
function capitalize(str) {
|
|
14
|
-
if (!str)
|
|
15
|
-
return '';
|
|
16
|
-
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
|
|
17
|
-
}
|
|
18
|
-
function lower(str) {
|
|
19
|
-
return str.toLowerCase();
|
|
20
|
-
}
|
|
21
|
-
function exportNamesAndPath(input) {
|
|
22
|
-
const parts = input.split('/');
|
|
23
|
-
const lastPart = parts.pop();
|
|
24
|
-
const filePath = parts.length ? parts.join('/') + '/' : '.';
|
|
25
|
-
// Normalize base name by removing trailing "Controller" (case-insensitive)
|
|
26
|
-
const rawName = lastPart.replace(/controller$/i, '');
|
|
27
|
-
// Create className in PascalCase + Controller
|
|
28
|
-
const className = (0, lodash_1.upperFirst)((0, lodash_1.camelCase)(rawName));
|
|
29
|
-
// Create fileName in kebab-case + .controller.ts
|
|
30
|
-
const fileName = `${(0, lodash_1.kebabCase)(rawName)}.controller.ts`;
|
|
31
|
-
return { className, fileName, filePath };
|
|
32
|
-
}
|
|
33
|
-
const controllersStubs = {
|
|
34
|
-
basic: path_helper_1.pathHelper.stubPath('controllers/basic-controller.stub'),
|
|
35
|
-
rest: path_helper_1.pathHelper.stubPath('controllers/basic-controller.stub'),
|
|
36
|
-
ormRest: path_helper_1.pathHelper.stubPath('controllers/orm-rest-controller.stub')
|
|
37
|
-
};
|
|
38
|
-
async function createController(name, options = { force: false, resource: false, prefix: true, rest: false, model: null, root: null }, p) {
|
|
39
|
-
if (!name) {
|
|
40
|
-
throw new Error("Controller name not found. use --name or npx avleon make:controller HomeController");
|
|
41
|
-
}
|
|
42
|
-
// determine stub for generate
|
|
43
|
-
let stubPath = controllersStubs.basic;
|
|
44
|
-
if (options.rest) {
|
|
45
|
-
stubPath = controllersStubs.rest;
|
|
46
|
-
if (options.model) {
|
|
47
|
-
stubPath = controllersStubs.ormRest;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
// determine root path for create controller file
|
|
51
|
-
const rootPath = options.root ? 'src/' + options.root + '/' : 'src/controllers/';
|
|
52
|
-
// ensure file create directory exits
|
|
53
|
-
if (name.split("/").length > 1) {
|
|
54
|
-
if (!(0, fs_1.existsSync)(path_1.default.join(rootPath, name.split("/").splice(-1, 1).join("/")))) {
|
|
55
|
-
await promises_1.default.mkdir(path_1.default.join(rootPath, name.replace('/' + file_helper_1.fh.filenameFromPath(name), '')), { recursive: true });
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
// read stub content from stub file
|
|
59
|
-
const content = await promises_1.default.readFile(stubPath, 'utf8');
|
|
60
|
-
const names = (0, file_helper_1.resolveNames)(file_helper_1.fh.filenameFromPath(name), 'Controller');
|
|
61
|
-
const className = names.className.replace("Controller", '');
|
|
62
|
-
if (options.model) {
|
|
63
|
-
await createRestService(className, options.model);
|
|
64
|
-
}
|
|
65
|
-
let replacedContent = content
|
|
66
|
-
.replaceAll('{Controller}', className)
|
|
67
|
-
.replaceAll('{controller}', names.varName);
|
|
68
|
-
if (options.model) {
|
|
69
|
-
replacedContent = replacedContent
|
|
70
|
-
.replaceAll('{Model}', capitalize(options.model))
|
|
71
|
-
.replaceAll('{model}', lower(options.model));
|
|
72
|
-
}
|
|
73
|
-
if (!options.prefix) {
|
|
74
|
-
replacedContent = replacedContent.replace(/@ApiController\s*\(([^)]*)\)/g, '@ApiController');
|
|
75
|
-
}
|
|
76
|
-
await promises_1.default.writeFile(path_1.default.join(rootPath, (0, file_helper_1.getFilePathWithoutName)(name) + "/" + (0, lodash_1.kebabCase)(className) + '.controller.ts'), replacedContent, 'utf8');
|
|
77
|
-
console.log("Controller created succssessfully!");
|
|
78
|
-
}
|
|
79
|
-
async function createRestService(name, model) {
|
|
80
|
-
let stubPath = path_helper_1.pathHelper.stubPath('services/rest-service.stub');
|
|
81
|
-
const content = await promises_1.default.readFile(stubPath, 'utf8');
|
|
82
|
-
const names = (0, file_helper_1.resolveNames)(file_helper_1.fh.filenameFromPath(name), 'Controller');
|
|
83
|
-
let replacedContent = content
|
|
84
|
-
.replaceAll('{Service}', name);
|
|
85
|
-
if (model) {
|
|
86
|
-
replacedContent = replacedContent
|
|
87
|
-
.replaceAll('{Model}', capitalize(model))
|
|
88
|
-
.replaceAll('{model}', lower(model));
|
|
89
|
-
}
|
|
90
|
-
await promises_1.default.writeFile(path_1.default.join('src/services/', (0, lodash_1.kebabCase)(name) + '.service.ts'), replacedContent, 'utf8');
|
|
91
|
-
console.log("Service created succssessfully!");
|
|
92
|
-
}
|