@barcidev/ngx-autogen 0.1.39 → 0.1.42

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.39",
3
+ "version": "0.1.42",
4
4
  "description": "A collection of Angular schematics for essential functionalities.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -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,3 @@
1
+ import { Rule } from "@angular-devkit/schematics";
2
+ import { ComponentSchemaOptions } from "./types/types";
3
+ export declare function component(options: ComponentSchemaOptions): Rule;
@@ -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
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -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
+ "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,4 @@
1
+ import { Tree } from "@angular-devkit/schematics";
2
+ export declare const getProjectMetadata: (tree: Tree) => {
3
+ angularVersion: number;
4
+ };
@@ -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
@@ -1,2 +1,3 @@
1
1
  import { Rule } from "@angular-devkit/schematics";
2
- export declare function ngAdd(): Rule;
2
+ import { NgAddSchemaOptions } from "./schema";
3
+ export declare function ngAdd(options: NgAddSchemaOptions): Rule;
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ngAdd = ngAdd;
4
4
  const schematics_1 = require("@angular-devkit/schematics");
5
5
  const LIBRARY_NAME = "@barcidev/ngx-autogen";
6
- function ngAdd() {
6
+ function ngAdd(options) {
7
7
  return () => {
8
- return (0, schematics_1.chain)([cleanupPackageJson(), registerInAngularJson()]);
8
+ return (0, schematics_1.chain)([cleanupPackageJson(), registerInAngularJson(options)]);
9
9
  };
10
10
  }
11
11
  /**
@@ -30,19 +30,24 @@ function cleanupPackageJson() {
30
30
  /**
31
31
  * Regla: Configura la CLI de Angular
32
32
  */
33
- function registerInAngularJson() {
33
+ function registerInAngularJson(options) {
34
34
  return (tree) => {
35
35
  const buffer = tree.read("angular.json");
36
36
  if (!buffer)
37
37
  return tree;
38
- const json = JSON.parse(buffer.toString());
39
- json.cli = json.cli || {};
40
- const collections = json.cli.schematicCollections || [];
38
+ const workspace = JSON.parse(buffer.toString());
39
+ workspace.cli = workspace.cli || {};
40
+ const collections = workspace.cli.schematicCollections || [];
41
41
  if (!collections.includes(LIBRARY_NAME)) {
42
42
  collections.push(LIBRARY_NAME);
43
- json.cli.schematicCollections = collections;
44
- tree.overwrite("angular.json", JSON.stringify(json, null, 2));
43
+ workspace.cli.schematicCollections = collections;
44
+ tree.overwrite("angular.json", JSON.stringify(workspace, null, 2));
45
45
  }
46
+ if (!workspace.schematics)
47
+ workspace.schematics = {};
48
+ workspace.schematics["@barcidev/ngx-autogen:all"] = {
49
+ lang: options.lang,
50
+ };
46
51
  return tree;
47
52
  };
48
53
  }
@@ -3,5 +3,11 @@
3
3
  "$id": "ng-add-schema",
4
4
  "type": "object",
5
5
  "properties": {
6
+ "lang":{
7
+ "type": "string",
8
+ "description": "The default language for the application (en, es); default is 'en'.",
9
+ "x-prompt": "What is the default language for the application (en, es)?",
10
+ "default": "en"
11
+ }
6
12
  }
7
13
  }
@@ -1,3 +1,3 @@
1
1
  import { Rule } from "@angular-devkit/schematics";
2
- import { StoreSchemaOptions } from "./schema";
2
+ import { StoreSchemaOptions } from "./types/types";
3
3
  export declare function signalStore(options: StoreSchemaOptions): Rule;
@@ -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 pk = options.pk || (globalConfig === null || globalConfig === void 0 ? void 0 : globalConfig.pk) || "id";
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), { pk, path: movePath, project: projectName }),
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"),
@@ -27,9 +27,7 @@
27
27
  },
28
28
  "lang":{
29
29
  "type": "string",
30
- "description": "The default language for the application (en, es); default is 'en'.",
31
- "x-prompt": "What is the default language for the application (en, es)?",
32
- "default": "en"
30
+ "description": "The default language for the application (en, es); default is 'en'."
33
31
  }
34
32
  },
35
33
  "required": ["name"]
@@ -0,0 +1,8 @@
1
+ export interface StoreSchemaOptions {
2
+ name: string;
3
+ path?: string;
4
+ project?: string;
5
+ grouped: boolean;
6
+ pk?: string;
7
+ lang: "en" | "es";
8
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -1,3 +1,3 @@
1
1
  import { Rule } from "@angular-devkit/schematics";
2
- import { TranslocoSchemaOptions } from "./scheme";
2
+ import { TranslocoSchemaOptions } from "./types/types";
3
3
  export declare function transloco(options: TranslocoSchemaOptions): Rule;
@@ -16,8 +16,7 @@
16
16
  "lang": {
17
17
  "type": "string",
18
18
  "description": "Language for pluralization ('en' for English, 'es' for Spanish).",
19
- "enum": ["en", "es"],
20
- "default": "en"
19
+ "enum": ["en", "es"]
21
20
  }
22
21
  }
23
22
  }
@@ -0,0 +1,6 @@
1
+ export interface TranslocoSchemaOptions {
2
+ path: string | null;
3
+ name: string;
4
+ lang: string | null;
5
+ project?: string;
6
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -1,8 +0,0 @@
1
- export interface StoreSchemaOptions {
2
- name: string;
3
- path?: string;
4
- project?: string;
5
- grouped: boolean;
6
- pk?: string;
7
- lang: "en" | "es";
8
- }
@@ -1,6 +0,0 @@
1
- export interface TranslocoSchemaOptions {
2
- path: string | null;
3
- name: string;
4
- lang: string | null;
5
- project?: string;
6
- }