@rxdi/schematics 0.7.124 → 0.7.128
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/lib/application/application.factory.js +4 -4
- package/lib/application/application.factory.test.ts +88 -0
- package/lib/application/application.factory.ts +54 -0
- package/lib/application/application.schema.d.ts +34 -0
- package/lib/application/files/js/.babelrc +4 -0
- package/lib/application/files/js/.prettierrc +4 -0
- package/lib/application/files/js/README.md +37 -0
- package/lib/application/files/js/index.js +3 -0
- package/lib/application/files/js/jsconfig.json +9 -0
- package/lib/application/files/js/nest-cli.json +5 -0
- package/lib/application/files/js/nodemon.json +6 -0
- package/lib/application/files/js/package.json +46 -0
- package/lib/application/files/js/test/app.e2e-spec.js +23 -0
- package/lib/application/files/js/test/jest-e2e.json +5 -0
- package/lib/application/files/ts/.prettierrc +4 -0
- package/lib/application/files/ts/README.md +75 -0
- package/lib/application/files/ts/nest-cli.json +5 -0
- package/lib/application/files/ts/nodemon-debug.json +6 -0
- package/lib/application/files/ts/nodemon.json +6 -0
- package/lib/application/files/ts/package.json +58 -0
- package/lib/application/files/ts/test/app.e2e-spec.ts +23 -0
- package/lib/application/files/ts/test/jest-e2e.json +9 -0
- package/lib/application/files/ts/tsconfig.build.json +4 -0
- package/lib/application/schema.json +49 -0
- package/lib/class/class.factory.js +6 -6
- package/lib/class/class.factory.test.ts +100 -0
- package/lib/class/class.factory.ts +54 -0
- package/lib/class/class.schema.d.ts +28 -0
- package/lib/class/files/js/__name__.js +1 -0
- package/lib/class/files/js/__name__.spec.js +7 -0
- package/lib/class/files/ts/__name__.spec.ts +7 -0
- package/lib/class/files/ts/__name__.ts +1 -0
- package/lib/class/schema.json +39 -0
- package/lib/client-app/angular/angular.factory.js +9 -9
- package/lib/client-app/angular/angular.factory.ts +139 -0
- package/lib/client-app/angular/angular.schema.d.ts +32 -0
- package/lib/client-app/angular/files/angular.constants.ts +4 -0
- package/lib/client-app/angular/files/angular.module.ts +41 -0
- package/lib/client-app/angular/files/angular.providers.ts +27 -0
- package/lib/client-app/angular/files/angular.utils.ts +19 -0
- package/lib/client-app/angular/files/interfaces/angular-options.interface.ts +87 -0
- package/lib/client-app/angular/files/loaders/abstract.loader.ts +16 -0
- package/lib/client-app/angular/files/loaders/express.loader.ts +25 -0
- package/lib/client-app/angular/files/loaders/fastify.loader.ts +34 -0
- package/lib/client-app/angular/files/loaders/noop.loader.ts +12 -0
- package/lib/client-app/angular/schema.json +24 -0
- package/lib/component/component.factory.js +8 -8
- package/lib/component/component.factory.test.ts +191 -0
- package/lib/component/component.factory.ts +91 -0
- package/lib/component/component.schema.d.ts +44 -0
- package/lib/component/files/js/__name__.component.js +56 -0
- package/lib/component/files/js/__name__.component.spec.js +31 -0
- package/lib/component/files/ts/__name__.component.spec.ts +31 -0
- package/lib/component/files/ts/__name__.component.ts +56 -0
- package/lib/component/schema.json +47 -0
- package/lib/configuration/configuration.factory.js +4 -4
- package/lib/configuration/configuration.factory.test.ts +60 -0
- package/lib/configuration/configuration.factory.ts +35 -0
- package/lib/configuration/configuration.schema.d.ts +18 -0
- package/lib/configuration/files/js/nest-cli.json +5 -0
- package/lib/configuration/files/ts/nest-cli.json +5 -0
- package/lib/controller/controller.factory.js +8 -8
- package/lib/controller/controller.factory.test.ts +191 -0
- package/lib/controller/controller.factory.ts +91 -0
- package/lib/controller/controller.schema.d.ts +44 -0
- package/lib/controller/files/js/__name__.controller.js +24 -0
- package/lib/controller/files/js/__name__.controller.spec.js +61 -0
- package/lib/controller/files/ts/__name__.controller.spec.ts +61 -0
- package/lib/controller/files/ts/__name__.controller.ts +24 -0
- package/lib/controller/schema.json +47 -0
- package/lib/decorator/decorator.factory.js +5 -5
- package/lib/decorator/decorator.factory.test.ts +111 -0
- package/lib/decorator/decorator.factory.ts +48 -0
- package/lib/decorator/decorator.schema.d.ts +24 -0
- package/lib/decorator/files/js/__name__.decorator.js +3 -0
- package/lib/decorator/files/ts/__name__.decorator.ts +3 -0
- package/lib/decorator/schema.json +35 -0
- package/lib/defaults.ts +6 -0
- package/lib/effect/effect.factory.js +9 -9
- package/lib/effect/effect.factory.test.ts +190 -0
- package/lib/effect/effect.factory.ts +91 -0
- package/lib/effect/effect.schema.d.ts +44 -0
- package/lib/effect/files/js/__name__.effect.js +11 -0
- package/lib/effect/files/js/__name__.effect.spec.js +17 -0
- package/lib/effect/files/ts/__name__.effect.spec.ts +17 -0
- package/lib/effect/files/ts/__name__.effect.ts +11 -0
- package/lib/effect/schema.json +39 -0
- package/lib/filter/files/js/__name__.filter.js +6 -0
- package/lib/filter/files/js/__name__.filter.spec.js +7 -0
- package/lib/filter/files/ts/__name__.filter.spec.ts +7 -0
- package/lib/filter/files/ts/__name__.filter.ts +6 -0
- package/lib/filter/filter.factory.js +6 -6
- package/lib/filter/filter.factory.test.ts +147 -0
- package/lib/filter/filter.factory.ts +51 -0
- package/lib/filter/filter.schema.d.ts +28 -0
- package/lib/filter/schema.json +39 -0
- package/lib/gateway/files/js/__name__.gateway.js +9 -0
- package/lib/gateway/files/js/__name__.gateway.spec.js +18 -0
- package/lib/gateway/files/ts/__name__.gateway.spec.ts +18 -0
- package/lib/gateway/files/ts/__name__.gateway.ts +9 -0
- package/lib/gateway/gateway.factory.js +8 -8
- package/lib/gateway/gateway.factory.test.ts +147 -0
- package/lib/gateway/gateway.factory.ts +92 -0
- package/lib/gateway/gateway.schema.d.ts +36 -0
- package/lib/gateway/schema.json +39 -0
- package/lib/guard/files/js/__name__.guard.js +17 -0
- package/lib/guard/files/js/__name__.guard.spec.js +7 -0
- package/lib/guard/files/ts/__name__.guard.spec.ts +7 -0
- package/lib/guard/files/ts/__name__.guard.ts +17 -0
- package/lib/guard/guard.factory.js +6 -6
- package/lib/guard/guard.factory.test.ts +156 -0
- package/lib/guard/guard.factory.ts +51 -0
- package/lib/guard/guard.schema.d.ts +28 -0
- package/lib/guard/schema.json +39 -0
- package/lib/interceptor/files/js/__name__.interceptor.js +18 -0
- package/lib/interceptor/files/js/__name__.interceptor.spec.js +7 -0
- package/lib/interceptor/files/ts/__name__.interceptor.spec.ts +7 -0
- package/lib/interceptor/files/ts/__name__.interceptor.ts +19 -0
- package/lib/interceptor/interceptor.factory.js +6 -6
- package/lib/interceptor/interceptor.factory.test.ts +146 -0
- package/lib/interceptor/interceptor.factory.ts +51 -0
- package/lib/interceptor/interceptor.schema.d.ts +28 -0
- package/lib/interceptor/schema.json +39 -0
- package/lib/interface/files/__name__.interface.ts +1 -0
- package/lib/interface/interface.factory.js +5 -5
- package/lib/interface/interface.factory.test.ts +84 -0
- package/lib/interface/interface.factory.ts +47 -0
- package/lib/interface/interface.schema.d.ts +20 -0
- package/lib/interface/schema.json +31 -0
- package/lib/library/files/js/.babelrc +4 -0
- package/lib/library/files/js/jsconfig.json +9 -0
- package/lib/library/files/js/package.json +8 -0
- package/lib/library/files/js/src/__name__.module.js +8 -0
- package/lib/library/files/js/src/__name__.service.js +4 -0
- package/lib/library/files/js/src/__name__.service.spec.js +18 -0
- package/lib/library/files/js/src/index.js +2 -0
- package/lib/library/files/ts/package.json +8 -0
- package/lib/library/files/ts/src/__name__.module.ts +8 -0
- package/lib/library/files/ts/src/__name__.service.spec.ts +18 -0
- package/lib/library/files/ts/src/__name__.service.ts +4 -0
- package/lib/library/files/ts/src/index.ts +2 -0
- package/lib/library/files/ts/tsconfig.lib.json +5 -0
- package/lib/library/library.factory.js +12 -12
- package/lib/library/library.factory.test.ts +68 -0
- package/lib/library/library.factory.ts +158 -0
- package/lib/library/library.schema.d.ts +24 -0
- package/lib/library/schema.json +37 -0
- package/lib/module/files/js/__name__.module.js +4 -0
- package/lib/module/files/ts/__name__.module.ts +4 -0
- package/lib/module/module.factory.js +7 -7
- package/lib/module/module.factory.test.ts +165 -0
- package/lib/module/module.factory.ts +79 -0
- package/lib/module/module.schema.d.ts +36 -0
- package/lib/module/schema.json +40 -0
- package/lib/pipe/files/js/__name__.pipe.js +8 -0
- package/lib/pipe/files/js/__name__.pipe.spec.js +7 -0
- package/lib/pipe/files/ts/__name__.pipe.spec.ts +7 -0
- package/lib/pipe/files/ts/__name__.pipe.ts +8 -0
- package/lib/pipe/pipe.factory.js +6 -6
- package/lib/pipe/pipe.factory.test.ts +141 -0
- package/lib/pipe/pipe.factory.ts +51 -0
- package/lib/pipe/pipe.schema.d.ts +28 -0
- package/lib/pipe/schema.json +39 -0
- package/lib/plugin/files/js/__name__.plugin.js +28 -0
- package/lib/plugin/files/js/__name__.plugin.spec.js +7 -0
- package/lib/plugin/files/ts/__name__.plugin.spec.ts +7 -0
- package/lib/plugin/files/ts/__name__.plugin.ts +28 -0
- package/lib/plugin/plugin.factory.d.ts +2 -2
- package/lib/plugin/plugin.factory.js +1 -2
- package/lib/plugin/plugin.factory.test.ts +191 -0
- package/lib/plugin/plugin.factory.ts +91 -0
- package/lib/plugin/plugin.schema.d.ts +44 -0
- package/lib/plugin/schema.json +52 -0
- package/lib/provider/files/js/__name__.js +4 -0
- package/lib/provider/files/js/__name__.spec.js +17 -0
- package/lib/provider/files/ts/__name__.spec.ts +17 -0
- package/lib/provider/files/ts/__name__.ts +4 -0
- package/lib/provider/provider.factory.js +1 -2
- package/lib/provider/provider.factory.test.ts +151 -0
- package/lib/provider/provider.factory.ts +89 -0
- package/lib/provider/provider.schema.d.ts +44 -0
- package/lib/provider/schema.json +39 -0
- package/lib/resolver/files/js/__name__.resolver.js +4 -0
- package/lib/resolver/files/js/__name__.resolver.spec.js +18 -0
- package/lib/resolver/files/ts/__name__.resolver.spec.ts +18 -0
- package/lib/resolver/files/ts/__name__.resolver.ts +4 -0
- package/lib/resolver/resolver.factory.js +8 -8
- package/lib/resolver/resolver.factory.test.ts +117 -0
- package/lib/resolver/resolver.factory.ts +92 -0
- package/lib/resolver/resolver.schema.d.ts +36 -0
- package/lib/resolver/schema.json +39 -0
- package/lib/service/files/js/__name__.service.js +4 -0
- package/lib/service/files/js/__name__.service.spec.js +17 -0
- package/lib/service/files/ts/__name__.service.spec.ts +17 -0
- package/lib/service/files/ts/__name__.service.ts +4 -0
- package/lib/service/schema.json +39 -0
- package/lib/service/service.factory.js +9 -9
- package/lib/service/service.factory.test.ts +190 -0
- package/lib/service/service.factory.ts +91 -0
- package/lib/service/service.schema.d.ts +44 -0
- package/lib/type/files/js/__name__.type.js +10 -0
- package/lib/type/files/ts/__name__.type.ts +10 -0
- package/lib/type/schema.json +43 -0
- package/lib/type/type.factory.d.ts +1 -1
- package/lib/type/type.factory.js +1 -2
- package/lib/type/type.factory.test.ts +191 -0
- package/lib/type/type.factory.ts +91 -0
- package/lib/type/type.schema.d.ts +44 -0
- package/package.json +2 -2
- package/utils/metadata.manager.js +1 -1
- package/utils/metadata.manager.ts +219 -0
- package/utils/module-import.declarator.js +2 -2
- package/utils/module-import.declarator.ts +41 -0
- package/utils/module-metadata.declarator.ts +14 -0
- package/utils/module.declarator.js +2 -2
- package/utils/module.declarator.ts +41 -0
- package/utils/module.finder.js +1 -1
- package/utils/module.finder.ts +32 -0
- package/utils/name.parser.js +3 -3
- package/utils/name.parser.ts +29 -0
- package/utils/path.solver.js +2 -2
- package/utils/path.solver.ts +17 -0
- package/utils/source-root.helpers.js +2 -2
- package/utils/source-root.helpers.ts +30 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SchematicTestRunner,
|
|
3
|
+
UnitTestTree,
|
|
4
|
+
} from '@angular-devkit/schematics/testing';
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
import { ClassOptions } from './class.schema';
|
|
7
|
+
|
|
8
|
+
describe('Class Factory', () => {
|
|
9
|
+
const runner: SchematicTestRunner = new SchematicTestRunner(
|
|
10
|
+
'.',
|
|
11
|
+
path.join(process.cwd(), 'src/collection.json'),
|
|
12
|
+
);
|
|
13
|
+
it('should manage name only', () => {
|
|
14
|
+
const options: ClassOptions = {
|
|
15
|
+
name: 'foo',
|
|
16
|
+
spec: true,
|
|
17
|
+
flat: true,
|
|
18
|
+
};
|
|
19
|
+
const tree: UnitTestTree = runner.runSchematic('class', options);
|
|
20
|
+
const files: string[] = tree.files;
|
|
21
|
+
|
|
22
|
+
expect(files.find(filename => filename === '/foo.ts')).not.toBeUndefined();
|
|
23
|
+
expect(tree.readContent('/foo.ts')).toEqual('export class Foo {}\n');
|
|
24
|
+
});
|
|
25
|
+
it('should manage name as a path', () => {
|
|
26
|
+
const options: ClassOptions = {
|
|
27
|
+
name: 'bar/foo',
|
|
28
|
+
flat: false,
|
|
29
|
+
spec: false,
|
|
30
|
+
};
|
|
31
|
+
const tree: UnitTestTree = runner.runSchematic('class', options);
|
|
32
|
+
const files: string[] = tree.files;
|
|
33
|
+
expect(
|
|
34
|
+
files.find(filename => filename === '/bar/foo/foo.ts'),
|
|
35
|
+
).not.toBeUndefined();
|
|
36
|
+
expect(tree.readContent('/bar/foo/foo.ts')).toEqual(
|
|
37
|
+
'export class Foo {}\n',
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
it('should manage name and path', () => {
|
|
41
|
+
const options: ClassOptions = {
|
|
42
|
+
name: 'foo',
|
|
43
|
+
path: 'baz',
|
|
44
|
+
flat: false,
|
|
45
|
+
spec: false,
|
|
46
|
+
};
|
|
47
|
+
const tree: UnitTestTree = runner.runSchematic('class', options);
|
|
48
|
+
const files: string[] = tree.files;
|
|
49
|
+
expect(
|
|
50
|
+
files.find(filename => filename === '/baz/foo/foo.ts'),
|
|
51
|
+
).not.toBeUndefined();
|
|
52
|
+
expect(tree.readContent('/baz/foo/foo.ts')).toEqual(
|
|
53
|
+
'export class Foo {}\n',
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
it('should manage name to dasherize', () => {
|
|
57
|
+
const options: ClassOptions = {
|
|
58
|
+
name: 'fooBar',
|
|
59
|
+
flat: false,
|
|
60
|
+
spec: false,
|
|
61
|
+
};
|
|
62
|
+
const tree: UnitTestTree = runner.runSchematic('class', options);
|
|
63
|
+
const files: string[] = tree.files;
|
|
64
|
+
expect(
|
|
65
|
+
files.find(filename => filename === '/foo-bar/foo-bar.ts'),
|
|
66
|
+
).not.toBeUndefined();
|
|
67
|
+
expect(tree.readContent('/foo-bar/foo-bar.ts')).toEqual(
|
|
68
|
+
'export class FooBar {}\n',
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
it('should manage path to dasherize', () => {
|
|
72
|
+
const options: ClassOptions = {
|
|
73
|
+
name: 'barBaz/foo',
|
|
74
|
+
spec: false,
|
|
75
|
+
flat: false,
|
|
76
|
+
};
|
|
77
|
+
const tree: UnitTestTree = runner.runSchematic('class', options);
|
|
78
|
+
const files: string[] = tree.files;
|
|
79
|
+
expect(
|
|
80
|
+
files.find(filename => filename === '/bar-baz/foo/foo.ts'),
|
|
81
|
+
).not.toBeUndefined();
|
|
82
|
+
expect(tree.readContent('/bar-baz/foo/foo.ts')).toEqual(
|
|
83
|
+
'export class Foo {}\n',
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
it('should manage javascript file', () => {
|
|
87
|
+
const options: ClassOptions = {
|
|
88
|
+
name: 'foo',
|
|
89
|
+
language: 'js',
|
|
90
|
+
flat: false,
|
|
91
|
+
spec: false,
|
|
92
|
+
};
|
|
93
|
+
const tree: UnitTestTree = runner.runSchematic('class', options);
|
|
94
|
+
const files: string[] = tree.files;
|
|
95
|
+
expect(
|
|
96
|
+
files.find(filename => filename === '/foo/foo.js'),
|
|
97
|
+
).not.toBeUndefined();
|
|
98
|
+
expect(tree.readContent('/foo/foo.js')).toEqual('export class Foo {}\n');
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { join, Path, strings } from '@angular-devkit/core';
|
|
2
|
+
import {
|
|
3
|
+
apply,
|
|
4
|
+
chain,
|
|
5
|
+
filter,
|
|
6
|
+
mergeWith,
|
|
7
|
+
move,
|
|
8
|
+
noop,
|
|
9
|
+
Rule,
|
|
10
|
+
SchematicContext,
|
|
11
|
+
SchematicsException,
|
|
12
|
+
Source,
|
|
13
|
+
template,
|
|
14
|
+
url,
|
|
15
|
+
} from '@angular-devkit/schematics';
|
|
16
|
+
import { Location, NameParser } from '../../utils/name.parser';
|
|
17
|
+
import { mergeSourceRoot } from '../../utils/source-root.helpers';
|
|
18
|
+
import { DEFAULT_LANGUAGE } from '../defaults';
|
|
19
|
+
import { ClassOptions } from './class.schema';
|
|
20
|
+
|
|
21
|
+
export function main(options: ClassOptions): Rule {
|
|
22
|
+
options = transform(options);
|
|
23
|
+
return chain([mergeSourceRoot(options), mergeWith(generate(options))]);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function transform(options: ClassOptions): ClassOptions {
|
|
27
|
+
const target: ClassOptions = Object.assign({}, options);
|
|
28
|
+
if (!target.name) {
|
|
29
|
+
throw new SchematicsException('Option (name) is required.');
|
|
30
|
+
}
|
|
31
|
+
const location: Location = new NameParser().parse(target);
|
|
32
|
+
target.name = strings.dasherize(location.name);
|
|
33
|
+
target.language =
|
|
34
|
+
target.language !== undefined ? target.language : DEFAULT_LANGUAGE;
|
|
35
|
+
|
|
36
|
+
target.path = strings.dasherize(location.path);
|
|
37
|
+
target.path = target.flat
|
|
38
|
+
? target.path
|
|
39
|
+
: join(target.path as Path, target.name);
|
|
40
|
+
|
|
41
|
+
return target;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function generate(options: ClassOptions): Source {
|
|
45
|
+
return (context: SchematicContext) =>
|
|
46
|
+
apply(url(join('./files' as Path, options.language)), [
|
|
47
|
+
options.spec ? noop() : filter(path => !path.endsWith('.spec.ts')),
|
|
48
|
+
template({
|
|
49
|
+
...strings,
|
|
50
|
+
...options,
|
|
51
|
+
}),
|
|
52
|
+
move(options.path),
|
|
53
|
+
])(context);
|
|
54
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Path } from '@angular-devkit/core';
|
|
2
|
+
|
|
3
|
+
export interface ClassOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The name of the class.
|
|
6
|
+
*/
|
|
7
|
+
name: string;
|
|
8
|
+
/**
|
|
9
|
+
* The path to create the class.
|
|
10
|
+
*/
|
|
11
|
+
path?: string | Path;
|
|
12
|
+
/**
|
|
13
|
+
* Application language.
|
|
14
|
+
*/
|
|
15
|
+
language?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The source root path
|
|
18
|
+
*/
|
|
19
|
+
sourceRoot?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Specifies if a spec file is generated.
|
|
22
|
+
*/
|
|
23
|
+
spec?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Flag to indicate if a directory is created.
|
|
26
|
+
*/
|
|
27
|
+
flat?: boolean;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export class <%= classify(name) %> {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export class <%= classify(name) %> {}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"id": "SchematicsNestClass",
|
|
4
|
+
"title": "Nest Class Options Schema",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"name": {
|
|
8
|
+
"type": "string",
|
|
9
|
+
"description": "The name of the class.",
|
|
10
|
+
"$default": {
|
|
11
|
+
"$source": "argv",
|
|
12
|
+
"index": 0
|
|
13
|
+
},
|
|
14
|
+
"x-prompt": "What name would you like to use for the class?"
|
|
15
|
+
},
|
|
16
|
+
"flat": {
|
|
17
|
+
"default": true,
|
|
18
|
+
"description": "Flag to indicate if a directory is created."
|
|
19
|
+
},
|
|
20
|
+
"spec": {
|
|
21
|
+
"default": true,
|
|
22
|
+
"description": "Specifies if a spec file is generated."
|
|
23
|
+
},
|
|
24
|
+
"path": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"format": "path",
|
|
27
|
+
"description": "The path to create the class."
|
|
28
|
+
},
|
|
29
|
+
"language": {
|
|
30
|
+
"type": "string",
|
|
31
|
+
"description": "Nest class language (ts/js)."
|
|
32
|
+
},
|
|
33
|
+
"sourceRoot": {
|
|
34
|
+
"type": "string",
|
|
35
|
+
"description": "Nest controller source root directory."
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"required": ["name"]
|
|
39
|
+
}
|
|
@@ -12,12 +12,12 @@ const source_root_helpers_1 = require("../../../utils/source-root.helpers");
|
|
|
12
12
|
function main(options) {
|
|
13
13
|
options = transform(options);
|
|
14
14
|
return (tree, context) => {
|
|
15
|
-
return schematics_1.branchAndMerge(schematics_1.chain([
|
|
15
|
+
return (0, schematics_1.branchAndMerge)((0, schematics_1.chain)([
|
|
16
16
|
createAngularApplication(options),
|
|
17
|
-
source_root_helpers_1.mergeSourceRoot(options),
|
|
17
|
+
(0, source_root_helpers_1.mergeSourceRoot)(options),
|
|
18
18
|
addDeclarationToModule(options),
|
|
19
19
|
addGlobalPrefix(),
|
|
20
|
-
schematics_1.mergeWith(generate(options)),
|
|
20
|
+
(0, schematics_1.mergeWith)(generate(options)),
|
|
21
21
|
]))(tree, context);
|
|
22
22
|
};
|
|
23
23
|
}
|
|
@@ -30,20 +30,20 @@ function transform(source) {
|
|
|
30
30
|
target.type = 'module';
|
|
31
31
|
const location = new name_parser_1.NameParser().parse(target);
|
|
32
32
|
target.name = core_1.strings.dasherize(location.name);
|
|
33
|
-
target.path = path_1.join(core_1.strings.dasherize(location.path), target.name);
|
|
33
|
+
target.path = (0, path_1.join)(core_1.strings.dasherize(location.path), target.name);
|
|
34
34
|
return target;
|
|
35
35
|
}
|
|
36
36
|
function generate(options) {
|
|
37
|
-
return (context) => schematics_1.apply(schematics_1.url('./files'), [
|
|
38
|
-
schematics_1.template(Object.assign(Object.assign({}, core_1.strings), options)),
|
|
39
|
-
schematics_1.move(options.path),
|
|
37
|
+
return (context) => (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
|
|
38
|
+
(0, schematics_1.template)(Object.assign(Object.assign({}, core_1.strings), options)),
|
|
39
|
+
(0, schematics_1.move)(options.path),
|
|
40
40
|
])(context);
|
|
41
41
|
}
|
|
42
42
|
function createAngularApplication(options) {
|
|
43
43
|
if (!options.initApp) {
|
|
44
|
-
return schematics_1.noop();
|
|
44
|
+
return (0, schematics_1.noop)();
|
|
45
45
|
}
|
|
46
|
-
return schematics_1.externalSchematic('@schematics/angular', 'ng-new', {
|
|
46
|
+
return (0, schematics_1.externalSchematic)('@schematics/angular', 'ng-new', {
|
|
47
47
|
name: options.directory,
|
|
48
48
|
version: '7.0.0',
|
|
49
49
|
});
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { strings } from '@angular-devkit/core';
|
|
2
|
+
import {
|
|
3
|
+
apply,
|
|
4
|
+
branchAndMerge,
|
|
5
|
+
chain,
|
|
6
|
+
externalSchematic,
|
|
7
|
+
mergeWith,
|
|
8
|
+
move,
|
|
9
|
+
noop,
|
|
10
|
+
Rule,
|
|
11
|
+
SchematicContext,
|
|
12
|
+
template,
|
|
13
|
+
Tree,
|
|
14
|
+
url,
|
|
15
|
+
} from '@angular-devkit/schematics';
|
|
16
|
+
import { join } from 'path';
|
|
17
|
+
import * as ts from 'ts-morph';
|
|
18
|
+
import { Path } from 'typescript';
|
|
19
|
+
import {
|
|
20
|
+
DeclarationOptions,
|
|
21
|
+
ModuleDeclarator,
|
|
22
|
+
} from '../../../utils/module.declarator';
|
|
23
|
+
import { ModuleFinder } from '../../../utils/module.finder';
|
|
24
|
+
import { Location, NameParser } from '../../../utils/name.parser';
|
|
25
|
+
import { mergeSourceRoot } from '../../../utils/source-root.helpers';
|
|
26
|
+
import { ModuleOptions } from '../../module/module.schema';
|
|
27
|
+
import { AngularOptions } from './angular.schema';
|
|
28
|
+
|
|
29
|
+
export function main(options: AngularOptions): Rule {
|
|
30
|
+
options = transform(options);
|
|
31
|
+
return (tree: Tree, context: SchematicContext) => {
|
|
32
|
+
return branchAndMerge(
|
|
33
|
+
chain([
|
|
34
|
+
createAngularApplication(options),
|
|
35
|
+
mergeSourceRoot(options),
|
|
36
|
+
addDeclarationToModule(options),
|
|
37
|
+
addGlobalPrefix(),
|
|
38
|
+
mergeWith(generate(options)),
|
|
39
|
+
]),
|
|
40
|
+
)(tree, context);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function transform(source: AngularOptions): ModuleOptions {
|
|
45
|
+
const target: AngularOptions = Object.assign({}, source);
|
|
46
|
+
target.directory = target.name ? strings.dasherize(target.name) : 'client';
|
|
47
|
+
target.name = 'Angular';
|
|
48
|
+
target.metadata = 'imports';
|
|
49
|
+
target.type = 'module';
|
|
50
|
+
|
|
51
|
+
const location: Location = new NameParser().parse(target);
|
|
52
|
+
target.name = strings.dasherize(location.name);
|
|
53
|
+
target.path = join(strings.dasherize(location.path) as Path, target.name);
|
|
54
|
+
return target;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function generate(options: AngularOptions) {
|
|
58
|
+
return (context: SchematicContext) =>
|
|
59
|
+
apply(url('./files' as Path), [
|
|
60
|
+
template({
|
|
61
|
+
...strings,
|
|
62
|
+
...options,
|
|
63
|
+
}),
|
|
64
|
+
move(options.path),
|
|
65
|
+
])(context);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function createAngularApplication(options: AngularOptions): Rule {
|
|
69
|
+
if (!options.initApp) {
|
|
70
|
+
return noop();
|
|
71
|
+
}
|
|
72
|
+
return externalSchematic('@schematics/angular', 'ng-new', {
|
|
73
|
+
name: options.directory,
|
|
74
|
+
version: '7.0.0',
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function addDeclarationToModule(options: AngularOptions): Rule {
|
|
79
|
+
return (tree: Tree) => {
|
|
80
|
+
options.module = new ModuleFinder(tree).find({
|
|
81
|
+
name: options.name,
|
|
82
|
+
path: options.path as any,
|
|
83
|
+
});
|
|
84
|
+
if (!options.module) {
|
|
85
|
+
return tree;
|
|
86
|
+
}
|
|
87
|
+
const content = tree.read(options.module).toString();
|
|
88
|
+
const declarator: ModuleDeclarator = new ModuleDeclarator();
|
|
89
|
+
|
|
90
|
+
const rootPath = `${options.directory}/dist/${options.directory}`;
|
|
91
|
+
const declarationOptions = ({
|
|
92
|
+
...options,
|
|
93
|
+
staticOptions: {
|
|
94
|
+
name: 'forRoot',
|
|
95
|
+
value: {
|
|
96
|
+
rootPath,
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
} as unknown) as DeclarationOptions;
|
|
100
|
+
tree.overwrite(
|
|
101
|
+
options.module,
|
|
102
|
+
declarator.declare(content, declarationOptions),
|
|
103
|
+
);
|
|
104
|
+
return tree;
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function addGlobalPrefix(): Rule {
|
|
109
|
+
return (tree: Tree) => {
|
|
110
|
+
const mainFilePath = 'src/main.ts';
|
|
111
|
+
const fileRef = tree.get(mainFilePath);
|
|
112
|
+
if (!fileRef) {
|
|
113
|
+
return tree;
|
|
114
|
+
}
|
|
115
|
+
const tsProject = new ts.Project({
|
|
116
|
+
manipulationSettings: {
|
|
117
|
+
indentationText: ts.IndentationText.TwoSpaces,
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
const tsFile = tsProject.addExistingSourceFile(mainFilePath);
|
|
121
|
+
const bootstrapFunction = tsFile.getFunction('bootstrap');
|
|
122
|
+
const listenStatement = bootstrapFunction.getStatement(node =>
|
|
123
|
+
node.getText().includes('listen'),
|
|
124
|
+
);
|
|
125
|
+
const setPrefixStatement = bootstrapFunction.getStatement(node =>
|
|
126
|
+
node.getText().includes('setGlobalPrefix'),
|
|
127
|
+
);
|
|
128
|
+
if (!listenStatement || setPrefixStatement) {
|
|
129
|
+
return tree;
|
|
130
|
+
}
|
|
131
|
+
const listenExprIndex = listenStatement.getChildIndex();
|
|
132
|
+
bootstrapFunction.insertStatements(
|
|
133
|
+
listenExprIndex,
|
|
134
|
+
`app.setGlobalPrefix('api');`,
|
|
135
|
+
);
|
|
136
|
+
tree.overwrite(mainFilePath, tsFile.getFullText());
|
|
137
|
+
return tree;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Path } from '@angular-devkit/core';
|
|
2
|
+
|
|
3
|
+
export interface AngularOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The name of the application.
|
|
6
|
+
*/
|
|
7
|
+
name: string;
|
|
8
|
+
/**
|
|
9
|
+
* The directory of the application.
|
|
10
|
+
*/
|
|
11
|
+
directory?: string;
|
|
12
|
+
/**
|
|
13
|
+
* The path to create the module.
|
|
14
|
+
*/
|
|
15
|
+
path?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The path to insert the module declaration.
|
|
18
|
+
*/
|
|
19
|
+
module?: Path;
|
|
20
|
+
/**
|
|
21
|
+
* Flag which indicates if Angular app should be scaffolded
|
|
22
|
+
*/
|
|
23
|
+
initApp?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Metadata name affected by declaration insertion.
|
|
26
|
+
*/
|
|
27
|
+
metadata?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Nest element type name
|
|
30
|
+
*/
|
|
31
|
+
type?: string;
|
|
32
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { DynamicModule, Inject, Module, OnModuleInit } from '@nestjs/common';
|
|
2
|
+
import { HttpAdapterHost } from '@nestjs/core';
|
|
3
|
+
import {
|
|
4
|
+
ANGULAR_MODULE_OPTIONS,
|
|
5
|
+
DEFAULT_RENDER_PATH,
|
|
6
|
+
DEFAULT_ROOT_PATH,
|
|
7
|
+
} from './angular.constants';
|
|
8
|
+
import { angularProviders } from './angular.providers';
|
|
9
|
+
import { AngularModuleOptions } from './interfaces/angular-options.interface';
|
|
10
|
+
import { AbstractLoader } from './loaders/abstract.loader';
|
|
11
|
+
|
|
12
|
+
@Module({
|
|
13
|
+
providers: [...angularProviders],
|
|
14
|
+
})
|
|
15
|
+
export class AngularModule implements OnModuleInit {
|
|
16
|
+
constructor(
|
|
17
|
+
@Inject(ANGULAR_MODULE_OPTIONS)
|
|
18
|
+
private readonly ngOptions: AngularModuleOptions,
|
|
19
|
+
private readonly loader: AbstractLoader,
|
|
20
|
+
private readonly httpAdapterHost: HttpAdapterHost,
|
|
21
|
+
) {}
|
|
22
|
+
|
|
23
|
+
public static forRoot(options: AngularModuleOptions = {}): DynamicModule {
|
|
24
|
+
options.rootPath = options.rootPath || DEFAULT_ROOT_PATH;
|
|
25
|
+
options.renderPath = options.renderPath || DEFAULT_RENDER_PATH;
|
|
26
|
+
return {
|
|
27
|
+
module: AngularModule,
|
|
28
|
+
providers: [
|
|
29
|
+
{
|
|
30
|
+
provide: ANGULAR_MODULE_OPTIONS,
|
|
31
|
+
useValue: options,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public async onModuleInit() {
|
|
38
|
+
const httpAdapter = this.httpAdapterHost.httpAdapter;
|
|
39
|
+
this.loader.register(httpAdapter, this.ngOptions);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Provider } from '@nestjs/common';
|
|
2
|
+
import { HttpAdapterHost } from '@nestjs/core';
|
|
3
|
+
import { AbstractLoader } from './loaders/abstract.loader';
|
|
4
|
+
import { ExpressLoader } from './loaders/express.loader';
|
|
5
|
+
import { FastifyLoader } from './loaders/fastify.loader';
|
|
6
|
+
import { NoopLoader } from './loaders/noop.loader';
|
|
7
|
+
|
|
8
|
+
export const angularProviders: Provider[] = [
|
|
9
|
+
{
|
|
10
|
+
provide: AbstractLoader,
|
|
11
|
+
useFactory: (httpAdapterHost: HttpAdapterHost) => {
|
|
12
|
+
if (!httpAdapterHost) {
|
|
13
|
+
return new NoopLoader();
|
|
14
|
+
}
|
|
15
|
+
const httpAdapter = httpAdapterHost.httpAdapter;
|
|
16
|
+
if (
|
|
17
|
+
httpAdapter &&
|
|
18
|
+
httpAdapter.constructor &&
|
|
19
|
+
httpAdapter.constructor.name === 'FastifyAdapter'
|
|
20
|
+
) {
|
|
21
|
+
return new FastifyLoader();
|
|
22
|
+
}
|
|
23
|
+
return new ExpressLoader();
|
|
24
|
+
},
|
|
25
|
+
inject: [HttpAdapterHost],
|
|
26
|
+
},
|
|
27
|
+
];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Logger } from '@nestjs/common';
|
|
2
|
+
|
|
3
|
+
const MISSING_REQUIRED_DEPENDENCY = (name: string, reason: string) =>
|
|
4
|
+
`The "${name}" package is missing. Please, make sure to install this library ($ npm install ${name}) to take advantage of ${reason}.`;
|
|
5
|
+
|
|
6
|
+
const logger = new Logger('PackageLoader');
|
|
7
|
+
|
|
8
|
+
export function loadPackage<T = any>(
|
|
9
|
+
packageName: string,
|
|
10
|
+
context: string,
|
|
11
|
+
loaderFn?: () => T,
|
|
12
|
+
): T {
|
|
13
|
+
try {
|
|
14
|
+
return loaderFn ? loaderFn() : require(packageName);
|
|
15
|
+
} catch (e) {
|
|
16
|
+
logger.error(MISSING_REQUIRED_DEPENDENCY(packageName, context));
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export interface AngularModuleOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Static files root directory.
|
|
4
|
+
* Default: "client/dist"
|
|
5
|
+
*/
|
|
6
|
+
rootPath?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Path to render Angular app.
|
|
9
|
+
* Default: * (wildcard - all paths)
|
|
10
|
+
*/
|
|
11
|
+
renderPath?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Serve static options (static files)
|
|
14
|
+
* Passed down to the underlying either `express.static` or `fastify-static.send`
|
|
15
|
+
*/
|
|
16
|
+
serveStaticOptions?: {
|
|
17
|
+
/**
|
|
18
|
+
* Enable or disable setting Cache-Control response header, defaults to true.
|
|
19
|
+
* Disabling this will ignore the immutable and maxAge options.
|
|
20
|
+
*/
|
|
21
|
+
cacheControl?: boolean;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Set how "dotfiles" are treated when encountered. A dotfile is a file or directory that begins with a dot (".").
|
|
25
|
+
* Note this check is done on the path itself without checking if the path actually exists on the disk.
|
|
26
|
+
* If root is specified, only the dotfiles above the root are checked
|
|
27
|
+
* (i.e. the root itself can be within a dotfile when when set to "deny").
|
|
28
|
+
* The default value is 'ignore'.
|
|
29
|
+
* 'allow' No special treatment for dotfiles
|
|
30
|
+
* 'deny' Send a 403 for any request for a dotfile
|
|
31
|
+
* 'ignore' Pretend like the dotfile does not exist and call next()
|
|
32
|
+
*/
|
|
33
|
+
dotfiles?: string;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Enable or disable etag generation, defaults to true.
|
|
37
|
+
*/
|
|
38
|
+
etag?: boolean;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Set file extension fallbacks. When set, if a file is not found, the given extensions
|
|
42
|
+
* will be added to the file name and search for.
|
|
43
|
+
* The first that exists will be served. Example: ['html', 'htm'].
|
|
44
|
+
* The default value is false.
|
|
45
|
+
*/
|
|
46
|
+
extensions?: string[];
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Enable or disable the immutable directive in the Cache-Control response header.
|
|
50
|
+
* If enabled, the maxAge option should also be specified to enable caching.
|
|
51
|
+
* The immutable directive will prevent supported clients from making conditional
|
|
52
|
+
* requests during the life of the maxAge option to check if the file has changed.
|
|
53
|
+
*/
|
|
54
|
+
immutable?: boolean;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* By default this module will send "index.html" files in response to a request on a directory.
|
|
58
|
+
* To disable this set false or to supply a new index pass a string or an array in preferred order.
|
|
59
|
+
*/
|
|
60
|
+
index?: boolean | string | string[];
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Enable or disable Last-Modified header, defaults to true. Uses the file system's last modified value.
|
|
64
|
+
*/
|
|
65
|
+
lastModified?: boolean;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Provide a max-age in milliseconds for http caching, defaults to 0.
|
|
69
|
+
* This can also be a string accepted by the ms module.
|
|
70
|
+
*/
|
|
71
|
+
maxAge?: number | string;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Redirect to trailing "/" when the pathname is a dir. Defaults to true.
|
|
75
|
+
*/
|
|
76
|
+
redirect?: boolean;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Function to set custom headers on response. Alterations to the headers need to occur synchronously.
|
|
80
|
+
* The function is called as fn(res, path, stat), where the arguments are:
|
|
81
|
+
* res the response object
|
|
82
|
+
* path the file path that is being sent
|
|
83
|
+
* stat the stat object of the file that is being sent
|
|
84
|
+
*/
|
|
85
|
+
setHeaders?: (res: any, path: string, stat: any) => any;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { AbstractHttpAdapter } from '@nestjs/core';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { AngularModuleOptions } from '../interfaces/angular-options.interface';
|
|
5
|
+
|
|
6
|
+
@Injectable()
|
|
7
|
+
export abstract class AbstractLoader {
|
|
8
|
+
public abstract register(
|
|
9
|
+
httpAdapter: AbstractHttpAdapter,
|
|
10
|
+
options: AngularModuleOptions,
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
public getIndexFilePath(clientPath: string): string {
|
|
14
|
+
return join(clientPath, 'index.html');
|
|
15
|
+
}
|
|
16
|
+
}
|