@tech4good/angular-schematics 13.0.0 → 13.2.0

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.
Files changed (64) hide show
  1. package/README.md +10 -10
  2. package/package.json +1 -1
  3. package/src/collection.json +9 -4
  4. package/src/component/files/__name@dasherize__/__name@dasherize__.animations.ts.template +4 -0
  5. package/src/component/files/__name@dasherize__/__name@dasherize__.component.html.template +3 -0
  6. package/src/component/files/__name@dasherize__/__name@dasherize__.component.scss.template +7 -0
  7. package/src/component/files/__name@dasherize__/__name@dasherize__.component.spec.ts.template +25 -0
  8. package/src/component/files/__name@dasherize__/__name@dasherize__.component.ts.template +30 -0
  9. package/src/component/index.d.ts +1 -1
  10. package/src/component/index.js +85 -94
  11. package/src/component/index.js.map +1 -1
  12. package/src/component/schema.json +27 -13
  13. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.actions.ts.template +27 -0
  14. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.effects.ts.template +47 -0
  15. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.model.ts.template +0 -0
  16. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.selectors.ts.template +20 -0
  17. package/src/container/files/__name@dasherize__/+state/__name@dasherize__.state.ts.template +13 -0
  18. package/src/container/files/__name@dasherize__/__name@dasherize__.animations.ts.template +4 -0
  19. package/src/container/files/__name@dasherize__/__name@dasherize__.component.html.template +3 -0
  20. package/src/container/files/__name@dasherize__/__name@dasherize__.component.scss.template +5 -0
  21. package/src/container/files/__name@dasherize__/__name@dasherize__.component.spec.ts.template +25 -0
  22. package/src/container/files/__name@dasherize__/__name@dasherize__.component.ts.template +81 -0
  23. package/src/container/index.d.ts +1 -1
  24. package/src/container/index.js +106 -273
  25. package/src/container/index.js.map +1 -1
  26. package/src/container/schema.json +28 -9
  27. package/src/entity/files/__name@dasherize__/__name@dasherize__.actions.ts.template +270 -0
  28. package/src/entity/files/__name@dasherize__/__name@dasherize__.effects.ts.template +131 -0
  29. package/src/entity/files/__name@dasherize__/__name@dasherize__.model.ts.template +7 -0
  30. package/src/entity/files/__name@dasherize__/__name@dasherize__.reducer.spec.ts.template +13 -0
  31. package/src/entity/files/__name@dasherize__/__name@dasherize__.reducer.ts.template +51 -0
  32. package/src/entity/files/__name@dasherize__/__name@dasherize__.service.ts.template +50 -0
  33. package/src/entity/index.d.ts +1 -1
  34. package/src/entity/index.js +105 -506
  35. package/src/entity/index.js.map +1 -1
  36. package/src/entity/schema.json +25 -6
  37. package/src/init/files/.eslintrc.json +120 -0
  38. package/src/init/files/.gitattributes +11 -0
  39. package/src/init/files/.github/workflows/angular-github-ci.yml.template +60 -0
  40. package/src/init/files/angular.json.template +132 -0
  41. package/src/init/files/package.json.template +60 -0
  42. package/src/init/files/src/app/app.component.html +3 -0
  43. package/src/init/files/src/app/app.component.scss +4 -0
  44. package/src/init/files/src/app/general/e404/e404.component.html +1 -0
  45. package/src/init/files/src/app/general/e404/e404.component.scss +0 -0
  46. package/src/init/files/src/app/general/login/login.component.html +11 -0
  47. package/src/init/files/src/app/general/login/login.component.scss +29 -0
  48. package/src/init/files/src/index.html.template +19 -0
  49. package/src/init/files/src/styles/_variables.scss +0 -0
  50. package/src/init/files/src/styles.scss +13 -0
  51. package/src/init/index.d.ts +2 -0
  52. package/src/init/index.js +50 -0
  53. package/src/init/index.js.map +1 -0
  54. package/src/init/schema.json +28 -0
  55. package/src/module/files/__name@dasherize__/__name@dasherize__-routing.module.ts.template +13 -0
  56. package/src/module/files/__name@dasherize__/__name@dasherize__.module.spec.ts.template +13 -0
  57. package/src/module/files/__name@dasherize__/__name@dasherize__.module.ts.template +24 -0
  58. package/src/module/index.d.ts +1 -1
  59. package/src/module/index.js +87 -78
  60. package/src/module/index.js.map +1 -1
  61. package/src/module/schema.json +21 -6
  62. package/src/shared/statements-adder.d.ts +3 -0
  63. package/src/shared/statements-adder.js +22 -1
  64. package/src/shared/statements-adder.js.map +1 -1
@@ -0,0 +1,28 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "InitSchema",
4
+ "title": "Init Schema",
5
+ "type": "object",
6
+ "description": "Adds initial project files to a newly created repo.",
7
+ "properties": {
8
+ "index": {
9
+ "type": "number",
10
+ "default": 1
11
+ },
12
+ "project": {
13
+ "type": "string",
14
+ "description": "The name of the project.",
15
+ "$default": {
16
+ "$source": "projectName"
17
+ }
18
+ },
19
+ "proceed": {
20
+ "type": "boolean",
21
+ "x-prompt": "This schematic is only designed for generating initial files on a FRESH repo created from ng new. If you use this outside of that context, YOU WILL OVERWRITE parts of your existing code. Are you sure you want to proceed?"
22
+ }
23
+
24
+ },
25
+ "required": [
26
+ "project"
27
+ ]
28
+ }
@@ -0,0 +1,13 @@
1
+ import { NgModule } from '@angular/core';
2
+ import { Routes, RouterModule } from '@angular/router';
3
+
4
+ // Containers
5
+
6
+ const routes: Routes = [
7
+ ];
8
+
9
+ @NgModule({
10
+ imports: [RouterModule.forChild(routes)],
11
+ exports: [RouterModule],
12
+ })
13
+ export class <%= classify(name) %>RoutingModule { }
@@ -0,0 +1,13 @@
1
+ import { <%= classify(name) %>Module } from './<%= dasherize(name) %>.module';
2
+
3
+ describe('<%= classify(name) %>Module', () => {
4
+ let <%= camelize(name) %>Module: <%= classify(name) %>Module;
5
+
6
+ beforeEach(() => {
7
+ <%= camelize(name) %>Module = new <%= classify(name) %>Module();
8
+ });
9
+
10
+ it('should create an instance', () => {
11
+ expect(<%= camelize(name) %>Module).toBeTruthy();
12
+ });
13
+ });
@@ -0,0 +1,24 @@
1
+ import { NgModule } from '@angular/core';
2
+ import { CommonModule } from '@angular/common';
3
+ import { EffectsModule } from '@ngrx/effects';
4
+ import { SharedModule } from '../shared/shared.module';
5
+ import { <%= classify(name) %>RoutingModule } from './<%= dasherize(name) %>-routing.module';
6
+
7
+ // Containers
8
+
9
+ // Components
10
+
11
+ @NgModule({
12
+ imports: [
13
+ CommonModule,
14
+ SharedModule,
15
+ <%= classify(name) %>RoutingModule,
16
+ EffectsModule.forFeature([
17
+ ]),
18
+ ],
19
+ declarations: [
20
+ // Containers
21
+ // Components
22
+ ],
23
+ })
24
+ export class <%= classify(name) %>Module { }
@@ -1,2 +1,2 @@
1
1
  import { Rule } from '@angular-devkit/schematics';
2
- export declare function module(_options: any): Rule;
2
+ export declare function module(options: any): Rule;
@@ -1,88 +1,97 @@
1
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
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.module = void 0;
4
13
  const schematics_1 = require("@angular-devkit/schematics");
5
- const camelcase_formatter_1 = require("../shared/camelcase-formatter");
14
+ const change_1 = require("@schematics/angular/utility/change");
15
+ const find_module_1 = require("@schematics/angular/utility/find-module");
16
+ const parse_name_1 = require("@schematics/angular/utility/parse-name");
17
+ const workspace_1 = require("@schematics/angular/utility/workspace");
18
+ const core_1 = require("@angular-devkit/core");
6
19
  const statements_adder_1 = require("../shared/statements-adder");
7
- const fs = require('fs');
8
- // You don't have to export the function as default. You can also have more than one rule factory
9
- // per file.
10
- function module(_options) {
11
- return (tree, _context) => {
12
- const angularConfig = 'angular.json';
13
- // Let's make sure we're in an angular workspace
14
- if (!tree.exists(angularConfig))
15
- throw new schematics_1.SchematicsException('???This is not an Angular worksapce! Try again in an Angular project.');
16
- const { name, description } = _options;
17
- const camelName = (0, camelcase_formatter_1.CamelCaseFormatter)(name, false);
18
- const lowerCamelName = (0, camelcase_formatter_1.CamelCaseFormatter)(name, true);
19
- const ModuleRoutingFile = `import { NgModule } from '@angular/core';
20
- import { Routes, RouterModule } from '@angular/router';
21
-
22
- // Containers
23
-
24
- const routes: Routes = [
25
- ];
26
-
27
- @NgModule({
28
- imports: [RouterModule.forChild(routes)],
29
- exports: [RouterModule],
30
- })
31
- export class ${camelName}RoutingModule { }
32
- `;
33
- const ModuleSpecFile = `import { ${camelName}Module } from './${name}.module';
34
-
35
- describe('${camelName}Module', () => {
36
- let ${lowerCamelName}Module: ${camelName}Module;
37
-
38
- beforeEach(() => {
39
- ${lowerCamelName}Module = new ${camelName}Module();
40
- });
41
-
42
- it('should create an instance', () => {
43
- expect(${lowerCamelName}Module).toBeTruthy();
44
- });
45
- });
46
- `;
47
- const ModuleFile = `import { NgModule } from '@angular/core';
48
- import { CommonModule } from '@angular/common';
49
- import { EffectsModule } from '@ngrx/effects';
50
- import { SharedModule } from '../shared/shared.module';
51
- import { ${camelName}RoutingModule } from './${name}-routing.module';
52
-
53
- // Containers
54
-
55
- // Components
56
-
57
- /** ${description} */
58
- @NgModule({
59
- imports: [
60
- CommonModule,
61
- SharedModule,
62
- ${camelName}RoutingModule,
63
- EffectsModule.forFeature([
64
- ]),
65
- ],
66
- declarations: [
67
- // Containers
68
- // Components
69
- ],
70
- })
71
- export class ${camelName}Module { }`;
72
- const filePath = 'src/app/app.module.ts';
73
- const labels = ['// Feature Modules', '// Feature Modules'];
74
- const statements = [`import { ${camelName}Module } from './${name}/${name}.module';`, ` ${camelName}Module,`];
75
- (0, statements_adder_1.AddStatements)(filePath, labels, statements, tree);
76
- // create directory before adding files
77
- const dir = `./src/app/${name}`;
78
- if (!fs.existsSync(dir)) {
79
- fs.mkdirSync(dir);
20
+ function addInserts(options) {
21
+ return (host, context) => {
22
+ const classifiedName = core_1.strings.classify(options.name);
23
+ const dasherizedName = core_1.strings.dasherize(options.name);
24
+ const modulePath = '//src/app/' +
25
+ core_1.strings.dasherize(options.name) + '/' +
26
+ core_1.strings.dasherize(options.name) + '.module';
27
+ context.logger.info(`modulePath: ${modulePath}`);
28
+ if (!options.lazyLoading) {
29
+ // Add app module changes if not lazy loaded
30
+ const appModulePath = '//src/app/app.module.ts';
31
+ const appModuleText = (0, statements_adder_1.getSourceText)(host, appModulePath);
32
+ context.logger.info(`appModulePath: ${appModulePath}`);
33
+ const appModuleToModulePath = (0, find_module_1.buildRelativePath)(appModulePath, modulePath);
34
+ let insertChanges = (0, statements_adder_1.simpleInsert)(appModuleText, appModulePath, [
35
+ '// Feature Modules',
36
+ '// Feature Modules'
37
+ ], [
38
+ `import { ${classifiedName}Module } from '${appModuleToModulePath}';`,
39
+ ` ${classifiedName}Module,`
40
+ ]);
41
+ const declarationRecorder = host.beginUpdate(appModulePath);
42
+ for (const change of insertChanges) {
43
+ if (change instanceof change_1.InsertChange) {
44
+ declarationRecorder.insertLeft(change.pos, change.toAdd);
45
+ }
46
+ }
47
+ host.commitUpdate(declarationRecorder);
80
48
  }
81
- tree.create(`${dir}/${name}-routing.module.ts`, ModuleRoutingFile);
82
- tree.create(`${dir}/${name}.module.spec.ts`, ModuleSpecFile);
83
- tree.create(`${dir}/${name}.module.ts`, ModuleFile);
84
- return tree;
49
+ else {
50
+ // Add app-routing module changes if lazy loaded
51
+ const appRoutingModulePath = '//src/app/app-routing.module.ts';
52
+ const appRoutingModuleText = (0, statements_adder_1.getSourceText)(host, appRoutingModulePath);
53
+ const appRoutingModuleToModulePath = (0, find_module_1.buildRelativePath)(appRoutingModulePath, modulePath);
54
+ context.logger.info(`appRoutingModuleToModulePath: ${appRoutingModuleToModulePath}`);
55
+ let insertChanges = (0, statements_adder_1.simpleInsert)(appRoutingModuleText, appRoutingModulePath, [
56
+ 'const appRoutes: Routes = ['
57
+ ], [
58
+ ` { path: '${dasherizedName}', loadChildren: () => import('${appRoutingModuleToModulePath}').then((mod) => mod.${classifiedName}Module) },`
59
+ ]);
60
+ context.logger.info(`insertChanges: ${insertChanges}`);
61
+ const declarationRecorder = host.beginUpdate(appRoutingModulePath);
62
+ for (const change of insertChanges) {
63
+ if (change instanceof change_1.InsertChange) {
64
+ declarationRecorder.insertLeft(change.pos, change.toAdd);
65
+ }
66
+ }
67
+ host.commitUpdate(declarationRecorder);
68
+ }
69
+ return host;
85
70
  };
86
71
  }
72
+ function module(options) {
73
+ return (tree, context) => __awaiter(this, void 0, void 0, function* () {
74
+ context.logger.info("Starting module generation");
75
+ const workspace = yield (0, workspace_1.getWorkspace)(tree);
76
+ const project = workspace.projects.get(options.project);
77
+ if (!project) {
78
+ throw new schematics_1.SchematicsException(`Project "${options.project}" does not exist.`);
79
+ }
80
+ if (options.path === undefined) {
81
+ options.path = (0, workspace_1.buildDefaultPath)(project);
82
+ }
83
+ const parsedPath = (0, parse_name_1.parseName)(options.path, options.name);
84
+ options.name = parsedPath.name;
85
+ options.path = parsedPath.path;
86
+ const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
87
+ (0, schematics_1.applyTemplates)(Object.assign(Object.assign({}, core_1.strings), options)),
88
+ (0, schematics_1.move)(parsedPath.path),
89
+ ]);
90
+ return (0, schematics_1.chain)([
91
+ addInserts(options),
92
+ (0, schematics_1.mergeWith)(templateSource)
93
+ ]);
94
+ });
95
+ }
87
96
  exports.module = module;
88
97
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,2DAA+F;AAC/F,uEAAmE;AACnE,iEAA2D;AAE3D,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzB,iGAAiG;AACjG,YAAY;AACZ,SAAgB,MAAM,CAAC,QAAa;IAClC,OAAO,CAAC,IAAU,EAAE,QAA0B,EAAE,EAAE;QAChD,MAAM,aAAa,GAAG,cAAc,CAAC;QAErC,gDAAgD;QAChD,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC;YAC3B,MAAM,IAAI,gCAAmB,CAAC,uEAAuE,CAAC,C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ullSchematicsSchema",
4
- "title": "My Full Schematics Schema",
3
+ "$id": "ModuleSchema",
4
+ "title": "Module Schema",
5
5
  "type": "object",
6
+ "description": "Creates a new module in the default project.",
6
7
  "properties": {
7
8
  "index": {
8
9
  "type": "number",
9
10
  "default": 1
10
11
  },
11
- "name": {
12
+ "project": {
12
13
  "type": "string",
13
- "x-prompt": "What should we name the files?"
14
+ "description": "The name of the project.",
15
+ "$default": {
16
+ "$source": "projectName"
17
+ }
14
18
  },
15
- "description": {
19
+ "name": {
16
20
  "type": "string",
17
- "x-prompt": "Short description of the module (inserted as a comment):"
21
+ "description": "The name of the module.",
22
+ "$default": {
23
+ "$source": "argv",
24
+ "index": 0
25
+ },
26
+ "x-prompt": "What name would you like to use for the module?"
27
+ },
28
+ "lazyLoading": {
29
+ "type": "boolean",
30
+ "description": "Have it lazy loaded.",
31
+ "default": false,
32
+ "x-prompt": "Would you like the module to be lazy loaded?"
18
33
  }
19
34
  },
20
35
  "required": [
@@ -1,5 +1,8 @@
1
1
  import { Tree } from '@angular-devkit/schematics';
2
+ import { Change } from '@schematics/angular/utility/change';
2
3
  export interface IHash {
3
4
  [details: string]: number;
4
5
  }
6
+ export declare function getSourceText(host: Tree, filePath: string): string;
7
+ export declare function simpleInsert(sourceText: string, fileToEdit: string, labels: string[], statements: string[]): Change[];
5
8
  export declare function AddStatements(filePath: string, labels: string[], statements: string[], tree: Tree): void;
@@ -1,9 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AddStatements = void 0;
3
+ exports.AddStatements = exports.simpleInsert = exports.getSourceText = void 0;
4
4
  const schematics_1 = require("@angular-devkit/schematics");
5
5
  const change_1 = require("@schematics/angular/utility/change");
6
+ function getSourceText(host, filePath) {
7
+ const text = host.read(filePath);
8
+ if (text === null) {
9
+ throw new schematics_1.SchematicsException(`File ${filePath} does not exist.`);
10
+ }
11
+ return text.toString('utf-8');
12
+ }
13
+ exports.getSourceText = getSourceText;
14
+ function simpleInsert(sourceText, fileToEdit, labels, statements) {
15
+ let labelMap = {};
16
+ return labels.map((label, i) => {
17
+ if (labelMap[label] === undefined)
18
+ labelMap[label] = 0;
19
+ labelMap[label]++;
20
+ let count = labelMap[label];
21
+ let index = getPosition(sourceText, label, count) + label.length;
22
+ return new change_1.InsertChange(fileToEdit, index, `\n${statements[i]}`);
23
+ });
24
+ }
25
+ exports.simpleInsert = simpleInsert;
6
26
  function AddStatements(filePath, labels, statements, tree) {
27
+ // getSourceText
7
28
  let text = tree.read(filePath); // reads the file from the tree
8
29
  if (!text) {
9
30
  throw new schematics_1.SchematicsException(`${filePath} does not exist.`); // throw an error if the file doesn't exist
@@ -1 +1 @@
1
- {"version":3,"file":"statements-adder.js","sourceRoot":"","sources":["statements-adder.ts"],"names":[],"mappings":";;;AAAA,2DAAuE;AACvE,+DAAkE;AAMlE,SAAgB,aAAa,CAAC,QAAgB,EAAE,MAAgB,EAAE,UAAoB,EAAE,IAAU;IAC9F,IAAI,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,+BAA+B;IAC/D,IAAI,CAAC,IAAI,EAAE;QACT,MAAM,IAAI,gCAAmB,CAAC,GAAG,QAAQ,kBAAkB,CAAC,CAAC,CAAC,2CAA2C;KAC1G;IACD,IAAI,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACxC,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,MAAM,cAAc,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IAClD,IAAI,QAAQ,GAAW,EAAE,CAAC;IAC1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACtC,wCAAwC;QACxC,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS;YACjC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,C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