ngx-essentials-schematics 0.0.14 → 0.0.16

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": "ngx-essentials-schematics",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "description": "A collection of Angular schematics for essential functionalities.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,3 +1,4 @@
1
1
  import { Rule } from "@angular-devkit/schematics";
2
- import { NgAddSchema } from "./schema";
3
- export declare function ngAdd(options: NgAddSchema): Rule;
2
+ export declare function ngAdd(options: {
3
+ primaryKey: string;
4
+ }): Rule;
@@ -2,31 +2,69 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ngAdd = ngAdd;
4
4
  const schematics_1 = require("@angular-devkit/schematics");
5
+ const tasks_1 = require("@angular-devkit/schematics/tasks");
5
6
  function ngAdd(options) {
6
7
  return (tree, _context) => {
7
- const workspacePath = "/angular.json";
8
- const buffer = tree.read(workspacePath);
8
+ const packagePath = "/package.json";
9
+ const buffer = tree.read(packagePath);
9
10
  if (!buffer) {
10
- throw new schematics_1.SchematicsException("Could not find angular.json");
11
+ throw new schematics_1.SchematicsException("Could not find package.json. Make sure you are in the root of an Angular project.");
11
12
  }
12
- const workspace = JSON.parse(buffer.toString());
13
- if (!workspace.cli) {
14
- workspace.cli = {};
13
+ const packageJson = JSON.parse(buffer.toString());
14
+ // 1. Obtener la versión de Angular Core
15
+ const angularCoreVer = packageJson.dependencies["@angular/core"] ||
16
+ packageJson.devDependencies["@angular/core"];
17
+ if (!angularCoreVer) {
18
+ throw new schematics_1.SchematicsException("The version of @angular/core could not be determined. Please ensure that Angular is installed in your project.");
15
19
  }
16
- const collections = workspace.cli.schematicCollections || [];
17
- if (!collections.includes("ngx-essentials-schematics")) {
18
- collections.push("ngx-essentials-schematics");
20
+ const mainVersion = parseInt(angularCoreVer.replace(/[^\d.]/g, "").split(".")[0], 10);
21
+ // 2. Validación: NgRx Signals requiere Angular 16+ (v17+ recomendado)
22
+ if (mainVersion < 16) {
23
+ _context.logger.error(`❌ Error: ngx-essentials requires Angular v16 or higher. Detected: v${mainVersion}`);
24
+ return tree; // Stop execution
19
25
  }
20
- workspace.cli.schematicCollections = collections;
21
- if (!workspace.schematics) {
22
- workspace.schematics = {};
26
+ // 3. Mapear versión de NgRx (NgRx suele ir a la par con Angular)
27
+ const ngrxVersion = `^${mainVersion}.0.0`;
28
+ _context.logger.info(`📦 Configuring dependencies for Angular v${mainVersion}...`);
29
+ // 4. Modificar package.json
30
+ const packageName = "ngx-essentials-schematics";
31
+ // Inyectar dependencias compatibles
32
+ packageJson.dependencies = Object.assign(Object.assign({}, packageJson.dependencies), { "@ngrx/signals": ngrxVersion });
33
+ // Mover a devDependencies si es necesario
34
+ if (packageJson.dependencies[packageName]) {
35
+ const currentVer = packageJson.dependencies[packageName];
36
+ delete packageJson.dependencies[packageName];
37
+ packageJson.devDependencies = Object.assign(Object.assign({}, packageJson.devDependencies), { [packageName]: currentVer });
23
38
  }
24
- workspace.schematics["ngx-essentials-schematics:all"] = {
25
- pk: options.pk,
26
- };
27
- tree.overwrite(workspacePath, JSON.stringify(workspace, null, 2));
28
- _context.logger.info("✅ Configuration completed. Your default Primary Key is: " + options.pk);
39
+ tree.overwrite(packagePath, JSON.stringify(packageJson, null, 2));
40
+ // 5. Configurar angular.json (Collections y Primary Key)
41
+ updateAngularJson(tree, options);
42
+ // 6. Tarea de instalación
43
+ _context.addTask(new tasks_1.NodePackageInstallTask());
29
44
  return tree;
30
45
  };
31
46
  }
47
+ // Función auxiliar para mantener el código limpio
48
+ function updateAngularJson(tree, options) {
49
+ const path = "/angular.json";
50
+ const buffer = tree.read(path);
51
+ if (!buffer)
52
+ return;
53
+ const workspace = JSON.parse(buffer.toString());
54
+ // Agregar a schematicCollections
55
+ if (!workspace.cli)
56
+ workspace.cli = {};
57
+ const collections = workspace.cli.schematicCollections || [];
58
+ if (!collections.includes("ngx-essentials-schematics")) {
59
+ collections.push("ngx-essentials-schematics");
60
+ workspace.cli.schematicCollections = collections;
61
+ }
62
+ // Guardar configuración global
63
+ if (!workspace.schematics)
64
+ workspace.schematics = {};
65
+ workspace.schematics["ngx-essentials-schematics:all"] = {
66
+ primaryKey: options.primaryKey,
67
+ };
68
+ tree.overwrite(path, JSON.stringify(workspace, null, 2));
69
+ }
32
70
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "http://json-schema.org/schema",
3
- "id": "ng-add-schema",
3
+ "$id": "ng-add-schema",
4
4
  "type": "object",
5
5
  "properties": {
6
6
  "pk": {