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 +1 -1
- package/src/ng-add/index.d.ts +3 -2
- package/src/ng-add/index.js +55 -17
- package/src/ng-add/schema.json +1 -1
package/package.json
CHANGED
package/src/ng-add/index.d.ts
CHANGED
package/src/ng-add/index.js
CHANGED
|
@@ -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
|
|
8
|
-
const buffer = tree.read(
|
|
8
|
+
const packagePath = "/package.json";
|
|
9
|
+
const buffer = tree.read(packagePath);
|
|
9
10
|
if (!buffer) {
|
|
10
|
-
throw new schematics_1.SchematicsException("Could not find
|
|
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
|
|
13
|
-
|
|
14
|
-
|
|
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
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
_context.
|
|
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
|