ngx-essentials-schematics 0.0.5 → 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 +1 -3
- package/src/ngrx/store/index.d.ts +0 -5
- package/src/ngrx/store/index.js +65 -17
- package/src/ngrx/store/schema.d.ts +10 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ngx-essentials-schematics",
|
|
3
|
-
"version": "0.0.
|
|
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": {
|
|
@@ -24,13 +24,11 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@angular-devkit/core": "^20.3.13",
|
|
26
26
|
"@angular-devkit/schematics": "^20.3.13",
|
|
27
|
-
"pluralize": "^8.0.0",
|
|
28
27
|
"typescript": "~5.9.2"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|
|
31
30
|
"@types/jasmine": "~5.1.0",
|
|
32
31
|
"@types/node": "^20.17.19",
|
|
33
|
-
"@types/pluralize": "^0.0.33",
|
|
34
32
|
"copyfiles": "^2.4.1",
|
|
35
33
|
"jasmine": "^5.0.0"
|
|
36
34
|
}
|
|
@@ -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;
|
package/src/ngrx/store/index.js
CHANGED
|
@@ -3,16 +3,63 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.signalStore = signalStore;
|
|
4
4
|
const core_1 = require("@angular-devkit/core");
|
|
5
5
|
const schematics_1 = require("@angular-devkit/schematics");
|
|
6
|
-
const
|
|
6
|
+
const pluralizeEs = (name) => {
|
|
7
|
+
if (!name)
|
|
8
|
+
return name;
|
|
9
|
+
const lastChar = name.slice(-1).toLowerCase();
|
|
10
|
+
const vowels = ["a", "e", "i", "o", "u"];
|
|
11
|
+
if (vowels.includes(lastChar))
|
|
12
|
+
return name + "s";
|
|
13
|
+
if (lastChar === "z")
|
|
14
|
+
return name.slice(0, -1) + "ces";
|
|
15
|
+
return name + "es";
|
|
16
|
+
};
|
|
17
|
+
const pluralizeEn = (name) => {
|
|
18
|
+
if (!name)
|
|
19
|
+
return name;
|
|
20
|
+
const lastChar = name.slice(-1).toLowerCase();
|
|
21
|
+
const vowels = ["a", "e", "i", "o", "u"];
|
|
22
|
+
if (lastChar === "y" && !vowels.includes(name.slice(-2, -1).toLowerCase())) {
|
|
23
|
+
return name.slice(0, -1) + "ies";
|
|
24
|
+
}
|
|
25
|
+
if (["s", "x", "z", "ch", "sh"].some((end) => name.toLowerCase().endsWith(end))) {
|
|
26
|
+
return name + "es";
|
|
27
|
+
}
|
|
28
|
+
return name + "s";
|
|
29
|
+
};
|
|
7
30
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @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.
|
|
11
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
|
|
12
57
|
function signalStore(options) {
|
|
13
58
|
return (tree) => {
|
|
59
|
+
treeRef = tree;
|
|
14
60
|
const defaultPath = "src/app/core";
|
|
15
61
|
const movePath = (0, core_1.normalize)(options.path || defaultPath);
|
|
62
|
+
// 1. Manejo del Index Principal (Export)
|
|
16
63
|
const indexPath = (0, core_1.join)(movePath, "index.ts");
|
|
17
64
|
const exportLine = `export * from './${core_1.strings.dasherize(options.name)}/${core_1.strings.dasherize(options.name)}.store';\n`;
|
|
18
65
|
if (tree.exists(indexPath)) {
|
|
@@ -24,24 +71,25 @@ function signalStore(options) {
|
|
|
24
71
|
else {
|
|
25
72
|
tree.create(indexPath, exportLine);
|
|
26
73
|
}
|
|
27
|
-
|
|
74
|
+
// 2. Archivos de la Store (Estos se crean siempre en carpeta nueva)
|
|
75
|
+
const templateStoreSource = (0, schematics_1.apply)((0, schematics_1.url)("./files/store"), [
|
|
28
76
|
(0, schematics_1.applyTemplates)(Object.assign(Object.assign(Object.assign({}, core_1.strings), options), { pluralize: (word) => {
|
|
29
|
-
|
|
77
|
+
switch (options.language) {
|
|
78
|
+
case "es":
|
|
79
|
+
return pluralizeEs(word);
|
|
80
|
+
default:
|
|
81
|
+
return pluralizeEn(word);
|
|
82
|
+
}
|
|
30
83
|
} })),
|
|
31
|
-
(0, schematics_1.move)(
|
|
32
|
-
]);
|
|
33
|
-
const templateFormSource = (0, schematics_1.apply)((0, schematics_1.url)("./files/form"), [
|
|
34
|
-
(0, schematics_1.applyTemplates)(Object.assign(Object.assign({}, core_1.strings), options)),
|
|
35
|
-
(0, schematics_1.move)(defaultPath + "/common/form"),
|
|
36
|
-
]);
|
|
37
|
-
const templateStoreSource = (0, schematics_1.apply)((0, schematics_1.url)("./files/store"), [
|
|
38
|
-
(0, schematics_1.applyTemplates)(Object.assign(Object.assign({}, core_1.strings), options)),
|
|
39
|
-
(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))),
|
|
40
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);
|
|
41
89
|
return (0, schematics_1.chain)([
|
|
42
90
|
(0, schematics_1.mergeWith)(templateStoreSource),
|
|
43
|
-
|
|
44
|
-
|
|
91
|
+
commonEntityRule,
|
|
92
|
+
commonFormRule,
|
|
45
93
|
]);
|
|
46
94
|
};
|
|
47
95
|
}
|
|
@@ -8,4 +8,14 @@ export interface SchemaOptions {
|
|
|
8
8
|
* La ruta donde se generará el archivo.
|
|
9
9
|
*/
|
|
10
10
|
path?: string;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Indica si se deben generar archivos adicionales para formularios y entidades.
|
|
14
|
+
*/
|
|
15
|
+
generateExtras?: boolean;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* El idioma para la pluralización ('en' para inglés, 'es' para español).
|
|
19
|
+
*/
|
|
20
|
+
language?: "en" | "es";
|
|
11
21
|
}
|