ngx-essentials-schematics 0.0.1

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/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Getting Started With Schematics
2
+
3
+ This repository is a basic Schematic implementation that serves as a starting point to create and publish Schematics to NPM.
4
+
5
+ ### Testing
6
+
7
+ To test locally, install `@angular-devkit/schematics-cli` globally and use the `schematics` command line tool. That tool acts the same as the `generate` command of the Angular CLI, but also has a debug mode.
8
+
9
+ Check the documentation with
10
+
11
+ ```bash
12
+ schematics --help
13
+ ```
14
+
15
+ ### Unit Testing
16
+
17
+ `npm run test` will run the unit tests, using Jasmine as a runner and test framework.
18
+
19
+ ### Publishing
20
+
21
+ To publish, simply do:
22
+
23
+ ```bash
24
+ npm run build
25
+ npm publish
26
+ ```
27
+
28
+ That's it!
@@ -0,0 +1,10 @@
1
+ {
2
+ "$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
3
+ "schematics": {
4
+ "app-store": {
5
+ "description": "Adds NgRx Store to the Angular application with signal support.",
6
+ "factory": "./ngrx/store/index#signalStore",
7
+ "schema": "./ngrx/store/schema.json"
8
+ }
9
+ }
10
+ }
@@ -0,0 +1,34 @@
1
+ import { signalStore, withState, withMethods, withComputed, patchState } from '@ngrx/signals';
2
+ import { withEntities } from '@ngrx/signals/entities';
3
+ import { computed } from '@angular/core';
4
+ import { EntityStatus } from '@shared/models/common.model';
5
+
6
+ export interface <%= classify(name) %> {
7
+ cod: number;
8
+ }
9
+
10
+ const initialStatus: EntityStatus = {
11
+ loading: false,
12
+ error: null,
13
+ };
14
+
15
+ export const <%= classify(name) %>Store = signalStore(
16
+ { providedIn: 'root' },
17
+ withEntities<<%= classify(name) %>>(),
18
+ withState({
19
+ status: initialStatus,
20
+ selectedId: null as number | null,
21
+ }),
22
+ withComputed(({ entityMap, selectedId }) => ({
23
+ selectedEntity: computed(() => {
24
+ const id = selectedId();
25
+ return id ? entityMap()[id] : null;
26
+ }),
27
+ })),
28
+ withMethods((store) => ({
29
+ setLoading: (loading: boolean) =>
30
+ patchState(store, (state) => ({ status: { ...state.status, loading } })),
31
+ setError: (error: string | null) =>
32
+ patchState(store, (state) => ({ status: { ...state.status, error, loading: false } })),
33
+ }))
34
+ );
@@ -0,0 +1,8 @@
1
+ import { Rule } from '@angular-devkit/schematics';
2
+ import { SchemaOptions } from './schema';
3
+ /**
4
+ * Genera un Signal Store profesional para Angular 20
5
+ * @param {SchemaOptions} options - Opciones del esquema
6
+ * @returns {Rule} - Una regla de esquema para generar el Signal Store
7
+ */
8
+ export declare function signalStore(options: SchemaOptions): Rule;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.signalStore = signalStore;
4
+ const core_1 = require("@angular-devkit/core");
5
+ const schematics_1 = require("@angular-devkit/schematics");
6
+ /**
7
+ * Genera un Signal Store profesional para Angular 20
8
+ * @param {SchemaOptions} options - Opciones del esquema
9
+ * @returns {Rule} - Una regla de esquema para generar el Signal Store
10
+ */
11
+ function signalStore(options) {
12
+ return (tree) => {
13
+ const movePath = (0, core_1.normalize)(options.path || 'src/app/state');
14
+ // 1. Lógica para actualizar el index.ts (Barrel)
15
+ const indexPath = (0, core_1.join)(movePath, 'index.ts');
16
+ const exportLine = `export * from './${core_1.strings.dasherize(options.name)}.store';\n`;
17
+ if (tree.exists(indexPath)) {
18
+ const content = tree.read(indexPath).toString();
19
+ if (!content.includes(exportLine)) {
20
+ tree.overwrite(indexPath, content + exportLine);
21
+ }
22
+ }
23
+ else {
24
+ tree.create(indexPath, exportLine);
25
+ }
26
+ // 2. Lógica de generación del archivo .store.ts
27
+ const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [(0, schematics_1.applyTemplates)(Object.assign(Object.assign({}, core_1.strings), options)), (0, schematics_1.move)(movePath)]);
28
+ return (0, schematics_1.chain)([(0, schematics_1.mergeWith)(templateSource)]);
29
+ };
30
+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}
@@ -0,0 +1,20 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "SignalStoreSchematic",
4
+ "title": "Signal Store Schema",
5
+ "type": "object",
6
+ "properties": {
7
+ "name": {
8
+ "type": "string",
9
+ "description": "Nombre de la entidad.",
10
+ "x-prompt": "¿Cómo se llama la entidad?",
11
+ "priority": 1
12
+ },
13
+ "path": {
14
+ "type": "string",
15
+ "description": "Ruta de destino.",
16
+ "default": "src/app/store"
17
+ }
18
+ },
19
+ "required": ["name"]
20
+ }
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "ngx-essentials-schematics",
3
+ "version": "0.0.1",
4
+ "description": "A collection of Angular schematics for essential functionalities.",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "build": "tsc -p tsconfig.json && copyfiles -u 1 \"src/**/*.json\" \"src/**/files/**/*\" dist/",
8
+ "test": "npm run build && jasmine src/**/*_spec.js",
9
+ "prepublishOnly": "npm run build"
10
+ },
11
+ "files": [
12
+ "dist/**/*",
13
+ "src/*/schema.json",
14
+ "src/collection.json"
15
+ ],
16
+ "keywords": [
17
+ "schematics"
18
+ ],
19
+ "author": "",
20
+ "license": "MIT",
21
+ "schematics": "./src/collection.json",
22
+ "dependencies": {
23
+ "@angular-devkit/core": "^20.3.13",
24
+ "@angular-devkit/schematics": "^20.3.13",
25
+ "typescript": "~5.9.2"
26
+ },
27
+ "devDependencies": {
28
+ "@types/jasmine": "~5.1.0",
29
+ "@types/node": "^20.17.19",
30
+ "copyfiles": "^2.4.1",
31
+ "jasmine": "^5.0.0"
32
+ }
33
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
3
+ "schematics": {
4
+ "app-store": {
5
+ "description": "Adds NgRx Store to the Angular application with signal support.",
6
+ "factory": "./ngrx/store/index#signalStore",
7
+ "schema": "./ngrx/store/schema.json"
8
+ }
9
+ }
10
+ }