@barcidev/ngx-autogen 0.1.8 → 0.1.10

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": "@barcidev/ngx-autogen",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "A collection of Angular schematics for essential functionalities.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -38,7 +38,9 @@ function transloco(options) {
38
38
  .replace(process.cwd(), "")
39
39
  .replace(/\\/g, "/");
40
40
  const directory = tree.getDir((0, path_1.normalize)(relativeExecutionPath));
41
+ console.log(`🔍 Buscando componente en: ${relativeExecutionPath}`);
41
42
  const componentFile = directory.subfiles.find((file) => file.endsWith(".component.ts"));
43
+ console.log(`📄 Componente detectado: ${componentFile || "Ninguno"}`);
42
44
  if (!componentFile && !options.name) {
43
45
  throw new schematics_1.SchematicsException("❌ No se encontró un archivo *.component.ts en este directorio.");
44
46
  }
@@ -46,12 +48,14 @@ function transloco(options) {
46
48
  ? componentFile.replace(".component.ts", "")
47
49
  : options.name;
48
50
  options.name = componentFileName;
51
+ console.log(`✅ Nombre del componente para i18n: ${options.name}`);
49
52
  // 3. Determinación de rutas para generación de archivos
50
53
  const srcIndex = fullPath.lastIndexOf("src");
51
54
  const relativePath = srcIndex !== -1
52
55
  ? fullPath.substring(srcIndex)
53
56
  : (0, path_1.join)((0, path_1.normalize)("src"), "app");
54
57
  options.path = (0, path_1.normalize)(relativePath);
58
+ console.log(`📂 Ruta de generación de archivos i18n: ${options.path}`);
55
59
  const namePath = options.path; // Generamos archivos en la misma carpeta del componente detectado
56
60
  const rules = [];
57
61
  // 4. Verificación de instalación de Transloco (Idempotencia)
@@ -94,6 +98,7 @@ function transloco(options) {
94
98
  if (componentFile) {
95
99
  const componentPath = (0, path_1.join)(namePath, componentFile);
96
100
  const i18nConstantName = `${schematics_1.strings.camelize(options.name)}I18n`;
101
+ console.log(`🔗 Registrando scope de Transloco en ${componentFile} con constante ${i18nConstantName}, este es el path: ${componentPath}`);
97
102
  rules.push((0, file_actions_1.addProviderToStandaloneComponent)(componentPath, `provideTranslocoScopeWrapper(${i18nConstantName})`, [
98
103
  {
99
104
  symbol: `provideTranslocoScopeWrapper`,
@@ -107,7 +112,42 @@ function transloco(options) {
107
112
  }
108
113
  // 7. Sincronización de archivos i18n comunes
109
114
  rules.push((0, file_actions_1.mergeFilesSmart)("./files/i18n", "src/app/i18n", options, tree));
115
+ updateTsConfig(tree);
110
116
  return (0, schematics_1.chain)(rules);
111
117
  });
118
+ function updateTsConfig(tree) {
119
+ const tsConfigPath = "/tsconfig.json";
120
+ const path = tree.exists(tsConfigPath)
121
+ ? tsConfigPath
122
+ : "/tsconfig.app.json";
123
+ const buffer = tree.read(path);
124
+ if (!buffer)
125
+ return;
126
+ let contentText = buffer.toString();
127
+ // Limpieza manual de comentarios para evitar que JSON.parse falle
128
+ const cleanJson = contentText.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm, "$1");
129
+ let tsconfig;
130
+ try {
131
+ tsconfig = JSON.parse(cleanJson);
132
+ }
133
+ catch (e) {
134
+ // Si falla, intentamos parsearlo tal cual por si no tiene comentarios
135
+ try {
136
+ tsconfig = JSON.parse(contentText);
137
+ }
138
+ catch (innerError) {
139
+ throw new schematics_1.SchematicsException(`No se pudo parsear ${path}. Asegúrate de que es un JSON válido.`);
140
+ }
141
+ }
142
+ // Configurar los paths
143
+ tsconfig.compilerOptions = tsconfig.compilerOptions || {};
144
+ tsconfig.compilerOptions.paths = tsconfig.compilerOptions.paths || {};
145
+ const sharedAlias = "@i18n/*";
146
+ const sharedPath = ["src/app/i18n/*"];
147
+ if (!tsconfig.compilerOptions.paths[sharedAlias]) {
148
+ tsconfig.compilerOptions.paths[sharedAlias] = sharedPath;
149
+ tree.overwrite(path, JSON.stringify(tsconfig, null, 2));
150
+ }
151
+ }
112
152
  }
113
153
  //# sourceMappingURL=index.js.map