@barcidev/ngx-autogen 0.1.57 → 0.1.58

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.57",
3
+ "version": "0.1.58",
4
4
  "description": "A collection of Angular schematics for essential functionalities.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -8,7 +8,7 @@ import { JsonPipe } from '@angular/common';
8
8
  imports: [<% if (store === 'Yes') { %>JsonPipe<% } %>],
9
9
  providers: [],
10
10
  selector: 'app-<%= dasherize(name) %>',
11
- styleUrls: ['./<%= dasherize(name) %>.component.scss'],
11
+ styleUrls: ['./<%= dasherize(name) %>.component.css'],
12
12
  templateUrl: './<%= dasherize(name) %>.component.html',
13
13
  })
14
14
  export class <%= classify(name) %>Component {
@@ -85,11 +85,19 @@ function resolveStoreContext(workspace, options) {
85
85
  */
86
86
  function ensureNgrxSignals(version) {
87
87
  return (tree) => {
88
+ // 1. Intentamos obtener la dependencia si ya existe
89
+ const existingDep = (0, dependencies_1.getPackageJsonDependency)(tree, NGRX_SIGNALS);
90
+ // 2. Si existe, simplemente retornamos el árbol sin hacer nada
91
+ if (existingDep) {
92
+ // Opcional: podrías loguear un mensaje aquí
93
+ return tree;
94
+ }
95
+ // 3. Si no existe, la añadimos
88
96
  (0, dependencies_1.addPackageJsonDependency)(tree, {
89
97
  type: dependencies_1.NodeDependencyType.Default,
90
98
  name: NGRX_SIGNALS,
91
99
  version: `^${version}.0.0`,
92
- overwrite: false, // NO sobreescribe si ya está instalado
100
+ overwrite: false,
93
101
  });
94
102
  return tree;
95
103
  };
@@ -1,3 +1,12 @@
1
1
  import { Rule } from "@angular-devkit/schematics";
2
+ import { ProjectDefinition } from "@schematics/angular/utility/workspace";
2
3
  import { TranslocoSchemaOptions } from "./types/types";
3
4
  export declare function transloco(options: TranslocoSchemaOptions): Rule;
5
+ /**
6
+ * --- REGLAS FUNCIONALES ---
7
+ */
8
+ /**
9
+ * Verifica si se requiere el setup global y lo ejecuta.
10
+ * Esto evita el Overlapping edit al no leer archivos antes de tiempo.
11
+ */
12
+ export declare function ensureExternalConfig(project: ProjectDefinition): Rule;
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.transloco = transloco;
13
+ exports.ensureExternalConfig = ensureExternalConfig;
13
14
  const schematics_1 = require("@angular-devkit/schematics");
14
15
  const workspace_1 = require("@schematics/angular/utility/workspace");
15
16
  const jsonc_parser_1 = require("jsonc-parser");
@@ -33,7 +34,7 @@ function transloco(options) {
33
34
  // Sincronizamos las opciones normalizadas
34
35
  const finalOptions = Object.assign(Object.assign({}, options), { name: componentName, path: path, project: projectName, projectRoot: projectRoot });
35
36
  return (0, schematics_1.chain)([
36
- ensureExternalConfig(),
37
+ ensureExternalConfig(project),
37
38
  generateI18nFiles(finalOptions),
38
39
  updateAppI18nTypeRule(finalOptions),
39
40
  registerProviderInComponent(finalOptions, componentFile),
@@ -47,20 +48,37 @@ function transloco(options) {
47
48
  * Verifica si se requiere el setup global y lo ejecuta.
48
49
  * Esto evita el Overlapping edit al no leer archivos antes de tiempo.
49
50
  */
50
- function ensureExternalConfig() {
51
- return (tree) => {
52
- const appConfigPath = "src/app/app.config.ts";
53
- const exists = tree.exists(appConfigPath);
54
- if (exists) {
55
- const content = tree.read(appConfigPath).toString();
56
- if (!content.includes("provideTransloco")) {
57
- // Al retornar el externalSchematic aquí, Angular CLI
58
- // gestiona la creación de archivos global antes de pasar a la siguiente regla del chain
59
- return (0, schematics_1.externalSchematic)("@barcidev/typed-transloco", "ng-add", {});
51
+ function ensureExternalConfig(project) {
52
+ return (tree) => __awaiter(this, void 0, void 0, function* () {
53
+ // Buscamos posibles archivos donde se registran providers
54
+ const configFiles = [
55
+ "src/app/app.config.ts", // Estándar Standalone
56
+ "src/app/app.module.ts", // Estándar basado en Módulos
57
+ getProjectMainFile(project), // Archivo definido en angular.json
58
+ ];
59
+ let providerExists = false;
60
+ for (const path of configFiles) {
61
+ if (path && tree.exists(path)) {
62
+ const content = tree.read(path).toString();
63
+ // Usamos Regex simple o mejor aún, validamos el string
64
+ if (content.includes("provideTransloco") ||
65
+ content.includes("TranslocoRootModule")) {
66
+ providerExists = true;
67
+ break;
68
+ }
60
69
  }
61
70
  }
71
+ if (!providerExists) {
72
+ return (0, schematics_1.externalSchematic)("@barcidev/typed-transloco", "ng-add", {});
73
+ }
62
74
  return tree;
63
- };
75
+ });
76
+ }
77
+ // Función auxiliar para obtener el "main" desde la configuración del proyecto
78
+ function getProjectMainFile(project) {
79
+ var _a;
80
+ const buildOptions = (_a = project.targets.get("build")) === null || _a === void 0 ? void 0 : _a.options;
81
+ return buildOptions === null || buildOptions === void 0 ? void 0 : buildOptions.main;
64
82
  }
65
83
  // Generación de archivos desde plantillas
66
84
  function generateI18nFiles(options) {