@barcidev/ngx-autogen 0.1.30 → 0.1.32
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 -1
- package/src/transloco/index.js +23 -3
package/package.json
CHANGED
package/src/transloco/index.js
CHANGED
|
@@ -33,6 +33,7 @@ function transloco(options) {
|
|
|
33
33
|
// Sincronizamos las opciones normalizadas
|
|
34
34
|
const finalOptions = Object.assign(Object.assign({}, options), { name: componentName, path: path, project: projectName, projectRoot: projectRoot });
|
|
35
35
|
return (0, schematics_1.chain)([
|
|
36
|
+
ensureExternalConfig(),
|
|
36
37
|
generateI18nFiles(finalOptions),
|
|
37
38
|
updateAppI18nTypeRule(finalOptions),
|
|
38
39
|
registerProviderInComponent(finalOptions, componentFile),
|
|
@@ -42,14 +43,33 @@ function transloco(options) {
|
|
|
42
43
|
/**
|
|
43
44
|
* --- REGLAS FUNCIONALES ---
|
|
44
45
|
*/
|
|
45
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Verifica si se requiere el setup global y lo ejecuta.
|
|
48
|
+
* Esto evita el Overlapping edit al no leer archivos antes de tiempo.
|
|
49
|
+
*/
|
|
50
|
+
function ensureExternalConfig() {
|
|
51
|
+
return (tree) => {
|
|
52
|
+
const appConfigPath = "src/app/app.config.ts";
|
|
53
|
+
// Si el archivo no existe, quizás es una app con NgModules,
|
|
54
|
+
// pero si existe y no tiene el provider, corremos el external.
|
|
55
|
+
if (tree.exists(appConfigPath)) {
|
|
56
|
+
const content = tree.read(appConfigPath).toString();
|
|
57
|
+
if (!content.includes("provideTransloco")) {
|
|
58
|
+
// Retornamos el schematic externo pasándole el proyecto explícitamente
|
|
59
|
+
return (0, schematics_1.externalSchematic)("@barcidev/typed-transloco", "ng-add", {});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return tree;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
// Generación de archivos desde plantillas
|
|
46
66
|
function generateI18nFiles(options) {
|
|
47
67
|
return (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)("./files/component"), [
|
|
48
68
|
(0, schematics_1.applyTemplates)(Object.assign(Object.assign(Object.assign({}, schematics_1.strings), options), { pluralize: (word) => options.lang === "es" ? (0, pluralize_1.pluralizeEs)(word) : (0, pluralize_1.pluralizeEn)(word) })),
|
|
49
69
|
(0, schematics_1.move)(options.path),
|
|
50
70
|
]));
|
|
51
71
|
}
|
|
52
|
-
//
|
|
72
|
+
// Actualización del archivo de tipos global
|
|
53
73
|
function updateAppI18nTypeRule(options) {
|
|
54
74
|
return (tree, context) => {
|
|
55
75
|
const i18nFilePath = `${options.projectRoot}/app/i18n/app.i18n.ts`;
|
|
@@ -87,7 +107,7 @@ function updateAppI18nTypeRule(options) {
|
|
|
87
107
|
return tree;
|
|
88
108
|
};
|
|
89
109
|
}
|
|
90
|
-
//
|
|
110
|
+
// Registro de Provider en el componente
|
|
91
111
|
function registerProviderInComponent(options, componentFile) {
|
|
92
112
|
if (!componentFile)
|
|
93
113
|
return (tree) => tree;
|