@abelfubu/schematics 0.0.3

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,7 @@
1
+ # schematics
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build schematics` to build the library.
@@ -0,0 +1,26 @@
1
+ {
2
+ "generators": {
3
+ "feature": {
4
+ "factory": "./src/feature/feature",
5
+ "schema": "./src/feature/schema.json",
6
+ "description": "Feature generator"
7
+ },
8
+ "ng-add": {
9
+ "factory": "./src/ng-add/index",
10
+ "schema": "./src/ng-add/schema.json",
11
+ "description": "Abelfubuize your project"
12
+ }
13
+ },
14
+ "schematics": {
15
+ "feature": {
16
+ "factory": "./src/feature/compat",
17
+ "schema": "./src/feature/schema.json",
18
+ "description": "Feature generator"
19
+ },
20
+ "ng-add": {
21
+ "factory": "./src/ng-add/compat",
22
+ "schema": "./src/ng-add/schema.json",
23
+ "description": "Abelfubuize your project"
24
+ }
25
+ }
26
+ }
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@abelfubu/schematics",
3
+ "version": "0.0.3",
4
+ "type": "commonjs",
5
+ "main": "./src/index.js",
6
+ "types": "./src/index.d.ts",
7
+ "dependencies": {
8
+ "@nx/devkit": "21.0.3",
9
+ "tslib": "^2.3.0"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/abelfubu/abelfubu-source.git"
17
+ },
18
+ "generators": "./generators.json",
19
+ "schematics": "./generators.json"
20
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: (generatorOptions: import("./schema").FeatureGeneratorSchema) => (tree: any, context: any) => Promise<any>;
2
+ export default _default;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ const feature_1 = require("./feature");
5
+ exports.default = (0, devkit_1.convertNxGenerator)(feature_1.featureGenerator);
6
+ //# sourceMappingURL=compat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compat.js","sourceRoot":"","sources":["../../../../../packages/schematics/src/feature/compat.ts"],"names":[],"mappings":";;AAAA,uCAAgD;AAEhD,uCAA6C;AAE7C,kBAAe,IAAA,2BAAkB,EAAC,0BAAgB,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { FeatureGeneratorSchema } from './schema';
3
+ export declare function featureGenerator(tree: Tree, options: FeatureGeneratorSchema): Promise<void>;
4
+ export default featureGenerator;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.featureGenerator = featureGenerator;
4
+ const tslib_1 = require("tslib");
5
+ const devkit_1 = require("@nx/devkit");
6
+ const path = require("path");
7
+ function featureGenerator(tree, options) {
8
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
9
+ const projectRoot = `src/${options.name}`;
10
+ const { className, fileName, propertyName } = (0, devkit_1.names)(options.name.split('/').pop());
11
+ (0, devkit_1.generateFiles)(tree, path.join(__dirname, 'files'), projectRoot, {
12
+ fileName,
13
+ className,
14
+ propertyName,
15
+ prefix: options.prefix,
16
+ });
17
+ yield (0, devkit_1.formatFiles)(tree);
18
+ });
19
+ }
20
+ exports.default = featureGenerator;
21
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature.js","sourceRoot":"","sources":["../../../../../packages/schematics/src/feature/feature.ts"],"names":[],"mappings":";;AAIA,4CAkBC;;AAtBD,uCAAqE;AACrE,6BAA6B;AAG7B,SAAsB,gBAAgB,CACpC,IAAU,EACV,OAA+B;;QAE/B,MAAM,WAAW,GAAG,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC;QAE1C,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,IAAA,cAAK,EACjD,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAC9B,CAAC;QAEF,IAAA,sBAAa,EAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,WAAW,EAAE;YAC9D,QAAQ;YACR,SAAS;YACT,YAAY;YACZ,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC,CAAC;QAEH,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CAAA;AAED,kBAAe,gBAAgB,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { signal } from '@angular/core';
2
+ import { TestBed } from '@angular/core/testing';
3
+ import { <%= className %>Component } from './<%= fileName %>.component';
4
+ import { <%= className %>Store } from './<%= fileName %>.store';
5
+
6
+ describe(<%= className %>Component.name, () => {
7
+ const StoreMock = {
8
+ initialize: jest.fn(),
9
+ name: signal('<%= className %>'),
10
+ };
11
+
12
+ beforeEach(async () => {
13
+ await TestBed.configureTestingModule({
14
+ imports: [<%= className %>Component],
15
+ providers: [
16
+ {
17
+ provide: <%= className %>Store,
18
+ useValue: StoreMock,
19
+ },
20
+ ],
21
+ }).compileComponents();
22
+ });
23
+
24
+ function setup() {
25
+ const fixture = TestBed.createComponent(<%= className %>Component);
26
+ fixture.detectChanges();
27
+
28
+ return { fixture };
29
+ }
30
+
31
+ it('should initialize store', () => {
32
+ setup();
33
+
34
+ expect(StoreMock.initialize).toHaveBeenCalled();
35
+ });
36
+ });
@@ -0,0 +1,17 @@
1
+ import { ChangeDetectionStrategy, Component, inject, OnInit } from '@angular/core';
2
+ import { <%= className %>Store } from './<%= fileName %>.store';
3
+
4
+ @Component({
5
+ changeDetection: ChangeDetectionStrategy.OnPush,
6
+ imports: [],
7
+ providers: [<%= className %>Store],
8
+ selector: '<%= prefix %>-<%= fileName %>',
9
+ template: `<h1>{{ store.name() }} works!!</h1>`,
10
+ })
11
+ export class <%= className %>Component implements OnInit {
12
+ protected readonly store = inject(<%= className %>Store);
13
+
14
+ ngOnInit(): void {
15
+ this.store.initialize();
16
+ }
17
+ }
@@ -0,0 +1,12 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { Observable, of, map } from 'rxjs';
3
+ import { <%= propertyName %>Adapter } from './adapters/<%= fileName %>.adapter';
4
+
5
+ @Injectable({
6
+ providedIn: 'root',
7
+ })
8
+ export class <%= className %>Facade {
9
+ get(): Observable<{ name: string }> {
10
+ return of({ name: '<%= className %>' }).pipe(map(<%= propertyName %>Adapter));
11
+ }
12
+ }
@@ -0,0 +1,8 @@
1
+ import { Routes } from '@angular/router';
2
+
3
+ export const routes: Routes = [
4
+ {
5
+ path: '',
6
+ loadComponent: () => import('./<%= fileName %>.component').then(m => m.<%= className %>Component),
7
+ }
8
+ ]
@@ -0,0 +1,38 @@
1
+ import { TestBed } from '@angular/core/testing';
2
+ import { of } from 'rxjs';
3
+
4
+ import { <%= className %>Facade } from './<%= fileName %>.facade';
5
+ import { <%= className %>Store } from './<%= fileName %>.store';
6
+
7
+ describe(<%= className %>Store.name, () => {
8
+ const FacadeMock = {
9
+ get: jest.fn(),
10
+ };
11
+
12
+ beforeEach(() => {
13
+ TestBed.configureTestingModule({
14
+ providers: [
15
+ {
16
+ provide: <%= className %>Facade,
17
+ useValue: FacadeMock,
18
+ },
19
+ ],
20
+ });
21
+ });
22
+
23
+ afterEach(() => jest.clearAllMocks());
24
+
25
+ function setup() {
26
+ const store = TestBed.inject(<%= className %>Store);
27
+
28
+ return { store };
29
+ }
30
+
31
+ it('should initialize', () => {
32
+ const { store } = setup();
33
+
34
+ FacadeMock.get.mockReturnValue(of({ name: '<%= className %>' }));
35
+ store.initialize();
36
+ expect(store.name()).toBe('<%= className %>');
37
+ });
38
+ });
@@ -0,0 +1,26 @@
1
+ import { Injectable, computed, inject, signal } from '@angular/core'
2
+
3
+ import { <%= className %>Facade } from './<%= fileName %>.facade';
4
+
5
+ interface <%= className %>State {
6
+ name: string;
7
+ };
8
+
9
+ const defaultState: <%= className %>State = {
10
+ name: '',
11
+ };
12
+
13
+ @Injectable({
14
+ providedIn: 'root',
15
+ })
16
+ export class <%= className %>Store {
17
+ private readonly facade = inject(<%= className %>Facade);
18
+
19
+ private readonly state = signal<<%= className %>State>(defaultState);
20
+
21
+ readonly name = computed(() => this.state().name);
22
+
23
+ initialize(): void {
24
+ this.facade.get().subscribe(({ name }) => this.state.set({ name }));
25
+ }
26
+ }
@@ -0,0 +1,3 @@
1
+ export function <%= propertyName %>Adapter(source: { name: string}): { name: string } {
2
+ return source;
3
+ }
@@ -0,0 +1,4 @@
1
+ export interface FeatureGeneratorSchema {
2
+ name: string;
3
+ prefix: string;
4
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "Feature",
4
+ "title": "",
5
+ "type": "object",
6
+ "properties": {
7
+ "name": {
8
+ "type": "string",
9
+ "description": "Name of the feature",
10
+ "$default": {
11
+ "$source": "argv",
12
+ "index": 0
13
+ },
14
+ "x-prompt": "What name would you like to use?"
15
+ },
16
+ "prefix": {
17
+ "type": "string",
18
+ "description": "Prefix to use for the feature",
19
+ "x-prompt": "What prefix would you like to use?"
20
+ }
21
+ },
22
+ "required": ["name", "prefix"]
23
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: (generatorOptions: any) => (tree: any, context: any) => Promise<any>;
2
+ export default _default;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ const index_1 = require("./index");
5
+ exports.default = (0, devkit_1.convertNxGenerator)(index_1.addGenerator);
6
+ //# sourceMappingURL=compat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compat.js","sourceRoot":"","sources":["../../../../../packages/schematics/src/ng-add/compat.ts"],"names":[],"mappings":";;AAAA,uCAAgD;AAEhD,mCAAuC;AAEvC,kBAAe,IAAA,2BAAkB,EAAC,oBAAY,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export declare function addGenerator(tree: Tree): Promise<import("@nx/devkit").GeneratorCallback>;
3
+ export default addGenerator;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addGenerator = addGenerator;
4
+ const tslib_1 = require("tslib");
5
+ const devkit_1 = require("@nx/devkit");
6
+ const child_process_1 = require("child_process");
7
+ /**
8
+ * Returns the latest version of a package
9
+ * @param packageName Name of the package
10
+ * @returns Latest version string or 'latest'
11
+ */
12
+ function getLatestVersion(packageName) {
13
+ try {
14
+ // Execute npm command to get the latest version
15
+ const latestVersion = (0, child_process_1.execSync)(`npm show ${packageName} version`, {
16
+ encoding: 'utf-8',
17
+ }).trim();
18
+ return latestVersion;
19
+ }
20
+ catch (error) {
21
+ devkit_1.logger.warn(`Could not fetch latest version for ${packageName}, using 'latest' instead`);
22
+ return 'latest';
23
+ }
24
+ }
25
+ function addGenerator(tree) {
26
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
27
+ const tasks = [];
28
+ // 1. Add Prettier
29
+ const prettier = getLatestVersion('prettier');
30
+ tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, { prettier }));
31
+ if (!tree.exists('.prettierrc')) {
32
+ tree.write('.prettierrc', JSON.stringify({
33
+ semi: false,
34
+ }, null, 2));
35
+ }
36
+ // 2. Add Tailwind
37
+ const tailwindcss = getLatestVersion('tailwindcss');
38
+ const postcss = getLatestVersion('postcss');
39
+ const tailwindPostcss = getLatestVersion('@tailwindcss/postcss');
40
+ tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
41
+ tailwindcss,
42
+ '@tailwindcss/postcss': tailwindPostcss,
43
+ postcss,
44
+ }));
45
+ tree.write('.postcssrc.json', `{
46
+ "plugins": {
47
+ "@tailwindcss/postcss": {}
48
+ }
49
+ }`);
50
+ tree.write('src/styles.css', `@import "tailwindcss";`);
51
+ // 3. Run ng add @angular-eslint/schematics
52
+ (0, child_process_1.execSync)('npx ng add @angular-eslint/schematics --skip-confirmation', {
53
+ stdio: 'inherit',
54
+ });
55
+ yield (0, devkit_1.formatFiles)(tree);
56
+ return (0, devkit_1.runTasksInSerial)(...tasks, () => (0, devkit_1.installPackagesTask)(tree));
57
+ });
58
+ }
59
+ exports.default = addGenerator;
60
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/schematics/src/ng-add/index.ts"],"names":[],"mappings":";;AA+BA,oCAuDC;;AAtFD,uCAOoB;AACpB,iDAAyC;AAEzC;;;;GAIG;AACH,SAAS,gBAAgB,CAAC,WAAmB;IAC3C,IAAI,CAAC;QACH,gDAAgD;QAChD,MAAM,aAAa,GAAG,IAAA,wBAAQ,EAAC,YAAY,WAAW,UAAU,EAAE;YAChE,QAAQ,EAAE,OAAO;SAClB,CAAC,CAAC,IAAI,EAAE,CAAC;QAEV,OAAO,aAAa,CAAC;IACvB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,eAAM,CAAC,IAAI,CACT,sCAAsC,WAAW,0BAA0B,CAC5E,CAAC;QACF,OAAO,QAAQ,CAAC;IAClB,CAAC;AACH,CAAC;AAED,SAAsB,YAAY,CAAC,IAAU;;QAC3C,MAAM,KAAK,GAAG,EAAE,CAAC;QAEjB,kBAAkB;QAClB,MAAM,QAAQ,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;QAC9C,KAAK,CAAC,IAAI,CAAC,IAAA,qCAA4B,EAAC,IAAI,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;QAEjE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;YAChC,IAAI,CAAC,KAAK,CACR,aAAa,EACb,IAAI,CAAC,SAAS,CACZ;gBACE,IAAI,EAAE,KAAK;aACZ,EACD,IAAI,EACJ,CAAC,CACF,CACF,CAAC;QACJ,CAAC;QAED,kBAAkB;QAClB,MAAM,WAAW,GAAG,gBAAgB,CAAC,aAAa,CAAC,CAAC;QACpD,MAAM,OAAO,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC;QAC5C,MAAM,eAAe,GAAG,gBAAgB,CAAC,sBAAsB,CAAC,CAAC;QACjE,KAAK,CAAC,IAAI,CACR,IAAA,qCAA4B,EAC1B,IAAI,EACJ,EAAE,EACF;YACE,WAAW;YACX,sBAAsB,EAAE,eAAe;YACvC,OAAO;SACR,CACF,CACF,CAAC;QAEF,IAAI,CAAC,KAAK,CACR,iBAAiB,EACjB;;;;EAIF,CACC,CAAC;QAEF,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,wBAAwB,CAAC,CAAC;QAEvD,2CAA2C;QAC3C,IAAA,wBAAQ,EAAC,2DAA2D,EAAE;YACpE,KAAK,EAAE,SAAS;SACjB,CAAC,CAAC;QAEH,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;QAExB,OAAO,IAAA,yBAAgB,EAAC,GAAG,KAAK,EAAE,GAAG,EAAE,CAAC,IAAA,4BAAmB,EAAC,IAAI,CAAC,CAAC,CAAC;IACrE,CAAC;CAAA;AAED,kBAAe,YAAY,CAAC"}
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "Add",
4
+ "title": "Abelfubuize your project",
5
+ "type": "object",
6
+ "properties": {},
7
+ "required": []
8
+ }