@nestjs/schematics 12.0.0-alpha.1 → 12.0.0-alpha.2
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/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/lib/application/application.factory.d.ts +3 -0
- package/dist/lib/application/application.factory.js +64 -0
- package/dist/lib/class/class.factory.d.ts +3 -0
- package/dist/lib/class/class.factory.js +48 -0
- package/dist/lib/client-app/angular/angular.factory.d.ts +3 -0
- package/dist/lib/client-app/angular/angular.factory.js +100 -0
- package/dist/lib/configuration/configuration.factory.d.ts +3 -0
- package/dist/lib/configuration/configuration.factory.js +24 -0
- package/dist/lib/controller/controller.factory.d.ts +3 -0
- package/dist/lib/controller/controller.factory.js +69 -0
- package/dist/lib/decorator/decorator.factory.d.ts +3 -0
- package/dist/lib/decorator/decorator.factory.js +32 -0
- package/dist/lib/defaults.d.ts +14 -0
- package/dist/lib/defaults.js +14 -0
- package/dist/lib/filter/filter.factory.d.ts +3 -0
- package/dist/lib/filter/filter.factory.js +40 -0
- package/dist/lib/gateway/gateway.factory.d.ts +3 -0
- package/dist/lib/gateway/gateway.factory.js +69 -0
- package/dist/lib/guard/guard.factory.d.ts +3 -0
- package/dist/lib/guard/guard.factory.js +40 -0
- package/dist/lib/interceptor/interceptor.factory.d.ts +3 -0
- package/dist/lib/interceptor/interceptor.factory.js +41 -0
- package/dist/lib/interface/interface.factory.d.ts +3 -0
- package/dist/lib/interface/interface.factory.js +31 -0
- package/dist/lib/library/library.factory.d.ts +3 -0
- package/dist/lib/library/library.factory.js +203 -0
- package/dist/lib/middleware/middleware.factory.d.ts +3 -0
- package/dist/lib/middleware/middleware.factory.js +40 -0
- package/dist/lib/module/module.factory.d.ts +3 -0
- package/dist/lib/module/module.factory.js +57 -0
- package/dist/lib/pipe/pipe.factory.d.ts +3 -0
- package/dist/lib/pipe/pipe.factory.js +41 -0
- package/dist/lib/provider/provider.factory.d.ts +3 -0
- package/dist/lib/provider/provider.factory.js +73 -0
- package/dist/lib/readers/file-system.reader.d.ts +10 -0
- package/dist/lib/readers/file-system.reader.js +41 -0
- package/dist/lib/readers/index.d.ts +2 -0
- package/dist/lib/readers/index.js +2 -0
- package/dist/lib/readers/reader.d.ts +7 -0
- package/dist/lib/readers/reader.js +1 -0
- package/dist/lib/resolver/resolver.factory.d.ts +3 -0
- package/dist/lib/resolver/resolver.factory.js +68 -0
- package/dist/lib/resource/resource.factory.d.ts +3 -0
- package/dist/lib/resource/resource.factory.js +142 -0
- package/dist/lib/service/service.factory.d.ts +3 -0
- package/dist/lib/service/service.factory.js +71 -0
- package/dist/lib/sub-app/sub-app.factory.d.ts +3 -0
- package/dist/lib/sub-app/sub-app.factory.js +296 -0
- package/dist/utils/dependencies.utils.d.ts +15 -0
- package/dist/utils/dependencies.utils.js +37 -0
- package/dist/utils/formatting.d.ts +1 -0
- package/dist/utils/formatting.js +9 -0
- package/dist/utils/index.d.ts +11 -0
- package/dist/utils/index.js +11 -0
- package/dist/utils/jest-module-mapper.d.ts +1 -0
- package/dist/utils/jest-module-mapper.js +6 -0
- package/dist/utils/json-file.util.d.ts +15 -0
- package/dist/utils/json-file.util.js +68 -0
- package/dist/utils/metadata.manager.d.ts +13 -0
- package/dist/utils/metadata.manager.js +171 -0
- package/dist/utils/module-import.declarator.d.ts +10 -0
- package/dist/utils/module-import.declarator.js +36 -0
- package/dist/utils/module-metadata.declarator.d.ts +4 -0
- package/dist/utils/module-metadata.declarator.js +8 -0
- package/dist/utils/module.declarator.d.ts +23 -0
- package/dist/utils/module.declarator.js +30 -0
- package/dist/utils/module.finder.d.ts +13 -0
- package/dist/utils/module.finder.js +21 -0
- package/dist/utils/name.parser.d.ts +12 -0
- package/dist/utils/name.parser.js +13 -0
- package/dist/utils/object-sorting.d.ts +1 -0
- package/dist/utils/object-sorting.js +10 -0
- package/dist/utils/path.solver.d.ts +4 -0
- package/dist/utils/path.solver.js +8 -0
- package/dist/utils/source-root.helpers.d.ts +6 -0
- package/dist/utils/source-root.helpers.js +20 -0
- package/package.json +2 -2
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { join, strings } from '@angular-devkit/core';
|
|
2
|
+
import { apply, filter, mergeWith, move, noop, template, url, } from '@angular-devkit/schematics';
|
|
3
|
+
import { basename, parse } from 'path';
|
|
4
|
+
import { normalizeToKebabOrSnakeCase } from '../../utils/formatting.js';
|
|
5
|
+
import { DEFAULT_AUTHOR, DEFAULT_DESCRIPTION, DEFAULT_LANGUAGE, DEFAULT_VERSION, } from '../defaults.js';
|
|
6
|
+
export function main(options) {
|
|
7
|
+
options.name = normalizeToKebabOrSnakeCase(options.name.toString());
|
|
8
|
+
const path = !options.directory || options.directory === 'undefined'
|
|
9
|
+
? options.name
|
|
10
|
+
: options.directory;
|
|
11
|
+
options = transform(options);
|
|
12
|
+
return mergeWith(generate(options, path));
|
|
13
|
+
}
|
|
14
|
+
function transform(options) {
|
|
15
|
+
const target = Object.assign({}, options);
|
|
16
|
+
target.author = target.author ? target.author : DEFAULT_AUTHOR;
|
|
17
|
+
target.description = target.description
|
|
18
|
+
? target.description
|
|
19
|
+
: DEFAULT_DESCRIPTION;
|
|
20
|
+
target.language = target.language ? target.language : DEFAULT_LANGUAGE;
|
|
21
|
+
target.name = resolvePackageName(target.name.toString());
|
|
22
|
+
target.version = target.version ? target.version : DEFAULT_VERSION;
|
|
23
|
+
target.type = target.type ?? 'cjs';
|
|
24
|
+
target.specFileSuffix = normalizeToKebabOrSnakeCase(options.specFileSuffix || 'spec');
|
|
25
|
+
target.packageManager =
|
|
26
|
+
!target.packageManager || target.packageManager === 'undefined'
|
|
27
|
+
? 'npm'
|
|
28
|
+
: target.packageManager;
|
|
29
|
+
target.dependencies = target.dependencies ? target.dependencies : '';
|
|
30
|
+
target.devDependencies = target.devDependencies ? target.devDependencies : '';
|
|
31
|
+
return target;
|
|
32
|
+
}
|
|
33
|
+
function resolvePackageName(path) {
|
|
34
|
+
const { base: baseFilename, dir: dirname } = parse(path);
|
|
35
|
+
if (baseFilename === '.') {
|
|
36
|
+
return basename(process.cwd());
|
|
37
|
+
}
|
|
38
|
+
if (dirname.match(/^@[^\s]/)) {
|
|
39
|
+
return `${dirname}/${baseFilename}`;
|
|
40
|
+
}
|
|
41
|
+
return baseFilename;
|
|
42
|
+
}
|
|
43
|
+
function generate(options, path) {
|
|
44
|
+
const templateDir = options.type === 'esm' && options.language === 'ts'
|
|
45
|
+
? 'ts-esm'
|
|
46
|
+
: options.language;
|
|
47
|
+
return apply(url(join('./files', templateDir)), [
|
|
48
|
+
options.spec
|
|
49
|
+
? noop()
|
|
50
|
+
: filter((path) => !path.endsWith('__specFileSuffix__.ts')),
|
|
51
|
+
options.spec
|
|
52
|
+
? noop()
|
|
53
|
+
: filter((path) => {
|
|
54
|
+
const languageExtension = options.language || 'ts';
|
|
55
|
+
const suffix = `__specFileSuffix__.${languageExtension}`;
|
|
56
|
+
return !path.endsWith(suffix);
|
|
57
|
+
}),
|
|
58
|
+
template({
|
|
59
|
+
...strings,
|
|
60
|
+
...options,
|
|
61
|
+
}),
|
|
62
|
+
move(path),
|
|
63
|
+
]);
|
|
64
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { join, strings } from '@angular-devkit/core';
|
|
2
|
+
import { apply, chain, filter, mergeWith, move, noop, SchematicsException, template, url, } from '@angular-devkit/schematics';
|
|
3
|
+
import { normalizeToKebabOrSnakeCase } from '../../utils/formatting.js';
|
|
4
|
+
import { NameParser } from '../../utils/name.parser.js';
|
|
5
|
+
import { mergeSourceRoot } from '../../utils/source-root.helpers.js';
|
|
6
|
+
import { DEFAULT_LANGUAGE } from '../defaults.js';
|
|
7
|
+
export function main(options) {
|
|
8
|
+
options = transform(options);
|
|
9
|
+
return chain([mergeSourceRoot(options), mergeWith(generate(options))]);
|
|
10
|
+
}
|
|
11
|
+
function transform(options) {
|
|
12
|
+
const target = Object.assign({}, options);
|
|
13
|
+
if (!target.name) {
|
|
14
|
+
throw new SchematicsException('Option (name) is required.');
|
|
15
|
+
}
|
|
16
|
+
const location = new NameParser().parse(target);
|
|
17
|
+
target.name = normalizeToKebabOrSnakeCase(location.name);
|
|
18
|
+
target.specFileSuffix = normalizeToKebabOrSnakeCase(options.specFileSuffix || 'spec');
|
|
19
|
+
if (target.name.includes('.')) {
|
|
20
|
+
target.className = strings.classify(target.name).replace('.', '');
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
target.className = target.name;
|
|
24
|
+
}
|
|
25
|
+
target.language =
|
|
26
|
+
target.language !== undefined ? target.language : DEFAULT_LANGUAGE;
|
|
27
|
+
target.path = normalizeToKebabOrSnakeCase(location.path);
|
|
28
|
+
target.path = target.flat
|
|
29
|
+
? target.path
|
|
30
|
+
: join(target.path, target.name);
|
|
31
|
+
return target;
|
|
32
|
+
}
|
|
33
|
+
function generate(options) {
|
|
34
|
+
return (context) => apply(url(join('./files', options.language)), [
|
|
35
|
+
options.spec
|
|
36
|
+
? noop()
|
|
37
|
+
: filter((path) => {
|
|
38
|
+
const languageExtension = options.language || 'ts';
|
|
39
|
+
const suffix = `.__specFileSuffix__.${languageExtension}`;
|
|
40
|
+
return !path.endsWith(suffix);
|
|
41
|
+
}),
|
|
42
|
+
template({
|
|
43
|
+
...strings,
|
|
44
|
+
...options,
|
|
45
|
+
}),
|
|
46
|
+
move(options.path),
|
|
47
|
+
])(context);
|
|
48
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { strings } from '@angular-devkit/core';
|
|
2
|
+
import { apply, branchAndMerge, chain, externalSchematic, mergeWith, move, noop, template, url, } from '@angular-devkit/schematics';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { ModuleDeclarator, } from '../../../utils/module.declarator.js';
|
|
5
|
+
import { ModuleFinder } from '../../../utils/module.finder.js';
|
|
6
|
+
import { NameParser } from '../../../utils/name.parser.js';
|
|
7
|
+
import { mergeSourceRoot } from '../../../utils/source-root.helpers.js';
|
|
8
|
+
export function main(options) {
|
|
9
|
+
options = transform(options);
|
|
10
|
+
return (tree, context) => {
|
|
11
|
+
return branchAndMerge(chain([
|
|
12
|
+
createAngularApplication(options),
|
|
13
|
+
mergeSourceRoot(options),
|
|
14
|
+
addDeclarationToModule(options),
|
|
15
|
+
addGlobalPrefix(),
|
|
16
|
+
mergeWith(generate(options)),
|
|
17
|
+
]))(tree, context);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function transform(source) {
|
|
21
|
+
const target = Object.assign({}, source);
|
|
22
|
+
target.directory = target.name ? strings.dasherize(target.name) : 'client';
|
|
23
|
+
target.name = 'Angular';
|
|
24
|
+
target.metadata = 'imports';
|
|
25
|
+
target.type = 'module';
|
|
26
|
+
const location = new NameParser().parse(target);
|
|
27
|
+
target.name = strings.dasherize(location.name);
|
|
28
|
+
target.path = join(strings.dasherize(location.path), target.name);
|
|
29
|
+
return target;
|
|
30
|
+
}
|
|
31
|
+
function generate(options) {
|
|
32
|
+
return (context) => apply(url('./files'), [
|
|
33
|
+
template({
|
|
34
|
+
...strings,
|
|
35
|
+
...options,
|
|
36
|
+
}),
|
|
37
|
+
move(options.path),
|
|
38
|
+
])(context);
|
|
39
|
+
}
|
|
40
|
+
function createAngularApplication(options) {
|
|
41
|
+
if (!options.initApp) {
|
|
42
|
+
return noop();
|
|
43
|
+
}
|
|
44
|
+
return externalSchematic('@schematics/angular', 'ng-new', {
|
|
45
|
+
name: options.directory,
|
|
46
|
+
version: '8.0.0',
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function addDeclarationToModule(options) {
|
|
50
|
+
return (tree) => {
|
|
51
|
+
options.module = new ModuleFinder(tree).find({
|
|
52
|
+
name: options.name,
|
|
53
|
+
path: options.path,
|
|
54
|
+
});
|
|
55
|
+
if (!options.module) {
|
|
56
|
+
return tree;
|
|
57
|
+
}
|
|
58
|
+
const content = tree.read(options.module).toString();
|
|
59
|
+
const declarator = new ModuleDeclarator();
|
|
60
|
+
const rootPath = `${options.directory}/dist/${options.directory}`;
|
|
61
|
+
const staticOptions = {
|
|
62
|
+
name: 'forRoot',
|
|
63
|
+
value: {
|
|
64
|
+
rootPath,
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
const declarationOptions = {
|
|
68
|
+
...options,
|
|
69
|
+
staticOptions,
|
|
70
|
+
};
|
|
71
|
+
tree.overwrite(options.module, declarator.declare(content, declarationOptions));
|
|
72
|
+
return tree;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function addGlobalPrefix() {
|
|
76
|
+
return (tree) => {
|
|
77
|
+
const mainFilePath = 'src/main.ts';
|
|
78
|
+
const fileRef = tree.get(mainFilePath);
|
|
79
|
+
if (!fileRef) {
|
|
80
|
+
return tree;
|
|
81
|
+
}
|
|
82
|
+
const ts = require('ts-morph');
|
|
83
|
+
const tsProject = new ts.Project({
|
|
84
|
+
manipulationSettings: {
|
|
85
|
+
indentationText: ts.IndentationText.TwoSpaces,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
const tsFile = tsProject.addSourceFileAtPath(mainFilePath);
|
|
89
|
+
const bootstrapFunction = tsFile.getFunction('bootstrap');
|
|
90
|
+
const listenStatement = bootstrapFunction.getStatement((node) => node.getText().includes('listen'));
|
|
91
|
+
const setPrefixStatement = bootstrapFunction.getStatement((node) => node.getText().includes('setGlobalPrefix'));
|
|
92
|
+
if (!listenStatement || setPrefixStatement) {
|
|
93
|
+
return tree;
|
|
94
|
+
}
|
|
95
|
+
const listenExprIndex = listenStatement.getChildIndex();
|
|
96
|
+
bootstrapFunction.insertStatements(listenExprIndex, `app.setGlobalPrefix('api');`);
|
|
97
|
+
tree.overwrite(mainFilePath, tsFile.getFullText());
|
|
98
|
+
return tree;
|
|
99
|
+
};
|
|
100
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { join, strings } from '@angular-devkit/core';
|
|
2
|
+
import { apply, mergeWith, move, template, url, } from '@angular-devkit/schematics';
|
|
3
|
+
import { DEFAULT_LANGUAGE } from '../defaults.js';
|
|
4
|
+
export function main(options) {
|
|
5
|
+
return mergeWith(generate(transform(options)));
|
|
6
|
+
}
|
|
7
|
+
function transform(options) {
|
|
8
|
+
const target = Object.assign({}, options);
|
|
9
|
+
target.language =
|
|
10
|
+
target.language !== undefined ? target.language : DEFAULT_LANGUAGE;
|
|
11
|
+
target.collection =
|
|
12
|
+
target.collection !== undefined ? target.collection : '@nestjs/schematics';
|
|
13
|
+
return target;
|
|
14
|
+
}
|
|
15
|
+
function generate(options) {
|
|
16
|
+
const projectOrPath = options.project ?? '.';
|
|
17
|
+
return apply(url(join('./files', options.language)), [
|
|
18
|
+
template({
|
|
19
|
+
...strings,
|
|
20
|
+
...options,
|
|
21
|
+
}),
|
|
22
|
+
move(projectOrPath),
|
|
23
|
+
]);
|
|
24
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { join, strings } from '@angular-devkit/core';
|
|
2
|
+
import { apply, branchAndMerge, chain, filter, mergeWith, move, noop, template, url, } from '@angular-devkit/schematics';
|
|
3
|
+
import { normalizeToKebabOrSnakeCase } from '../../utils/formatting.js';
|
|
4
|
+
import { ModuleDeclarator, } from '../../utils/module.declarator.js';
|
|
5
|
+
import { ModuleFinder } from '../../utils/module.finder.js';
|
|
6
|
+
import { NameParser } from '../../utils/name.parser.js';
|
|
7
|
+
import { mergeSourceRoot } from '../../utils/source-root.helpers.js';
|
|
8
|
+
import { DEFAULT_LANGUAGE } from '../defaults.js';
|
|
9
|
+
const ELEMENT_METADATA = 'controllers';
|
|
10
|
+
const ELEMENT_TYPE = 'controller';
|
|
11
|
+
export function main(options) {
|
|
12
|
+
options = transform(options);
|
|
13
|
+
return (tree, context) => {
|
|
14
|
+
return branchAndMerge(chain([
|
|
15
|
+
mergeSourceRoot(options),
|
|
16
|
+
mergeWith(generate(options)),
|
|
17
|
+
addDeclarationToModule(options),
|
|
18
|
+
]))(tree, context);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function transform(source) {
|
|
22
|
+
const target = Object.assign({}, source);
|
|
23
|
+
target.metadata = ELEMENT_METADATA;
|
|
24
|
+
target.type = ELEMENT_TYPE;
|
|
25
|
+
const location = new NameParser().parse(target);
|
|
26
|
+
target.name = normalizeToKebabOrSnakeCase(location.name);
|
|
27
|
+
target.path = normalizeToKebabOrSnakeCase(location.path);
|
|
28
|
+
target.language =
|
|
29
|
+
target.language !== undefined ? target.language : DEFAULT_LANGUAGE;
|
|
30
|
+
target.specFileSuffix = normalizeToKebabOrSnakeCase(source.specFileSuffix || 'spec');
|
|
31
|
+
target.path = target.flat
|
|
32
|
+
? target.path
|
|
33
|
+
: join(target.path, target.name);
|
|
34
|
+
return target;
|
|
35
|
+
}
|
|
36
|
+
function generate(options) {
|
|
37
|
+
return (context) => apply(url(join('./files', options.language)), [
|
|
38
|
+
options.spec
|
|
39
|
+
? noop()
|
|
40
|
+
: filter((path) => {
|
|
41
|
+
const languageExtension = options.language || 'ts';
|
|
42
|
+
const suffix = `.__specFileSuffix__.${languageExtension}`;
|
|
43
|
+
return !path.endsWith(suffix);
|
|
44
|
+
}),
|
|
45
|
+
template({
|
|
46
|
+
...strings,
|
|
47
|
+
...options,
|
|
48
|
+
}),
|
|
49
|
+
move(options.path),
|
|
50
|
+
])(context);
|
|
51
|
+
}
|
|
52
|
+
function addDeclarationToModule(options) {
|
|
53
|
+
return (tree) => {
|
|
54
|
+
if (options.skipImport !== undefined && options.skipImport) {
|
|
55
|
+
return tree;
|
|
56
|
+
}
|
|
57
|
+
options.module = new ModuleFinder(tree).find({
|
|
58
|
+
name: options.name,
|
|
59
|
+
path: options.path,
|
|
60
|
+
});
|
|
61
|
+
if (!options.module) {
|
|
62
|
+
return tree;
|
|
63
|
+
}
|
|
64
|
+
const content = tree.read(options.module).toString();
|
|
65
|
+
const declarator = new ModuleDeclarator();
|
|
66
|
+
tree.overwrite(options.module, declarator.declare(content, options));
|
|
67
|
+
return tree;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { join, strings } from '@angular-devkit/core';
|
|
2
|
+
import { apply, chain, mergeWith, move, SchematicsException, template, url, } from '@angular-devkit/schematics';
|
|
3
|
+
import { normalizeToKebabOrSnakeCase } from '../../utils/formatting.js';
|
|
4
|
+
import { NameParser } from '../../utils/name.parser.js';
|
|
5
|
+
import { mergeSourceRoot } from '../../utils/source-root.helpers.js';
|
|
6
|
+
export function main(options) {
|
|
7
|
+
options = transform(options);
|
|
8
|
+
return chain([mergeSourceRoot(options), mergeWith(generate(options))]);
|
|
9
|
+
}
|
|
10
|
+
function transform(options) {
|
|
11
|
+
const target = Object.assign({}, options);
|
|
12
|
+
if (!target.name) {
|
|
13
|
+
throw new SchematicsException('Option (name) is required.');
|
|
14
|
+
}
|
|
15
|
+
const location = new NameParser().parse(target);
|
|
16
|
+
target.name = normalizeToKebabOrSnakeCase(location.name);
|
|
17
|
+
target.path = normalizeToKebabOrSnakeCase(location.path);
|
|
18
|
+
target.language = target.language !== undefined ? target.language : 'ts';
|
|
19
|
+
target.path = target.flat
|
|
20
|
+
? target.path
|
|
21
|
+
: join(target.path, target.name);
|
|
22
|
+
return target;
|
|
23
|
+
}
|
|
24
|
+
function generate(options) {
|
|
25
|
+
return (context) => apply(url(join('./files', options.language)), [
|
|
26
|
+
template({
|
|
27
|
+
...strings,
|
|
28
|
+
...options,
|
|
29
|
+
}),
|
|
30
|
+
move(options.path),
|
|
31
|
+
])(context);
|
|
32
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const DEFAULT_AUTHOR = "";
|
|
2
|
+
export declare const DEFAULT_DESCRIPTION = "";
|
|
3
|
+
export declare const DEFAULT_LANGUAGE = "ts";
|
|
4
|
+
export declare const DEFAULT_VERSION = "0.0.1";
|
|
5
|
+
export declare const DEFAULT_PATH_NAME = "src";
|
|
6
|
+
export declare const DEFAULT_LIB_PATH = "libs";
|
|
7
|
+
export declare const DEFAULT_APPS_PATH = "apps";
|
|
8
|
+
export declare const DEFAULT_APP_NAME = "app";
|
|
9
|
+
export declare const DEFAULT_DIR_ENTRY_APP = "main";
|
|
10
|
+
export declare const TEST_ENV = "test";
|
|
11
|
+
export declare const PROJECT_TYPE: {
|
|
12
|
+
LIBRARY: string;
|
|
13
|
+
APPLICATION: string;
|
|
14
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const DEFAULT_AUTHOR = '';
|
|
2
|
+
export const DEFAULT_DESCRIPTION = '';
|
|
3
|
+
export const DEFAULT_LANGUAGE = 'ts';
|
|
4
|
+
export const DEFAULT_VERSION = '0.0.1';
|
|
5
|
+
export const DEFAULT_PATH_NAME = 'src';
|
|
6
|
+
export const DEFAULT_LIB_PATH = 'libs';
|
|
7
|
+
export const DEFAULT_APPS_PATH = 'apps';
|
|
8
|
+
export const DEFAULT_APP_NAME = 'app';
|
|
9
|
+
export const DEFAULT_DIR_ENTRY_APP = 'main';
|
|
10
|
+
export const TEST_ENV = 'test';
|
|
11
|
+
export const PROJECT_TYPE = {
|
|
12
|
+
LIBRARY: 'library',
|
|
13
|
+
APPLICATION: 'application',
|
|
14
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { join, strings } from '@angular-devkit/core';
|
|
2
|
+
import { apply, chain, filter, mergeWith, move, noop, SchematicsException, template, url, } from '@angular-devkit/schematics';
|
|
3
|
+
import { normalizeToKebabOrSnakeCase } from '../../utils/formatting.js';
|
|
4
|
+
import { NameParser } from '../../utils/name.parser.js';
|
|
5
|
+
import { mergeSourceRoot } from '../../utils/source-root.helpers.js';
|
|
6
|
+
export function main(options) {
|
|
7
|
+
options = transform(options);
|
|
8
|
+
return chain([mergeSourceRoot(options), mergeWith(generate(options))]);
|
|
9
|
+
}
|
|
10
|
+
function transform(options) {
|
|
11
|
+
const target = Object.assign({}, options);
|
|
12
|
+
if (!target.name) {
|
|
13
|
+
throw new SchematicsException('Option (name) is required.');
|
|
14
|
+
}
|
|
15
|
+
const location = new NameParser().parse(target);
|
|
16
|
+
target.name = normalizeToKebabOrSnakeCase(location.name);
|
|
17
|
+
target.path = normalizeToKebabOrSnakeCase(location.path);
|
|
18
|
+
target.language = target.language !== undefined ? target.language : 'ts';
|
|
19
|
+
target.specFileSuffix = normalizeToKebabOrSnakeCase(options.specFileSuffix || 'spec');
|
|
20
|
+
target.path = target.flat
|
|
21
|
+
? target.path
|
|
22
|
+
: join(target.path, target.name);
|
|
23
|
+
return target;
|
|
24
|
+
}
|
|
25
|
+
function generate(options) {
|
|
26
|
+
return (context) => apply(url(join('./files', options.language)), [
|
|
27
|
+
options.spec
|
|
28
|
+
? noop()
|
|
29
|
+
: filter((path) => {
|
|
30
|
+
const languageExtension = options.language || 'ts';
|
|
31
|
+
const suffix = `.__specFileSuffix__.${languageExtension}`;
|
|
32
|
+
return !path.endsWith(suffix);
|
|
33
|
+
}),
|
|
34
|
+
template({
|
|
35
|
+
...strings,
|
|
36
|
+
...options,
|
|
37
|
+
}),
|
|
38
|
+
move(options.path),
|
|
39
|
+
])(context);
|
|
40
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { join, strings } from '@angular-devkit/core';
|
|
2
|
+
import { apply, branchAndMerge, chain, filter, mergeWith, move, noop, SchematicsException, template, url, } from '@angular-devkit/schematics';
|
|
3
|
+
import { normalizeToKebabOrSnakeCase } from '../../utils/formatting.js';
|
|
4
|
+
import { ModuleDeclarator, } from '../../utils/module.declarator.js';
|
|
5
|
+
import { ModuleFinder } from '../../utils/module.finder.js';
|
|
6
|
+
import { NameParser } from '../../utils/name.parser.js';
|
|
7
|
+
import { mergeSourceRoot } from '../../utils/source-root.helpers.js';
|
|
8
|
+
export function main(options) {
|
|
9
|
+
options = transform(options);
|
|
10
|
+
return (tree, context) => {
|
|
11
|
+
return branchAndMerge(chain([
|
|
12
|
+
mergeSourceRoot(options),
|
|
13
|
+
addDeclarationToModule(options),
|
|
14
|
+
mergeWith(generate(options)),
|
|
15
|
+
]))(tree, context);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function transform(options) {
|
|
19
|
+
const target = Object.assign({}, options);
|
|
20
|
+
if (!target.name) {
|
|
21
|
+
throw new SchematicsException('Option (name) is required.');
|
|
22
|
+
}
|
|
23
|
+
target.metadata = 'providers';
|
|
24
|
+
target.type = 'gateway';
|
|
25
|
+
target.specFileSuffix = normalizeToKebabOrSnakeCase(options.specFileSuffix || 'spec');
|
|
26
|
+
const location = new NameParser().parse(target);
|
|
27
|
+
target.name = normalizeToKebabOrSnakeCase(location.name);
|
|
28
|
+
target.path = normalizeToKebabOrSnakeCase(location.path);
|
|
29
|
+
target.language = target.language !== undefined ? target.language : 'ts';
|
|
30
|
+
target.path = target.flat
|
|
31
|
+
? target.path
|
|
32
|
+
: join(target.path, target.name);
|
|
33
|
+
return target;
|
|
34
|
+
}
|
|
35
|
+
function generate(options) {
|
|
36
|
+
return (context) => apply(url(join('./files', options.language)), [
|
|
37
|
+
options.spec ? noop() : filter((path) => !path.endsWith('.spec.ts')),
|
|
38
|
+
options.spec
|
|
39
|
+
? noop()
|
|
40
|
+
: filter((path) => {
|
|
41
|
+
const languageExtension = options.language || 'ts';
|
|
42
|
+
const suffix = `.__specFileSuffix__.${languageExtension}`;
|
|
43
|
+
return !path.endsWith(suffix);
|
|
44
|
+
}),
|
|
45
|
+
template({
|
|
46
|
+
...strings,
|
|
47
|
+
...options,
|
|
48
|
+
}),
|
|
49
|
+
move(options.path),
|
|
50
|
+
])(context);
|
|
51
|
+
}
|
|
52
|
+
function addDeclarationToModule(options) {
|
|
53
|
+
return (tree) => {
|
|
54
|
+
if (options.skipImport !== undefined && options.skipImport) {
|
|
55
|
+
return tree;
|
|
56
|
+
}
|
|
57
|
+
options.module = new ModuleFinder(tree).find({
|
|
58
|
+
name: options.name,
|
|
59
|
+
path: options.path,
|
|
60
|
+
});
|
|
61
|
+
if (!options.module) {
|
|
62
|
+
return tree;
|
|
63
|
+
}
|
|
64
|
+
const content = tree.read(options.module).toString();
|
|
65
|
+
const declarator = new ModuleDeclarator();
|
|
66
|
+
tree.overwrite(options.module, declarator.declare(content, options));
|
|
67
|
+
return tree;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { join, strings } from '@angular-devkit/core';
|
|
2
|
+
import { apply, chain, filter, mergeWith, move, noop, SchematicsException, template, url, } from '@angular-devkit/schematics';
|
|
3
|
+
import { normalizeToKebabOrSnakeCase } from '../../utils/formatting.js';
|
|
4
|
+
import { NameParser } from '../../utils/name.parser.js';
|
|
5
|
+
import { mergeSourceRoot } from '../../utils/source-root.helpers.js';
|
|
6
|
+
export function main(options) {
|
|
7
|
+
options = transform(options);
|
|
8
|
+
return chain([mergeSourceRoot(options), mergeWith(generate(options))]);
|
|
9
|
+
}
|
|
10
|
+
function transform(options) {
|
|
11
|
+
const target = Object.assign({}, options);
|
|
12
|
+
if (!target.name) {
|
|
13
|
+
throw new SchematicsException('Option (name) is required.');
|
|
14
|
+
}
|
|
15
|
+
const location = new NameParser().parse(target);
|
|
16
|
+
target.name = normalizeToKebabOrSnakeCase(location.name);
|
|
17
|
+
target.path = normalizeToKebabOrSnakeCase(location.path);
|
|
18
|
+
target.language = target.language !== undefined ? target.language : 'ts';
|
|
19
|
+
target.specFileSuffix = normalizeToKebabOrSnakeCase(options.specFileSuffix || 'spec');
|
|
20
|
+
target.path = target.flat
|
|
21
|
+
? target.path
|
|
22
|
+
: join(target.path, target.name);
|
|
23
|
+
return target;
|
|
24
|
+
}
|
|
25
|
+
function generate(options) {
|
|
26
|
+
return (context) => apply(url(join('./files', options.language)), [
|
|
27
|
+
options.spec
|
|
28
|
+
? noop()
|
|
29
|
+
: filter((path) => {
|
|
30
|
+
const languageExtension = options.language || 'ts';
|
|
31
|
+
const suffix = `.__specFileSuffix__.${languageExtension}`;
|
|
32
|
+
return !path.endsWith(suffix);
|
|
33
|
+
}),
|
|
34
|
+
template({
|
|
35
|
+
...strings,
|
|
36
|
+
...options,
|
|
37
|
+
}),
|
|
38
|
+
move(options.path),
|
|
39
|
+
])(context);
|
|
40
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { join, strings } from '@angular-devkit/core';
|
|
2
|
+
import { apply, chain, filter, mergeWith, move, noop, SchematicsException, template, url, } from '@angular-devkit/schematics';
|
|
3
|
+
import { normalizeToKebabOrSnakeCase } from '../../utils/formatting.js';
|
|
4
|
+
import { NameParser } from '../../utils/name.parser.js';
|
|
5
|
+
import { mergeSourceRoot } from '../../utils/source-root.helpers.js';
|
|
6
|
+
export function main(options) {
|
|
7
|
+
options = transform(options);
|
|
8
|
+
return chain([mergeSourceRoot(options), mergeWith(generate(options))]);
|
|
9
|
+
}
|
|
10
|
+
function transform(options) {
|
|
11
|
+
const target = Object.assign({}, options);
|
|
12
|
+
if (!target.name) {
|
|
13
|
+
throw new SchematicsException('Option (name) is required.');
|
|
14
|
+
}
|
|
15
|
+
const location = new NameParser().parse(target);
|
|
16
|
+
target.name = normalizeToKebabOrSnakeCase(location.name);
|
|
17
|
+
target.path = normalizeToKebabOrSnakeCase(location.path);
|
|
18
|
+
target.language = target.language !== undefined ? target.language : 'ts';
|
|
19
|
+
target.specFileSuffix = normalizeToKebabOrSnakeCase(options.specFileSuffix || 'spec');
|
|
20
|
+
target.path = target.flat
|
|
21
|
+
? target.path
|
|
22
|
+
: join(target.path, target.name);
|
|
23
|
+
return target;
|
|
24
|
+
}
|
|
25
|
+
function generate(options) {
|
|
26
|
+
return (context) => apply(url(join('./files', options.language)), [
|
|
27
|
+
options.spec ? noop() : filter((path) => !path.endsWith('.spec.ts')),
|
|
28
|
+
options.spec
|
|
29
|
+
? noop()
|
|
30
|
+
: filter((path) => {
|
|
31
|
+
const languageExtension = options.language || 'ts';
|
|
32
|
+
const suffix = `.__specFileSuffix__.${languageExtension}`;
|
|
33
|
+
return !path.endsWith(suffix);
|
|
34
|
+
}),
|
|
35
|
+
template({
|
|
36
|
+
...strings,
|
|
37
|
+
...options,
|
|
38
|
+
}),
|
|
39
|
+
move(options.path),
|
|
40
|
+
])(context);
|
|
41
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { join, strings } from '@angular-devkit/core';
|
|
2
|
+
import { apply, chain, mergeWith, move, SchematicsException, template, url, } from '@angular-devkit/schematics';
|
|
3
|
+
import { normalizeToKebabOrSnakeCase } from '../../utils/formatting.js';
|
|
4
|
+
import { NameParser } from '../../utils/name.parser.js';
|
|
5
|
+
import { mergeSourceRoot } from '../../utils/source-root.helpers.js';
|
|
6
|
+
export function main(options) {
|
|
7
|
+
options = transform(options);
|
|
8
|
+
return chain([mergeSourceRoot(options), mergeWith(generate(options))]);
|
|
9
|
+
}
|
|
10
|
+
function transform(options) {
|
|
11
|
+
const target = Object.assign({}, options);
|
|
12
|
+
if (!target.name) {
|
|
13
|
+
throw new SchematicsException('Option (name) is required.');
|
|
14
|
+
}
|
|
15
|
+
const location = new NameParser().parse(target);
|
|
16
|
+
target.name = normalizeToKebabOrSnakeCase(location.name);
|
|
17
|
+
target.path = normalizeToKebabOrSnakeCase(location.path);
|
|
18
|
+
target.path = target.flat
|
|
19
|
+
? target.path
|
|
20
|
+
: join(target.path, target.name);
|
|
21
|
+
return target;
|
|
22
|
+
}
|
|
23
|
+
function generate(options) {
|
|
24
|
+
return (context) => apply(url('./files'), [
|
|
25
|
+
template({
|
|
26
|
+
...strings,
|
|
27
|
+
...options,
|
|
28
|
+
}),
|
|
29
|
+
move(options.path),
|
|
30
|
+
])(context);
|
|
31
|
+
}
|