@anu8151/adonisjs-blueprint 0.2.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.md +9 -0
- package/README.md +131 -0
- package/build/configure.d.ts +2 -0
- package/build/configure.js +7 -0
- package/build/index.d.ts +16 -0
- package/build/index.js +9 -0
- package/build/init-TjAcOVVP.js +64 -0
- package/build/main-1fZp_M_R.js +8 -0
- package/build/parser-DJB5DEck.js +5832 -0
- package/build/src/commands/build.d.ts +14 -0
- package/build/src/commands/build.js +177 -0
- package/build/src/commands/erase.d.ts +6 -0
- package/build/src/commands/erase.js +23 -0
- package/build/src/commands/init.d.ts +6 -0
- package/build/src/commands/main.d.ts +1 -0
- package/build/src/commands/main.js +10 -0
- package/build/src/commands/stubs.d.ts +6 -0
- package/build/src/commands/stubs.js +16 -0
- package/build/src/commands/trace.d.ts +6 -0
- package/build/src/commands/trace.js +60 -0
- package/build/src/generators/base_generator.d.ts +12 -0
- package/build/src/generators/base_generator.js +31 -0
- package/build/src/generators/channel_generator.d.ts +4 -0
- package/build/src/generators/channel_generator.js +25 -0
- package/build/src/generators/class_generator.d.ts +4 -0
- package/build/src/generators/class_generator.js +11 -0
- package/build/src/generators/controller_generator.d.ts +5 -0
- package/build/src/generators/controller_generator.js +355 -0
- package/build/src/generators/enum_generator.d.ts +4 -0
- package/build/src/generators/enum_generator.js +17 -0
- package/build/src/generators/event_generator.d.ts +4 -0
- package/build/src/generators/event_generator.js +10 -0
- package/build/src/generators/factory_generator.d.ts +4 -0
- package/build/src/generators/factory_generator.js +50 -0
- package/build/src/generators/job_generator.d.ts +4 -0
- package/build/src/generators/job_generator.js +10 -0
- package/build/src/generators/mail_generator.d.ts +4 -0
- package/build/src/generators/mail_generator.js +10 -0
- package/build/src/generators/middleware_generator.d.ts +4 -0
- package/build/src/generators/middleware_generator.js +10 -0
- package/build/src/generators/migration_generator.d.ts +5 -0
- package/build/src/generators/migration_generator.js +46 -0
- package/build/src/generators/model_generator.d.ts +4 -0
- package/build/src/generators/model_generator.js +57 -0
- package/build/src/generators/notification_generator.d.ts +4 -0
- package/build/src/generators/notification_generator.js +10 -0
- package/build/src/generators/openapi_generator.d.ts +8 -0
- package/build/src/generators/openapi_generator.js +200 -0
- package/build/src/generators/policy_generator.d.ts +4 -0
- package/build/src/generators/policy_generator.js +29 -0
- package/build/src/generators/route_generator.d.ts +4 -0
- package/build/src/generators/route_generator.js +34 -0
- package/build/src/generators/seeder_generator.d.ts +4 -0
- package/build/src/generators/seeder_generator.js +16 -0
- package/build/src/generators/service_generator.d.ts +4 -0
- package/build/src/generators/service_generator.js +14 -0
- package/build/src/generators/test_generator.d.ts +5 -0
- package/build/src/generators/test_generator.js +38 -0
- package/build/src/generators/validator_generator.d.ts +4 -0
- package/build/src/generators/validator_generator.js +70 -0
- package/build/src/generators/view_generator.d.ts +4 -0
- package/build/src/generators/view_generator.js +23 -0
- package/build/src/parser.d.ts +7 -0
- package/build/src/parser.js +2 -0
- package/build/src/statements/index.d.ts +1 -0
- package/build/src/statements_registry.d.ts +47 -0
- package/build/src/types.d.ts +50 -0
- package/build/statements_registry-DzyxAiKP.js +19 -0
- package/build/stubs/config.stub +32 -0
- package/build/stubs/main.d.ts +5 -0
- package/build/stubs/make/controller/main.stub +47 -0
- package/build/stubs/make/enum/main.stub +10 -0
- package/build/stubs/make/event/main.stub +12 -0
- package/build/stubs/make/factory/main.stub +25 -0
- package/build/stubs/make/job/main.stub +12 -0
- package/build/stubs/make/mail/main.stub +23 -0
- package/build/stubs/make/middleware/main.stub +16 -0
- package/build/stubs/make/migration/main.stub +25 -0
- package/build/stubs/make/model/main.stub +19 -0
- package/build/stubs/make/notification/main.stub +28 -0
- package/build/stubs/make/policy/main.stub +17 -0
- package/build/stubs/make/seeder/main.stub +21 -0
- package/build/stubs/make/service/main.stub +8 -0
- package/build/stubs/make/test/controller.stub +23 -0
- package/build/stubs/make/validator/main.stub +22 -0
- package/build/stubs/make/view/edge.stub +65 -0
- package/build/stubs/make/view/react.stub +57 -0
- package/build/stubs/make/view/svelte.stub +67 -0
- package/build/stubs/make/view/vue.stub +74 -0
- package/package.json +151 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseCommand } from '@adonisjs/core/ace';
|
|
2
|
+
export declare class BuildBlueprint extends BaseCommand {
|
|
3
|
+
static commandName: string;
|
|
4
|
+
static description: string;
|
|
5
|
+
draftFile: string;
|
|
6
|
+
erase: boolean;
|
|
7
|
+
watch: boolean;
|
|
8
|
+
force: boolean;
|
|
9
|
+
private manifest;
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
private eraseExisting;
|
|
12
|
+
private build;
|
|
13
|
+
}
|
|
14
|
+
export default BuildBlueprint;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { t as BlueprintParser } from "../../parser-DJB5DEck.js";
|
|
2
|
+
import { ModelGenerator } from "../generators/model_generator.js";
|
|
3
|
+
import { MigrationGenerator } from "../generators/migration_generator.js";
|
|
4
|
+
import { ControllerGenerator } from "../generators/controller_generator.js";
|
|
5
|
+
import { ValidatorGenerator } from "../generators/validator_generator.js";
|
|
6
|
+
import { FactoryGenerator } from "../generators/factory_generator.js";
|
|
7
|
+
import { RouteGenerator } from "../generators/route_generator.js";
|
|
8
|
+
import { TestGenerator } from "../generators/test_generator.js";
|
|
9
|
+
import { ViewGenerator } from "../generators/view_generator.js";
|
|
10
|
+
import { SeederGenerator } from "../generators/seeder_generator.js";
|
|
11
|
+
import { PolicyGenerator } from "../generators/policy_generator.js";
|
|
12
|
+
import { EnumGenerator } from "../generators/enum_generator.js";
|
|
13
|
+
import { MiddlewareGenerator } from "../generators/middleware_generator.js";
|
|
14
|
+
import { OpenAPIGenerator } from "../generators/openapi_generator.js";
|
|
15
|
+
import { ChannelGenerator } from "../generators/channel_generator.js";
|
|
16
|
+
import { existsSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
|
|
17
|
+
import { BaseCommand, args, flags } from "@adonisjs/core/ace";
|
|
18
|
+
import string from "@adonisjs/core/helpers/string";
|
|
19
|
+
//#region \0@oxc-project+runtime@0.122.0/helpers/decorate.js
|
|
20
|
+
function __decorate(decorators, target, key, desc) {
|
|
21
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
22
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
23
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
24
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/commands/build.ts
|
|
28
|
+
var BuildBlueprint = class extends BaseCommand {
|
|
29
|
+
static commandName = "blueprint:build";
|
|
30
|
+
static description = "Build the application from the draft.yaml file";
|
|
31
|
+
manifest = [];
|
|
32
|
+
async run() {
|
|
33
|
+
if (this.watch) {
|
|
34
|
+
this.logger.info(`Watching for changes in ${this.draftFile}...`);
|
|
35
|
+
const { watch } = await import("node:fs");
|
|
36
|
+
await this.build();
|
|
37
|
+
watch(this.app.makePath(this.draftFile)).on("change", async () => {
|
|
38
|
+
this.logger.info("Changes detected, rebuilding...");
|
|
39
|
+
await this.build();
|
|
40
|
+
});
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
await this.build();
|
|
44
|
+
}
|
|
45
|
+
async eraseExisting() {
|
|
46
|
+
const manifestPath = this.app.makePath(".blueprint_manifest.json");
|
|
47
|
+
if (existsSync(manifestPath)) {
|
|
48
|
+
this.logger.info("Erasing existing generated files...");
|
|
49
|
+
const files = JSON.parse(readFileSync(manifestPath, "utf8")).files || [];
|
|
50
|
+
for (const file of files) if (existsSync(file)) {
|
|
51
|
+
unlinkSync(file);
|
|
52
|
+
this.logger.action(`deleted ${file}`).succeeded();
|
|
53
|
+
}
|
|
54
|
+
unlinkSync(manifestPath);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async build() {
|
|
58
|
+
if (this.erase) await this.eraseExisting();
|
|
59
|
+
this.logger.info("Building application from " + this.draftFile);
|
|
60
|
+
const blueprint = await new BlueprintParser().parse(this.draftFile);
|
|
61
|
+
this.manifest = [];
|
|
62
|
+
if (blueprint.auth) {
|
|
63
|
+
this.logger.info("Auth shorthand detected. Injecting AuthController...");
|
|
64
|
+
if (!blueprint.controllers) blueprint.controllers = {};
|
|
65
|
+
if (!blueprint.controllers["Auth"]) blueprint.controllers["Auth"] = {
|
|
66
|
+
login: { render: "auth/login" },
|
|
67
|
+
register: { render: "auth/register" },
|
|
68
|
+
store: {
|
|
69
|
+
validate: "email, password",
|
|
70
|
+
auth: "true",
|
|
71
|
+
redirect: "dashboard"
|
|
72
|
+
},
|
|
73
|
+
logout: {
|
|
74
|
+
auth: "logout",
|
|
75
|
+
redirect: "login"
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
if (!blueprint.models) blueprint.models = {};
|
|
79
|
+
if (!blueprint.models["User"]) blueprint.models["User"] = { attributes: {
|
|
80
|
+
email: "string:unique",
|
|
81
|
+
password: "string",
|
|
82
|
+
full_name: "string:optional"
|
|
83
|
+
} };
|
|
84
|
+
}
|
|
85
|
+
const forceOverwrite = this.force || this.erase;
|
|
86
|
+
if (blueprint.models) {
|
|
87
|
+
const modelGenerator = new ModelGenerator(this.app, this.logger, this.manifest, void 0, forceOverwrite);
|
|
88
|
+
const migrationGenerator = new MigrationGenerator(this.app, this.logger, this.manifest, void 0, forceOverwrite);
|
|
89
|
+
const validatorGenerator = new ValidatorGenerator(this.app, this.logger, this.manifest, void 0, forceOverwrite);
|
|
90
|
+
const factoryGenerator = new FactoryGenerator(this.app, this.logger, this.manifest, void 0, forceOverwrite);
|
|
91
|
+
const seederGenerator = new SeederGenerator(this.app, this.logger, this.manifest, void 0, forceOverwrite);
|
|
92
|
+
const enumGenerator = new EnumGenerator(this.app, this.logger, this.manifest, void 0, forceOverwrite);
|
|
93
|
+
for (const [name, definition] of Object.entries(blueprint.models)) {
|
|
94
|
+
this.logger.info(`Generating model, migration, validator, factory and seeder for ${name}`);
|
|
95
|
+
await modelGenerator.generate(name, definition);
|
|
96
|
+
await migrationGenerator.generate(name, definition);
|
|
97
|
+
await validatorGenerator.generate(name, definition);
|
|
98
|
+
await factoryGenerator.generate(name, definition);
|
|
99
|
+
await seederGenerator.generate(name, definition);
|
|
100
|
+
if (definition.attributes) {
|
|
101
|
+
for (const [attrName, attrType] of Object.entries(definition.attributes)) if (typeof attrType === "string" && attrType.startsWith("enum:")) {
|
|
102
|
+
const enumName = string.pascalCase(name + "_" + attrName);
|
|
103
|
+
const values = attrType.split(":")[1].split(",").map((v) => v.trim());
|
|
104
|
+
this.logger.info(`Generating enum ${enumName}`);
|
|
105
|
+
await enumGenerator.generate(enumName, { values });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (blueprint.controllers) {
|
|
111
|
+
const controllerGenerator = new ControllerGenerator(this.app, this.logger, this.manifest, void 0, forceOverwrite);
|
|
112
|
+
const routeGenerator = new RouteGenerator(this.app, this.logger, this.manifest, void 0, forceOverwrite);
|
|
113
|
+
const testGenerator = new TestGenerator(this.app, this.logger, this.manifest, void 0, forceOverwrite);
|
|
114
|
+
const viewGenerator = new ViewGenerator(this.app, this.logger, this.manifest, void 0, forceOverwrite);
|
|
115
|
+
const policyGenerator = new PolicyGenerator(this.app, this.logger, this.manifest, void 0, forceOverwrite);
|
|
116
|
+
const middlewareGenerator = new MiddlewareGenerator(this.app, this.logger, this.manifest, void 0, forceOverwrite);
|
|
117
|
+
const useInertia = blueprint.settings?.inertia?.enabled || false;
|
|
118
|
+
const adapter = blueprint.settings?.inertia?.adapter || "react";
|
|
119
|
+
const isApi = blueprint.settings?.api || false;
|
|
120
|
+
for (const [name, definition] of Object.entries(blueprint.controllers)) {
|
|
121
|
+
this.logger.info(`Generating controller, routes, tests and policies for ${name}`);
|
|
122
|
+
await controllerGenerator.generate(name, definition, useInertia, isApi, blueprint.models);
|
|
123
|
+
await routeGenerator.generate(name, definition, isApi);
|
|
124
|
+
await testGenerator.generate(name, definition, blueprint);
|
|
125
|
+
await policyGenerator.generate(name, definition);
|
|
126
|
+
if (definition.middleware) {
|
|
127
|
+
for (const mw of definition.middleware) if (![
|
|
128
|
+
"auth",
|
|
129
|
+
"guest",
|
|
130
|
+
"silentAuth"
|
|
131
|
+
].includes(mw)) {
|
|
132
|
+
this.logger.info(`Generating middleware ${mw}`);
|
|
133
|
+
await middlewareGenerator.generate(mw);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (!isApi) {
|
|
137
|
+
for (const actionDef of Object.values(definition)) if (typeof actionDef === "object" && actionDef !== null && actionDef.render) {
|
|
138
|
+
const viewPath = actionDef.render;
|
|
139
|
+
this.logger.info(`Generating view ${viewPath} (${useInertia ? adapter : "edge"})`);
|
|
140
|
+
const modelName = string.pascalCase(string.singular(name));
|
|
141
|
+
const modelDef = blueprint.models ? blueprint.models[modelName] : null;
|
|
142
|
+
await viewGenerator.generate(viewPath, useInertia, adapter, modelDef);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (blueprint.channels) await new ChannelGenerator(this.app, this.logger, this.manifest).generate("", blueprint.channels);
|
|
148
|
+
if (blueprint.settings?.api) {
|
|
149
|
+
this.logger.info("Generating API documentation...");
|
|
150
|
+
await new OpenAPIGenerator(this.app, this.logger, this.manifest).generate("", blueprint);
|
|
151
|
+
}
|
|
152
|
+
if (this.manifest.length > 0) {
|
|
153
|
+
const manifestPath = this.app.makePath(".blueprint_manifest.json");
|
|
154
|
+
writeFileSync(manifestPath, JSON.stringify({ files: this.manifest }, null, 2));
|
|
155
|
+
this.logger.info(`Manifest saved to ${manifestPath}`);
|
|
156
|
+
}
|
|
157
|
+
this.logger.success("Application built successfully");
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
__decorate([args.string({
|
|
161
|
+
description: "The draft file to build from",
|
|
162
|
+
default: "draft.yaml"
|
|
163
|
+
})], BuildBlueprint.prototype, "draftFile", void 0);
|
|
164
|
+
__decorate([flags.boolean({
|
|
165
|
+
alias: "e",
|
|
166
|
+
description: "Erase existing files before building"
|
|
167
|
+
})], BuildBlueprint.prototype, "erase", void 0);
|
|
168
|
+
__decorate([flags.boolean({
|
|
169
|
+
alias: "w",
|
|
170
|
+
description: "Watch the draft file for changes"
|
|
171
|
+
})], BuildBlueprint.prototype, "watch", void 0);
|
|
172
|
+
__decorate([flags.boolean({
|
|
173
|
+
alias: "f",
|
|
174
|
+
description: "Force overwrite existing files"
|
|
175
|
+
})], BuildBlueprint.prototype, "force", void 0);
|
|
176
|
+
//#endregion
|
|
177
|
+
export { BuildBlueprint, BuildBlueprint as default };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { existsSync, readFileSync, unlinkSync } from "node:fs";
|
|
2
|
+
import { BaseCommand } from "@adonisjs/core/ace";
|
|
3
|
+
//#region src/commands/erase.ts
|
|
4
|
+
var EraseBlueprint = class extends BaseCommand {
|
|
5
|
+
static commandName = "blueprint:erase";
|
|
6
|
+
static description = "Erase the files generated by the last blueprint:build";
|
|
7
|
+
async run() {
|
|
8
|
+
const manifestPath = this.app.makePath(".blueprint_manifest.json");
|
|
9
|
+
if (!existsSync(manifestPath)) {
|
|
10
|
+
this.logger.error("Manifest file not found. Nothing to erase.");
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const files = JSON.parse(readFileSync(manifestPath, "utf8")).files || [];
|
|
14
|
+
for (const file of files) if (existsSync(file)) {
|
|
15
|
+
unlinkSync(file);
|
|
16
|
+
this.logger.action(`deleted ${file}`).succeeded();
|
|
17
|
+
}
|
|
18
|
+
unlinkSync(manifestPath);
|
|
19
|
+
this.logger.success("Erased generated files successfully");
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { EraseBlueprint as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const commands: (() => Promise<typeof import("./erase.js")>)[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { t as stubsRoot } from "../../main-1fZp_M_R.js";
|
|
2
|
+
import { BaseCommand } from "@adonisjs/core/ace";
|
|
3
|
+
//#region src/commands/stubs.ts
|
|
4
|
+
var EjectStubs = class extends BaseCommand {
|
|
5
|
+
static commandName = "blueprint:stubs";
|
|
6
|
+
static description = "Publish blueprint stubs to your project root";
|
|
7
|
+
async run() {
|
|
8
|
+
await (await this.app.stubs.create()).copy(stubsRoot, {
|
|
9
|
+
overwrite: false,
|
|
10
|
+
source: stubsRoot
|
|
11
|
+
});
|
|
12
|
+
this.logger.success("Stubs published to ./stubs/blueprint");
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { EjectStubs as default };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { writeFileSync } from "node:fs";
|
|
2
|
+
import { stringify } from "yaml";
|
|
3
|
+
import { BaseCommand } from "@adonisjs/core/ace";
|
|
4
|
+
import string from "@adonisjs/core/helpers/string";
|
|
5
|
+
//#region src/commands/trace.ts
|
|
6
|
+
var TraceBlueprint = class extends BaseCommand {
|
|
7
|
+
static commandName = "blueprint:trace";
|
|
8
|
+
static description = "Trace the database and generate a draft.yaml file";
|
|
9
|
+
async run() {
|
|
10
|
+
this.logger.info("Tracing database to generate draft.yaml...");
|
|
11
|
+
try {
|
|
12
|
+
const connection = (await import("@adonisjs/lucid/services/db")).default.connection();
|
|
13
|
+
const tables = await connection.inspect();
|
|
14
|
+
const draft = { models: {} };
|
|
15
|
+
for (const table of tables) {
|
|
16
|
+
if ([
|
|
17
|
+
"adonis_schema",
|
|
18
|
+
"adonis_schema_versions",
|
|
19
|
+
"lucid_models"
|
|
20
|
+
].includes(table.name)) continue;
|
|
21
|
+
const modelName = string.pascalCase(string.singular(table.name));
|
|
22
|
+
draft.models[modelName] = {
|
|
23
|
+
attributes: {},
|
|
24
|
+
relationships: {}
|
|
25
|
+
};
|
|
26
|
+
const columns = await connection.getColumns(table.name);
|
|
27
|
+
for (const column of columns) {
|
|
28
|
+
if ([
|
|
29
|
+
"id",
|
|
30
|
+
"created_at",
|
|
31
|
+
"updated_at",
|
|
32
|
+
"deleted_at"
|
|
33
|
+
].includes(column.name)) {
|
|
34
|
+
if (column.name === "deleted_at") draft.models[modelName].softDeletes = true;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (column.name.endsWith("_id")) {
|
|
38
|
+
const relName = string.camelCase(column.name.replace("_id", ""));
|
|
39
|
+
draft.models[modelName].relationships[relName] = "belongsTo";
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
let type = "string";
|
|
43
|
+
if (column.type === "integer" || column.type === "int") type = "integer";
|
|
44
|
+
if (column.type === "boolean" || column.type === "tinyint") type = "boolean";
|
|
45
|
+
if (column.type === "timestamp" || column.type === "datetime") type = "timestamp";
|
|
46
|
+
draft.models[modelName].attributes[column.name] = type;
|
|
47
|
+
}
|
|
48
|
+
if (Object.keys(draft.models[modelName].attributes).length === 0) delete draft.models[modelName].attributes;
|
|
49
|
+
if (Object.keys(draft.models[modelName].relationships).length === 0) delete draft.models[modelName].relationships;
|
|
50
|
+
}
|
|
51
|
+
writeFileSync(this.app.makePath("draft.yaml"), stringify(draft));
|
|
52
|
+
this.logger.success("draft.yaml generated successfully from database");
|
|
53
|
+
} catch (error) {
|
|
54
|
+
this.logger.error("Failed to trace database. Make sure Lucid is configured.");
|
|
55
|
+
this.logger.debug(error);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
//#endregion
|
|
60
|
+
export { TraceBlueprint as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ApplicationService } from '@adonisjs/core/types';
|
|
2
|
+
import { Codemods } from '@adonisjs/core/ace/codemods';
|
|
3
|
+
export declare abstract class BaseGenerator {
|
|
4
|
+
protected app: ApplicationService;
|
|
5
|
+
protected logger: any;
|
|
6
|
+
protected manifest?: string[] | undefined;
|
|
7
|
+
protected forceOverwrite: boolean;
|
|
8
|
+
protected codemods: Codemods;
|
|
9
|
+
constructor(app: ApplicationService, logger: any, manifest?: string[] | undefined, codemods?: Codemods, forceOverwrite?: boolean);
|
|
10
|
+
protected generateStub(stubPath: string, stubState: any, customStubPath?: string): Promise<import("@adonisjs/application/types").GeneratedStub>;
|
|
11
|
+
abstract generate(name: string, definition: any, ...args: any[]): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { t as stubsRoot } from "../../main-1fZp_M_R.js";
|
|
2
|
+
import { basename, dirname, isAbsolute } from "node:path";
|
|
3
|
+
import { Codemods } from "@adonisjs/core/ace/codemods";
|
|
4
|
+
//#region src/generators/base_generator.ts
|
|
5
|
+
var BaseGenerator = class {
|
|
6
|
+
codemods;
|
|
7
|
+
constructor(app, logger, manifest, codemods, forceOverwrite = false) {
|
|
8
|
+
this.app = app;
|
|
9
|
+
this.logger = logger;
|
|
10
|
+
this.manifest = manifest;
|
|
11
|
+
this.forceOverwrite = forceOverwrite;
|
|
12
|
+
this.codemods = codemods || new Codemods(this.app, this.logger);
|
|
13
|
+
}
|
|
14
|
+
async generateStub(stubPath, stubState, customStubPath) {
|
|
15
|
+
let finalStubRoot = stubsRoot;
|
|
16
|
+
let finalStubPath = stubPath;
|
|
17
|
+
if (customStubPath) if (isAbsolute(customStubPath)) {
|
|
18
|
+
finalStubRoot = dirname(customStubPath);
|
|
19
|
+
finalStubPath = basename(customStubPath);
|
|
20
|
+
} else {
|
|
21
|
+
finalStubRoot = this.app.appRoot.toString();
|
|
22
|
+
finalStubPath = customStubPath;
|
|
23
|
+
}
|
|
24
|
+
this.codemods.overwriteExisting = this.forceOverwrite;
|
|
25
|
+
const result = await this.codemods.makeUsingStub(finalStubRoot, finalStubPath, stubState);
|
|
26
|
+
if (this.manifest && result && result.destination) this.manifest.push(result.destination);
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { BaseGenerator };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BaseGenerator } from "./base_generator.js";
|
|
2
|
+
//#region src/generators/channel_generator.ts
|
|
3
|
+
var ChannelGenerator = class extends BaseGenerator {
|
|
4
|
+
async generate(_name, channels) {
|
|
5
|
+
const outputPath = this.app.makePath("start/transmission.ts");
|
|
6
|
+
let content = "import transmission from '@adonisjs/transmission/services/main'\n\n";
|
|
7
|
+
for (const [name, definition] of Object.entries(channels)) {
|
|
8
|
+
const channelName = definition.name || name.toLowerCase();
|
|
9
|
+
content += `transmission.authorize('${channelName}', async (user) => {\n`;
|
|
10
|
+
if (definition.authorized) content += ` return !!user\n`;
|
|
11
|
+
else content += ` return true\n`;
|
|
12
|
+
content += `})\n\n`;
|
|
13
|
+
}
|
|
14
|
+
const { writeFileSync } = await import("node:fs");
|
|
15
|
+
const { existsSync, mkdirSync } = await import("node:fs");
|
|
16
|
+
const { dirname } = await import("node:path");
|
|
17
|
+
const dir = dirname(outputPath);
|
|
18
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
19
|
+
writeFileSync(outputPath, content);
|
|
20
|
+
this.logger.action(`create ${outputPath}`).succeeded();
|
|
21
|
+
if (this.manifest) this.manifest.push(outputPath);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
export { ChannelGenerator };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BaseGenerator } from "./base_generator.js";
|
|
2
|
+
//#region src/generators/class_generator.ts
|
|
3
|
+
var ClassGenerator = class extends BaseGenerator {
|
|
4
|
+
async generate(name, type) {
|
|
5
|
+
const entity = this.app.generators.createEntity(name);
|
|
6
|
+
const stubPath = `make/${type}/main.stub`;
|
|
7
|
+
await this.generateStub(stubPath, { entity });
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { ClassGenerator };
|