@barcidev/ngx-autogen 0.1.31 → 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 -10
package/package.json
CHANGED
package/src/transloco/index.js
CHANGED
|
@@ -19,7 +19,6 @@ const file_actions_1 = require("../common/file-actions");
|
|
|
19
19
|
const pluralize_1 = require("../common/pluralize");
|
|
20
20
|
function transloco(options) {
|
|
21
21
|
return (tree) => __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
var _a;
|
|
23
22
|
const workspace = yield (0, workspace_1.getWorkspace)(tree);
|
|
24
23
|
// 1. Configuración de Proyecto y Roots
|
|
25
24
|
const projectName = options.project ||
|
|
@@ -33,13 +32,8 @@ function transloco(options) {
|
|
|
33
32
|
const { path, componentFile, componentName } = resolveComponentContext(tree, options);
|
|
34
33
|
// Sincronizamos las opciones normalizadas
|
|
35
34
|
const finalOptions = Object.assign(Object.assign({}, options), { name: componentName, path: path, project: projectName, projectRoot: projectRoot });
|
|
36
|
-
// 3. Verificación de Provider Existente
|
|
37
|
-
const appConfigPath = "src/app/app.config.ts";
|
|
38
|
-
const appConfigContent = ((_a = tree.read(appConfigPath)) === null || _a === void 0 ? void 0 : _a.toString()) || "";
|
|
39
35
|
return (0, schematics_1.chain)([
|
|
40
|
-
|
|
41
|
-
? (0, schematics_1.externalSchematic)("@barcidev/typed-transloco", "ng-add", {})
|
|
42
|
-
: (tree) => tree,
|
|
36
|
+
ensureExternalConfig(),
|
|
43
37
|
generateI18nFiles(finalOptions),
|
|
44
38
|
updateAppI18nTypeRule(finalOptions),
|
|
45
39
|
registerProviderInComponent(finalOptions, componentFile),
|
|
@@ -49,14 +43,33 @@ function transloco(options) {
|
|
|
49
43
|
/**
|
|
50
44
|
* --- REGLAS FUNCIONALES ---
|
|
51
45
|
*/
|
|
52
|
-
|
|
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
|
|
53
66
|
function generateI18nFiles(options) {
|
|
54
67
|
return (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)("./files/component"), [
|
|
55
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) })),
|
|
56
69
|
(0, schematics_1.move)(options.path),
|
|
57
70
|
]));
|
|
58
71
|
}
|
|
59
|
-
//
|
|
72
|
+
// Actualización del archivo de tipos global
|
|
60
73
|
function updateAppI18nTypeRule(options) {
|
|
61
74
|
return (tree, context) => {
|
|
62
75
|
const i18nFilePath = `${options.projectRoot}/app/i18n/app.i18n.ts`;
|
|
@@ -94,7 +107,7 @@ function updateAppI18nTypeRule(options) {
|
|
|
94
107
|
return tree;
|
|
95
108
|
};
|
|
96
109
|
}
|
|
97
|
-
//
|
|
110
|
+
// Registro de Provider en el componente
|
|
98
111
|
function registerProviderInComponent(options, componentFile) {
|
|
99
112
|
if (!componentFile)
|
|
100
113
|
return (tree) => tree;
|