@barcidev/ngx-autogen 0.1.40 → 0.1.43
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/angular/component/files/__name@dasherize__.component.css.template +0 -0
- package/src/angular/component/files/__name@dasherize__.component.html.template +9 -0
- package/src/angular/component/files/__name@dasherize__.component.spec.ts.template +25 -0
- package/src/angular/component/files/__name@dasherize__.component.ts.template +18 -0
- package/src/angular/component/index.d.ts +3 -0
- package/src/angular/component/index.js +70 -0
- package/src/angular/component/schema.json +38 -0
- package/src/angular/component/types/types.d.ts +15 -0
- package/src/angular/component/types/types.js +3 -0
- package/src/collection.json +5 -0
- package/src/common/project-metadata.d.ts +4 -0
- package/src/common/project-metadata.js +17 -0
- package/src/ngrx/store/index.d.ts +1 -1
- package/src/ngrx/store/index.js +4 -14
- package/src/ngrx/store/types/types.d.ts +8 -0
- package/src/ngrx/store/types/types.js +3 -0
- package/src/transloco/index.d.ts +1 -1
- package/src/transloco/schema.json +1 -2
- package/src/transloco/types/types.d.ts +6 -0
- package/src/transloco/types/types.js +3 -0
- package/src/ngrx/store/schema.d.ts +0 -8
- package/src/transloco/scheme.d.ts +0 -6
package/package.json
CHANGED
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<div<% if (i18n === 'y') { %> *typedTransloco="let t; prefix:'<%= camelize(name) %>'"<% } %>>
|
|
2
|
+
<h1>
|
|
3
|
+
<% if (i18n === 'y') { %>{{ t('title') }}<% } else { %><%= classify(name) %> Works!<% } %>
|
|
4
|
+
</h1>
|
|
5
|
+
|
|
6
|
+
<% if (store === 'y') { %>
|
|
7
|
+
<pre>{{ data$() | json }}</pre>
|
|
8
|
+
<% } %>
|
|
9
|
+
</div>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
+
import { <%= classify(name) %>Component } from './<%= dasherize(name) %>.component';
|
|
3
|
+
<% if (store === 'y') { %>import { <%= classify(name) %>Store } from './state';<% } %>
|
|
4
|
+
|
|
5
|
+
describe('<%= classify(name) %>Component', () => {
|
|
6
|
+
let component: <%= classify(name) %>Component;
|
|
7
|
+
let fixture: ComponentFixture<<%= classify(name) %>Component>;
|
|
8
|
+
|
|
9
|
+
beforeEach(async () => {
|
|
10
|
+
await TestBed.configureTestingModule({
|
|
11
|
+
imports: [<%= classify(name) %>Component],
|
|
12
|
+
providers: [
|
|
13
|
+
<% if (store === 'y') { %><%= classify(name) %>Store,<% } %>
|
|
14
|
+
]
|
|
15
|
+
}).compileComponents();
|
|
16
|
+
|
|
17
|
+
fixture = TestBed.createComponent(<%= classify(name) %>Component);
|
|
18
|
+
component = fixture.componentInstance;
|
|
19
|
+
fixture.detectChanges();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should create', () => {
|
|
23
|
+
expect(component).toBeTruthy();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Component, inject } from '@angular/core';
|
|
2
|
+
import { JsonPipe } from '@angular/common';
|
|
3
|
+
<% if (i18n === 'y') { %>import { provideTranslocoScopeWrapper } from '@barcidev/typed-transloco';
|
|
4
|
+
import { <%= camelize(name) %>I18n } from './<%= dasherize(name) %>.i18n';
|
|
5
|
+
import { AppTypedTranslocoDirective } from '@i18n/app-typed-transloco.directive';<% } %>
|
|
6
|
+
<% if (store === 'y') { %>import { <%= classify(name) %>Store } from './state';<% } %>
|
|
7
|
+
|
|
8
|
+
@Component({
|
|
9
|
+
imports: [<% if (i18n === 'y') { %>AppTypedTranslocoDirective, JsonPipe<% } %>],
|
|
10
|
+
selector: 'app-<%= dasherize(name) %>',
|
|
11
|
+
<% if (i18n === 'y') { %>providers: [provideTranslocoScopeWrapper(<%= camelize(name) %>I18n)],<% } %>
|
|
12
|
+
styleUrls: ['./<%= dasherize(name) %>.component.scss'],
|
|
13
|
+
templateUrl: './<%= dasherize(name) %>.component.html',
|
|
14
|
+
})
|
|
15
|
+
export class <%= classify(name) %>Component {
|
|
16
|
+
<% if (store === 'y') { %> private _<%= camelize(name) %>Store = inject(<%= classify(name) %>Store);
|
|
17
|
+
data$ = this._<%= camelize(name) %>Store.entities();<% } %>
|
|
18
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.component = component;
|
|
13
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
14
|
+
const workspace_1 = require("@schematics/angular/utility/workspace");
|
|
15
|
+
const path_1 = require("path");
|
|
16
|
+
const pluralize_1 = require("../../common/pluralize");
|
|
17
|
+
function component(options) {
|
|
18
|
+
return (tree) => __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const workspace = yield (0, workspace_1.getWorkspace)(tree);
|
|
20
|
+
// 1. Preparar contexto y opciones enriquecidas
|
|
21
|
+
const context = resolveComponentContext(workspace, options);
|
|
22
|
+
// Aquí podrías agregar más reglas para otras funcionalidades, como NgRx
|
|
23
|
+
return (0, schematics_1.chain)([
|
|
24
|
+
generateComponentFiles(context),
|
|
25
|
+
options.i18n.toLowerCase() === "y"
|
|
26
|
+
? (0, schematics_1.schematic)("app-i18n", { name: context.options.name })
|
|
27
|
+
: (0, schematics_1.noop)(),
|
|
28
|
+
options.store.toLowerCase() === "y"
|
|
29
|
+
? (0, schematics_1.schematic)("app-store", { name: context.options.name })
|
|
30
|
+
: (0, schematics_1.noop)(),
|
|
31
|
+
]);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* --- LÓGICA DE EXTRACCIÓN Y PREPARACIÓN ---
|
|
36
|
+
*/
|
|
37
|
+
function resolveComponentContext(workspace, options) {
|
|
38
|
+
var _a;
|
|
39
|
+
// Configuración Global de PK
|
|
40
|
+
const globalConfig = (_a = workspace.extensions.schematics) === null || _a === void 0 ? void 0 : _a["@barcidev/ngx-autogen:all"];
|
|
41
|
+
const lang = options.lang || (globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.lang) || "en";
|
|
42
|
+
// Resolución de Rutas (Lógica de Directorio Actual)
|
|
43
|
+
const fullPath = process.cwd();
|
|
44
|
+
const srcIndex = fullPath.lastIndexOf("src");
|
|
45
|
+
let relativePath = srcIndex !== -1
|
|
46
|
+
? fullPath.substring(srcIndex)
|
|
47
|
+
: (0, path_1.join)((0, path_1.normalize)("src"), "app");
|
|
48
|
+
let movePath = (0, path_1.normalize)(relativePath);
|
|
49
|
+
if (!movePath.endsWith("state"))
|
|
50
|
+
movePath = (0, path_1.join)(movePath, "state");
|
|
51
|
+
// Resolución de Proyecto
|
|
52
|
+
const projectName = options.project ||
|
|
53
|
+
workspace.extensions.defaultProject ||
|
|
54
|
+
Array.from(workspace.projects.keys())[0];
|
|
55
|
+
return {
|
|
56
|
+
options: Object.assign(Object.assign({}, options), { lang, path: movePath, project: projectName }),
|
|
57
|
+
projectName,
|
|
58
|
+
movePath,
|
|
59
|
+
nameDash: schematics_1.strings.dasherize(options.name),
|
|
60
|
+
entityName: schematics_1.strings.classify(options.name),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function generateComponentFiles(ctx) {
|
|
64
|
+
const { options, movePath, nameDash } = ctx;
|
|
65
|
+
const targetPath = (0, path_1.join)(movePath, nameDash);
|
|
66
|
+
const templateUtils = Object.assign(Object.assign(Object.assign({}, schematics_1.strings), options), { pluralize: (word) => options.lang === "es" ? (0, pluralize_1.pluralizeEs)(word) : (0, pluralize_1.pluralizeEn)(word) });
|
|
67
|
+
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)]));
|
|
68
|
+
return (0, schematics_1.chain)([createSource("./files", targetPath)]);
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"$id": "TranslocoSchematic",
|
|
4
|
+
"title": "Transloco Schema",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"name": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"description": "Name of the component.",
|
|
10
|
+
"x-prompt": "What's the name of the component?",
|
|
11
|
+
"priority": 1
|
|
12
|
+
},
|
|
13
|
+
"store":{
|
|
14
|
+
"type": "string",
|
|
15
|
+
"description": "Whether to create a store for the component.",
|
|
16
|
+
"x-prompt": "Do you want to create a store for the component? (Y/N)",
|
|
17
|
+
"default": "Y",
|
|
18
|
+
"enum": ["Y", "N", "y", "n"]
|
|
19
|
+
},
|
|
20
|
+
"i18n": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"description": "Whether to create an i18n file for the component.",
|
|
23
|
+
"x-prompt": "Do you want to create an i18n file for the component? (Y/N)",
|
|
24
|
+
"default": "Y",
|
|
25
|
+
"enum": ["Y", "N", "y", "n"]
|
|
26
|
+
},
|
|
27
|
+
"path": {
|
|
28
|
+
"type": "string",
|
|
29
|
+
"description": "Destination path."
|
|
30
|
+
},
|
|
31
|
+
"lang": {
|
|
32
|
+
"type": "string",
|
|
33
|
+
"description": "Language for pluralization ('en' for English, 'es' for Spanish).",
|
|
34
|
+
"enum": ["en", "es"]
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"required": ["name"]
|
|
38
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface ComponentContext {
|
|
2
|
+
options: ComponentSchemaOptions;
|
|
3
|
+
projectName: string;
|
|
4
|
+
movePath: string;
|
|
5
|
+
nameDash: string;
|
|
6
|
+
entityName: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ComponentSchemaOptions {
|
|
9
|
+
name: string;
|
|
10
|
+
project?: string;
|
|
11
|
+
store: "Y" | "N" | "y" | "n";
|
|
12
|
+
i18n: "Y" | "N" | "y" | "n";
|
|
13
|
+
path?: string;
|
|
14
|
+
lang?: "en" | "es";
|
|
15
|
+
}
|
package/src/collection.json
CHANGED
|
@@ -15,6 +15,11 @@
|
|
|
15
15
|
"description": "Adds Transloco to the Angular application.",
|
|
16
16
|
"factory": "./transloco/index#transloco",
|
|
17
17
|
"schema": "./transloco/schema.json"
|
|
18
|
+
},
|
|
19
|
+
"app-component": {
|
|
20
|
+
"description": "Generates an Angular component with optional i18n and NgRx support.",
|
|
21
|
+
"factory": "./component/index#component",
|
|
22
|
+
"schema": "./component/schema.json"
|
|
18
23
|
}
|
|
19
24
|
}
|
|
20
25
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getProjectMetadata = void 0;
|
|
4
|
+
const schematics_1 = require("@angular-devkit/schematics");
|
|
5
|
+
const getProjectMetadata = (tree) => {
|
|
6
|
+
var _a, _b;
|
|
7
|
+
const buffer = tree.read("package.json");
|
|
8
|
+
if (!buffer)
|
|
9
|
+
throw new schematics_1.SchematicsException("No se encontró package.json");
|
|
10
|
+
const packageJson = JSON.parse(buffer.toString());
|
|
11
|
+
const angularCore = ((_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a["@angular/core"]) ||
|
|
12
|
+
((_b = packageJson.devDependencies) === null || _b === void 0 ? void 0 : _b["@angular/core"]);
|
|
13
|
+
const angularVersion = parseInt(angularCore.replace(/[^\d.]/g, "").split(".")[0], 10);
|
|
14
|
+
return { angularVersion };
|
|
15
|
+
};
|
|
16
|
+
exports.getProjectMetadata = getProjectMetadata;
|
|
17
|
+
//# sourceMappingURL=project-metadata.js.map
|
package/src/ngrx/store/index.js
CHANGED
|
@@ -18,6 +18,7 @@ const workspace_1 = require("@schematics/angular/utility/workspace");
|
|
|
18
18
|
const jsonc_parser_1 = require("jsonc-parser");
|
|
19
19
|
const file_actions_1 = require("../../common/file-actions");
|
|
20
20
|
const pluralize_1 = require("../../common/pluralize");
|
|
21
|
+
const project_metadata_1 = require("../../common/project-metadata");
|
|
21
22
|
const NGRX_SIGNALS = "@ngrx/signals";
|
|
22
23
|
function signalStore(options) {
|
|
23
24
|
return (tree) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -26,7 +27,7 @@ function signalStore(options) {
|
|
|
26
27
|
const context = resolveStoreContext(workspace, options);
|
|
27
28
|
const project = workspace.projects.get(context.projectName);
|
|
28
29
|
const projectRoot = (project === null || project === void 0 ? void 0 : project.sourceRoot) || "src";
|
|
29
|
-
const { angularVersion } = getProjectMetadata(tree);
|
|
30
|
+
const { angularVersion } = (0, project_metadata_1.getProjectMetadata)(tree);
|
|
30
31
|
// 2. Orquestar la ejecución
|
|
31
32
|
return (0, schematics_1.chain)([
|
|
32
33
|
ensureNgrxSignals(angularVersion),
|
|
@@ -46,22 +47,11 @@ function signalStore(options) {
|
|
|
46
47
|
/**
|
|
47
48
|
* --- LÓGICA DE EXTRACCIÓN Y PREPARACIÓN ---
|
|
48
49
|
*/
|
|
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
50
|
function resolveStoreContext(workspace, options) {
|
|
61
51
|
var _a;
|
|
62
52
|
// Configuración Global de PK
|
|
63
53
|
const globalConfig = (_a = workspace.extensions.schematics) === null || _a === void 0 ? void 0 : _a["@barcidev/ngx-autogen:all"];
|
|
64
|
-
const
|
|
54
|
+
const lang = options.lang || (globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.lang) || "en";
|
|
65
55
|
// Resolución de Rutas (Lógica de Directorio Actual)
|
|
66
56
|
const fullPath = process.cwd();
|
|
67
57
|
const srcIndex = fullPath.lastIndexOf("src");
|
|
@@ -76,7 +66,7 @@ function resolveStoreContext(workspace, options) {
|
|
|
76
66
|
workspace.extensions.defaultProject ||
|
|
77
67
|
Array.from(workspace.projects.keys())[0];
|
|
78
68
|
return {
|
|
79
|
-
options: Object.assign(Object.assign({}, options), {
|
|
69
|
+
options: Object.assign(Object.assign({}, options), { lang, path: movePath, project: projectName }),
|
|
80
70
|
projectName,
|
|
81
71
|
movePath,
|
|
82
72
|
indexPath: (0, core_1.join)(movePath, "index.ts"),
|
package/src/transloco/index.d.ts
CHANGED