@chejende/clean-arch 1.0.2 → 1.0.4

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.
@@ -0,0 +1,6 @@
1
+ import { Rule } from '@angular-devkit/schematics';
2
+ interface SchemaOptions {
3
+ name: string;
4
+ }
5
+ export declare function feature(options: SchemaOptions): Rule;
6
+ export {};
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.feature = feature;
4
+ const schematics_1 = require("@angular-devkit/schematics");
5
+ function feature(options) {
6
+ return (tree, _context) => {
7
+ if (!options.name) {
8
+ throw new schematics_1.SchematicsException('❌ Feature name is required');
9
+ }
10
+ const name = options.name.toLowerCase();
11
+ const Name = capitalize(name);
12
+ const base = `src/app/features/${name}`;
13
+ if (tree.exists(base)) {
14
+ throw new schematics_1.SchematicsException(`❌ Feature "${name}" already exists`);
15
+ }
16
+ const files = buildFileStructure(base, name, Name);
17
+ files.forEach(({ path, content }) => {
18
+ tree.create(path, content);
19
+ });
20
+ return tree;
21
+ };
22
+ }
23
+ /* ========================= */
24
+ /* 🧱 FILE STRUCTURE BUILDER */
25
+ /* ========================= */
26
+ function buildFileStructure(base, name, Name) {
27
+ return [
28
+ // DOMAIN
29
+ file(`${base}/domain/models/${name}.model.ts`, modelTemplate(Name)),
30
+ file(`${base}/domain/repositories/${name}.repository.ts`, repositoryTemplate(Name)),
31
+ // APPLICATION
32
+ file(`${base}/application/dto/${name}.dto.ts`, dtoTemplate(Name)),
33
+ file(`${base}/application/use-cases/get-${name}.use-case.ts`, useCaseTemplate(name, Name)),
34
+ file(`${base}/application/providers/${name}.providers.ts`, providersTemplate(name, Name)),
35
+ // INFRASTRUCTURE
36
+ file(`${base}/infrastructure/services/${name}-api.service.ts`, apiTemplate(name, Name)),
37
+ file(`${base}/infrastructure/repositories/${name}.repository.impl.ts`, repoImplTemplate(name, Name)),
38
+ file(`${base}/infrastructure/mappers/${name}.mapper.ts`, mapperTemplate(Name)),
39
+ // PRESENTATION
40
+ file(`${base}/presentation/pages/${name}.page.ts`, pageTemplate(Name)),
41
+ file(`${base}/presentation/store/${name}.store.ts`, storeTemplate(Name)),
42
+ ];
43
+ }
44
+ /* ========================= */
45
+ /* 🧩 HELPERS */
46
+ /* ========================= */
47
+ function file(path, content) {
48
+ return { path, content };
49
+ }
50
+ function capitalize(str) {
51
+ return str.charAt(0).toUpperCase() + str.slice(1);
52
+ }
53
+ /* ========================= */
54
+ /* 🧾 TEMPLATES */
55
+ /* ========================= */
56
+ function modelTemplate(Name) {
57
+ return `
58
+ export interface ${Name} {
59
+ id: string;
60
+ }
61
+ `;
62
+ }
63
+ function repositoryTemplate(Name) {
64
+ return `
65
+ export abstract class ${Name}Repository {
66
+ abstract getAll(): Promise<${Name}[]>;
67
+ }
68
+ `;
69
+ }
70
+ function dtoTemplate(Name) {
71
+ return `
72
+ export interface ${Name}Dto {
73
+ id: string;
74
+ }
75
+ `;
76
+ }
77
+ function useCaseTemplate(name, Name) {
78
+ return `
79
+ import { ${Name}Repository } from '../../domain/repositories/${name}.repository';
80
+
81
+ export class Get${Name}UseCase {
82
+ constructor(private repo: ${Name}Repository) {}
83
+
84
+ execute() {
85
+ return this.repo.getAll();
86
+ }
87
+ }
88
+ `;
89
+ }
90
+ function apiTemplate(name, Name) {
91
+ return `
92
+ import { Injectable } from '@angular/core';
93
+ import { HttpClient } from '@angular/common/http';
94
+
95
+ @Injectable({ providedIn: 'root' })
96
+ export class ${Name}ApiService {
97
+ constructor(private http: HttpClient) {}
98
+
99
+ getAll() {
100
+ return this.http.get('/api/${name}');
101
+ }
102
+ }
103
+ `;
104
+ }
105
+ function repoImplTemplate(name, Name) {
106
+ return `
107
+ import { Injectable } from '@angular/core';
108
+ import { ${Name}Repository } from '../../domain/repositories/${name}.repository';
109
+ import { ${Name}ApiService } from '../services/${name}-api.service';
110
+ import { firstValueFrom } from 'rxjs';
111
+
112
+ @Injectable()
113
+ export class ${Name}RepositoryImpl implements ${Name}Repository {
114
+ constructor(private api: ${Name}ApiService) {}
115
+
116
+ async getAll() {
117
+ return await firstValueFrom(this.api.getAll());
118
+ }
119
+ }
120
+ `;
121
+ }
122
+ function mapperTemplate(Name) {
123
+ return `
124
+ export class ${Name}Mapper {
125
+ static toDomain(data: any): ${Name} {
126
+ return {
127
+ id: data.id
128
+ };
129
+ }
130
+ }
131
+ `;
132
+ }
133
+ function pageTemplate(Name) {
134
+ return `
135
+ import { Component } from '@angular/core';
136
+
137
+ @Component({
138
+ standalone: true,
139
+ template: \`<h1>${Name} works!</h1>\`
140
+ })
141
+ export class ${Name}Page {}
142
+ `;
143
+ }
144
+ function storeTemplate(Name) {
145
+ return `
146
+ import { signal, computed } from '@angular/core';
147
+
148
+ export class ${Name}Store {
149
+ private data = signal<any[]>([]);
150
+
151
+ readonly items = computed(() => this.data());
152
+
153
+ set(data: any[]) {
154
+ this.data.set(data);
155
+ }
156
+ }
157
+ `;
158
+ }
159
+ function providersTemplate(name, Name) {
160
+ return `
161
+ import { Provider } from '@angular/core';
162
+ import { ${Name}Repository } from '../../domain/repositories/${name}.repository';
163
+ import { ${Name}RepositoryImpl } from '../../infrastructure/repositories/${name}.repository.impl';
164
+
165
+ export const ${Name.toUpperCase()}_PROVIDERS: Provider[] = [
166
+ {
167
+ provide: ${Name}Repository,
168
+ useClass: ${Name}RepositoryImpl
169
+ }
170
+ ];
171
+ `;
172
+ }
173
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/clean-arch/index.ts"],"names":[],"mappings":";;AAWA,0BAuBC;AAlCD,2DAKoC;AAMpC,SAAgB,OAAO,CAAC,OAAsB;IAC5C,OAAO,CAAC,IAAU,EAAE,QAA0B,EAAE,EAAE;QAChD,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAClB,MAAM,IAAI,gCAAmB,CAAC,4BAA4B,CAAC,CAAC;QAC9D,C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C;AAED,SAAS,WAAW,CAAC,IAAY,EAAE,IAAY;IAC7C,OAAO;;;;;eAKM,IAAI;;;;iCAIc,IAAI;;;CAGpC,CAAC;AACF,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAY,EAAE,IAAY;IAClD,OAAO;;WAEE,IAAI,gDAAgD,IAAI;WACxD,IAAI,kCAAkC,IAAI;;;;eAItC,IAAI,6BAA6B,IAAI;6BACvB,IAAI;;;;;;CAMhC,CAAC;AACF,CAAC;AAED,SAAS,cAAc,CAAC,IAAY;IAClC,OAAO;eACM,IAAI;gCACa,IAAI;;;;;;CAMnC,CAAC;AACF,CAAC;AAED,SAAS,YAAY,CAAC,IAAY;IAChC,OAAO;;;;;oBAKW,IAAI;;eAET,IAAI;CAClB,CAAC;AACF,CAAC;AAED,SAAS,aAAa,CAAC,IAAY;IACjC,OAAO;;;eAGM,IAAI;;;;;;;;;CASlB,CAAC;AACF,CAAC;AAED,SAAS,iBAAiB,CAAC,IAAY,EAAE,IAAY;IACnD,OAAO;;WAEE,IAAI,gDAAgD,IAAI;WACxD,IAAI,4DAA4D,IAAI;;eAEhE,IAAI,CAAC,WAAW,EAAE;;eAElB,IAAI;gBACH,IAAI;;;CAGnB,CAAC;AACF,CAAC"}
@@ -0,0 +1,10 @@
1
+ {
2
+ "$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
3
+ "schematics": {
4
+ "feature": {
5
+ "description": "Create clean architecture feature",
6
+ "factory": "./clean-arch/index#feature",
7
+ "schema": "./clean-arch/schema.json"
8
+ }
9
+ }
10
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chejende/clean-arch",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Angular Clean Architecture schematics",
5
5
  "keywords": [
6
6
  "angular",
@@ -10,23 +10,21 @@
10
10
  ],
11
11
  "author": "Estarlin Lopez",
12
12
  "license": "MIT",
13
-
14
- "schematics": "./src/collection.json",
15
- "main": "./src/index.ts",
16
- "files": ["dist"],
17
-
13
+ "schematics": "./dist/collection.json",
14
+ "main": "./dist/clean-arch/index.js",
15
+ "files": [
16
+ "dist"
17
+ ],
18
18
  "scripts": {
19
- "build": "tsc -p tsconfig.json",
19
+ "build": "tsc -p tsconfig.json && copy src\\collection.json dist\\collection.json",
20
20
  "prepublishOnly": "npm run build"
21
21
  },
22
-
23
22
  "dependencies": {
24
23
  "@angular-devkit/core": "^21.2.5",
25
24
  "@angular-devkit/schematics": "^21.2.5"
26
25
  },
27
-
28
26
  "devDependencies": {
29
27
  "@types/node": "^20.17.19",
30
28
  "typescript": "~5.9.2"
31
29
  }
32
- }
30
+ }