@barcidev/ngx-autogen 0.1.35 → 0.1.37
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/common/file-actions.d.ts +2 -2
- package/src/common/file-actions.js +34 -34
- package/src/ng-add/index.d.ts +1 -2
- package/src/ng-add/index.js +36 -93
- package/src/ngrx/store/index.js +155 -85
- package/src/ngrx/store/schema.d.ts +1 -0
- package/src/transloco/index.js +3 -3
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@ export declare const mergeFilesSmart: (urlPath: string, destPath: string, option
|
|
|
3
3
|
/**
|
|
4
4
|
* Añade un provider a un componente Standalone y gestiona sus imports.
|
|
5
5
|
*/
|
|
6
|
-
export declare function
|
|
6
|
+
export declare function addMetadataToStandaloneComponent(componentPath: string, symbolName: string, importSources: {
|
|
7
7
|
symbol: string;
|
|
8
8
|
path: string;
|
|
9
|
-
}[]): Rule;
|
|
9
|
+
}[], metadataField?: "providers" | "imports"): Rule;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mergeFilesSmart = void 0;
|
|
4
|
-
exports.
|
|
4
|
+
exports.addMetadataToStandaloneComponent = addMetadataToStandaloneComponent;
|
|
5
5
|
const schematics_1 = require("@angular-devkit/schematics");
|
|
6
6
|
const change_1 = require("@schematics/angular/utility/change");
|
|
7
7
|
const ts = require("typescript");
|
|
@@ -26,58 +26,58 @@ exports.mergeFilesSmart = mergeFilesSmart;
|
|
|
26
26
|
/**
|
|
27
27
|
* Añade un provider a un componente Standalone y gestiona sus imports.
|
|
28
28
|
*/
|
|
29
|
-
function
|
|
29
|
+
function addMetadataToStandaloneComponent(componentPath, symbolName, importSources, metadataField = "imports") {
|
|
30
30
|
return (tree) => {
|
|
31
|
-
var _a;
|
|
32
31
|
const text = tree.read(componentPath);
|
|
33
32
|
if (!text)
|
|
34
33
|
throw new schematics_2.SchematicsException(`No se encontró el archivo: ${componentPath}`);
|
|
35
34
|
const sourceText = text.toString("utf-8");
|
|
36
35
|
const source = ts.createSourceFile(componentPath, sourceText, ts.ScriptTarget.Latest, true);
|
|
37
36
|
const recorder = tree.beginUpdate(componentPath);
|
|
38
|
-
// 1. Gestionar Imports
|
|
39
|
-
|
|
37
|
+
// 1. Gestionar Imports de TypeScript (Cabecera del archivo)
|
|
38
|
+
importSources.forEach((item) => {
|
|
40
39
|
const importChange = (0, ast_utils_1.insertImport)(source, componentPath, item.symbol, item.path);
|
|
41
40
|
if (importChange instanceof change_1.InsertChange) {
|
|
42
41
|
recorder.insertLeft(importChange.pos, importChange.toAdd);
|
|
43
42
|
}
|
|
44
43
|
});
|
|
45
|
-
// 2. Buscar el decorador @Component
|
|
44
|
+
// 2. Buscar la clase con el decorador @Component
|
|
46
45
|
const componentClass = source.statements.find((s) => {
|
|
47
46
|
var _a;
|
|
48
47
|
return ts.isClassDeclaration(s) &&
|
|
49
|
-
!!((_a =
|
|
48
|
+
!!((_a = ts
|
|
49
|
+
.getDecorators(s)) === null || _a === void 0 ? void 0 : _a.some((d) => ts.isCallExpression(d.expression) &&
|
|
50
|
+
ts.isIdentifier(d.expression.expression) &&
|
|
51
|
+
d.expression.expression.text === "Component"));
|
|
50
52
|
});
|
|
51
53
|
if (!componentClass)
|
|
52
54
|
return tree;
|
|
53
|
-
const decorator =
|
|
54
|
-
.getDecorators(componentClass)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
? elements[elements.length - 1].getEnd()
|
|
70
|
-
: providersProp.initializer.getStart() + 1;
|
|
71
|
-
const toAdd = elements.length > 0 ? `, ${providerName}` : providerName;
|
|
72
|
-
recorder.insertRight(pos, toAdd);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
// Caso: El array de providers NO existe, lo creamos
|
|
76
|
-
const pos = objectLiteral.getStart() + 1;
|
|
77
|
-
const toAdd = `\n providers: [${providerName}],`;
|
|
78
|
-
recorder.insertRight(pos, toAdd);
|
|
79
|
-
}
|
|
55
|
+
const decorator = ts
|
|
56
|
+
.getDecorators(componentClass)
|
|
57
|
+
.find((d) => d.expression.expression.getText() ===
|
|
58
|
+
"Component");
|
|
59
|
+
const callExpr = decorator.expression;
|
|
60
|
+
const objectLiteral = callExpr.arguments[0];
|
|
61
|
+
// 3. Buscar la propiedad específica (imports o providers)
|
|
62
|
+
const targetProp = objectLiteral.properties.find((p) => ts.isPropertyAssignment(p) &&
|
|
63
|
+
ts.isIdentifier(p.name) &&
|
|
64
|
+
p.name.text === metadataField);
|
|
65
|
+
if (targetProp && ts.isArrayLiteralExpression(targetProp.initializer)) {
|
|
66
|
+
// CASO A: El array YA existe
|
|
67
|
+
const elements = targetProp.initializer.elements;
|
|
68
|
+
if (elements.length > 0) {
|
|
69
|
+
const lastElement = elements[elements.length - 1];
|
|
70
|
+
recorder.insertRight(lastElement.getEnd(), `, ${symbolName}`);
|
|
80
71
|
}
|
|
72
|
+
else {
|
|
73
|
+
recorder.insertRight(targetProp.initializer.getStart() + 1, symbolName);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
// CASO B: La propiedad NO existe, la creamos al inicio del objeto
|
|
78
|
+
const pos = objectLiteral.getStart() + 1;
|
|
79
|
+
const toAdd = `\n ${metadataField}: [${symbolName}],`;
|
|
80
|
+
recorder.insertRight(pos, toAdd);
|
|
81
81
|
}
|
|
82
82
|
tree.commitUpdate(recorder);
|
|
83
83
|
return tree;
|
package/src/ng-add/index.d.ts
CHANGED
package/src/ng-add/index.js
CHANGED
|
@@ -2,105 +2,48 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ngAdd = ngAdd;
|
|
4
4
|
const schematics_1 = require("@angular-devkit/schematics");
|
|
5
|
-
const
|
|
6
|
-
function ngAdd(
|
|
7
|
-
return (
|
|
8
|
-
|
|
9
|
-
const buffer = tree.read(packagePath);
|
|
10
|
-
if (!buffer) {
|
|
11
|
-
throw new schematics_1.SchematicsException("Could not find package.json. Make sure you are in the root of an Angular project.");
|
|
12
|
-
}
|
|
13
|
-
const packageJson = JSON.parse(buffer.toString());
|
|
14
|
-
const angularCoreVer = packageJson.dependencies["@angular/core"] ||
|
|
15
|
-
packageJson.devDependencies["@angular/core"];
|
|
16
|
-
if (!angularCoreVer) {
|
|
17
|
-
throw new schematics_1.SchematicsException("The version of @angular/core could not be determined. Please ensure that Angular is installed in your project.");
|
|
18
|
-
}
|
|
19
|
-
const mainVersion = parseInt(angularCoreVer.replace(/[^\d.]/g, "").split(".")[0], 10);
|
|
20
|
-
if (mainVersion < 20) {
|
|
21
|
-
_context.logger.error(`❌ Error: @barcidev/ngx-autogen requires Angular v20 or higher. Detected: v${mainVersion}`);
|
|
22
|
-
return tree; // Stop execution
|
|
23
|
-
}
|
|
24
|
-
const ngrxVersion = `^${mainVersion}.0.0`;
|
|
25
|
-
_context.logger.info(`📦 Configuring dependencies for Angular v${mainVersion}...`);
|
|
26
|
-
const packageName = "@barcidev/ngx-autogen";
|
|
27
|
-
packageJson.dependencies = Object.assign(Object.assign({}, packageJson.dependencies), { "@ngrx/signals": ngrxVersion });
|
|
28
|
-
if (packageJson.dependencies[packageName]) {
|
|
29
|
-
const currentVer = packageJson.dependencies[packageName];
|
|
30
|
-
delete packageJson.dependencies[packageName];
|
|
31
|
-
packageJson.devDependencies = Object.assign(Object.assign({}, packageJson.devDependencies), { [packageName]: currentVer });
|
|
32
|
-
}
|
|
33
|
-
packageJson.dependencies = sortObjectKeys(packageJson.dependencies);
|
|
34
|
-
packageJson.devDependencies = sortObjectKeys(packageJson.devDependencies);
|
|
35
|
-
tree.overwrite(packagePath, JSON.stringify(packageJson, null, 2));
|
|
36
|
-
updateAngularJson(tree, options);
|
|
37
|
-
updateTsConfig(tree);
|
|
38
|
-
_context.addTask(new tasks_1.NodePackageInstallTask());
|
|
39
|
-
return tree;
|
|
5
|
+
const LIBRARY_NAME = "@barcidev/ngx-autogen";
|
|
6
|
+
function ngAdd() {
|
|
7
|
+
return () => {
|
|
8
|
+
return (0, schematics_1.chain)([cleanupPackageJson(), registerInAngularJson()]);
|
|
40
9
|
};
|
|
41
10
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (!collections.includes("@barcidev/ngx-autogen")) {
|
|
60
|
-
collections.push("@barcidev/ngx-autogen");
|
|
61
|
-
workspace.cli.schematicCollections = collections;
|
|
62
|
-
}
|
|
63
|
-
if (!workspace.schematics)
|
|
64
|
-
workspace.schematics = {};
|
|
65
|
-
workspace.schematics["@barcidev/ngx-autogen:all"] = {
|
|
66
|
-
pk: options.pk,
|
|
67
|
-
lang: options.lang,
|
|
11
|
+
/**
|
|
12
|
+
* Regla: Mueve la lib a devDependencies
|
|
13
|
+
*/
|
|
14
|
+
function cleanupPackageJson() {
|
|
15
|
+
return (tree) => {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
const content = (_a = tree.read("package.json")) === null || _a === void 0 ? void 0 : _a.toString();
|
|
18
|
+
if (!content)
|
|
19
|
+
return tree;
|
|
20
|
+
const json = JSON.parse(content);
|
|
21
|
+
if ((_b = json.dependencies) === null || _b === void 0 ? void 0 : _b[LIBRARY_NAME]) {
|
|
22
|
+
const ver = json.dependencies[LIBRARY_NAME];
|
|
23
|
+
delete json.dependencies[LIBRARY_NAME];
|
|
24
|
+
json.devDependencies = Object.assign(Object.assign({}, json.devDependencies), { [LIBRARY_NAME]: ver });
|
|
25
|
+
tree.overwrite("package.json", JSON.stringify(json, null, 2));
|
|
26
|
+
}
|
|
27
|
+
return tree;
|
|
68
28
|
};
|
|
69
|
-
tree.overwrite(path, JSON.stringify(workspace, null, 2));
|
|
70
29
|
}
|
|
71
30
|
/**
|
|
72
|
-
* Configura
|
|
31
|
+
* Regla: Configura la CLI de Angular
|
|
73
32
|
*/
|
|
74
|
-
function
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
catch (e) {
|
|
88
|
-
// Si falla, intentamos parsearlo tal cual por si no tiene comentarios
|
|
89
|
-
try {
|
|
90
|
-
tsconfig = JSON.parse(contentText);
|
|
33
|
+
function registerInAngularJson() {
|
|
34
|
+
return (tree) => {
|
|
35
|
+
const buffer = tree.read("angular.json");
|
|
36
|
+
if (!buffer)
|
|
37
|
+
return tree;
|
|
38
|
+
const json = JSON.parse(buffer.toString());
|
|
39
|
+
json.cli = json.cli || {};
|
|
40
|
+
const collections = json.cli.schematicCollections || [];
|
|
41
|
+
if (!collections.includes(LIBRARY_NAME)) {
|
|
42
|
+
collections.push(LIBRARY_NAME);
|
|
43
|
+
json.cli.schematicCollections = collections;
|
|
44
|
+
tree.overwrite("angular.json", JSON.stringify(json, null, 2));
|
|
91
45
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
// Configurar los paths
|
|
97
|
-
tsconfig.compilerOptions = tsconfig.compilerOptions || {};
|
|
98
|
-
tsconfig.compilerOptions.paths = tsconfig.compilerOptions.paths || {};
|
|
99
|
-
const sharedAlias = "@shared-state/*";
|
|
100
|
-
const sharedPath = ["src/app/shared/state/*"];
|
|
101
|
-
if (!tsconfig.compilerOptions.paths[sharedAlias]) {
|
|
102
|
-
tsconfig.compilerOptions.paths[sharedAlias] = sharedPath;
|
|
103
|
-
tree.overwrite(path, JSON.stringify(tsconfig, null, 2));
|
|
104
|
-
}
|
|
46
|
+
return tree;
|
|
47
|
+
};
|
|
105
48
|
}
|
|
106
49
|
//# sourceMappingURL=index.js.map
|
package/src/ngrx/store/index.js
CHANGED
|
@@ -12,40 +12,98 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.signalStore = signalStore;
|
|
13
13
|
const core_1 = require("@angular-devkit/core");
|
|
14
14
|
const schematics_1 = require("@angular-devkit/schematics");
|
|
15
|
+
const tasks_1 = require("@angular-devkit/schematics/tasks");
|
|
16
|
+
const dependencies_1 = require("@schematics/angular/utility/dependencies");
|
|
15
17
|
const workspace_1 = require("@schematics/angular/utility/workspace");
|
|
18
|
+
const jsonc_parser_1 = require("jsonc-parser");
|
|
16
19
|
const file_actions_1 = require("../../common/file-actions");
|
|
17
20
|
const pluralize_1 = require("../../common/pluralize");
|
|
21
|
+
const NGRX_SIGNALS = "@ngrx/signals";
|
|
18
22
|
function signalStore(options) {
|
|
19
23
|
return (tree) => __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
var _a;
|
|
21
24
|
const workspace = yield (0, workspace_1.getWorkspace)(tree);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
25
|
+
// 1. Preparar contexto y opciones enriquecidas
|
|
26
|
+
const context = resolveStoreContext(workspace, options);
|
|
27
|
+
const project = workspace.projects.get(context.projectName);
|
|
28
|
+
const projectRoot = (project === null || project === void 0 ? void 0 : project.sourceRoot) || "src";
|
|
29
|
+
const { angularVersion } = getProjectMetadata(tree);
|
|
30
|
+
// 2. Orquestar la ejecución
|
|
31
|
+
return (0, schematics_1.chain)([
|
|
32
|
+
ensureNgrxSignals(angularVersion),
|
|
33
|
+
updateIndexFile(context),
|
|
34
|
+
generateStoreFiles(context),
|
|
35
|
+
(0, file_actions_1.mergeFilesSmart)("./files/entity", "src/app/shared/state", context.options, tree),
|
|
36
|
+
updateAngularJson(context.options),
|
|
37
|
+
updateTsConfigRule(projectRoot),
|
|
38
|
+
(host, context) => {
|
|
39
|
+
context.addTask(new tasks_1.NodePackageInstallTask());
|
|
40
|
+
context.logger.info("🚀 Entorno preparado con éxito.");
|
|
41
|
+
return host;
|
|
42
|
+
},
|
|
43
|
+
]);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* --- LÓGICA DE EXTRACCIÓN Y PREPARACIÓN ---
|
|
48
|
+
*/
|
|
49
|
+
function getProjectMetadata(tree) {
|
|
50
|
+
var _a, _b;
|
|
51
|
+
const buffer = tree.read("package.json");
|
|
52
|
+
if (!buffer)
|
|
53
|
+
throw new schematics_1.SchematicsException("No se encontró package.json");
|
|
54
|
+
const packageJson = JSON.parse(buffer.toString());
|
|
55
|
+
const angularCore = ((_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a["@angular/core"]) ||
|
|
56
|
+
((_b = packageJson.devDependencies) === null || _b === void 0 ? void 0 : _b["@angular/core"]);
|
|
57
|
+
const angularVersion = parseInt(angularCore.replace(/[^\d.]/g, "").split(".")[0], 10);
|
|
58
|
+
return { angularVersion };
|
|
59
|
+
}
|
|
60
|
+
function resolveStoreContext(workspace, options) {
|
|
61
|
+
var _a;
|
|
62
|
+
// Configuración Global de PK
|
|
63
|
+
const globalConfig = (_a = workspace.extensions.schematics) === null || _a === void 0 ? void 0 : _a["@barcidev/ngx-autogen:all"];
|
|
64
|
+
const pk = options.pk || (globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.pk) || "id";
|
|
65
|
+
// Resolución de Rutas (Lógica de Directorio Actual)
|
|
66
|
+
const fullPath = process.cwd();
|
|
67
|
+
const srcIndex = fullPath.lastIndexOf("src");
|
|
68
|
+
let relativePath = srcIndex !== -1
|
|
69
|
+
? fullPath.substring(srcIndex)
|
|
70
|
+
: (0, core_1.join)((0, core_1.normalize)("src"), "app");
|
|
71
|
+
let movePath = (0, core_1.normalize)(relativePath);
|
|
72
|
+
if (!movePath.endsWith("state"))
|
|
73
|
+
movePath = (0, core_1.join)(movePath, "state");
|
|
74
|
+
// Resolución de Proyecto
|
|
75
|
+
const projectName = options.project ||
|
|
76
|
+
workspace.extensions.defaultProject ||
|
|
77
|
+
Array.from(workspace.projects.keys())[0];
|
|
78
|
+
return {
|
|
79
|
+
options: Object.assign(Object.assign({}, options), { pk, path: movePath, project: projectName }),
|
|
80
|
+
projectName,
|
|
81
|
+
movePath,
|
|
82
|
+
indexPath: (0, core_1.join)(movePath, "index.ts"),
|
|
83
|
+
nameDash: core_1.strings.dasherize(options.name),
|
|
84
|
+
entityName: core_1.strings.classify(options.name),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* --- REGLAS DE TRANSFORMACIÓN ---
|
|
89
|
+
*/
|
|
90
|
+
/**
|
|
91
|
+
* Regla: Añade @ngrx/signals si no existe
|
|
92
|
+
*/
|
|
93
|
+
function ensureNgrxSignals(version) {
|
|
94
|
+
return (tree) => {
|
|
95
|
+
(0, dependencies_1.addPackageJsonDependency)(tree, {
|
|
96
|
+
type: dependencies_1.NodeDependencyType.Default,
|
|
97
|
+
name: NGRX_SIGNALS,
|
|
98
|
+
version: `^${version}.0.0`,
|
|
99
|
+
overwrite: false, // NO sobreescribe si ya está instalado
|
|
100
|
+
});
|
|
101
|
+
return tree;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function updateIndexFile(ctx) {
|
|
105
|
+
return (tree) => {
|
|
106
|
+
const { options, indexPath, nameDash, entityName } = ctx;
|
|
49
107
|
const entityHeader = `/* ${entityName.toUpperCase()} */`;
|
|
50
108
|
const exportBlock = [
|
|
51
109
|
entityHeader,
|
|
@@ -54,70 +112,82 @@ function signalStore(options) {
|
|
|
54
112
|
`export * from './${nameDash}/${nameDash}.store';`,
|
|
55
113
|
"",
|
|
56
114
|
].join("\n");
|
|
57
|
-
let content =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
115
|
+
let content = tree.exists(indexPath)
|
|
116
|
+
? tree.read(indexPath).toString()
|
|
117
|
+
: "";
|
|
61
118
|
if (content.includes(entityHeader)) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
119
|
+
// Evitar duplicados línea por línea
|
|
120
|
+
const newLines = exportBlock
|
|
121
|
+
.split("\n")
|
|
122
|
+
.filter((line) => line.trim() !== "" && !content.includes(line));
|
|
123
|
+
if (newLines.length > 0)
|
|
124
|
+
content += newLines.join("\n") + "\n";
|
|
68
125
|
}
|
|
69
126
|
else {
|
|
70
127
|
content =
|
|
71
128
|
content.trim() + (content.length > 0 ? "\n\n" : "") + exportBlock;
|
|
72
129
|
}
|
|
73
|
-
|
|
74
|
-
tree.overwrite(indexPath, content)
|
|
130
|
+
tree.exists(indexPath)
|
|
131
|
+
? tree.overwrite(indexPath, content)
|
|
132
|
+
: tree.create(indexPath, content);
|
|
133
|
+
return tree;
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function generateStoreFiles(ctx) {
|
|
137
|
+
const { options, movePath, nameDash } = ctx;
|
|
138
|
+
const targetPath = (0, core_1.join)(movePath, nameDash);
|
|
139
|
+
const templateUtils = Object.assign(Object.assign(Object.assign({}, core_1.strings), options), { pluralize: (word) => options.lang === "es" ? (0, pluralize_1.pluralizeEs)(word) : (0, pluralize_1.pluralizeEn)(word) });
|
|
140
|
+
const createSource = (srcUrl, dest) => (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)(srcUrl), [(0, schematics_1.applyTemplates)(templateUtils), (0, schematics_1.move)(dest)]));
|
|
141
|
+
return (0, schematics_1.chain)([
|
|
142
|
+
createSource("./files/state/store", targetPath),
|
|
143
|
+
createSource("./files/state/services", (0, core_1.join)(targetPath, options.grouped ? "services" : "")),
|
|
144
|
+
createSource("./files/state/models", (0, core_1.join)(targetPath, options.grouped ? "models" : "")),
|
|
145
|
+
]);
|
|
146
|
+
}
|
|
147
|
+
function updateTsConfigRule(root) {
|
|
148
|
+
return (tree, context) => {
|
|
149
|
+
var _a, _b;
|
|
150
|
+
const tsConfigPath = tree.exists("/tsconfig.app.json")
|
|
151
|
+
? "/tsconfig.app.json"
|
|
152
|
+
: "/tsconfig.json";
|
|
153
|
+
const buffer = tree.read(tsConfigPath);
|
|
154
|
+
if (!buffer)
|
|
155
|
+
return;
|
|
156
|
+
let content = buffer.toString();
|
|
157
|
+
const modOptions = {
|
|
158
|
+
formattingOptions: { insertSpaces: true, tabSize: 2 },
|
|
159
|
+
};
|
|
160
|
+
// 1. Asegurar baseUrl
|
|
161
|
+
if (!((_a = (0, jsonc_parser_1.parse)(content).compilerOptions) === null || _a === void 0 ? void 0 : _a.baseUrl)) {
|
|
162
|
+
content = (0, jsonc_parser_1.applyEdits)(content, (0, jsonc_parser_1.modify)(content, ["compilerOptions", "baseUrl"], "./", modOptions));
|
|
75
163
|
}
|
|
76
|
-
|
|
77
|
-
|
|
164
|
+
// 2. Calcular path relativo al baseUrl
|
|
165
|
+
const baseUrl = ((_b = (0, jsonc_parser_1.parse)(content).compilerOptions) === null || _b === void 0 ? void 0 : _b.baseUrl) || "./";
|
|
166
|
+
let i18nPath = `${root}/app/shared/state/*`;
|
|
167
|
+
const normalizedBase = baseUrl.replace(/^\.\/|\/$/g, "");
|
|
168
|
+
if (normalizedBase && i18nPath.startsWith(normalizedBase)) {
|
|
169
|
+
i18nPath = i18nPath.replace(normalizedBase, "").replace(/^\//, "");
|
|
78
170
|
}
|
|
79
|
-
//
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
default:
|
|
101
|
-
return (0, pluralize_1.pluralizeEn)(word);
|
|
102
|
-
}
|
|
103
|
-
}, pk: options.pk || "id" })),
|
|
104
|
-
(0, schematics_1.move)((0, core_1.join)(namePath, options.grouped ? "services" : "")),
|
|
105
|
-
])));
|
|
106
|
-
// models
|
|
107
|
-
rules.push((0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)("./files/state/models"), [
|
|
108
|
-
(0, schematics_1.applyTemplates)(Object.assign(Object.assign(Object.assign({}, core_1.strings), options), { pluralize: (word) => {
|
|
109
|
-
switch (options.lang) {
|
|
110
|
-
case "es":
|
|
111
|
-
return (0, pluralize_1.pluralizeEs)(word);
|
|
112
|
-
default:
|
|
113
|
-
return (0, pluralize_1.pluralizeEn)(word);
|
|
114
|
-
}
|
|
115
|
-
}, pk: options.pk || "id" })),
|
|
116
|
-
(0, schematics_1.move)((0, core_1.join)(namePath, options.grouped ? "models" : "")),
|
|
117
|
-
])));
|
|
118
|
-
// common entity
|
|
119
|
-
rules.push((0, file_actions_1.mergeFilesSmart)("./files/entity", "src/app/shared/state", options, tree));
|
|
120
|
-
return (0, schematics_1.chain)(rules);
|
|
121
|
-
});
|
|
171
|
+
// 3. Aplicar alias
|
|
172
|
+
const finalContent = (0, jsonc_parser_1.applyEdits)(content, (0, jsonc_parser_1.modify)(content, ["compilerOptions", "paths", "@shared-state/*"], [i18nPath], modOptions));
|
|
173
|
+
tree.overwrite(tsConfigPath, finalContent);
|
|
174
|
+
context.logger.info(`✅ Alias @shared-state configurado.`);
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function updateAngularJson(options) {
|
|
178
|
+
return (tree) => {
|
|
179
|
+
const path = "/angular.json";
|
|
180
|
+
const buffer = tree.read(path);
|
|
181
|
+
if (!buffer)
|
|
182
|
+
return;
|
|
183
|
+
const workspace = JSON.parse(buffer.toString());
|
|
184
|
+
if (!workspace.schematics)
|
|
185
|
+
workspace.schematics = {};
|
|
186
|
+
workspace.schematics["@barcidev/ngx-autogen:signal-state"] = {
|
|
187
|
+
pk: options.pk,
|
|
188
|
+
lang: options.lang,
|
|
189
|
+
};
|
|
190
|
+
tree.overwrite(path, JSON.stringify(workspace, null, 2));
|
|
191
|
+
};
|
|
122
192
|
}
|
|
123
193
|
//# sourceMappingURL=index.js.map
|
package/src/transloco/index.js
CHANGED
|
@@ -114,7 +114,7 @@ function registerProviderInComponent(options, componentFile) {
|
|
|
114
114
|
const componentPath = (0, path_1.join)(options.path, componentFile);
|
|
115
115
|
const i18nConstantName = `${schematics_1.strings.camelize(options.name)}I18n`;
|
|
116
116
|
return (0, schematics_1.chain)([
|
|
117
|
-
(0, file_actions_1.
|
|
117
|
+
(0, file_actions_1.addMetadataToStandaloneComponent)(componentPath, `provideTranslocoScopeWrapper(${i18nConstantName})`, [
|
|
118
118
|
{
|
|
119
119
|
symbol: "provideTranslocoScopeWrapper",
|
|
120
120
|
path: "@barcidev/typed-transloco",
|
|
@@ -123,8 +123,8 @@ function registerProviderInComponent(options, componentFile) {
|
|
|
123
123
|
symbol: i18nConstantName,
|
|
124
124
|
path: `./${schematics_1.strings.dasherize(options.name)}.i18n`,
|
|
125
125
|
},
|
|
126
|
-
]),
|
|
127
|
-
(0, file_actions_1.
|
|
126
|
+
], "providers"),
|
|
127
|
+
(0, file_actions_1.addMetadataToStandaloneComponent)(componentPath, "AppTypedTranslocoDirective", [
|
|
128
128
|
{
|
|
129
129
|
symbol: "AppTypedTranslocoDirective",
|
|
130
130
|
path: "@i18n/app-typed-transloco.directive",
|