ngx-essentials-schematics 0.0.7 → 0.0.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ngx-essentials-schematics",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "A collection of Angular schematics for essential functionalities.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -53,25 +53,44 @@ function mergeFilesSmart(urlPath, destPath, options) {
53
53
  }),
54
54
  ]));
55
55
  }
56
- let treeRef; // Referencia global temporal para el filtro forEach
56
+ let treeRef;
57
57
  function signalStore(options) {
58
58
  return (tree) => {
59
59
  treeRef = tree;
60
- const defaultPath = "src/app/core";
61
- const movePath = (0, core_1.normalize)(options.path || defaultPath);
62
- // 1. Manejo del Index Principal (Export)
60
+ const movePath = (0, core_1.normalize)(options.path);
63
61
  const indexPath = (0, core_1.join)(movePath, "index.ts");
64
- const exportLine = `export * from './${core_1.strings.dasherize(options.name)}/${core_1.strings.dasherize(options.name)}.store';\n`;
62
+ const nameDash = core_1.strings.dasherize(options.name);
63
+ const entityName = core_1.strings.classify(options.name);
64
+ const entityHeader = `/** ${entityName.toUpperCase()} **/`;
65
+ const exportBlock = [
66
+ entityHeader,
67
+ `export * from './${nameDash}/${nameDash}.model';`,
68
+ `export * from './${nameDash}/${nameDash}.service';`,
69
+ `export * from './${nameDash}/${nameDash}.store';`,
70
+ "",
71
+ ].join("\n");
72
+ let content = "";
65
73
  if (tree.exists(indexPath)) {
66
- const content = tree.read(indexPath).toString();
67
- if (!content.includes(exportLine)) {
68
- tree.overwrite(indexPath, content + exportLine);
69
- }
74
+ content = tree.read(indexPath).toString();
75
+ }
76
+ if (content.includes(entityHeader)) {
77
+ const lines = exportBlock.split("\n");
78
+ lines.forEach((line) => {
79
+ if (line.trim() !== "" && !content.includes(line)) {
80
+ content += line + "\n";
81
+ }
82
+ });
83
+ }
84
+ else {
85
+ content =
86
+ content.trim() + (content.length > 0 ? "\n\n" : "") + exportBlock;
87
+ }
88
+ if (tree.exists(indexPath)) {
89
+ tree.overwrite(indexPath, content);
70
90
  }
71
91
  else {
72
- tree.create(indexPath, exportLine);
92
+ tree.create(indexPath, content);
73
93
  }
74
- // 2. Archivos de la Store (Estos se crean siempre en carpeta nueva)
75
94
  const templateStoreSource = (0, schematics_1.apply)((0, schematics_1.url)("./files/store"), [
76
95
  (0, schematics_1.applyTemplates)(Object.assign(Object.assign(Object.assign({}, core_1.strings), options), { pluralize: (word) => {
77
96
  switch (options.language) {
@@ -83,9 +102,8 @@ function signalStore(options) {
83
102
  } })),
84
103
  (0, schematics_1.move)((0, core_1.join)(movePath, core_1.strings.dasherize(options.name))),
85
104
  ]);
86
- // 3. Archivos Comunes con verificación de existencia
87
- const commonEntityRule = mergeFilesSmart("./files/entity", (0, core_1.join)((0, core_1.normalize)(defaultPath), "common/entity"), options);
88
- const commonFormRule = mergeFilesSmart("./files/form", (0, core_1.join)((0, core_1.normalize)(defaultPath), "common/form"), options);
105
+ const commonEntityRule = mergeFilesSmart("./files/entity", (0, core_1.join)(movePath, "common/entity"), options);
106
+ const commonFormRule = mergeFilesSmart("./files/form", (0, core_1.join)(movePath, "common/form"), options);
89
107
  return (0, schematics_1.chain)([
90
108
  (0, schematics_1.mergeWith)(templateStoreSource),
91
109
  commonEntityRule,
@@ -7,7 +7,7 @@ export interface SchemaOptions {
7
7
  /**
8
8
  * La ruta donde se generará el archivo.
9
9
  */
10
- path?: string;
10
+ path: string;
11
11
 
12
12
  /**
13
13
  * Indica si se deben generar archivos adicionales para formularios y entidades.
@@ -13,7 +13,18 @@
13
13
  "path": {
14
14
  "type": "string",
15
15
  "description": "Ruta de destino.",
16
- "default": "src/app/store"
16
+ "default": "src/app/core"
17
+ },
18
+ "generateExtras": {
19
+ "type": "boolean",
20
+ "description": "¿Generar archivos adicionales para formularios y entidades?",
21
+ "default": false
22
+ },
23
+ "language": {
24
+ "type": "string",
25
+ "description": "Idioma para la pluralización ('en' para inglés, 'es' para español).",
26
+ "enum": ["en", "es"],
27
+ "default": "en"
17
28
  }
18
29
  },
19
30
  "required": ["name"]