@skalfa/skalfa-api-core 1.0.2
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/.github/workflows/publish.yml +40 -0
- package/dist/auth/auth.d.ts +19 -0
- package/dist/auth/auth.js +227 -0
- package/dist/auth/auth.js.map +1 -0
- package/dist/auth/index.d.ts +1 -0
- package/dist/auth/index.js +2 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth.util.d.ts +19 -0
- package/dist/auth.util.js +183 -0
- package/dist/auth.util.js.map +1 -0
- package/dist/commands/cli.d.ts +1 -0
- package/dist/commands/cli.js +78 -0
- package/dist/commands/cli.js.map +1 -0
- package/dist/commands/make/basic-controller.d.ts +2 -0
- package/dist/commands/make/basic-controller.js +40 -0
- package/dist/commands/make/basic-controller.js.map +1 -0
- package/dist/commands/make/basic-migration.d.ts +5 -0
- package/dist/commands/make/basic-migration.js +60 -0
- package/dist/commands/make/basic-migration.js.map +1 -0
- package/dist/commands/make/basic-model.d.ts +2 -0
- package/dist/commands/make/basic-model.js +25 -0
- package/dist/commands/make/basic-model.js.map +1 -0
- package/dist/commands/make/basic-seeder.d.ts +3 -0
- package/dist/commands/make/basic-seeder.js +32 -0
- package/dist/commands/make/basic-seeder.js.map +1 -0
- package/dist/commands/make/blueprint.d.ts +2 -0
- package/dist/commands/make/blueprint.js +29 -0
- package/dist/commands/make/blueprint.js.map +1 -0
- package/dist/commands/make/da-migration.d.ts +5 -0
- package/dist/commands/make/da-migration.js +60 -0
- package/dist/commands/make/da-migration.js.map +1 -0
- package/dist/commands/make/light-controller.d.ts +3 -0
- package/dist/commands/make/light-controller.js +54 -0
- package/dist/commands/make/light-controller.js.map +1 -0
- package/dist/commands/make/light-model.d.ts +3 -0
- package/dist/commands/make/light-model.js +50 -0
- package/dist/commands/make/light-model.js.map +1 -0
- package/dist/commands/make/mail.d.ts +2 -0
- package/dist/commands/make/mail.js +41 -0
- package/dist/commands/make/mail.js.map +1 -0
- package/dist/commands/make/notification.d.ts +2 -0
- package/dist/commands/make/notification.js +33 -0
- package/dist/commands/make/notification.js.map +1 -0
- package/dist/commands/make/queue.d.ts +2 -0
- package/dist/commands/make/queue.js +35 -0
- package/dist/commands/make/queue.js.map +1 -0
- package/dist/commands/runner/barrels.d.ts +3 -0
- package/dist/commands/runner/barrels.js +78 -0
- package/dist/commands/runner/barrels.js.map +1 -0
- package/dist/commands/runner/blueprint/controller-generation.d.ts +1 -0
- package/dist/commands/runner/blueprint/controller-generation.js +147 -0
- package/dist/commands/runner/blueprint/controller-generation.js.map +1 -0
- package/dist/commands/runner/blueprint/documentation-generation.d.ts +6 -0
- package/dist/commands/runner/blueprint/documentation-generation.js +337 -0
- package/dist/commands/runner/blueprint/documentation-generation.js.map +1 -0
- package/dist/commands/runner/blueprint/migration-generation.d.ts +1 -0
- package/dist/commands/runner/blueprint/migration-generation.js +120 -0
- package/dist/commands/runner/blueprint/migration-generation.js.map +1 -0
- package/dist/commands/runner/blueprint/model-generation.d.ts +1 -0
- package/dist/commands/runner/blueprint/model-generation.js +122 -0
- package/dist/commands/runner/blueprint/model-generation.js.map +1 -0
- package/dist/commands/runner/blueprint/runner.d.ts +23 -0
- package/dist/commands/runner/blueprint/runner.js +139 -0
- package/dist/commands/runner/blueprint/runner.js.map +1 -0
- package/dist/commands/runner/blueprint/seeder-generation.d.ts +1 -0
- package/dist/commands/runner/blueprint/seeder-generation.js +40 -0
- package/dist/commands/runner/blueprint/seeder-generation.js.map +1 -0
- package/dist/commands/runner/da-migration.d.ts +39 -0
- package/dist/commands/runner/da-migration.js +262 -0
- package/dist/commands/runner/da-migration.js.map +1 -0
- package/dist/commands/runner/migration.d.ts +11 -0
- package/dist/commands/runner/migration.js +188 -0
- package/dist/commands/runner/migration.js.map +1 -0
- package/dist/commands/runner/seeder.d.ts +3 -0
- package/dist/commands/runner/seeder.js +40 -0
- package/dist/commands/runner/seeder.js.map +1 -0
- package/dist/commands/stubs/index.d.ts +14 -0
- package/dist/commands/stubs/index.js +277 -0
- package/dist/commands/stubs/index.js.map +1 -0
- package/dist/context/context.d.ts +7 -0
- package/dist/context/context.js +11 -0
- package/dist/context/context.js.map +1 -0
- package/dist/context/index.d.ts +1 -0
- package/dist/context/index.js +2 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context.util.d.ts +7 -0
- package/dist/context.util.js +11 -0
- package/dist/context.util.js.map +1 -0
- package/dist/controller/controller.d.ts +118 -0
- package/dist/controller/controller.js +147 -0
- package/dist/controller/controller.js.map +1 -0
- package/dist/controller/index.d.ts +1 -0
- package/dist/controller/index.js +2 -0
- package/dist/controller/index.js.map +1 -0
- package/dist/controller.util.d.ts +118 -0
- package/dist/controller.util.js +144 -0
- package/dist/controller.util.js.map +1 -0
- package/dist/conversion/conversion.d.ts +8 -0
- package/dist/conversion/conversion.js +52 -0
- package/dist/conversion/conversion.js.map +1 -0
- package/dist/conversion/index.d.ts +1 -0
- package/dist/conversion/index.js +2 -0
- package/dist/conversion/index.js.map +1 -0
- package/dist/conversion.util.d.ts +8 -0
- package/dist/conversion.util.js +52 -0
- package/dist/conversion.util.js.map +1 -0
- package/dist/db/db.d.ts +84 -0
- package/dist/db/db.js +177 -0
- package/dist/db/db.js.map +1 -0
- package/dist/db/index.d.ts +1 -0
- package/dist/db/index.js +2 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db.util.d.ts +84 -0
- package/dist/db.util.js +177 -0
- package/dist/db.util.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/logger/index.d.ts +1 -0
- package/dist/logger/index.js +2 -0
- package/dist/logger/index.js.map +1 -0
- package/dist/logger/logger.d.ts +30 -0
- package/dist/logger/logger.js +126 -0
- package/dist/logger/logger.js.map +1 -0
- package/dist/logger.util.d.ts +30 -0
- package/dist/logger.util.js +126 -0
- package/dist/logger.util.js.map +1 -0
- package/dist/mail/index.d.ts +1 -0
- package/dist/mail/index.js +2 -0
- package/dist/mail/index.js.map +1 -0
- package/dist/mail/mail.d.ts +21 -0
- package/dist/mail/mail.js +53 -0
- package/dist/mail/mail.js.map +1 -0
- package/dist/mail.util.d.ts +21 -0
- package/dist/mail.util.js +53 -0
- package/dist/mail.util.js.map +1 -0
- package/dist/middleware/index.d.ts +1 -0
- package/dist/middleware/index.js +2 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/middleware/middleware.d.ts +263 -0
- package/dist/middleware/middleware.js +233 -0
- package/dist/middleware/middleware.js.map +1 -0
- package/dist/middleware.util.d.ts +263 -0
- package/dist/middleware.util.js +233 -0
- package/dist/middleware.util.js.map +1 -0
- package/dist/model/index.d.ts +3 -0
- package/dist/model/index.js +4 -0
- package/dist/model/index.js.map +1 -0
- package/dist/model/model.d.ts +204 -0
- package/dist/model/model.js +1495 -0
- package/dist/model/model.js.map +1 -0
- package/dist/model.util.d.ts +204 -0
- package/dist/model.util.js +1495 -0
- package/dist/model.util.js.map +1 -0
- package/dist/permission/index.d.ts +1 -0
- package/dist/permission/index.js +2 -0
- package/dist/permission/index.js.map +1 -0
- package/dist/permission/permission.d.ts +38 -0
- package/dist/permission/permission.js +91 -0
- package/dist/permission/permission.js.map +1 -0
- package/dist/permission.util.d.ts +38 -0
- package/dist/permission.util.js +91 -0
- package/dist/permission.util.js.map +1 -0
- package/dist/registry/index.d.ts +1 -0
- package/dist/registry/index.js +2 -0
- package/dist/registry/index.js.map +1 -0
- package/dist/registry/registry.d.ts +28 -0
- package/dist/registry/registry.js +19 -0
- package/dist/registry/registry.js.map +1 -0
- package/dist/registry.util.d.ts +28 -0
- package/dist/registry.util.js +19 -0
- package/dist/registry.util.js.map +1 -0
- package/dist/route/index.d.ts +1 -0
- package/dist/route/index.js +2 -0
- package/dist/route/index.js.map +1 -0
- package/dist/route/route.d.ts +1 -0
- package/dist/route/route.js +12 -0
- package/dist/route/route.js.map +1 -0
- package/dist/route.util.d.ts +1 -0
- package/dist/route.util.js +12 -0
- package/dist/route.util.js.map +1 -0
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.js +2 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/storage.d.ts +56 -0
- package/dist/storage/storage.js +86 -0
- package/dist/storage/storage.js.map +1 -0
- package/dist/storage.util.d.ts +56 -0
- package/dist/storage.util.js +82 -0
- package/dist/storage.util.js.map +1 -0
- package/dist/validation/index.d.ts +1 -0
- package/dist/validation/index.js +2 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/validation.d.ts +7 -0
- package/dist/validation/validation.js +245 -0
- package/dist/validation/validation.js.map +1 -0
- package/dist/validation.util.d.ts +7 -0
- package/dist/validation.util.js +237 -0
- package/dist/validation.util.js.map +1 -0
- package/package.json +34 -0
- package/src/auth/auth.ts +282 -0
- package/src/auth/index.ts +1 -0
- package/src/commands/cli.ts +89 -0
- package/src/commands/make/basic-controller.ts +49 -0
- package/src/commands/make/basic-migration.ts +89 -0
- package/src/commands/make/basic-model.ts +32 -0
- package/src/commands/make/basic-seeder.ts +38 -0
- package/src/commands/make/blueprint.ts +36 -0
- package/src/commands/make/da-migration.ts +90 -0
- package/src/commands/make/light-controller.ts +67 -0
- package/src/commands/make/light-model.ts +61 -0
- package/src/commands/make/mail.ts +51 -0
- package/src/commands/make/notification.ts +43 -0
- package/src/commands/make/queue.ts +45 -0
- package/src/commands/runner/barrels.ts +85 -0
- package/src/commands/runner/blueprint/controller-generation.ts +194 -0
- package/src/commands/runner/blueprint/documentation-generation.ts +463 -0
- package/src/commands/runner/blueprint/migration-generation.ts +153 -0
- package/src/commands/runner/blueprint/model-generation.ts +149 -0
- package/src/commands/runner/blueprint/runner.ts +181 -0
- package/src/commands/runner/blueprint/seeder-generation.ts +55 -0
- package/src/commands/runner/da-migration.ts +333 -0
- package/src/commands/runner/migration.ts +245 -0
- package/src/commands/runner/seeder.ts +44 -0
- package/src/commands/stubs/index.ts +289 -0
- package/src/context/context.ts +17 -0
- package/src/context/index.ts +1 -0
- package/src/controller/controller.ts +240 -0
- package/src/controller/index.ts +1 -0
- package/src/conversion/conversion.ts +65 -0
- package/src/conversion/index.ts +1 -0
- package/src/index.ts +22 -0
- package/src/logger/index.ts +1 -0
- package/src/logger/logger.ts +177 -0
- package/src/mail/index.ts +1 -0
- package/src/mail/mail.ts +86 -0
- package/src/middleware/index.ts +1 -0
- package/src/middleware/middleware.ts +289 -0
- package/src/permission/index.ts +1 -0
- package/src/permission/permission.ts +136 -0
- package/src/registry/index.ts +1 -0
- package/src/registry/registry.ts +37 -0
- package/src/route/index.ts +1 -0
- package/src/route/route.ts +12 -0
- package/src/storage/index.ts +1 -0
- package/src/storage/storage.ts +107 -0
- package/src/validation/index.ts +1 -0
- package/src/validation/validation.ts +346 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { writeFileSync, mkdirSync, existsSync } from "fs";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import { conversion, logger } from "@utils";
|
|
5
|
+
import { basicControllerStub } from "../stubs";
|
|
6
|
+
|
|
7
|
+
// =====================================>
|
|
8
|
+
// ## Command: make:controller
|
|
9
|
+
// =====================================>
|
|
10
|
+
export const makeControllerCommand = new Command("make:controller")
|
|
11
|
+
.argument("<name>", "Name of controller")
|
|
12
|
+
.description("Create new controller")
|
|
13
|
+
.action((controllerName) => {
|
|
14
|
+
const basePath = path.join(process.cwd(), "src", "controllers");
|
|
15
|
+
|
|
16
|
+
if (!controllerName || controllerName.trim() === "") {
|
|
17
|
+
logger.error("Controller name invalid!");
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const names = controllerName.split("/");
|
|
22
|
+
const realName = names[names.length - 1];
|
|
23
|
+
const name = conversion.strPascal(realName) + "Controller";
|
|
24
|
+
const filename = conversion.strSlug(realName) + ".controller.ts";
|
|
25
|
+
|
|
26
|
+
names.pop();
|
|
27
|
+
const folder = names.join("/");
|
|
28
|
+
|
|
29
|
+
const filePath = folder ? path.join(basePath, folder, filename) : path.join(basePath, filename);
|
|
30
|
+
|
|
31
|
+
if (existsSync(filePath)) {
|
|
32
|
+
logger.error("Controller already exists!");
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const targetDir = folder ? path.join(basePath, folder) : basePath;
|
|
37
|
+
if (!existsSync(targetDir)) {
|
|
38
|
+
mkdirSync(targetDir, { recursive: true });
|
|
39
|
+
logger.info(`Create folder ${targetDir}...`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let content = basicControllerStub;
|
|
43
|
+
content = content.replace(/{{\s*name\s*}}/g, name || "");
|
|
44
|
+
|
|
45
|
+
writeFileSync(filePath, content);
|
|
46
|
+
|
|
47
|
+
logger.info(`Controller ${controllerName} created!`);
|
|
48
|
+
process.exit(0);
|
|
49
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { writeFileSync, mkdirSync, existsSync } from "fs";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import { conversion, logger } from "@utils";
|
|
5
|
+
import { basicMigrationStub } from "../stubs";
|
|
6
|
+
|
|
7
|
+
// =====================================>
|
|
8
|
+
// ## Command: make:migration
|
|
9
|
+
// =====================================>
|
|
10
|
+
export const makeMigrationCommand = new Command("make:migration")
|
|
11
|
+
.argument("<name>", "Nama migration")
|
|
12
|
+
.option("--init", "Buat migration init (0000_00)")
|
|
13
|
+
.description("Membuat file migration baru")
|
|
14
|
+
.action((name, options) => {
|
|
15
|
+
makeMigration(name, options);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// =====================================>
|
|
19
|
+
// ## Command: migration helpers
|
|
20
|
+
// =====================================>
|
|
21
|
+
export const makeMigration = (
|
|
22
|
+
migrationName: string,
|
|
23
|
+
options: { init?: boolean }
|
|
24
|
+
) => {
|
|
25
|
+
const name = conversion.strSnake(conversion.strPlural(migrationName));
|
|
26
|
+
|
|
27
|
+
const now = new Date();
|
|
28
|
+
|
|
29
|
+
const baseDir = path.join(
|
|
30
|
+
process.cwd(),
|
|
31
|
+
"src",
|
|
32
|
+
"database",
|
|
33
|
+
"migrations"
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
let targetDir: string;
|
|
37
|
+
let fileName: string;
|
|
38
|
+
|
|
39
|
+
if (options.init) {
|
|
40
|
+
targetDir = path.join(baseDir, "0000_00");
|
|
41
|
+
fileName = `${name}.ts`;
|
|
42
|
+
} else {
|
|
43
|
+
const yearMonth = `${now.getFullYear()}_${String(
|
|
44
|
+
now.getMonth() + 1
|
|
45
|
+
).padStart(2, "0")}`;
|
|
46
|
+
|
|
47
|
+
targetDir = path.join(baseDir, yearMonth);
|
|
48
|
+
|
|
49
|
+
const time = migrationPrefixFile(now);
|
|
50
|
+
fileName = `${time}_${name}_table.ts`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (!existsSync(targetDir)) {
|
|
54
|
+
mkdirSync(targetDir, { recursive: true });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const { className, tableName } = parseName(name);
|
|
58
|
+
|
|
59
|
+
let content = basicMigrationStub;
|
|
60
|
+
|
|
61
|
+
content = content.replace(/{{\s*className\s*}}/g, className);
|
|
62
|
+
content = content.replace(/{{\s*tableName\s*}}/g, tableName);
|
|
63
|
+
|
|
64
|
+
const filePath = path.join(targetDir, fileName);
|
|
65
|
+
|
|
66
|
+
writeFileSync(filePath, content);
|
|
67
|
+
|
|
68
|
+
logger.info(`Migration created: ${path.relative(baseDir, filePath)}`);
|
|
69
|
+
|
|
70
|
+
process.exit(0);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const migrationPrefixFile = (date: Date) => {
|
|
74
|
+
const d = String(date.getDate()).padStart(2, '0');
|
|
75
|
+
const h = String(date.getHours()).padStart(2, "0");
|
|
76
|
+
const m = String(date.getMinutes()).padStart(2, "0");
|
|
77
|
+
const s = String(date.getSeconds()).padStart(2, "0");
|
|
78
|
+
|
|
79
|
+
return `${d}_${h}${m}${s}`;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const parseName = (str: string) => {
|
|
83
|
+
const parts = str.split('_');
|
|
84
|
+
|
|
85
|
+
const className = parts.map(p => p.charAt(0).toUpperCase() + p.slice(1)).join('');
|
|
86
|
+
const tableName = parts.slice(1).join('_');
|
|
87
|
+
|
|
88
|
+
return { className, tableName };
|
|
89
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { writeFileSync, mkdirSync, existsSync } from "fs";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import { conversion, logger } from "@utils";
|
|
5
|
+
import { basicModelStub } from "../stubs";
|
|
6
|
+
|
|
7
|
+
// =====================================>
|
|
8
|
+
// ## Command: make:model
|
|
9
|
+
// =====================================>
|
|
10
|
+
export const makeModelCommand = new Command("make:model")
|
|
11
|
+
.argument("<name>", "Name of model")
|
|
12
|
+
.description("Membuat file model baru")
|
|
13
|
+
.action((modelName) => {
|
|
14
|
+
const name = conversion.strPascal(modelName);
|
|
15
|
+
const filename = conversion.strSlug(modelName) + ".model.ts";
|
|
16
|
+
|
|
17
|
+
const filePath = path.join(process.cwd(), "src", "models", filename);
|
|
18
|
+
|
|
19
|
+
if (!existsSync(path.dirname(filePath))) {
|
|
20
|
+
mkdirSync(path.dirname(filePath), { recursive: true });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let content = basicModelStub;
|
|
24
|
+
|
|
25
|
+
content = content.replace(/{{\s*name\s*}}/g, name || "");
|
|
26
|
+
|
|
27
|
+
writeFileSync(filePath, content);
|
|
28
|
+
|
|
29
|
+
logger.info(`Model ${modelName} created!`);
|
|
30
|
+
|
|
31
|
+
process.exit(0);
|
|
32
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { writeFileSync, mkdirSync, existsSync } from "fs";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import { conversion, logger } from "@utils";
|
|
5
|
+
import { basicSeederStub } from "../stubs";
|
|
6
|
+
|
|
7
|
+
// =====================================>
|
|
8
|
+
// ## Command: make:seeder
|
|
9
|
+
// =====================================>
|
|
10
|
+
export const makeSeederCommand = new Command("make:seeder")
|
|
11
|
+
.argument("<name>", "Name of seeder")
|
|
12
|
+
.option("-m, --model <model>", "Attach model to controller")
|
|
13
|
+
.description("Buat seeder baru")
|
|
14
|
+
.action((name, options) => {
|
|
15
|
+
makeSeeder(name, options.model);
|
|
16
|
+
process.exit(0);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export const makeSeeder = (seederName: string, model?: string) => {
|
|
20
|
+
const name = conversion.strPascal(seederName) + "Seeder";
|
|
21
|
+
const filename = conversion.strSlug(seederName) + ".seeder.ts";
|
|
22
|
+
const modelName = model || conversion.strPascal(seederName);
|
|
23
|
+
|
|
24
|
+
const dir = path.join(process.cwd(), "src", "database", "seeders");
|
|
25
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
26
|
+
|
|
27
|
+
const filePath = path.join(dir, filename);
|
|
28
|
+
|
|
29
|
+
let content = basicSeederStub;
|
|
30
|
+
|
|
31
|
+
content = content
|
|
32
|
+
.replace(/{{\s*name\s*}}/g, name || "")
|
|
33
|
+
.replace(/{{\s*model\s*}}/g, modelName || "");
|
|
34
|
+
|
|
35
|
+
writeFileSync(filePath, content, { flag: "w" });
|
|
36
|
+
|
|
37
|
+
logger.info(`Seeder ${name} created`);
|
|
38
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { writeFileSync, existsSync } from "fs";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import { conversion, logger } from "@utils";
|
|
5
|
+
import { blueprintStub } from "../stubs";
|
|
6
|
+
|
|
7
|
+
// =====================================>
|
|
8
|
+
// ## Command: make:blueprint
|
|
9
|
+
// =====================================>
|
|
10
|
+
export const makeBlueprintCommand = new Command("make:blueprint")
|
|
11
|
+
.argument("<name>", "Name of blueprint")
|
|
12
|
+
.description("Create new blueprint")
|
|
13
|
+
.action((name) => {
|
|
14
|
+
const basePath = path.join(process.cwd(), "src", "blueprints");
|
|
15
|
+
|
|
16
|
+
if (!name || name.trim() === "") {
|
|
17
|
+
logger.error("Blueprint name invalid!");
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const filename = conversion.strSlug(name) + ".blueprint.json";
|
|
22
|
+
|
|
23
|
+
const filePath = path.join(basePath, filename);
|
|
24
|
+
|
|
25
|
+
if (existsSync(filePath)) {
|
|
26
|
+
logger.error("Blueprint already exists!");
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const content = blueprintStub;
|
|
31
|
+
|
|
32
|
+
writeFileSync(filePath, content);
|
|
33
|
+
|
|
34
|
+
logger.info(`Blueprint ${filename} created!`);
|
|
35
|
+
process.exit(0);
|
|
36
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { writeFileSync, mkdirSync, existsSync } from "fs";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import { logger } from "@utils";
|
|
5
|
+
import { daMigrationStub } from "../stubs";
|
|
6
|
+
|
|
7
|
+
// =====================================>
|
|
8
|
+
// ## Command: make:da:migration
|
|
9
|
+
// =====================================>
|
|
10
|
+
export const makeDaMigrationCommand = new Command("make:da:migration")
|
|
11
|
+
.argument("<name>", "Nama migration")
|
|
12
|
+
.option("--init", "Buat migration init (0000_00)")
|
|
13
|
+
.description("Membuat file migration baru")
|
|
14
|
+
.action((name, options) => {
|
|
15
|
+
makeDaMigration(name, options);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export const makeDaMigration = (
|
|
19
|
+
migrationName: string,
|
|
20
|
+
options: { init?: boolean }
|
|
21
|
+
) => {
|
|
22
|
+
const name = migrationName.toLowerCase();
|
|
23
|
+
const now = new Date();
|
|
24
|
+
|
|
25
|
+
const baseDir = path.join(
|
|
26
|
+
process.cwd(),
|
|
27
|
+
"src",
|
|
28
|
+
"database",
|
|
29
|
+
"da.migrations"
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
let targetDir: string;
|
|
33
|
+
let fileName: string;
|
|
34
|
+
|
|
35
|
+
if (options.init) {
|
|
36
|
+
targetDir = path.join(baseDir, "0000_00");
|
|
37
|
+
fileName = `${name}.ts`;
|
|
38
|
+
} else {
|
|
39
|
+
const yearMonth = `${now.getFullYear()}_${String(
|
|
40
|
+
now.getMonth() + 1
|
|
41
|
+
).padStart(2, "0")}`;
|
|
42
|
+
|
|
43
|
+
targetDir = path.join(baseDir, yearMonth);
|
|
44
|
+
|
|
45
|
+
const time = migrationPrefixFile(now);
|
|
46
|
+
fileName = `${time}_${name}_table.ts`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (!existsSync(targetDir)) {
|
|
50
|
+
mkdirSync(targetDir, { recursive: true });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const { className, tableName } = parseName(name);
|
|
54
|
+
|
|
55
|
+
let content = daMigrationStub;
|
|
56
|
+
|
|
57
|
+
content = content.replace(/{{\s*className\s*}}/g, className);
|
|
58
|
+
content = content.replace(/{{\s*tableName\s*}}/g, tableName);
|
|
59
|
+
|
|
60
|
+
const filePath = path.join(targetDir, fileName);
|
|
61
|
+
|
|
62
|
+
writeFileSync(filePath, content);
|
|
63
|
+
|
|
64
|
+
logger.info(
|
|
65
|
+
`DA Migration created: ${path.relative(baseDir, filePath)}`
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
process.exit(0);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// =====================================>
|
|
72
|
+
// ## Command: migration helpers
|
|
73
|
+
// =====================================>
|
|
74
|
+
const migrationPrefixFile = (date: Date) => {
|
|
75
|
+
const d = String(date.getDate()).padStart(2, '0');
|
|
76
|
+
const h = String(date.getHours()).padStart(2, "0");
|
|
77
|
+
const m = String(date.getMinutes()).padStart(2, "0");
|
|
78
|
+
const s = String(date.getSeconds()).padStart(2, "0");
|
|
79
|
+
|
|
80
|
+
return `${d}_${h}${m}${s}`;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const parseName = (str: string) => {
|
|
84
|
+
const parts = str.split('_');
|
|
85
|
+
|
|
86
|
+
const className = parts.map(p => p.charAt(0).toUpperCase() + p.slice(1)).join('');
|
|
87
|
+
const tableName = parts.slice(1).join('_');
|
|
88
|
+
|
|
89
|
+
return { className, tableName };
|
|
90
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { writeFileSync, mkdirSync, existsSync } from "fs";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import { conversion, logger } from "@utils";
|
|
5
|
+
import { lightControllerStub } from "../stubs";
|
|
6
|
+
|
|
7
|
+
// =====================================>
|
|
8
|
+
// ## Command: make:light-controller
|
|
9
|
+
// =====================================>
|
|
10
|
+
export const makeLightControllerCommand = new Command("make:light-controller")
|
|
11
|
+
.argument("<name>", "Name of controller")
|
|
12
|
+
.option("-m, --model <model>", "Attach model to controller")
|
|
13
|
+
.description("Make the Light Controller")
|
|
14
|
+
.action((name, options) => {
|
|
15
|
+
makeLightController(name, options.model);
|
|
16
|
+
process.exit(0);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export const makeLightController = (controllerName: string, modelName?: string) => {
|
|
20
|
+
const basePath = path.join(process.cwd(), "src", "controllers");
|
|
21
|
+
|
|
22
|
+
if (!controllerName || controllerName.trim() === "") {
|
|
23
|
+
logger.error("Controller name invalid!");
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const names = controllerName.split("/");
|
|
28
|
+
const realName = names[names.length - 1];
|
|
29
|
+
const name = conversion.strPascal(realName) + "Controller";
|
|
30
|
+
const filename = conversion.strSlug(realName) + ".controller.ts";
|
|
31
|
+
const model = modelName || conversion.strPascal(realName);
|
|
32
|
+
|
|
33
|
+
names.pop();
|
|
34
|
+
const folder = names.join("/");
|
|
35
|
+
|
|
36
|
+
const filePath = path.join(basePath, filename);
|
|
37
|
+
|
|
38
|
+
if (existsSync(filePath)) {
|
|
39
|
+
logger.error("Controller already exists!");
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const targetDir = folder ? path.join(basePath, folder) : basePath;
|
|
44
|
+
if (!existsSync(targetDir)) {
|
|
45
|
+
mkdirSync(targetDir, { recursive: true });
|
|
46
|
+
logger.info(`Create folder ${targetDir}...`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let stub = lightControllerStub;
|
|
50
|
+
|
|
51
|
+
stub = stub.replace(
|
|
52
|
+
/{{\s*name\s*}}|{{\s*model\s*}}|{{\s*validations\s*}}|{{\s*marker\s*}}/g,
|
|
53
|
+
(match) => {
|
|
54
|
+
switch (match) {
|
|
55
|
+
case "{{ name }}":
|
|
56
|
+
return name;
|
|
57
|
+
case "{{ model }}":
|
|
58
|
+
return model;
|
|
59
|
+
default:
|
|
60
|
+
return "";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
writeFileSync(filePath, stub);
|
|
66
|
+
logger.info(`Successfully create light controller: ${filePath}!`);
|
|
67
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { writeFileSync, mkdirSync, existsSync } from "fs";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import { conversion, logger } from "@utils";
|
|
5
|
+
import { makeLightController } from "./light-controller";
|
|
6
|
+
import { makeMigration } from "./basic-migration";
|
|
7
|
+
import { makeSeeder } from "./basic-seeder";
|
|
8
|
+
import { lightModelStub } from "../stubs";
|
|
9
|
+
|
|
10
|
+
// =====================================>
|
|
11
|
+
// ## Command: make:light-model
|
|
12
|
+
// =====================================>
|
|
13
|
+
export const makeLightModelCommand = new Command("make:light-model")
|
|
14
|
+
.argument("<name>", "Name of model")
|
|
15
|
+
.option("-r", "Generate all resource (controller, migration, seeder)")
|
|
16
|
+
.description("Make the Light Model")
|
|
17
|
+
.action((name, options) => {
|
|
18
|
+
makeLightModel(name);
|
|
19
|
+
|
|
20
|
+
if (options.r) {
|
|
21
|
+
makeLightController(name);
|
|
22
|
+
makeMigration("create_" + name, { init: true });
|
|
23
|
+
makeSeeder(name);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
process.exit(0);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export const makeLightModel = (modelName: string) => {
|
|
30
|
+
const name = conversion.strPascal(modelName);
|
|
31
|
+
const filename = conversion.strSlug(modelName) + ".model.ts";
|
|
32
|
+
|
|
33
|
+
const basePath = path.join(process.cwd(), "src", "models");
|
|
34
|
+
|
|
35
|
+
if (!existsSync(basePath)) {
|
|
36
|
+
mkdirSync(basePath, { recursive: true });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const filePath = path.join(basePath, filename);
|
|
40
|
+
|
|
41
|
+
if (existsSync(filePath)) {
|
|
42
|
+
logger.error(`Model ${name} already exists!`);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let stub = lightModelStub;
|
|
47
|
+
|
|
48
|
+
stub = stub
|
|
49
|
+
.replace(/{{\s*name\s*}}/g, name)
|
|
50
|
+
.replace(/{{\s*fields\s*}}/g, "")
|
|
51
|
+
.replace(/{{\s*attributes\s*}}/g, "")
|
|
52
|
+
.replace(/{{\s*relations\s*}}/g, "")
|
|
53
|
+
.replace(/{{\s*hooks\s*}}/g, "")
|
|
54
|
+
.replace(/{{\s*import\s*}}/g, "")
|
|
55
|
+
.replace(/{{\s*import_utils\s*}}/g, "")
|
|
56
|
+
.replace(/{{\s*marker\s*}}/g, "");
|
|
57
|
+
|
|
58
|
+
writeFileSync(filePath, stub);
|
|
59
|
+
|
|
60
|
+
logger.info(`Successfully create light model ${name}!`);
|
|
61
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { writeFileSync, existsSync, mkdirSync } from "fs";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import { conversion, logger } from "@utils";
|
|
5
|
+
import { mailStub } from "../stubs";
|
|
6
|
+
|
|
7
|
+
// =====================================>
|
|
8
|
+
// ## Command: make:mail
|
|
9
|
+
// =====================================>
|
|
10
|
+
export const makeMailCommand = new Command("make:mail")
|
|
11
|
+
.argument("<name>", "Name of mail")
|
|
12
|
+
.description("Create new mail")
|
|
13
|
+
.action((name) => {
|
|
14
|
+
const basePath = path.join(process.cwd(), "src", "outputs", "mails");
|
|
15
|
+
const templatePath = path.join(process.cwd(), "src", "outputs", "mails", "templates");
|
|
16
|
+
|
|
17
|
+
if (!name || name.trim() === "") {
|
|
18
|
+
logger.error("Mail name invalid!");
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const filename = conversion.strSlug(name) + ".mail.ts";
|
|
23
|
+
const templateName = conversion.strSlug(name) + ".mail.stub";
|
|
24
|
+
|
|
25
|
+
const filePath = path.join(basePath, filename);
|
|
26
|
+
|
|
27
|
+
if (existsSync(filePath)) {
|
|
28
|
+
logger.error("Mail already exists!");
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!existsSync(basePath)) {
|
|
33
|
+
mkdirSync(basePath, { recursive: true });
|
|
34
|
+
}
|
|
35
|
+
if (!existsSync(templatePath)) {
|
|
36
|
+
mkdirSync(templatePath, { recursive: true });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let content = mailStub;
|
|
40
|
+
|
|
41
|
+
content = content
|
|
42
|
+
.replace(/{{\s*name\s*}}/g, conversion.strCamel(name) || "")
|
|
43
|
+
.replace(/{{\s*title\s*}}/g, conversion.strPascal(name, " ") || "");
|
|
44
|
+
|
|
45
|
+
writeFileSync(filePath, content);
|
|
46
|
+
writeFileSync(path.join(templatePath, templateName), "");
|
|
47
|
+
|
|
48
|
+
logger.info(`Mail ${filename} created!`);
|
|
49
|
+
|
|
50
|
+
process.exit(0);
|
|
51
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { writeFileSync, existsSync, mkdirSync } from "fs";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import { conversion, logger } from "@utils";
|
|
5
|
+
import { notificationStub } from "../stubs";
|
|
6
|
+
|
|
7
|
+
// =====================================>
|
|
8
|
+
// ## Command: make:notification
|
|
9
|
+
// =====================================>
|
|
10
|
+
export const makeNotificationCommand = new Command("make:notification")
|
|
11
|
+
.argument("<name>", "Name of notification")
|
|
12
|
+
.description("Create new notification")
|
|
13
|
+
.action((name) => {
|
|
14
|
+
const basePath = path.join(process.cwd(), "src", "outputs", "notifications");
|
|
15
|
+
|
|
16
|
+
if (!name || name.trim() === "") {
|
|
17
|
+
logger.error("Notification name invalid!");
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const filename = conversion.strSlug(name) + ".notification.ts";
|
|
22
|
+
|
|
23
|
+
const filePath = path.join(basePath, filename);
|
|
24
|
+
|
|
25
|
+
if (existsSync(filePath)) {
|
|
26
|
+
logger.error("Notification already exists!");
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!existsSync(basePath)) {
|
|
31
|
+
mkdirSync(basePath, { recursive: true });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let content = notificationStub;
|
|
35
|
+
|
|
36
|
+
content = content.replace(/{{\s*name\s*}}/g, conversion.strCamel(name) || "");
|
|
37
|
+
|
|
38
|
+
writeFileSync(filePath, content);
|
|
39
|
+
|
|
40
|
+
logger.info(`Notification ${filename} created!`);
|
|
41
|
+
|
|
42
|
+
process.exit(0);
|
|
43
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { writeFileSync, existsSync, mkdirSync } from "fs";
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import { conversion, logger } from "@utils";
|
|
5
|
+
import { queueStub } from "../stubs";
|
|
6
|
+
|
|
7
|
+
// =====================================>
|
|
8
|
+
// ## Command: make:queue
|
|
9
|
+
// =====================================>
|
|
10
|
+
export const makeQueueCommand = new Command("make:queue")
|
|
11
|
+
.argument("<name>", "Name of queue")
|
|
12
|
+
.description("Create new queue")
|
|
13
|
+
.action((name) => {
|
|
14
|
+
const basePath = path.join(process.cwd(), "src", "jobs", "queues");
|
|
15
|
+
|
|
16
|
+
if (!name || name.trim() === "") {
|
|
17
|
+
logger.error("Queue name invalid!");
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const filename = conversion.strSlug(name) + ".queue.worker.ts";
|
|
22
|
+
|
|
23
|
+
const filePath = path.join(basePath, filename);
|
|
24
|
+
|
|
25
|
+
if (existsSync(filePath)) {
|
|
26
|
+
logger.error("Queue already exists!");
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!existsSync(basePath)) {
|
|
31
|
+
mkdirSync(basePath, { recursive: true });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let content = queueStub;
|
|
35
|
+
|
|
36
|
+
content = content
|
|
37
|
+
.replace(/{{\s*name\s*}}/g, conversion.strCamel(name) || "")
|
|
38
|
+
.replace(/{{\s*worker_name\s*}}/g, conversion.strSlug(name, " ") || "");
|
|
39
|
+
|
|
40
|
+
writeFileSync(filePath, content);
|
|
41
|
+
|
|
42
|
+
logger.info(`Queue ${filename} created!`);
|
|
43
|
+
|
|
44
|
+
process.exit(0);
|
|
45
|
+
});
|