@rxdi/schematics 0.7.190 → 0.7.191-nightly.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/lib/component/component.factory.js +1 -2
- package/lib/controller/controller.factory.js +1 -2
- package/lib/effect/effect.factory.js +2 -4
- package/lib/effect/effect.factory.ts +1 -2
- package/lib/guard/guard.factory.js +1 -2
- package/lib/interceptor/interceptor.factory.js +1 -2
- package/lib/module/module.factory.js +1 -2
- package/lib/service/service.factory.js +2 -4
- package/lib/service/service.factory.ts +1 -2
- package/package.json +8 -8
- package/utils/source-root.helpers.js +2 -3
- package/lib/application/application.factory.d.ts +0 -3
- package/lib/application/application.factory.js +0 -35
- package/lib/application/application.factory.test.ts +0 -88
- package/lib/application/application.factory.ts +0 -54
- package/lib/application/application.schema.d.ts +0 -34
- package/lib/application/files/js/.babelrc +0 -4
- package/lib/application/files/js/.prettierrc +0 -4
- package/lib/application/files/js/README.md +0 -37
- package/lib/application/files/js/index.js +0 -3
- package/lib/application/files/js/jsconfig.json +0 -9
- package/lib/application/files/js/nest-cli.json +0 -5
- package/lib/application/files/js/nodemon.json +0 -6
- package/lib/application/files/js/package.json +0 -46
- package/lib/application/files/js/test/app.e2e-spec.js +0 -23
- package/lib/application/files/js/test/jest-e2e.json +0 -5
- package/lib/application/files/ts/.prettierrc +0 -4
- package/lib/application/files/ts/README.md +0 -75
- package/lib/application/files/ts/nest-cli.json +0 -5
- package/lib/application/files/ts/nodemon-debug.json +0 -6
- package/lib/application/files/ts/nodemon.json +0 -6
- package/lib/application/files/ts/package.json +0 -58
- package/lib/application/files/ts/test/app.e2e-spec.ts +0 -23
- package/lib/application/files/ts/test/jest-e2e.json +0 -9
- package/lib/application/files/ts/tsconfig.build.json +0 -4
- package/lib/application/schema.json +0 -49
- package/lib/class/class.factory.d.ts +0 -3
- package/lib/class/class.factory.js +0 -35
- package/lib/class/class.factory.test.ts +0 -100
- package/lib/class/class.factory.ts +0 -54
- package/lib/class/class.schema.d.ts +0 -28
- package/lib/class/files/js/__name__.js +0 -1
- package/lib/class/files/js/__name__.spec.js +0 -7
- package/lib/class/files/ts/__name__.spec.ts +0 -7
- package/lib/class/files/ts/__name__.ts +0 -1
- package/lib/class/schema.json +0 -39
- package/lib/client-app/angular/angular.factory.d.ts +0 -3
- package/lib/client-app/angular/angular.factory.js +0 -97
- package/lib/client-app/angular/angular.factory.ts +0 -139
- package/lib/client-app/angular/angular.schema.d.ts +0 -32
- package/lib/client-app/angular/files/angular.constants.ts +0 -4
- package/lib/client-app/angular/files/angular.module.ts +0 -41
- package/lib/client-app/angular/files/angular.providers.ts +0 -27
- package/lib/client-app/angular/files/angular.utils.ts +0 -19
- package/lib/client-app/angular/files/interfaces/angular-options.interface.ts +0 -87
- package/lib/client-app/angular/files/loaders/abstract.loader.ts +0 -16
- package/lib/client-app/angular/files/loaders/express.loader.ts +0 -25
- package/lib/client-app/angular/files/loaders/fastify.loader.ts +0 -34
- package/lib/client-app/angular/files/loaders/noop.loader.ts +0 -12
- package/lib/client-app/angular/schema.json +0 -24
- package/lib/configuration/configuration.factory.d.ts +0 -3
- package/lib/configuration/configuration.factory.js +0 -24
- package/lib/configuration/configuration.factory.test.ts +0 -60
- package/lib/configuration/configuration.factory.ts +0 -35
- package/lib/configuration/configuration.schema.d.ts +0 -18
- package/lib/configuration/files/js/nest-cli.json +0 -5
- package/lib/configuration/files/ts/nest-cli.json +0 -5
- package/lib/decorator/decorator.factory.d.ts +0 -3
- package/lib/decorator/decorator.factory.js +0 -32
- package/lib/decorator/decorator.factory.test.ts +0 -111
- package/lib/decorator/decorator.factory.ts +0 -48
- package/lib/decorator/decorator.schema.d.ts +0 -24
- package/lib/decorator/files/js/__name__.decorator.js +0 -3
- package/lib/decorator/files/ts/__name__.decorator.ts +0 -3
- package/lib/decorator/schema.json +0 -35
- package/lib/filter/files/js/__name__.filter.js +0 -6
- package/lib/filter/files/js/__name__.filter.spec.js +0 -7
- package/lib/filter/files/ts/__name__.filter.spec.ts +0 -7
- package/lib/filter/files/ts/__name__.filter.ts +0 -6
- package/lib/filter/filter.factory.d.ts +0 -3
- package/lib/filter/filter.factory.js +0 -33
- package/lib/filter/filter.factory.test.ts +0 -147
- package/lib/filter/filter.factory.ts +0 -51
- package/lib/filter/filter.schema.d.ts +0 -28
- package/lib/filter/schema.json +0 -39
- package/lib/gateway/files/js/__name__.gateway.js +0 -9
- package/lib/gateway/files/js/__name__.gateway.spec.js +0 -18
- package/lib/gateway/files/ts/__name__.gateway.spec.ts +0 -18
- package/lib/gateway/files/ts/__name__.gateway.ts +0 -9
- package/lib/gateway/gateway.factory.d.ts +0 -3
- package/lib/gateway/gateway.factory.js +0 -61
- package/lib/gateway/gateway.factory.test.ts +0 -147
- package/lib/gateway/gateway.factory.ts +0 -92
- package/lib/gateway/gateway.schema.d.ts +0 -36
- package/lib/gateway/schema.json +0 -39
- package/lib/interface/files/__name__.interface.ts +0 -1
- package/lib/interface/interface.factory.d.ts +0 -3
- package/lib/interface/interface.factory.js +0 -31
- package/lib/interface/interface.factory.test.ts +0 -84
- package/lib/interface/interface.factory.ts +0 -47
- package/lib/interface/interface.schema.d.ts +0 -20
- package/lib/interface/schema.json +0 -31
- package/lib/library/files/js/.babelrc +0 -4
- package/lib/library/files/js/jsconfig.json +0 -9
- package/lib/library/files/js/package.json +0 -8
- package/lib/library/files/js/src/__name__.module.js +0 -8
- package/lib/library/files/js/src/__name__.service.js +0 -4
- package/lib/library/files/js/src/__name__.service.spec.js +0 -18
- package/lib/library/files/js/src/index.js +0 -2
- package/lib/library/files/ts/package.json +0 -8
- package/lib/library/files/ts/src/__name__.module.ts +0 -8
- package/lib/library/files/ts/src/__name__.service.spec.ts +0 -18
- package/lib/library/files/ts/src/__name__.service.ts +0 -4
- package/lib/library/files/ts/src/index.ts +0 -2
- package/lib/library/files/ts/tsconfig.lib.json +0 -5
- package/lib/library/library.factory.d.ts +0 -3
- package/lib/library/library.factory.js +0 -97
- package/lib/library/library.factory.test.ts +0 -68
- package/lib/library/library.factory.ts +0 -158
- package/lib/library/library.schema.d.ts +0 -24
- package/lib/library/schema.json +0 -37
- package/lib/pipe/files/js/__name__.pipe.js +0 -8
- package/lib/pipe/files/js/__name__.pipe.spec.js +0 -7
- package/lib/pipe/files/ts/__name__.pipe.spec.ts +0 -7
- package/lib/pipe/files/ts/__name__.pipe.ts +0 -8
- package/lib/pipe/pipe.factory.d.ts +0 -3
- package/lib/pipe/pipe.factory.js +0 -33
- package/lib/pipe/pipe.factory.test.ts +0 -141
- package/lib/pipe/pipe.factory.ts +0 -51
- package/lib/pipe/pipe.schema.d.ts +0 -28
- package/lib/pipe/schema.json +0 -39
- package/lib/resolver/files/js/__name__.resolver.js +0 -4
- package/lib/resolver/files/js/__name__.resolver.spec.js +0 -18
- package/lib/resolver/files/ts/__name__.resolver.spec.ts +0 -18
- package/lib/resolver/files/ts/__name__.resolver.ts +0 -4
- package/lib/resolver/resolver.factory.d.ts +0 -3
- package/lib/resolver/resolver.factory.js +0 -61
- package/lib/resolver/resolver.factory.test.ts +0 -117
- package/lib/resolver/resolver.factory.ts +0 -92
- package/lib/resolver/resolver.schema.d.ts +0 -36
- package/lib/resolver/schema.json +0 -39
package/lib/pipe/pipe.factory.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
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 { PipeOptions } from './pipe.schema';
|
|
19
|
-
|
|
20
|
-
export function main(options: PipeOptions): Rule {
|
|
21
|
-
options = transform(options);
|
|
22
|
-
return chain([mergeSourceRoot(options), mergeWith(generate(options))]);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function transform(options: PipeOptions): PipeOptions {
|
|
26
|
-
const target: PipeOptions = Object.assign({}, options);
|
|
27
|
-
if (!target.name) {
|
|
28
|
-
throw new SchematicsException('Option (name) is required.');
|
|
29
|
-
}
|
|
30
|
-
const location: Location = new NameParser().parse(target);
|
|
31
|
-
target.name = strings.dasherize(location.name);
|
|
32
|
-
target.path = strings.dasherize(location.path);
|
|
33
|
-
target.language = target.language !== undefined ? target.language : 'ts';
|
|
34
|
-
|
|
35
|
-
target.path = target.flat
|
|
36
|
-
? target.path
|
|
37
|
-
: join(target.path as Path, target.name);
|
|
38
|
-
return target;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function generate(options: PipeOptions): Source {
|
|
42
|
-
return (context: SchematicContext) =>
|
|
43
|
-
apply(url(join('./files' as Path, options.language)), [
|
|
44
|
-
options.spec ? noop() : filter(path => !path.endsWith('.spec.ts')),
|
|
45
|
-
template({
|
|
46
|
-
...strings,
|
|
47
|
-
...options,
|
|
48
|
-
}),
|
|
49
|
-
move(options.path),
|
|
50
|
-
])(context);
|
|
51
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Path } from '@angular-devkit/core';
|
|
2
|
-
|
|
3
|
-
export interface PipeOptions {
|
|
4
|
-
/**
|
|
5
|
-
* The name of the pipe.
|
|
6
|
-
*/
|
|
7
|
-
name: string;
|
|
8
|
-
/**
|
|
9
|
-
* The path to create the pipe.
|
|
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
|
-
}
|
package/lib/pipe/schema.json
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://json-schema.org/schema",
|
|
3
|
-
"id": "SchematicsNestPipe",
|
|
4
|
-
"title": "Nest Pipe Options Schema",
|
|
5
|
-
"type": "object",
|
|
6
|
-
"properties": {
|
|
7
|
-
"name": {
|
|
8
|
-
"type": "string",
|
|
9
|
-
"description": "The name of the pipe.",
|
|
10
|
-
"$default": {
|
|
11
|
-
"$source": "argv",
|
|
12
|
-
"index": 0
|
|
13
|
-
},
|
|
14
|
-
"x-prompt": "What name would you like to use for the pipe?"
|
|
15
|
-
},
|
|
16
|
-
"path": {
|
|
17
|
-
"type": "string",
|
|
18
|
-
"format": "path",
|
|
19
|
-
"description": "The path to create the pipe."
|
|
20
|
-
},
|
|
21
|
-
"language": {
|
|
22
|
-
"type": "string",
|
|
23
|
-
"description": "Nest pipe language (ts/js)."
|
|
24
|
-
},
|
|
25
|
-
"sourceRoot": {
|
|
26
|
-
"type": "string",
|
|
27
|
-
"description": "Nest pipe source root directory."
|
|
28
|
-
},
|
|
29
|
-
"flat": {
|
|
30
|
-
"default": true,
|
|
31
|
-
"description": "Flag to indicate if a directory is created."
|
|
32
|
-
},
|
|
33
|
-
"spec": {
|
|
34
|
-
"default": true,
|
|
35
|
-
"description": "Specifies if a spec file is generated."
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
"required": ["name"]
|
|
39
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Test } from '@nestjs/testing';
|
|
2
|
-
import { <%= classify(name) %>Resolver } from './<%= name %>.resolver';
|
|
3
|
-
|
|
4
|
-
describe('<%= classify(name) %>Resolver', () => {
|
|
5
|
-
let resolver;
|
|
6
|
-
|
|
7
|
-
beforeEach(async () => {
|
|
8
|
-
const module = await Test.createTestingModule({
|
|
9
|
-
providers: [<%= classify(name) %>Resolver],
|
|
10
|
-
}).compile();
|
|
11
|
-
|
|
12
|
-
resolver = module.get(<%= classify(name) %>Resolver);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should be defined', () => {
|
|
16
|
-
expect(resolver).toBeDefined();
|
|
17
|
-
});
|
|
18
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Test, TestingModule } from '@nestjs/testing';
|
|
2
|
-
import { <%= classify(name) %>Resolver } from './<%= name %>.resolver';
|
|
3
|
-
|
|
4
|
-
describe('<%= classify(name) %>Resolver', () => {
|
|
5
|
-
let resolver: <%= classify(name) %>Resolver;
|
|
6
|
-
|
|
7
|
-
beforeEach(async () => {
|
|
8
|
-
const module: TestingModule = await Test.createTestingModule({
|
|
9
|
-
providers: [<%= classify(name) %>Resolver],
|
|
10
|
-
}).compile();
|
|
11
|
-
|
|
12
|
-
resolver = module.get<<%= classify(name) %>Resolver>(<%= classify(name) %>Resolver);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should be defined', () => {
|
|
16
|
-
expect(resolver).toBeDefined();
|
|
17
|
-
});
|
|
18
|
-
});
|
|
@@ -1,61 +0,0 @@
|
|
|
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
|
-
function main(options) {
|
|
11
|
-
options = transform(options);
|
|
12
|
-
return (tree, context) => {
|
|
13
|
-
return (0, schematics_1.branchAndMerge)((0, schematics_1.chain)([
|
|
14
|
-
(0, source_root_helpers_1.mergeSourceRoot)(options),
|
|
15
|
-
addDeclarationToModule(options),
|
|
16
|
-
(0, schematics_1.mergeWith)(generate(options)),
|
|
17
|
-
]))(tree, context);
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
exports.main = main;
|
|
21
|
-
function transform(options) {
|
|
22
|
-
const target = Object.assign({}, options);
|
|
23
|
-
if (!target.name) {
|
|
24
|
-
throw new schematics_1.SchematicsException('Option (name) is required.');
|
|
25
|
-
}
|
|
26
|
-
target.metadata = 'providers';
|
|
27
|
-
target.type = 'resolver';
|
|
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 = target.language !== undefined ? target.language : 'ts';
|
|
32
|
-
target.path = target.flat
|
|
33
|
-
? target.path
|
|
34
|
-
: (0, core_1.join)(target.path, target.name);
|
|
35
|
-
return target;
|
|
36
|
-
}
|
|
37
|
-
function generate(options) {
|
|
38
|
-
return (context) => (0, schematics_1.apply)((0, schematics_1.url)((0, core_1.join)('./files', options.language)), [
|
|
39
|
-
options.spec ? (0, schematics_1.noop)() : (0, schematics_1.filter)(path => !path.endsWith('.spec.ts')),
|
|
40
|
-
(0, schematics_1.template)(Object.assign(Object.assign({}, core_1.strings), options)),
|
|
41
|
-
(0, schematics_1.move)(options.path),
|
|
42
|
-
])(context);
|
|
43
|
-
}
|
|
44
|
-
function addDeclarationToModule(options) {
|
|
45
|
-
return (tree) => {
|
|
46
|
-
if (options.skipImport !== undefined && options.skipImport) {
|
|
47
|
-
return tree;
|
|
48
|
-
}
|
|
49
|
-
options.module = new module_finder_1.ModuleFinder(tree).find({
|
|
50
|
-
name: options.name,
|
|
51
|
-
path: options.path,
|
|
52
|
-
});
|
|
53
|
-
if (!options.module) {
|
|
54
|
-
return tree;
|
|
55
|
-
}
|
|
56
|
-
const content = tree.read(options.module).toString();
|
|
57
|
-
const declarator = new module_declarator_1.ModuleDeclarator();
|
|
58
|
-
tree.overwrite(options.module, declarator.declare(content, options));
|
|
59
|
-
return tree;
|
|
60
|
-
};
|
|
61
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SchematicTestRunner,
|
|
3
|
-
UnitTestTree,
|
|
4
|
-
} from '@angular-devkit/schematics/testing';
|
|
5
|
-
import * as path from 'path';
|
|
6
|
-
import { ResolverOptions } from './resolver.schema';
|
|
7
|
-
|
|
8
|
-
describe('Resolver 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: ResolverOptions = {
|
|
15
|
-
name: 'foo',
|
|
16
|
-
flat: false,
|
|
17
|
-
};
|
|
18
|
-
const tree: UnitTestTree = runner.runSchematic('resolver', options);
|
|
19
|
-
const files: string[] = tree.files;
|
|
20
|
-
expect(
|
|
21
|
-
files.find(filename => filename === '/foo/foo.resolver.ts'),
|
|
22
|
-
).not.toBeUndefined();
|
|
23
|
-
expect(tree.readContent('/foo/foo.resolver.ts')).toEqual(
|
|
24
|
-
"import { Resolver } from '@nestjs/graphql';\n" +
|
|
25
|
-
'\n' +
|
|
26
|
-
'@Resolver(\'Foo\')\n' +
|
|
27
|
-
'export class FooResolver {}\n',
|
|
28
|
-
);
|
|
29
|
-
});
|
|
30
|
-
it('should manage name as a path', () => {
|
|
31
|
-
const options: ResolverOptions = {
|
|
32
|
-
name: 'bar/foo',
|
|
33
|
-
flat: false,
|
|
34
|
-
};
|
|
35
|
-
const tree: UnitTestTree = runner.runSchematic('resolver', options);
|
|
36
|
-
const files: string[] = tree.files;
|
|
37
|
-
expect(
|
|
38
|
-
files.find(filename => filename === '/bar/foo/foo.resolver.ts'),
|
|
39
|
-
).not.toBeUndefined();
|
|
40
|
-
expect(tree.readContent('/bar/foo/foo.resolver.ts')).toEqual(
|
|
41
|
-
"import { Resolver } from '@nestjs/graphql';\n" +
|
|
42
|
-
'\n' +
|
|
43
|
-
'@Resolver(\'Foo\')\n' +
|
|
44
|
-
'export class FooResolver {}\n',
|
|
45
|
-
);
|
|
46
|
-
});
|
|
47
|
-
it('should manage name and path', () => {
|
|
48
|
-
const options: ResolverOptions = {
|
|
49
|
-
name: 'foo',
|
|
50
|
-
path: 'baz',
|
|
51
|
-
flat: false,
|
|
52
|
-
};
|
|
53
|
-
const tree: UnitTestTree = runner.runSchematic('resolver', options);
|
|
54
|
-
const files: string[] = tree.files;
|
|
55
|
-
expect(
|
|
56
|
-
files.find(filename => filename === '/baz/foo/foo.resolver.ts'),
|
|
57
|
-
).not.toBeUndefined();
|
|
58
|
-
expect(tree.readContent('/baz/foo/foo.resolver.ts')).toEqual(
|
|
59
|
-
"import { Resolver } from '@nestjs/graphql';\n" +
|
|
60
|
-
'\n' +
|
|
61
|
-
'@Resolver(\'Foo\')\n' +
|
|
62
|
-
'export class FooResolver {}\n',
|
|
63
|
-
);
|
|
64
|
-
});
|
|
65
|
-
it('should manage name to dasherize', () => {
|
|
66
|
-
const options: ResolverOptions = {
|
|
67
|
-
name: 'fooBar',
|
|
68
|
-
flat: false,
|
|
69
|
-
};
|
|
70
|
-
const tree: UnitTestTree = runner.runSchematic('resolver', options);
|
|
71
|
-
const files: string[] = tree.files;
|
|
72
|
-
expect(
|
|
73
|
-
files.find(filename => filename === '/foo-bar/foo-bar.resolver.ts'),
|
|
74
|
-
).not.toBeUndefined();
|
|
75
|
-
expect(tree.readContent('/foo-bar/foo-bar.resolver.ts')).toEqual(
|
|
76
|
-
"import { Resolver } from '@nestjs/graphql';\n" +
|
|
77
|
-
'\n' +
|
|
78
|
-
'@Resolver(\'FooBar\')\n' +
|
|
79
|
-
'export class FooBarResolver {}\n',
|
|
80
|
-
);
|
|
81
|
-
});
|
|
82
|
-
it('should manage path to dasherize', () => {
|
|
83
|
-
const options: ResolverOptions = {
|
|
84
|
-
name: 'barBaz/foo',
|
|
85
|
-
flat: false,
|
|
86
|
-
};
|
|
87
|
-
const tree: UnitTestTree = runner.runSchematic('resolver', options);
|
|
88
|
-
const files: string[] = tree.files;
|
|
89
|
-
expect(
|
|
90
|
-
files.find(filename => filename === '/bar-baz/foo/foo.resolver.ts'),
|
|
91
|
-
).not.toBeUndefined();
|
|
92
|
-
expect(tree.readContent('/bar-baz/foo/foo.resolver.ts')).toEqual(
|
|
93
|
-
"import { Resolver } from '@nestjs/graphql';\n" +
|
|
94
|
-
'\n' +
|
|
95
|
-
'@Resolver(\'Foo\')\n' +
|
|
96
|
-
'export class FooResolver {}\n',
|
|
97
|
-
);
|
|
98
|
-
});
|
|
99
|
-
it('should manage javascript file', () => {
|
|
100
|
-
const options: ResolverOptions = {
|
|
101
|
-
name: 'foo',
|
|
102
|
-
language: 'js',
|
|
103
|
-
flat: false,
|
|
104
|
-
};
|
|
105
|
-
const tree: UnitTestTree = runner.runSchematic('resolver', options);
|
|
106
|
-
const files: string[] = tree.files;
|
|
107
|
-
expect(
|
|
108
|
-
files.find(filename => filename === '/foo/foo.resolver.js'),
|
|
109
|
-
).not.toBeUndefined();
|
|
110
|
-
expect(tree.readContent('/foo/foo.resolver.js')).toEqual(
|
|
111
|
-
"import { Resolver } from '@nestjs/graphql';\n" +
|
|
112
|
-
'\n' +
|
|
113
|
-
'@Resolver(\'Foo\')\n' +
|
|
114
|
-
'export class FooResolver {}\n',
|
|
115
|
-
);
|
|
116
|
-
});
|
|
117
|
-
});
|
|
@@ -1,92 +0,0 @@
|
|
|
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
|
-
SchematicsException,
|
|
13
|
-
Source,
|
|
14
|
-
template,
|
|
15
|
-
Tree,
|
|
16
|
-
url,
|
|
17
|
-
} from '@angular-devkit/schematics';
|
|
18
|
-
import {
|
|
19
|
-
DeclarationOptions,
|
|
20
|
-
ModuleDeclarator,
|
|
21
|
-
} from '../../utils/module.declarator';
|
|
22
|
-
import { ModuleFinder } from '../../utils/module.finder';
|
|
23
|
-
import { Location, NameParser } from '../../utils/name.parser';
|
|
24
|
-
import { mergeSourceRoot } from '../../utils/source-root.helpers';
|
|
25
|
-
import { ProviderOptions } from '../provider/provider.schema';
|
|
26
|
-
import { ResolverOptions } from './resolver.schema';
|
|
27
|
-
|
|
28
|
-
export function main(options: ResolverOptions): Rule {
|
|
29
|
-
options = transform(options);
|
|
30
|
-
return (tree: Tree, context: SchematicContext) => {
|
|
31
|
-
return branchAndMerge(
|
|
32
|
-
chain([
|
|
33
|
-
mergeSourceRoot(options),
|
|
34
|
-
addDeclarationToModule(options),
|
|
35
|
-
mergeWith(generate(options)),
|
|
36
|
-
]),
|
|
37
|
-
)(tree, context);
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function transform(options: ResolverOptions): ResolverOptions {
|
|
42
|
-
const target: ResolverOptions = Object.assign({}, options);
|
|
43
|
-
if (!target.name) {
|
|
44
|
-
throw new SchematicsException('Option (name) is required.');
|
|
45
|
-
}
|
|
46
|
-
target.metadata = 'providers';
|
|
47
|
-
target.type = 'resolver';
|
|
48
|
-
|
|
49
|
-
const location: Location = new NameParser().parse(target);
|
|
50
|
-
target.name = strings.dasherize(location.name);
|
|
51
|
-
target.path = strings.dasherize(location.path);
|
|
52
|
-
target.language = target.language !== undefined ? target.language : 'ts';
|
|
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: ResolverOptions): Source {
|
|
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: ProviderOptions): 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
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Path } from '@angular-devkit/core';
|
|
2
|
-
|
|
3
|
-
export interface ResolverOptions {
|
|
4
|
-
/**
|
|
5
|
-
* The name of the resolver.
|
|
6
|
-
*/
|
|
7
|
-
name: string;
|
|
8
|
-
/**
|
|
9
|
-
* The path to create the resolver.
|
|
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
|
-
/**
|
|
29
|
-
* Metadata name affected by declaration insertion.
|
|
30
|
-
*/
|
|
31
|
-
metadata?: string;
|
|
32
|
-
/**
|
|
33
|
-
* Nest element type name
|
|
34
|
-
*/
|
|
35
|
-
type?: string;
|
|
36
|
-
}
|
package/lib/resolver/schema.json
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://json-schema.org/schema",
|
|
3
|
-
"id": "SchematicsNestResolver",
|
|
4
|
-
"title": "Nest Resolver Options Schema",
|
|
5
|
-
"type": "object",
|
|
6
|
-
"properties": {
|
|
7
|
-
"name": {
|
|
8
|
-
"type": "string",
|
|
9
|
-
"description": "The name of the resolver.",
|
|
10
|
-
"$default": {
|
|
11
|
-
"$source": "argv",
|
|
12
|
-
"index": 0
|
|
13
|
-
},
|
|
14
|
-
"x-prompt": "What name would you like to use for the resolver?"
|
|
15
|
-
},
|
|
16
|
-
"path": {
|
|
17
|
-
"type": "string",
|
|
18
|
-
"format": "path",
|
|
19
|
-
"description": "The path to create the resolver."
|
|
20
|
-
},
|
|
21
|
-
"language": {
|
|
22
|
-
"type": "string",
|
|
23
|
-
"description": "Nest resolver language (ts/js)."
|
|
24
|
-
},
|
|
25
|
-
"sourceRoot": {
|
|
26
|
-
"type": "string",
|
|
27
|
-
"description": "Nest resolver source root directory."
|
|
28
|
-
},
|
|
29
|
-
"flat": {
|
|
30
|
-
"default": false,
|
|
31
|
-
"description": "Flag to indicate if a directory is created."
|
|
32
|
-
},
|
|
33
|
-
"spec": {
|
|
34
|
-
"default": true,
|
|
35
|
-
"description": "Specifies if a spec file is generated."
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
"required": ["name"]
|
|
39
|
-
}
|