ngx-essentials-schematics 0.0.6 → 0.0.7

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.6",
3
+ "version": "0.0.7",
4
4
  "description": "A collection of Angular schematics for essential functionalities.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,8 +1,3 @@
1
1
  import { Rule } from "@angular-devkit/schematics";
2
2
  import { SchemaOptions } from "./schema";
3
- /**
4
- * Genera un Signal Store profesional para Angular 20
5
- * @param {SchemaOptions} options - Opciones del esquema
6
- * @returns {Rule} - Una regla de esquema para generar el Signal Store
7
- */
8
3
  export declare function signalStore(options: SchemaOptions): Rule;
@@ -28,14 +28,38 @@ const pluralizeEn = (name) => {
28
28
  return name + "s";
29
29
  };
30
30
  /**
31
- * Genera un Signal Store profesional para Angular 20
32
- * @param {SchemaOptions} options - Opciones del esquema
33
- * @returns {Rule} - Una regla de esquema para generar el Signal Store
31
+ * Filtra y fusiona archivos de forma segura.
32
+ * Si el archivo ya existe, comprueba si el contenido clave ya está presente.
34
33
  */
34
+ function mergeFilesSmart(urlPath, destPath, options) {
35
+ return (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)(urlPath), [
36
+ (0, schematics_1.applyTemplates)(Object.assign(Object.assign({}, core_1.strings), options)),
37
+ (0, schematics_1.move)(destPath),
38
+ (0, schematics_1.forEach)((fileEntry) => {
39
+ // Si el archivo ya existe en el árbol
40
+ if (treeRef.exists(fileEntry.path)) {
41
+ const existingContent = treeRef.read(fileEntry.path).toString();
42
+ const newContent = fileEntry.content.toString();
43
+ // Solo escribimos si el contenido nuevo no está ya incluido (basado en una cadena clave o firma)
44
+ // Puedes ajustar esta condición según lo que necesites verificar
45
+ if (existingContent.includes(newContent.trim())) {
46
+ return null; // Descarta el archivo del proceso de merge (no hace nada)
47
+ }
48
+ // Si el archivo existe pero queremos añadir contenido al final (opcional)
49
+ // treeRef.overwrite(fileEntry.path, existingContent + '\n' + newContent);
50
+ return null;
51
+ }
52
+ return fileEntry;
53
+ }),
54
+ ]));
55
+ }
56
+ let treeRef; // Referencia global temporal para el filtro forEach
35
57
  function signalStore(options) {
36
58
  return (tree) => {
59
+ treeRef = tree;
37
60
  const defaultPath = "src/app/core";
38
61
  const movePath = (0, core_1.normalize)(options.path || defaultPath);
62
+ // 1. Manejo del Index Principal (Export)
39
63
  const indexPath = (0, core_1.join)(movePath, "index.ts");
40
64
  const exportLine = `export * from './${core_1.strings.dasherize(options.name)}/${core_1.strings.dasherize(options.name)}.store';\n`;
41
65
  if (tree.exists(indexPath)) {
@@ -47,14 +71,7 @@ function signalStore(options) {
47
71
  else {
48
72
  tree.create(indexPath, exportLine);
49
73
  }
50
- const templateEntitySource = (0, schematics_1.apply)((0, schematics_1.url)("./files/entity"), [
51
- (0, schematics_1.applyTemplates)(Object.assign(Object.assign({}, core_1.strings), options)),
52
- (0, schematics_1.move)(defaultPath + "/common/entity"),
53
- ]);
54
- const templateFormSource = (0, schematics_1.apply)((0, schematics_1.url)("./files/form"), [
55
- (0, schematics_1.applyTemplates)(Object.assign(Object.assign({}, core_1.strings), options)),
56
- (0, schematics_1.move)(defaultPath + "/common/form"),
57
- ]);
74
+ // 2. Archivos de la Store (Estos se crean siempre en carpeta nueva)
58
75
  const templateStoreSource = (0, schematics_1.apply)((0, schematics_1.url)("./files/store"), [
59
76
  (0, schematics_1.applyTemplates)(Object.assign(Object.assign(Object.assign({}, core_1.strings), options), { pluralize: (word) => {
60
77
  switch (options.language) {
@@ -64,12 +81,15 @@ function signalStore(options) {
64
81
  return pluralizeEn(word);
65
82
  }
66
83
  } })),
67
- (0, schematics_1.move)(movePath + `/${core_1.strings.dasherize(options.name)}`),
84
+ (0, schematics_1.move)((0, core_1.join)(movePath, core_1.strings.dasherize(options.name))),
68
85
  ]);
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);
69
89
  return (0, schematics_1.chain)([
70
90
  (0, schematics_1.mergeWith)(templateStoreSource),
71
- (0, schematics_1.mergeWith)(templateEntitySource),
72
- (0, schematics_1.mergeWith)(templateFormSource),
91
+ commonEntityRule,
92
+ commonFormRule,
73
93
  ]);
74
94
  };
75
95
  }