@rhtml/schematics 0.0.131 → 0.0.133

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/collection.json CHANGED
@@ -20,6 +20,11 @@
20
20
  "factory": "./dist/lib/service/service.factory#main",
21
21
  "description": "Create a @rhtml service.",
22
22
  "schema": "./dist/lib/service/schema.json"
23
+ },
24
+ "controller": {
25
+ "factory": "./dist/lib/controller/controller.factory#main",
26
+ "description": "Create a @rhtml controller.",
27
+ "schema": "./dist/lib/controller/schema.json"
23
28
  }
24
29
  }
25
- }
30
+ }
@@ -0,0 +1,3 @@
1
+ import { Rule } from '@angular-devkit/schematics';
2
+ import { ControllerOptions } from './controller.schema';
3
+ export declare function main(options: ControllerOptions): Rule;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.main = void 0;
4
+ const core_1 = require("@angular-devkit/core");
5
+ const schematics_1 = require("@angular-devkit/schematics");
6
+ const module_declarator_1 = require("../../utils/module.declarator");
7
+ const module_finder_1 = require("../../utils/module.finder");
8
+ const name_parser_1 = require("../../utils/name.parser");
9
+ const source_root_helpers_1 = require("../../utils/source-root.helpers");
10
+ const defaults_1 = require("../defaults");
11
+ const ELEMENT_METADATA = 'bootstrap';
12
+ const ELEMENT_TYPE = 'controller';
13
+ function main(options) {
14
+ options = transform(options);
15
+ return (tree, context) => {
16
+ return (0, schematics_1.branchAndMerge)((0, schematics_1.chain)([
17
+ (0, source_root_helpers_1.mergeSourceRoot)(options),
18
+ (0, schematics_1.mergeWith)(generate(options)),
19
+ addDeclarationToModule(options),
20
+ ]))(tree, context);
21
+ };
22
+ }
23
+ exports.main = main;
24
+ function transform(source) {
25
+ const target = Object.assign({}, source);
26
+ target.metadata = ELEMENT_METADATA;
27
+ target.type = ELEMENT_TYPE;
28
+ const location = new name_parser_1.NameParser().parse(target);
29
+ target.name = core_1.strings.dasherize(location.name);
30
+ target.path = core_1.strings.dasherize(location.path);
31
+ target.language =
32
+ target.language !== undefined ? target.language : defaults_1.DEFAULT_LANGUAGE;
33
+ target.path = target.flat
34
+ ? target.path
35
+ : (0, core_1.join)(target.path, target.name);
36
+ return target;
37
+ }
38
+ function generate(options) {
39
+ return (context) => (0, schematics_1.apply)((0, schematics_1.url)((0, core_1.join)('./files', options.language)), [
40
+ options.spec ? (0, schematics_1.noop)() : (0, schematics_1.filter)((path) => !path.endsWith('.spec.ts')),
41
+ (0, schematics_1.template)(Object.assign(Object.assign({}, core_1.strings), options)),
42
+ (0, schematics_1.move)(options.path),
43
+ ])(context);
44
+ }
45
+ function addDeclarationToModule(options) {
46
+ return (tree) => {
47
+ if (options.skipImport !== undefined && options.skipImport) {
48
+ return tree;
49
+ }
50
+ options.module = new module_finder_1.ModuleFinder(tree).find({
51
+ name: options.name,
52
+ path: options.path,
53
+ });
54
+ if (!options.module) {
55
+ return tree;
56
+ }
57
+ const content = tree.read(options.module).toString();
58
+ const declarator = new module_declarator_1.ModuleDeclarator();
59
+ tree.overwrite(options.module, declarator.declare(content, options));
60
+ return tree;
61
+ };
62
+ }
@@ -0,0 +1,92 @@
1
+ import { join, Path, strings } from '@angular-devkit/core';
2
+ import {
3
+ apply,
4
+ branchAndMerge,
5
+ chain,
6
+ filter,
7
+ mergeWith,
8
+ move,
9
+ noop,
10
+ Rule,
11
+ SchematicContext,
12
+ template,
13
+ Tree,
14
+ url,
15
+ } from '@angular-devkit/schematics';
16
+
17
+ import {
18
+ DeclarationOptions,
19
+ ModuleDeclarator,
20
+ } from '../../utils/module.declarator';
21
+ import { ModuleFinder } from '../../utils/module.finder';
22
+ import { Location, NameParser } from '../../utils/name.parser';
23
+ import { mergeSourceRoot } from '../../utils/source-root.helpers';
24
+ import { DEFAULT_LANGUAGE } from '../defaults';
25
+ import { ControllerOptions } from './controller.schema';
26
+
27
+ const ELEMENT_METADATA = 'bootstrap';
28
+ const ELEMENT_TYPE = 'controller';
29
+
30
+ export function main(options: ControllerOptions): Rule {
31
+ options = transform(options);
32
+ return (tree: Tree, context: SchematicContext) => {
33
+ return branchAndMerge(
34
+ chain([
35
+ mergeSourceRoot(options),
36
+ mergeWith(generate(options)),
37
+ addDeclarationToModule(options),
38
+ ])
39
+ )(tree, context);
40
+ };
41
+ }
42
+
43
+ function transform(source: ControllerOptions): ControllerOptions {
44
+ const target: ControllerOptions = Object.assign({}, source);
45
+ target.metadata = ELEMENT_METADATA;
46
+ target.type = ELEMENT_TYPE;
47
+
48
+ const location: Location = new NameParser().parse(target);
49
+ target.name = strings.dasherize(location.name);
50
+ target.path = strings.dasherize(location.path);
51
+ target.language =
52
+ target.language !== undefined ? target.language : DEFAULT_LANGUAGE;
53
+
54
+ target.path = target.flat
55
+ ? target.path
56
+ : join(target.path as Path, target.name);
57
+ return target;
58
+ }
59
+
60
+ function generate(options: ControllerOptions) {
61
+ return (context: SchematicContext) =>
62
+ apply(url(join('./files' as Path, options.language)), [
63
+ options.spec ? noop() : filter((path) => !path.endsWith('.spec.ts')),
64
+ template({
65
+ ...strings,
66
+ ...options,
67
+ }),
68
+ move(options.path),
69
+ ])(context);
70
+ }
71
+
72
+ function addDeclarationToModule(options: ControllerOptions): Rule {
73
+ return (tree: Tree) => {
74
+ if (options.skipImport !== undefined && options.skipImport) {
75
+ return tree;
76
+ }
77
+ options.module = new ModuleFinder(tree).find({
78
+ name: options.name,
79
+ path: options.path as Path,
80
+ });
81
+ if (!options.module) {
82
+ return tree;
83
+ }
84
+ const content = tree.read(options.module).toString();
85
+ const declarator: ModuleDeclarator = new ModuleDeclarator();
86
+ tree.overwrite(
87
+ options.module,
88
+ declarator.declare(content, options as DeclarationOptions)
89
+ );
90
+ return tree;
91
+ };
92
+ }
@@ -0,0 +1,33 @@
1
+ import { Bootstrap, get, Module } from '@rhtml/di'
2
+ import { FastifyModule } from '@rhtml/fastify'
3
+ import fastify from 'fastify'
4
+
5
+ import { <%= classify(name) %>Controller } from './<%= name %>.controller';
6
+
7
+ describe('<%= classify(name) %> Controller', () => {
8
+ let <%= decamelize(name) %>Controller: <%= classify(name) %>Controller
9
+
10
+ beforeAll(async () => {
11
+ @Module({
12
+ imports: [
13
+ FastifyModule.forRoot(fastify, {
14
+ logger: true,
15
+ }),
16
+ ],
17
+ bootstrap: [<%= classify(name) %>Controller],
18
+ })
19
+ class AppModule {}
20
+
21
+ await Bootstrap(AppModule)
22
+ <%= decamelize(name) %>Controller = get(<%= classify(name) %>Controller)
23
+
24
+ });
25
+
26
+ it('e2e: get => (<%= classify(name) %>) : Should sucessfully return expected result', async () => {
27
+ const response = {
28
+ hello: 'world',
29
+ }
30
+ const result = await <%= decamelize(name) %>Controller.get<%= classify(name) %>()
31
+ expect(result).toEqual(response)
32
+ });
33
+ });
@@ -0,0 +1,16 @@
1
+ import { Controller, Route } from '@rhtml/fastify'
2
+
3
+ @Controller({
4
+ route: '/<%= decamelize(name) %>',
5
+ })
6
+ export class <%= classify(name) %>Controller {
7
+
8
+ @Route({
9
+ method: 'GET',
10
+ })
11
+ get<%= classify(name) %>() {
12
+ return {
13
+ hello: 'world'
14
+ }
15
+ }
16
+ }
@@ -0,0 +1,49 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "id": "SchematicsRHTMLController",
4
+ "title": "RHTML Controller Options Schema",
5
+ "type": "object",
6
+ "properties": {
7
+ "name": {
8
+ "type": "string",
9
+ "description": "The name of the controller.",
10
+ "$default": {
11
+ "$source": "argv",
12
+ "index": 0
13
+ },
14
+ "x-prompt": "What name would you like to use for the controller?"
15
+ },
16
+ "path": {
17
+ "type": "string",
18
+ "format": "path",
19
+ "description": "The path to create the controller."
20
+ },
21
+ "language": {
22
+ "type": "string",
23
+ "description": "RHTML controller language (ts/js)."
24
+ },
25
+ "sourceRoot": {
26
+ "type": "string",
27
+ "description": "RHTML controller source root directory."
28
+ },
29
+ "skipImport": {
30
+ "description": "Flag to skip the module import.",
31
+ "default": false
32
+ },
33
+ "module": {
34
+ "type": "string",
35
+ "description": "Allows specification of the declaring module."
36
+ },
37
+ "flat": {
38
+ "default": false,
39
+ "description": "Flag to indicate if a directory is created."
40
+ },
41
+ "spec": {
42
+ "default": true,
43
+ "description": "Specifies if a spec file is generated."
44
+ }
45
+ },
46
+ "required": [
47
+ "name"
48
+ ]
49
+ }
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.main = void 0;
4
4
  const core_1 = require("@angular-devkit/core");
5
5
  const schematics_1 = require("@angular-devkit/schematics");
6
- const util_1 = require("util");
7
6
  const module_declarator_1 = require("../../utils/module.declarator");
8
7
  const module_finder_1 = require("../../utils/module.finder");
9
8
  const name_parser_1 = require("../../utils/name.parser");
@@ -30,7 +29,7 @@ function transform(source) {
30
29
  const target = Object.assign({}, source);
31
30
  target.metadata = 'providers';
32
31
  target.type = 'service';
33
- if ((0, util_1.isNullOrUndefined)(target.name)) {
32
+ if (!target.name) {
34
33
  throw new schematics_1.SchematicsException('Option (name) is required.');
35
34
  }
36
35
  const location = new name_parser_1.NameParser().parse(target);
@@ -14,7 +14,6 @@ import {
14
14
  Tree,
15
15
  url,
16
16
  } from '@angular-devkit/schematics';
17
- import { isNullOrUndefined } from 'util';
18
17
 
19
18
  import {
20
19
  DeclarationOptions,
@@ -52,7 +51,7 @@ function transform(source: ServiceOptions): ServiceOptions {
52
51
  target.metadata = 'providers';
53
52
  target.type = 'service';
54
53
 
55
- if (isNullOrUndefined(target.name)) {
54
+ if (!target.name) {
56
55
  throw new SchematicsException('Option (name) is required.');
57
56
  }
58
57
  const location: Location = new NameParser().parse(target);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhtml/schematics",
3
- "version": "0.0.131",
3
+ "version": "0.0.133",
4
4
  "description": "Reactive HyperText Markup Language",
5
5
  "scripts": {
6
6
  "start": "npx parcel ./examples/index.html --out-dir build/examples",
@@ -0,0 +1,92 @@
1
+ import { join, Path, strings } from '@angular-devkit/core';
2
+ import {
3
+ apply,
4
+ branchAndMerge,
5
+ chain,
6
+ filter,
7
+ mergeWith,
8
+ move,
9
+ noop,
10
+ Rule,
11
+ SchematicContext,
12
+ template,
13
+ Tree,
14
+ url,
15
+ } from '@angular-devkit/schematics';
16
+
17
+ import {
18
+ DeclarationOptions,
19
+ ModuleDeclarator,
20
+ } from '../../utils/module.declarator';
21
+ import { ModuleFinder } from '../../utils/module.finder';
22
+ import { Location, NameParser } from '../../utils/name.parser';
23
+ import { mergeSourceRoot } from '../../utils/source-root.helpers';
24
+ import { DEFAULT_LANGUAGE } from '../defaults';
25
+ import { ControllerOptions } from './controller.schema';
26
+
27
+ const ELEMENT_METADATA = 'bootstrap';
28
+ const ELEMENT_TYPE = 'controller';
29
+
30
+ export function main(options: ControllerOptions): Rule {
31
+ options = transform(options);
32
+ return (tree: Tree, context: SchematicContext) => {
33
+ return branchAndMerge(
34
+ chain([
35
+ mergeSourceRoot(options),
36
+ mergeWith(generate(options)),
37
+ addDeclarationToModule(options),
38
+ ])
39
+ )(tree, context);
40
+ };
41
+ }
42
+
43
+ function transform(source: ControllerOptions): ControllerOptions {
44
+ const target: ControllerOptions = Object.assign({}, source);
45
+ target.metadata = ELEMENT_METADATA;
46
+ target.type = ELEMENT_TYPE;
47
+
48
+ const location: Location = new NameParser().parse(target);
49
+ target.name = strings.dasherize(location.name);
50
+ target.path = strings.dasherize(location.path);
51
+ target.language =
52
+ target.language !== undefined ? target.language : DEFAULT_LANGUAGE;
53
+
54
+ target.path = target.flat
55
+ ? target.path
56
+ : join(target.path as Path, target.name);
57
+ return target;
58
+ }
59
+
60
+ function generate(options: ControllerOptions) {
61
+ return (context: SchematicContext) =>
62
+ apply(url(join('./files' as Path, options.language)), [
63
+ options.spec ? noop() : filter((path) => !path.endsWith('.spec.ts')),
64
+ template({
65
+ ...strings,
66
+ ...options,
67
+ }),
68
+ move(options.path),
69
+ ])(context);
70
+ }
71
+
72
+ function addDeclarationToModule(options: ControllerOptions): Rule {
73
+ return (tree: Tree) => {
74
+ if (options.skipImport !== undefined && options.skipImport) {
75
+ return tree;
76
+ }
77
+ options.module = new ModuleFinder(tree).find({
78
+ name: options.name,
79
+ path: options.path as Path,
80
+ });
81
+ if (!options.module) {
82
+ return tree;
83
+ }
84
+ const content = tree.read(options.module).toString();
85
+ const declarator: ModuleDeclarator = new ModuleDeclarator();
86
+ tree.overwrite(
87
+ options.module,
88
+ declarator.declare(content, options as DeclarationOptions)
89
+ );
90
+ return tree;
91
+ };
92
+ }
@@ -0,0 +1,33 @@
1
+ import { Bootstrap, get, Module } from '@rhtml/di'
2
+ import { FastifyModule } from '@rhtml/fastify'
3
+ import fastify from 'fastify'
4
+
5
+ import { <%= classify(name) %>Controller } from './<%= name %>.controller';
6
+
7
+ describe('<%= classify(name) %> Controller', () => {
8
+ let <%= decamelize(name) %>Controller: <%= classify(name) %>Controller
9
+
10
+ beforeAll(async () => {
11
+ @Module({
12
+ imports: [
13
+ FastifyModule.forRoot(fastify, {
14
+ logger: true,
15
+ }),
16
+ ],
17
+ bootstrap: [<%= classify(name) %>Controller],
18
+ })
19
+ class AppModule {}
20
+
21
+ await Bootstrap(AppModule)
22
+ <%= decamelize(name) %>Controller = get(<%= classify(name) %>Controller)
23
+
24
+ });
25
+
26
+ it('e2e: get => (<%= classify(name) %>) : Should sucessfully return expected result', async () => {
27
+ const response = {
28
+ hello: 'world',
29
+ }
30
+ const result = await <%= decamelize(name) %>Controller.get<%= classify(name) %>()
31
+ expect(result).toEqual(response)
32
+ });
33
+ });
@@ -0,0 +1,16 @@
1
+ import { Controller, Route } from '@rhtml/fastify'
2
+
3
+ @Controller({
4
+ route: '/<%= decamelize(name) %>',
5
+ })
6
+ export class <%= classify(name) %>Controller {
7
+
8
+ @Route({
9
+ method: 'GET',
10
+ })
11
+ get<%= classify(name) %>() {
12
+ return {
13
+ hello: 'world'
14
+ }
15
+ }
16
+ }
@@ -0,0 +1,49 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "id": "SchematicsRHTMLController",
4
+ "title": "RHTML Controller Options Schema",
5
+ "type": "object",
6
+ "properties": {
7
+ "name": {
8
+ "type": "string",
9
+ "description": "The name of the controller.",
10
+ "$default": {
11
+ "$source": "argv",
12
+ "index": 0
13
+ },
14
+ "x-prompt": "What name would you like to use for the controller?"
15
+ },
16
+ "path": {
17
+ "type": "string",
18
+ "format": "path",
19
+ "description": "The path to create the controller."
20
+ },
21
+ "language": {
22
+ "type": "string",
23
+ "description": "RHTML controller language (ts/js)."
24
+ },
25
+ "sourceRoot": {
26
+ "type": "string",
27
+ "description": "RHTML controller source root directory."
28
+ },
29
+ "skipImport": {
30
+ "description": "Flag to skip the module import.",
31
+ "default": false
32
+ },
33
+ "module": {
34
+ "type": "string",
35
+ "description": "Allows specification of the declaring module."
36
+ },
37
+ "flat": {
38
+ "default": false,
39
+ "description": "Flag to indicate if a directory is created."
40
+ },
41
+ "spec": {
42
+ "default": true,
43
+ "description": "Specifies if a spec file is generated."
44
+ }
45
+ },
46
+ "required": [
47
+ "name"
48
+ ]
49
+ }
@@ -14,7 +14,6 @@ import {
14
14
  Tree,
15
15
  url,
16
16
  } from '@angular-devkit/schematics';
17
- import { isNullOrUndefined } from 'util';
18
17
 
19
18
  import {
20
19
  DeclarationOptions,
@@ -52,7 +51,7 @@ function transform(source: ServiceOptions): ServiceOptions {
52
51
  target.metadata = 'providers';
53
52
  target.type = 'service';
54
53
 
55
- if (isNullOrUndefined(target.name)) {
54
+ if (!target.name) {
56
55
  throw new SchematicsException('Option (name) is required.');
57
56
  }
58
57
  const location: Location = new NameParser().parse(target);