@anu8151/adonisjs-blueprint 0.4.8 → 0.4.10

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.
@@ -331,11 +331,31 @@ var ControllerGenerator = class extends BaseGenerator {
331
331
  logic: logicLines.join("\n ") || "// Action logic here"
332
332
  });
333
333
  }
334
+ const importsLines = [];
335
+ imports.models.forEach((model) => {
336
+ importsLines.push(`import ${model} from '#models/${string.snakeCase(model)}'`);
337
+ });
338
+ imports.validators.forEach((v) => {
339
+ importsLines.push(`import { ${v} } from '#validators/${entity.name.toLowerCase()}'`);
340
+ });
341
+ imports.events.forEach((e) => {
342
+ importsLines.push(`import ${e} from '#events/${e.toLowerCase()}'`);
343
+ });
344
+ imports.policies.forEach((p) => {
345
+ importsLines.push(`import ${p} from '#policies/${entity.name.toLowerCase()}_policy'`);
346
+ });
347
+ imports.services.forEach((path, serviceName) => {
348
+ importsLines.push(`import ${serviceName} from '#services/${path}'`);
349
+ });
350
+ const middlewareLines = middleware.length > 0 ? `static middleware = [\n ${middleware.map((m) => `middleware.${m}()`).join(",\n ")}\n ]` : "";
351
+ const actionLines = actions.map((action) => {
352
+ return `async ${action.name}({ ${action.context} }: HttpContext) {\n ${action.logic}\n }`;
353
+ }).join("\n\n ");
334
354
  await this.generateStub("make/controller/main.stub", {
335
355
  entity,
336
356
  actions,
337
357
  middleware,
338
- imports: {
358
+ importsData: {
339
359
  models: Array.from(imports.models),
340
360
  validators: Array.from(imports.validators),
341
361
  events: Array.from(imports.events),
@@ -347,7 +367,10 @@ var ControllerGenerator = class extends BaseGenerator {
347
367
  name: serviceName,
348
368
  path
349
369
  }))
350
- }
370
+ },
371
+ importsLines: importsLines.join("\n"),
372
+ middlewareLines,
373
+ actionLines
351
374
  }, definition.stub);
352
375
  }
353
376
  };
@@ -9,7 +9,8 @@ var EnumGenerator = class extends BaseGenerator {
9
9
  }));
10
10
  await this.generateStub("make/enum/main.stub", {
11
11
  entity,
12
- values
12
+ values,
13
+ valuesLines: values.map((v) => `${v.key} = '${v.value}'`).join(",\n ")
13
14
  });
14
15
  }
15
16
  };
@@ -4,44 +4,10 @@
4
4
  })
5
5
  }}}
6
6
  import type { HttpContext } from '@adonisjs/core/http'
7
- @if(imports.models)
8
- @each(model in imports.models)
9
- import {{ model }} from '#models/{{ model.toLowerCase() }}'
10
- @end
11
- @end
12
- @if(imports.validators)
13
- @each(validator in imports.validators)
14
- import { {{ validator }} } from '#validators/{{ entity.name.toLowerCase() }}'
15
- @end
16
- @end
17
- @if(imports.events)
18
- @each(event in imports.events)
19
- import {{ event }} from '#events/{{ event.toLowerCase() }}'
20
- @end
21
- @end
22
- @if(imports.policies)
23
- @each(policy in imports.policies)
24
- import {{ policy }} from '#policies/{{ entity.name.toLowerCase() }}_policy'
25
- @end
26
- @end
27
- @if(imports.services)
28
- @each(service in imports.services)
29
- import {{ service.name }} from '#services/{{ service.path }}'
30
- @end
31
- @end
7
+ {{{ importsLines }}}
32
8
 
33
9
  export default class {{ entity.className }}Controller {
34
- @if(middleware.length)
35
- static middleware = [
36
- @each(item in middleware)
37
- middleware.{{ item }}(),
38
- @end
39
- ]
40
- @end
10
+ {{{ middlewareLines }}}
41
11
 
42
- @each(action in actions)
43
- async {{ action.name }}({ {{ action.context }} }: HttpContext) {
44
- {{ action.logic }}
45
- }
46
- @end
12
+ {{{ actionLines }}}
47
13
  }
@@ -4,7 +4,5 @@
4
4
  })
5
5
  }}}
6
6
  export enum {{ entity.className }} {
7
- @each(val in values)
8
- {{ val.key }} = '{{ val.value }}',
9
- @end
7
+ {{{ valuesLines }}}
10
8
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@anu8151/adonisjs-blueprint",
3
3
  "description": "Blueprint for AdonisJS 7",
4
- "version": "0.4.8",
4
+ "version": "0.4.10",
5
5
  "engines": {
6
6
  "node": ">=24.0.0"
7
7
  },
@@ -4,44 +4,10 @@
4
4
  })
5
5
  }}}
6
6
  import type { HttpContext } from '@adonisjs/core/http'
7
- @if(imports.models)
8
- @each(model in imports.models)
9
- import {{ model }} from '#models/{{ model.toLowerCase() }}'
10
- @end
11
- @end
12
- @if(imports.validators)
13
- @each(validator in imports.validators)
14
- import { {{ validator }} } from '#validators/{{ entity.name.toLowerCase() }}'
15
- @end
16
- @end
17
- @if(imports.events)
18
- @each(event in imports.events)
19
- import {{ event }} from '#events/{{ event.toLowerCase() }}'
20
- @end
21
- @end
22
- @if(imports.policies)
23
- @each(policy in imports.policies)
24
- import {{ policy }} from '#policies/{{ entity.name.toLowerCase() }}_policy'
25
- @end
26
- @end
27
- @if(imports.services)
28
- @each(service in imports.services)
29
- import {{ service.name }} from '#services/{{ service.path }}'
30
- @end
31
- @end
7
+ {{{ importsLines }}}
32
8
 
33
9
  export default class {{ entity.className }}Controller {
34
- @if(middleware.length)
35
- static middleware = [
36
- @each(item in middleware)
37
- middleware.{{ item }}(),
38
- @end
39
- ]
40
- @end
10
+ {{{ middlewareLines }}}
41
11
 
42
- @each(action in actions)
43
- async {{ action.name }}({ {{ action.context }} }: HttpContext) {
44
- {{ action.logic }}
45
- }
46
- @end
12
+ {{{ actionLines }}}
47
13
  }
@@ -4,7 +4,5 @@
4
4
  })
5
5
  }}}
6
6
  export enum {{ entity.className }} {
7
- @each(val in values)
8
- {{ val.key }} = '{{ val.value }}',
9
- @end
7
+ {{{ valuesLines }}}
10
8
  }