@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.
Files changed (90) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +131 -0
  3. package/build/configure.d.ts +2 -0
  4. package/build/configure.js +7 -0
  5. package/build/index.d.ts +16 -0
  6. package/build/index.js +9 -0
  7. package/build/init-TjAcOVVP.js +64 -0
  8. package/build/main-1fZp_M_R.js +8 -0
  9. package/build/parser-DJB5DEck.js +5832 -0
  10. package/build/src/commands/build.d.ts +14 -0
  11. package/build/src/commands/build.js +177 -0
  12. package/build/src/commands/erase.d.ts +6 -0
  13. package/build/src/commands/erase.js +23 -0
  14. package/build/src/commands/init.d.ts +6 -0
  15. package/build/src/commands/main.d.ts +1 -0
  16. package/build/src/commands/main.js +10 -0
  17. package/build/src/commands/stubs.d.ts +6 -0
  18. package/build/src/commands/stubs.js +16 -0
  19. package/build/src/commands/trace.d.ts +6 -0
  20. package/build/src/commands/trace.js +60 -0
  21. package/build/src/generators/base_generator.d.ts +12 -0
  22. package/build/src/generators/base_generator.js +31 -0
  23. package/build/src/generators/channel_generator.d.ts +4 -0
  24. package/build/src/generators/channel_generator.js +25 -0
  25. package/build/src/generators/class_generator.d.ts +4 -0
  26. package/build/src/generators/class_generator.js +11 -0
  27. package/build/src/generators/controller_generator.d.ts +5 -0
  28. package/build/src/generators/controller_generator.js +355 -0
  29. package/build/src/generators/enum_generator.d.ts +4 -0
  30. package/build/src/generators/enum_generator.js +17 -0
  31. package/build/src/generators/event_generator.d.ts +4 -0
  32. package/build/src/generators/event_generator.js +10 -0
  33. package/build/src/generators/factory_generator.d.ts +4 -0
  34. package/build/src/generators/factory_generator.js +50 -0
  35. package/build/src/generators/job_generator.d.ts +4 -0
  36. package/build/src/generators/job_generator.js +10 -0
  37. package/build/src/generators/mail_generator.d.ts +4 -0
  38. package/build/src/generators/mail_generator.js +10 -0
  39. package/build/src/generators/middleware_generator.d.ts +4 -0
  40. package/build/src/generators/middleware_generator.js +10 -0
  41. package/build/src/generators/migration_generator.d.ts +5 -0
  42. package/build/src/generators/migration_generator.js +46 -0
  43. package/build/src/generators/model_generator.d.ts +4 -0
  44. package/build/src/generators/model_generator.js +57 -0
  45. package/build/src/generators/notification_generator.d.ts +4 -0
  46. package/build/src/generators/notification_generator.js +10 -0
  47. package/build/src/generators/openapi_generator.d.ts +8 -0
  48. package/build/src/generators/openapi_generator.js +200 -0
  49. package/build/src/generators/policy_generator.d.ts +4 -0
  50. package/build/src/generators/policy_generator.js +29 -0
  51. package/build/src/generators/route_generator.d.ts +4 -0
  52. package/build/src/generators/route_generator.js +34 -0
  53. package/build/src/generators/seeder_generator.d.ts +4 -0
  54. package/build/src/generators/seeder_generator.js +16 -0
  55. package/build/src/generators/service_generator.d.ts +4 -0
  56. package/build/src/generators/service_generator.js +14 -0
  57. package/build/src/generators/test_generator.d.ts +5 -0
  58. package/build/src/generators/test_generator.js +38 -0
  59. package/build/src/generators/validator_generator.d.ts +4 -0
  60. package/build/src/generators/validator_generator.js +70 -0
  61. package/build/src/generators/view_generator.d.ts +4 -0
  62. package/build/src/generators/view_generator.js +23 -0
  63. package/build/src/parser.d.ts +7 -0
  64. package/build/src/parser.js +2 -0
  65. package/build/src/statements/index.d.ts +1 -0
  66. package/build/src/statements_registry.d.ts +47 -0
  67. package/build/src/types.d.ts +50 -0
  68. package/build/statements_registry-DzyxAiKP.js +19 -0
  69. package/build/stubs/config.stub +32 -0
  70. package/build/stubs/main.d.ts +5 -0
  71. package/build/stubs/make/controller/main.stub +47 -0
  72. package/build/stubs/make/enum/main.stub +10 -0
  73. package/build/stubs/make/event/main.stub +12 -0
  74. package/build/stubs/make/factory/main.stub +25 -0
  75. package/build/stubs/make/job/main.stub +12 -0
  76. package/build/stubs/make/mail/main.stub +23 -0
  77. package/build/stubs/make/middleware/main.stub +16 -0
  78. package/build/stubs/make/migration/main.stub +25 -0
  79. package/build/stubs/make/model/main.stub +19 -0
  80. package/build/stubs/make/notification/main.stub +28 -0
  81. package/build/stubs/make/policy/main.stub +17 -0
  82. package/build/stubs/make/seeder/main.stub +21 -0
  83. package/build/stubs/make/service/main.stub +8 -0
  84. package/build/stubs/make/test/controller.stub +23 -0
  85. package/build/stubs/make/validator/main.stub +22 -0
  86. package/build/stubs/make/view/edge.stub +65 -0
  87. package/build/stubs/make/view/react.stub +57 -0
  88. package/build/stubs/make/view/svelte.stub +67 -0
  89. package/build/stubs/make/view/vue.stub +74 -0
  90. package/package.json +151 -0
package/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ # The MIT License
2
+
3
+ Copyright (c) 2023
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # AdonisJS Blueprint
2
+
3
+ > [!note]
4
+ > This package targets **AdonisJS v7**
5
+
6
+ A professional-grade code generator for AdonisJS 7 inspired by [Laravel Blueprint](https://blueprint.laravelshift.com/). Rapidly scaffold your entire application infrastructure from a single, human-readable YAML file.
7
+
8
+ ## Features
9
+
10
+ - **API-First Mode**: Switch between traditional MVC, InertiaJS, or pure JSON APIs with a single setting.
11
+ - **Watch Mode**: Automatically rebuilds your application infrastructure whenever you save your `draft.yaml`.
12
+ - **JSON Schema Support**: Get full IDE auto-completion and validation for your `draft.yaml` file.
13
+ - **Models & Migrations**: Generates Lucid models with support for **Soft Deletes**, **Enums**, and automatic **Pivot Tables**.
14
+ - **Smart Relationships**: Infers foreign keys and generates proper TypeScript types for `belongsTo`, `hasMany`, etc.
15
+ - **Controllers & Routes**: Generates controllers with advanced logic, **Middleware** support, and registers **Resource** or **API** routes.
16
+ - **Advanced CRUD Views**: Generates full CRUD pages (Index, Create, Edit, Show) for **Edge**, **React**, **Vue**, and **Svelte**.
17
+ - **Authorization**: Integrated **Bouncer** support—generates Policy classes with smart method mapping (`index` -> `viewAny`, etc.).
18
+ - **Validators & Factories**: Creates advanced **VineJS** validators and Faker-powered factories.
19
+ - **Real-time Communication**: Integrated **AdonisJS Transmission** support—generates channels and authorization logic.
20
+ - **Infrastructure**: Generates **Smart Seeders**, Events, Mails, Jobs, Notifications, and **Japa** functional tests.
21
+ - **OpenAPI Documentation**: Automatically generates full Swagger/OpenAPI 3.0 specs with request/response schemas.
22
+ - **Reverse Engineering**: Trace your existing database to generate a `draft.yaml` automatically.
23
+
24
+ ## Setup
25
+
26
+ Install the package via npm:
27
+
28
+ ```sh
29
+ npm install @anu8151/adonisjs-blueprint
30
+ ```
31
+
32
+ Configure the package to publish the default configuration:
33
+
34
+ ```sh
35
+ node ace configure @anu8151/adonisjs-blueprint
36
+ ```
37
+
38
+ ## Developer Experience (DX)
39
+
40
+ To enable **Auto-completion** and **Validation** in VS Code, add the following comment to the top of your `draft.yaml`:
41
+
42
+ ```yaml
43
+ # yaml-language-server: $schema=node_modules/@anu8151/adonisjs-blueprint/build/src/schema.json
44
+
45
+ settings:
46
+ api: true
47
+ ...
48
+ ```
49
+
50
+ ## Usage
51
+
52
+ ### 1. Initialize your project
53
+
54
+ Run the init command to create a sample `draft.yaml`:
55
+
56
+ ```sh
57
+ node ace blueprint:init
58
+ ```
59
+
60
+ ### 2. Define your application
61
+
62
+ Edit the generated `draft.yaml` file in your project root.
63
+
64
+ ```yaml
65
+ settings:
66
+ api: true
67
+ inertia:
68
+ enabled: true
69
+ adapter: react
70
+
71
+ models:
72
+ Post:
73
+ attributes:
74
+ title: string:min:5
75
+ content: text
76
+ status: enum:draft,published,archived
77
+ softDeletes: true
78
+ relationships:
79
+ user: belongsTo
80
+
81
+ controllers:
82
+ Post:
83
+ resource: true
84
+
85
+ channels:
86
+ Chat:
87
+ authorized: true
88
+ ```
89
+
90
+ ### 3. Build your application
91
+
92
+ Run the build command to generate all files:
93
+
94
+ ```sh
95
+ node ace blueprint:build
96
+ ```
97
+
98
+ For a seamless experience, use the **Watch Mode**:
99
+
100
+ ```sh
101
+ node ace blueprint:build --watch
102
+ ```
103
+
104
+ ### 4. Core Commands
105
+
106
+ - **Init**: Create a sample `draft.yaml` with best practices.
107
+ - **Build**: Generate all files from `draft.yaml`. Supports `--watch` and `--force`.
108
+ - **Erase**: Undo the last build and remove generated files using the manifest.
109
+ - **Trace**: Generate a `draft.yaml` from your current database (Full Reverse Engineering).
110
+ - **Stubs**: Copy all stubs to your project root for customization.
111
+
112
+ ## Controller Statements
113
+
114
+ Blueprint supports several "smart" statements in your controller actions:
115
+
116
+ - `query: all | paginate:20 | find [, with: rel1, rel2]`: Generates Lucid query logic with optional preloads.
117
+ - `validate: title, content`: Generates advanced VineJS validation logic.
118
+ - `authorize: action, model`: Generates Bouncer Policy and authorization check.
119
+ - `save: true [, with: rel1, rel2]`: Generates `Model.create()` and optional `.sync()` logic.
120
+ - `delete: true`: Generates `findOrFail` and `delete()` logic.
121
+ - `upload: field to: disk`: Generates file upload logic using AdonisJS Drive.
122
+ - `fire: EventName`: Generates an Event class and `emitter.emit()` call.
123
+ - `send: MailName`: Generates a Mail class and `mail.sendLater()` call.
124
+ - `notify: target, NotificationName`: Generates a Notification class and `target.notify()` call.
125
+ - `dispatch: JobName`: Generates a Job class and handles execution.
126
+ - `render: view with: data`: Generates the view (Edge/Inertia/JSON) and passes data.
127
+ - `service: ServiceName.method`: Generates a Service class and calls the specified method.
128
+
129
+ ## License
130
+
131
+ MIT
@@ -0,0 +1,2 @@
1
+ import type Configure from '@adonisjs/core/commands/configure';
2
+ export declare function configure(command: Configure): Promise<void>;
@@ -0,0 +1,7 @@
1
+ import { t as stubsRoot } from "./main-1fZp_M_R.js";
2
+ //#region configure.ts
3
+ async function configure(command) {
4
+ await (await command.createCodemods()).makeUsingStub(stubsRoot, "config.stub", {});
5
+ }
6
+ //#endregion
7
+ export { configure };
@@ -0,0 +1,16 @@
1
+ export { configure } from './configure.js';
2
+ export { stubsRoot } from './stubs/main.js';
3
+ export { statementsRegistry } from './src/statements_registry.js';
4
+ export interface BlueprintConfig {
5
+ viewer?: 'edge' | 'inertia';
6
+ inertia?: {
7
+ adapter?: 'react' | 'vue' | 'svelte';
8
+ };
9
+ namespaces?: {
10
+ models?: string;
11
+ controllers?: string;
12
+ validators?: string;
13
+ factories?: string;
14
+ };
15
+ }
16
+ export declare function defineConfig(config: BlueprintConfig): BlueprintConfig;
package/build/index.js ADDED
@@ -0,0 +1,9 @@
1
+ import { t as stubsRoot } from "./main-1fZp_M_R.js";
2
+ import { configure } from "./configure.js";
3
+ import { t as statementsRegistry } from "./statements_registry-DzyxAiKP.js";
4
+ //#region index.ts
5
+ function defineConfig(config) {
6
+ return config;
7
+ }
8
+ //#endregion
9
+ export { configure, defineConfig, statementsRegistry, stubsRoot };
@@ -0,0 +1,64 @@
1
+ import { existsSync, writeFileSync } from "node:fs";
2
+ import { BaseCommand } from "@adonisjs/core/ace";
3
+ //#region src/commands/init.ts
4
+ var InitBlueprint = class extends BaseCommand {
5
+ static commandName = "blueprint:init";
6
+ static description = "Initialize a draft.yaml file with a professional-grade example";
7
+ async run() {
8
+ const draftPath = this.app.makePath("draft.yaml");
9
+ if (existsSync(draftPath)) {
10
+ if (!await this.prompt.confirm("A draft.yaml already exists. Do you want to overwrite it?")) {
11
+ this.logger.info("Initialization cancelled.");
12
+ return;
13
+ }
14
+ }
15
+ writeFileSync(draftPath, `# yaml-language-server: $schema=node_modules/@anu8151/adonisjs-blueprint/build/src/schema.json
16
+
17
+ settings:
18
+ api: true
19
+ inertia:
20
+ enabled: false
21
+ adapter: react
22
+
23
+ # Define your models here
24
+ models:
25
+ User:
26
+ attributes:
27
+ email: string:unique
28
+ password: string
29
+ full_name: string:optional
30
+ relationships:
31
+ posts: hasMany
32
+
33
+ Post:
34
+ attributes:
35
+ title: string:min:5
36
+ content: text
37
+ status: enum:draft,published,archived
38
+ softDeletes: true
39
+ relationships:
40
+ user: belongsTo
41
+ tags: belongsToMany
42
+
43
+ Tag:
44
+ attributes:
45
+ name: string:unique
46
+
47
+ # Define your controllers and business logic here
48
+ controllers:
49
+ Post:
50
+ resource: true
51
+ publish:
52
+ query: find
53
+ validate: title, content
54
+ save: true
55
+ fire: PostPublished
56
+ send: NewPostMail
57
+ render: 'json with: post'
58
+ `);
59
+ this.logger.success("draft.yaml initialized successfully.");
60
+ this.logger.info("You can now run: node ace blueprint:build");
61
+ }
62
+ };
63
+ //#endregion
64
+ export { InitBlueprint as default };
@@ -0,0 +1,8 @@
1
+ //#region stubs/main.ts
2
+ /**
3
+ * Path to the root directory where the stubs are stored. We use
4
+ * this path within commands and the configure hook
5
+ */
6
+ const stubsRoot = import.meta.dirname;
7
+ //#endregion
8
+ export { stubsRoot as t };