@rhtml/schematics 0.0.132 → 0.0.134
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/collection.json +6 -1
- package/dist/lib/component/schema.json +1 -1
- package/dist/lib/controller/controller.factory.d.ts +3 -0
- package/dist/lib/controller/controller.factory.js +62 -0
- package/dist/lib/controller/controller.factory.ts +92 -0
- package/dist/lib/controller/files/ts/__name__.controller.spec.ts +33 -0
- package/dist/lib/controller/files/ts/__name__.controller.ts +16 -0
- package/dist/lib/controller/schema.json +49 -0
- package/dist/lib/module/schema.json +4 -4
- package/dist/lib/provider/schema.json +4 -4
- package/dist/lib/service/schema.json +3 -3
- package/dist/lib/service/service.factory.js +1 -2
- package/dist/lib/service/service.factory.ts +1 -2
- package/dist/utils/metadata.manager.d.ts +65 -2
- package/dist/utils/metadata.manager.js +103 -23
- package/dist/utils/metadata.manager.ts +127 -46
- package/dist/utils/module-import.declarator.d.ts +31 -2
- package/dist/utils/module-import.declarator.js +42 -10
- package/dist/utils/module-import.declarator.ts +45 -12
- package/dist/utils/module-metadata.declarator.d.ts +12 -0
- package/dist/utils/module-metadata.declarator.js +13 -1
- package/dist/utils/module-metadata.declarator.ts +13 -1
- package/dist/utils/module.declarator.d.ts +21 -1
- package/dist/utils/module.declarator.js +23 -1
- package/dist/utils/module.declarator.ts +24 -2
- package/dist/utils/module.finder.d.ts +12 -0
- package/dist/utils/module.finder.js +13 -1
- package/dist/utils/module.finder.ts +13 -1
- package/dist/utils/name.parser.d.ts +6 -0
- package/dist/utils/name.parser.js +6 -0
- package/dist/utils/name.parser.ts +6 -0
- package/dist/utils/path.solver.d.ts +7 -0
- package/dist/utils/path.solver.js +7 -0
- package/dist/utils/path.solver.ts +7 -0
- package/dist/utils/source-root.helpers.d.ts +13 -1
- package/dist/utils/source-root.helpers.js +13 -1
- package/dist/utils/source-root.helpers.ts +14 -2
- package/package.json +5 -5
- package/src/lib/component/schema.json +1 -1
- package/src/lib/controller/controller.factory.ts +92 -0
- package/src/lib/controller/files/ts/__name__.controller.spec.ts +33 -0
- package/src/lib/controller/files/ts/__name__.controller.ts +16 -0
- package/src/lib/controller/schema.json +49 -0
- package/src/lib/module/schema.json +4 -4
- package/src/lib/provider/schema.json +4 -4
- package/src/lib/service/schema.json +3 -3
- package/src/lib/service/service.factory.ts +1 -2
- package/src/utils/metadata.manager.ts +127 -46
- package/src/utils/module-import.declarator.ts +45 -12
- package/src/utils/module-metadata.declarator.ts +13 -1
- package/src/utils/module.declarator.ts +24 -2
- package/src/utils/module.finder.ts +13 -1
- package/src/utils/name.parser.ts +6 -0
- package/src/utils/path.solver.ts +7 -0
- package/src/utils/source-root.helpers.ts +14 -2
|
@@ -3,31 +3,64 @@ import { normalize, Path } from '@angular-devkit/core';
|
|
|
3
3
|
import { DeclarationOptions } from './module.declarator';
|
|
4
4
|
import { PathSolver } from './path.solver';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* The `ModuleImportDeclarator` class is responsible for declaring module imports
|
|
8
|
+
* in a TypeScript file. It provides methods to insert import statements into the
|
|
9
|
+
* file content based on the provided declaration options.
|
|
10
|
+
*/
|
|
6
11
|
export class ModuleImportDeclarator {
|
|
7
12
|
constructor(private solver: PathSolver = new PathSolver()) {}
|
|
8
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Declares a module import in the given content string.
|
|
16
|
+
*
|
|
17
|
+
* @param content - The content of the file where the import will be declared.
|
|
18
|
+
* @param options - The options for the declaration, including the symbol and path.
|
|
19
|
+
* @returns The updated content string with the import statement inserted.
|
|
20
|
+
*/
|
|
9
21
|
public declare(content: string, options: DeclarationOptions): string {
|
|
10
|
-
const toInsert
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
return
|
|
22
|
+
const toInsert = this.buildLineToInsert(options);
|
|
23
|
+
const contentLines = content.split('\n');
|
|
24
|
+
const finalImportIndex = this.findImportsEndpoint(contentLines);
|
|
25
|
+
contentLines.splice(finalImportIndex + 1, 0, toInsert);
|
|
26
|
+
return contentLines.join('\n');
|
|
15
27
|
}
|
|
16
28
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Finds the endpoint of the existing import statements in the content.
|
|
31
|
+
*
|
|
32
|
+
* @param contentLines - The lines of the content.
|
|
33
|
+
* @returns The index of the last import statement.
|
|
34
|
+
*/
|
|
35
|
+
private findImportsEndpoint(contentLines: string[]): number {
|
|
36
|
+
const reversedContent = Array.from(contentLines).reverse();
|
|
37
|
+
const reverseImports = reversedContent.filter((line) =>
|
|
38
|
+
line.match(/\} from ('|")/)
|
|
39
|
+
);
|
|
40
|
+
if (reverseImports.length <= 0) {
|
|
41
|
+
return 0;
|
|
42
|
+
}
|
|
43
|
+
return contentLines.indexOf(reverseImports[0]);
|
|
23
44
|
}
|
|
24
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Builds the import line to insert based on the declaration options.
|
|
48
|
+
*
|
|
49
|
+
* @param options - The options for the declaration, including the symbol and path.
|
|
50
|
+
* @returns The import line to insert.
|
|
51
|
+
*/
|
|
25
52
|
private buildLineToInsert(options: DeclarationOptions): string {
|
|
26
53
|
return `import { ${options.symbol} } from '${this.computeRelativePath(
|
|
27
54
|
options
|
|
28
|
-
)}'
|
|
55
|
+
)}';`;
|
|
29
56
|
}
|
|
30
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Computes the relative path for the import statement.
|
|
60
|
+
*
|
|
61
|
+
* @param options - The options for the declaration, including the symbol and path.
|
|
62
|
+
* @returns The relative path for the import statement.
|
|
63
|
+
*/
|
|
31
64
|
private computeRelativePath(options: DeclarationOptions): string {
|
|
32
65
|
let importModulePath: Path;
|
|
33
66
|
if (options.type !== undefined) {
|
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import { DeclarationOptions } from './module.declarator';
|
|
2
|
+
/**
|
|
3
|
+
* The `ModuleMetadataDeclarator` class is responsible for declaring metadata
|
|
4
|
+
* in a TypeScript file. It provides methods to insert metadata entries into the
|
|
5
|
+
* file content based on the provided declaration options.
|
|
6
|
+
*/
|
|
2
7
|
export declare class ModuleMetadataDeclarator {
|
|
8
|
+
/**
|
|
9
|
+
* Declares metadata in the given content string.
|
|
10
|
+
*
|
|
11
|
+
* @param content - The content of the file where the metadata will be declared.
|
|
12
|
+
* @param options - The options for the declaration, including the metadata, symbol, and static options.
|
|
13
|
+
* @returns The updated content string with the metadata entry inserted.
|
|
14
|
+
*/
|
|
3
15
|
declare(content: string, options: DeclarationOptions): string;
|
|
4
16
|
}
|
|
@@ -2,11 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ModuleMetadataDeclarator = void 0;
|
|
4
4
|
const metadata_manager_1 = require("./metadata.manager");
|
|
5
|
+
/**
|
|
6
|
+
* The `ModuleMetadataDeclarator` class is responsible for declaring metadata
|
|
7
|
+
* in a TypeScript file. It provides methods to insert metadata entries into the
|
|
8
|
+
* file content based on the provided declaration options.
|
|
9
|
+
*/
|
|
5
10
|
class ModuleMetadataDeclarator {
|
|
11
|
+
/**
|
|
12
|
+
* Declares metadata in the given content string.
|
|
13
|
+
*
|
|
14
|
+
* @param content - The content of the file where the metadata will be declared.
|
|
15
|
+
* @param options - The options for the declaration, including the metadata, symbol, and static options.
|
|
16
|
+
* @returns The updated content string with the metadata entry inserted.
|
|
17
|
+
*/
|
|
6
18
|
declare(content, options) {
|
|
7
19
|
const manager = new metadata_manager_1.MetadataManager(content);
|
|
8
20
|
const inserted = manager.insert(options.metadata, options.symbol, options.staticOptions);
|
|
9
|
-
return inserted;
|
|
21
|
+
return inserted !== null && inserted !== void 0 ? inserted : content;
|
|
10
22
|
}
|
|
11
23
|
}
|
|
12
24
|
exports.ModuleMetadataDeclarator = ModuleMetadataDeclarator;
|
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import { MetadataManager } from './metadata.manager';
|
|
2
2
|
import { DeclarationOptions } from './module.declarator';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* The `ModuleMetadataDeclarator` class is responsible for declaring metadata
|
|
6
|
+
* in a TypeScript file. It provides methods to insert metadata entries into the
|
|
7
|
+
* file content based on the provided declaration options.
|
|
8
|
+
*/
|
|
4
9
|
export class ModuleMetadataDeclarator {
|
|
10
|
+
/**
|
|
11
|
+
* Declares metadata in the given content string.
|
|
12
|
+
*
|
|
13
|
+
* @param content - The content of the file where the metadata will be declared.
|
|
14
|
+
* @param options - The options for the declaration, including the metadata, symbol, and static options.
|
|
15
|
+
* @returns The updated content string with the metadata entry inserted.
|
|
16
|
+
*/
|
|
5
17
|
public declare(content: string, options: DeclarationOptions): string {
|
|
6
18
|
const manager = new MetadataManager(content);
|
|
7
19
|
const inserted = manager.insert(
|
|
@@ -9,6 +21,6 @@ export class ModuleMetadataDeclarator {
|
|
|
9
21
|
options.symbol,
|
|
10
22
|
options.staticOptions
|
|
11
23
|
);
|
|
12
|
-
return inserted;
|
|
24
|
+
return inserted ?? content;
|
|
13
25
|
}
|
|
14
26
|
}
|
|
@@ -5,18 +5,38 @@ export interface DeclarationOptions {
|
|
|
5
5
|
metadata: string;
|
|
6
6
|
type?: string;
|
|
7
7
|
name: string;
|
|
8
|
+
className?: string;
|
|
8
9
|
path: Path;
|
|
9
10
|
module: Path;
|
|
10
11
|
symbol?: string;
|
|
11
12
|
staticOptions?: {
|
|
12
13
|
name: string;
|
|
13
|
-
value: Record<string,
|
|
14
|
+
value: Record<string, never>;
|
|
14
15
|
};
|
|
15
16
|
}
|
|
16
17
|
export declare class ModuleDeclarator {
|
|
17
18
|
private imports;
|
|
18
19
|
private metadata;
|
|
20
|
+
/**
|
|
21
|
+
* Constructs a new `ModuleDeclarator` instance.
|
|
22
|
+
*
|
|
23
|
+
* @param imports - The `ModuleImportDeclarator` instance for handling import declarations.
|
|
24
|
+
* @param metadata - The `ModuleMetadataDeclarator` instance for handling metadata declarations.
|
|
25
|
+
*/
|
|
19
26
|
constructor(imports?: ModuleImportDeclarator, metadata?: ModuleMetadataDeclarator);
|
|
27
|
+
/**
|
|
28
|
+
* Declares module imports and metadata in the given content string.
|
|
29
|
+
*
|
|
30
|
+
* @param content - The content of the file where the declarations will be made.
|
|
31
|
+
* @param options - The options for the declaration, including the symbol and static options.
|
|
32
|
+
* @returns The updated content string with the declarations inserted.
|
|
33
|
+
*/
|
|
20
34
|
declare(content: string, options: DeclarationOptions): string;
|
|
35
|
+
/**
|
|
36
|
+
* Computes the symbol for the declaration options if not provided.
|
|
37
|
+
*
|
|
38
|
+
* @param options - The options for the declaration.
|
|
39
|
+
* @returns The updated declaration options with the computed symbol.
|
|
40
|
+
*/
|
|
21
41
|
private computeSymbol;
|
|
22
42
|
}
|
|
@@ -5,19 +5,41 @@ const strings_1 = require("@angular-devkit/core/src/utils/strings");
|
|
|
5
5
|
const module_import_declarator_1 = require("./module-import.declarator");
|
|
6
6
|
const module_metadata_declarator_1 = require("./module-metadata.declarator");
|
|
7
7
|
class ModuleDeclarator {
|
|
8
|
+
/**
|
|
9
|
+
* Constructs a new `ModuleDeclarator` instance.
|
|
10
|
+
*
|
|
11
|
+
* @param imports - The `ModuleImportDeclarator` instance for handling import declarations.
|
|
12
|
+
* @param metadata - The `ModuleMetadataDeclarator` instance for handling metadata declarations.
|
|
13
|
+
*/
|
|
8
14
|
constructor(imports = new module_import_declarator_1.ModuleImportDeclarator(), metadata = new module_metadata_declarator_1.ModuleMetadataDeclarator()) {
|
|
9
15
|
this.imports = imports;
|
|
10
16
|
this.metadata = metadata;
|
|
11
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Declares module imports and metadata in the given content string.
|
|
20
|
+
*
|
|
21
|
+
* @param content - The content of the file where the declarations will be made.
|
|
22
|
+
* @param options - The options for the declaration, including the symbol and static options.
|
|
23
|
+
* @returns The updated content string with the declarations inserted.
|
|
24
|
+
*/
|
|
12
25
|
declare(content, options) {
|
|
13
26
|
options = this.computeSymbol(options);
|
|
14
27
|
content = this.imports.declare(content, options);
|
|
15
28
|
content = this.metadata.declare(content, options);
|
|
16
29
|
return content;
|
|
17
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Computes the symbol for the declaration options if not provided.
|
|
33
|
+
*
|
|
34
|
+
* @param options - The options for the declaration.
|
|
35
|
+
* @returns The updated declaration options with the computed symbol.
|
|
36
|
+
*/
|
|
18
37
|
computeSymbol(options) {
|
|
19
38
|
const target = Object.assign({}, options);
|
|
20
|
-
if (options.
|
|
39
|
+
if (options.className) {
|
|
40
|
+
target.symbol = options.className;
|
|
41
|
+
}
|
|
42
|
+
else if (options.type !== undefined) {
|
|
21
43
|
target.symbol = (0, strings_1.classify)(options.name).concat((0, strings_1.capitalize)(options.type));
|
|
22
44
|
}
|
|
23
45
|
else {
|
|
@@ -8,21 +8,35 @@ export interface DeclarationOptions {
|
|
|
8
8
|
metadata: string;
|
|
9
9
|
type?: string;
|
|
10
10
|
name: string;
|
|
11
|
+
className?: string;
|
|
11
12
|
path: Path;
|
|
12
13
|
module: Path;
|
|
13
14
|
symbol?: string;
|
|
14
15
|
staticOptions?: {
|
|
15
16
|
name: string;
|
|
16
|
-
value: Record<string,
|
|
17
|
+
value: Record<string, never>;
|
|
17
18
|
};
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
export class ModuleDeclarator {
|
|
22
|
+
/**
|
|
23
|
+
* Constructs a new `ModuleDeclarator` instance.
|
|
24
|
+
*
|
|
25
|
+
* @param imports - The `ModuleImportDeclarator` instance for handling import declarations.
|
|
26
|
+
* @param metadata - The `ModuleMetadataDeclarator` instance for handling metadata declarations.
|
|
27
|
+
*/
|
|
21
28
|
constructor(
|
|
22
29
|
private imports: ModuleImportDeclarator = new ModuleImportDeclarator(),
|
|
23
30
|
private metadata: ModuleMetadataDeclarator = new ModuleMetadataDeclarator()
|
|
24
31
|
) {}
|
|
25
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Declares module imports and metadata in the given content string.
|
|
35
|
+
*
|
|
36
|
+
* @param content - The content of the file where the declarations will be made.
|
|
37
|
+
* @param options - The options for the declaration, including the symbol and static options.
|
|
38
|
+
* @returns The updated content string with the declarations inserted.
|
|
39
|
+
*/
|
|
26
40
|
public declare(content: string, options: DeclarationOptions): string {
|
|
27
41
|
options = this.computeSymbol(options);
|
|
28
42
|
content = this.imports.declare(content, options);
|
|
@@ -30,9 +44,17 @@ export class ModuleDeclarator {
|
|
|
30
44
|
return content;
|
|
31
45
|
}
|
|
32
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Computes the symbol for the declaration options if not provided.
|
|
49
|
+
*
|
|
50
|
+
* @param options - The options for the declaration.
|
|
51
|
+
* @returns The updated declaration options with the computed symbol.
|
|
52
|
+
*/
|
|
33
53
|
private computeSymbol(options: DeclarationOptions): DeclarationOptions {
|
|
34
54
|
const target = Object.assign({}, options);
|
|
35
|
-
if (options.
|
|
55
|
+
if (options.className) {
|
|
56
|
+
target.symbol = options.className;
|
|
57
|
+
} else if (options.type !== undefined) {
|
|
36
58
|
target.symbol = classify(options.name).concat(capitalize(options.type));
|
|
37
59
|
} else {
|
|
38
60
|
target.symbol = classify(options.name);
|
|
@@ -8,6 +8,18 @@ export interface FindOptions {
|
|
|
8
8
|
export declare class ModuleFinder {
|
|
9
9
|
private tree;
|
|
10
10
|
constructor(tree: Tree);
|
|
11
|
+
/**
|
|
12
|
+
* Finds the module file in the given path.
|
|
13
|
+
*
|
|
14
|
+
* @param options - The options for finding the module, including the path.
|
|
15
|
+
* @returns The path to the module file, or null if not found.
|
|
16
|
+
*/
|
|
11
17
|
find(options: FindOptions): Path | null;
|
|
18
|
+
/**
|
|
19
|
+
* Recursively searches for the module file in the given directory.
|
|
20
|
+
*
|
|
21
|
+
* @param directory - The directory to search in.
|
|
22
|
+
* @returns The path to the module file, or null if not found.
|
|
23
|
+
*/
|
|
12
24
|
private findIn;
|
|
13
25
|
}
|
|
@@ -6,16 +6,28 @@ class ModuleFinder {
|
|
|
6
6
|
constructor(tree) {
|
|
7
7
|
this.tree = tree;
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Finds the module file in the given path.
|
|
11
|
+
*
|
|
12
|
+
* @param options - The options for finding the module, including the path.
|
|
13
|
+
* @returns The path to the module file, or null if not found.
|
|
14
|
+
*/
|
|
9
15
|
find(options) {
|
|
10
16
|
const generatedDirectoryPath = options.path;
|
|
11
17
|
const generatedDirectory = this.tree.getDir(generatedDirectoryPath);
|
|
12
18
|
return this.findIn(generatedDirectory);
|
|
13
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Recursively searches for the module file in the given directory.
|
|
22
|
+
*
|
|
23
|
+
* @param directory - The directory to search in.
|
|
24
|
+
* @returns The path to the module file, or null if not found.
|
|
25
|
+
*/
|
|
14
26
|
findIn(directory) {
|
|
15
27
|
if (!directory) {
|
|
16
28
|
return null;
|
|
17
29
|
}
|
|
18
|
-
const moduleFilename = directory.subfiles.find((filename) => /\.module\.(t|j)s
|
|
30
|
+
const moduleFilename = directory.subfiles.find((filename) => /\.module\.(t|j)s$/.test(filename));
|
|
19
31
|
return moduleFilename !== undefined
|
|
20
32
|
? (0, core_1.join)(directory.path, moduleFilename.valueOf())
|
|
21
33
|
: this.findIn(directory.parent);
|
|
@@ -10,6 +10,12 @@ export interface FindOptions {
|
|
|
10
10
|
export class ModuleFinder {
|
|
11
11
|
constructor(private tree: Tree) {}
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Finds the module file in the given path.
|
|
15
|
+
*
|
|
16
|
+
* @param options - The options for finding the module, including the path.
|
|
17
|
+
* @returns The path to the module file, or null if not found.
|
|
18
|
+
*/
|
|
13
19
|
public find(options: FindOptions): Path | null {
|
|
14
20
|
const generatedDirectoryPath: Path = options.path;
|
|
15
21
|
const generatedDirectory: DirEntry = this.tree.getDir(
|
|
@@ -18,12 +24,18 @@ export class ModuleFinder {
|
|
|
18
24
|
return this.findIn(generatedDirectory);
|
|
19
25
|
}
|
|
20
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Recursively searches for the module file in the given directory.
|
|
29
|
+
*
|
|
30
|
+
* @param directory - The directory to search in.
|
|
31
|
+
* @returns The path to the module file, or null if not found.
|
|
32
|
+
*/
|
|
21
33
|
private findIn(directory: DirEntry): Path | null {
|
|
22
34
|
if (!directory) {
|
|
23
35
|
return null;
|
|
24
36
|
}
|
|
25
37
|
const moduleFilename: PathFragment = directory.subfiles.find((filename) =>
|
|
26
|
-
/\.module\.(t|j)s
|
|
38
|
+
/\.module\.(t|j)s$/.test(filename)
|
|
27
39
|
);
|
|
28
40
|
return moduleFilename !== undefined
|
|
29
41
|
? join(directory.path, moduleFilename.valueOf())
|
|
@@ -8,5 +8,11 @@ export interface Location {
|
|
|
8
8
|
path: Path;
|
|
9
9
|
}
|
|
10
10
|
export declare class NameParser {
|
|
11
|
+
/**
|
|
12
|
+
* Parses the provided options to extract the name and path.
|
|
13
|
+
*
|
|
14
|
+
* @param options - The options containing the name and path.
|
|
15
|
+
* @returns An object containing the parsed name and normalized path.
|
|
16
|
+
*/
|
|
11
17
|
parse(options: ParseOptions): Location;
|
|
12
18
|
}
|
|
@@ -3,6 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.NameParser = void 0;
|
|
4
4
|
const core_1 = require("@angular-devkit/core");
|
|
5
5
|
class NameParser {
|
|
6
|
+
/**
|
|
7
|
+
* Parses the provided options to extract the name and path.
|
|
8
|
+
*
|
|
9
|
+
* @param options - The options containing the name and path.
|
|
10
|
+
* @returns An object containing the parsed name and normalized path.
|
|
11
|
+
*/
|
|
6
12
|
parse(options) {
|
|
7
13
|
const nameWithoutPath = (0, core_1.basename)(options.name);
|
|
8
14
|
const namePath = (0, core_1.dirname)((options.path === undefined ? '' : options.path)
|
|
@@ -11,6 +11,12 @@ export interface Location {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export class NameParser {
|
|
14
|
+
/**
|
|
15
|
+
* Parses the provided options to extract the name and path.
|
|
16
|
+
*
|
|
17
|
+
* @param options - The options containing the name and path.
|
|
18
|
+
* @returns An object containing the parsed name and normalized path.
|
|
19
|
+
*/
|
|
14
20
|
public parse(options: ParseOptions): Location {
|
|
15
21
|
const nameWithoutPath: string = basename(options.name as Path);
|
|
16
22
|
const namePath: string = dirname(
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { Path } from '@angular-devkit/core';
|
|
2
2
|
export declare class PathSolver {
|
|
3
|
+
/**
|
|
4
|
+
* Computes the relative path between two paths.
|
|
5
|
+
*
|
|
6
|
+
* @param from - The source path.
|
|
7
|
+
* @param to - The target path.
|
|
8
|
+
* @returns The relative path between the two paths.
|
|
9
|
+
*/
|
|
3
10
|
relative(from: Path, to: Path): string;
|
|
4
11
|
}
|
|
@@ -3,6 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PathSolver = void 0;
|
|
4
4
|
const core_1 = require("@angular-devkit/core");
|
|
5
5
|
class PathSolver {
|
|
6
|
+
/**
|
|
7
|
+
* Computes the relative path between two paths.
|
|
8
|
+
*
|
|
9
|
+
* @param from - The source path.
|
|
10
|
+
* @param to - The target path.
|
|
11
|
+
* @returns The relative path between the two paths.
|
|
12
|
+
*/
|
|
6
13
|
relative(from, to) {
|
|
7
14
|
const placeholder = '/placeholder';
|
|
8
15
|
const relativeDir = (0, core_1.relative)((0, core_1.dirname)((placeholder + from)), (0, core_1.dirname)((placeholder + to)));
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { basename, dirname, Path, relative } from '@angular-devkit/core';
|
|
2
2
|
|
|
3
3
|
export class PathSolver {
|
|
4
|
+
/**
|
|
5
|
+
* Computes the relative path between two paths.
|
|
6
|
+
*
|
|
7
|
+
* @param from - The source path.
|
|
8
|
+
* @param to - The target path.
|
|
9
|
+
* @returns The relative path between the two paths.
|
|
10
|
+
*/
|
|
4
11
|
public relative(from: Path, to: Path): string {
|
|
5
12
|
const placeholder = '/placeholder';
|
|
6
13
|
const relativeDir = relative(
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import { Rule, Tree } from '@angular-devkit/schematics';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if the current directory is the root directory.
|
|
4
|
+
*
|
|
5
|
+
* @param host - The file tree representing the project.
|
|
6
|
+
* @param extraFiles - Additional files to check for in the root directory.
|
|
7
|
+
* @returns True if the current directory is the root directory, otherwise false.
|
|
8
|
+
*/
|
|
2
9
|
export declare function isInRootDirectory(host: Tree, extraFiles?: string[]): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Merges the source root with the provided options.
|
|
12
|
+
* @param options - The options to merge with the source root.
|
|
13
|
+
* @returns A rule to merge the source root with the provided options.
|
|
14
|
+
*/
|
|
3
15
|
export declare function mergeSourceRoot<T extends {
|
|
4
16
|
sourceRoot?: string;
|
|
5
17
|
path?: string;
|
|
6
|
-
} =
|
|
18
|
+
} = never>(options: T): Rule;
|
|
@@ -3,11 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.mergeSourceRoot = exports.isInRootDirectory = void 0;
|
|
4
4
|
const core_1 = require("@angular-devkit/core");
|
|
5
5
|
const defaults_1 = require("../lib/defaults");
|
|
6
|
+
/**
|
|
7
|
+
* Checks if the current directory is the root directory.
|
|
8
|
+
*
|
|
9
|
+
* @param host - The file tree representing the project.
|
|
10
|
+
* @param extraFiles - Additional files to check for in the root directory.
|
|
11
|
+
* @returns True if the current directory is the root directory, otherwise false.
|
|
12
|
+
*/
|
|
6
13
|
function isInRootDirectory(host, extraFiles = []) {
|
|
7
|
-
const files = [
|
|
14
|
+
const files = [].concat(extraFiles || []);
|
|
8
15
|
return files.map((file) => host.exists(file)).some((isPresent) => isPresent);
|
|
9
16
|
}
|
|
10
17
|
exports.isInRootDirectory = isInRootDirectory;
|
|
18
|
+
/**
|
|
19
|
+
* Merges the source root with the provided options.
|
|
20
|
+
* @param options - The options to merge with the source root.
|
|
21
|
+
* @returns A rule to merge the source root with the provided options.
|
|
22
|
+
*/
|
|
11
23
|
function mergeSourceRoot(options) {
|
|
12
24
|
return (host) => {
|
|
13
25
|
const isInRoot = isInRootDirectory(host, ['tsconfig.json', 'package.json']);
|
|
@@ -3,16 +3,28 @@ import { Rule, Tree } from '@angular-devkit/schematics';
|
|
|
3
3
|
|
|
4
4
|
import { DEFAULT_PATH_NAME } from '../lib/defaults';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Checks if the current directory is the root directory.
|
|
8
|
+
*
|
|
9
|
+
* @param host - The file tree representing the project.
|
|
10
|
+
* @param extraFiles - Additional files to check for in the root directory.
|
|
11
|
+
* @returns True if the current directory is the root directory, otherwise false.
|
|
12
|
+
*/
|
|
6
13
|
export function isInRootDirectory(
|
|
7
14
|
host: Tree,
|
|
8
15
|
extraFiles: string[] = []
|
|
9
16
|
): boolean {
|
|
10
|
-
const files = [
|
|
17
|
+
const files = [].concat(extraFiles || []);
|
|
11
18
|
return files.map((file) => host.exists(file)).some((isPresent) => isPresent);
|
|
12
19
|
}
|
|
13
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Merges the source root with the provided options.
|
|
23
|
+
* @param options - The options to merge with the source root.
|
|
24
|
+
* @returns A rule to merge the source root with the provided options.
|
|
25
|
+
*/
|
|
14
26
|
export function mergeSourceRoot<
|
|
15
|
-
T extends { sourceRoot?: string; path?: string } =
|
|
27
|
+
T extends { sourceRoot?: string; path?: string } = never
|
|
16
28
|
>(options: T): Rule {
|
|
17
29
|
return (host: Tree) => {
|
|
18
30
|
const isInRoot = isInRootDirectory(host, ['tsconfig.json', 'package.json']);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rhtml/schematics",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.134",
|
|
4
4
|
"description": "Reactive HyperText Markup Language",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"start": "npx parcel ./examples/index.html --out-dir build/examples",
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
"build": "rm -rf dist && tsc || true && rsync -a --prune-empty-dirs --include '*/' --include '*' --exclude '*' src/ dist/"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@angular-devkit/core": "^
|
|
19
|
-
"@angular-devkit/schematics": "^
|
|
20
|
-
"@angular-devkit/schematics-cli": "^
|
|
21
|
-
"ts-morph": "^
|
|
18
|
+
"@angular-devkit/core": "^19.2.0",
|
|
19
|
+
"@angular-devkit/schematics": "^19.2.0",
|
|
20
|
+
"@angular-devkit/schematics-cli": "^19.2.0",
|
|
21
|
+
"ts-morph": "^25.0.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {},
|
|
24
24
|
"repository": {
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { join, Path, strings } from '@angular-devkit/core';
|
|
2
|
+
import {
|
|
3
|
+
apply,
|
|
4
|
+
branchAndMerge,
|
|
5
|
+
chain,
|
|
6
|
+
filter,
|
|
7
|
+
mergeWith,
|
|
8
|
+
move,
|
|
9
|
+
noop,
|
|
10
|
+
Rule,
|
|
11
|
+
SchematicContext,
|
|
12
|
+
template,
|
|
13
|
+
Tree,
|
|
14
|
+
url,
|
|
15
|
+
} from '@angular-devkit/schematics';
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
DeclarationOptions,
|
|
19
|
+
ModuleDeclarator,
|
|
20
|
+
} from '../../utils/module.declarator';
|
|
21
|
+
import { ModuleFinder } from '../../utils/module.finder';
|
|
22
|
+
import { Location, NameParser } from '../../utils/name.parser';
|
|
23
|
+
import { mergeSourceRoot } from '../../utils/source-root.helpers';
|
|
24
|
+
import { DEFAULT_LANGUAGE } from '../defaults';
|
|
25
|
+
import { ControllerOptions } from './controller.schema';
|
|
26
|
+
|
|
27
|
+
const ELEMENT_METADATA = 'bootstrap';
|
|
28
|
+
const ELEMENT_TYPE = 'controller';
|
|
29
|
+
|
|
30
|
+
export function main(options: ControllerOptions): Rule {
|
|
31
|
+
options = transform(options);
|
|
32
|
+
return (tree: Tree, context: SchematicContext) => {
|
|
33
|
+
return branchAndMerge(
|
|
34
|
+
chain([
|
|
35
|
+
mergeSourceRoot(options),
|
|
36
|
+
mergeWith(generate(options)),
|
|
37
|
+
addDeclarationToModule(options),
|
|
38
|
+
])
|
|
39
|
+
)(tree, context);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function transform(source: ControllerOptions): ControllerOptions {
|
|
44
|
+
const target: ControllerOptions = Object.assign({}, source);
|
|
45
|
+
target.metadata = ELEMENT_METADATA;
|
|
46
|
+
target.type = ELEMENT_TYPE;
|
|
47
|
+
|
|
48
|
+
const location: Location = new NameParser().parse(target);
|
|
49
|
+
target.name = strings.dasherize(location.name);
|
|
50
|
+
target.path = strings.dasherize(location.path);
|
|
51
|
+
target.language =
|
|
52
|
+
target.language !== undefined ? target.language : DEFAULT_LANGUAGE;
|
|
53
|
+
|
|
54
|
+
target.path = target.flat
|
|
55
|
+
? target.path
|
|
56
|
+
: join(target.path as Path, target.name);
|
|
57
|
+
return target;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function generate(options: ControllerOptions) {
|
|
61
|
+
return (context: SchematicContext) =>
|
|
62
|
+
apply(url(join('./files' as Path, options.language)), [
|
|
63
|
+
options.spec ? noop() : filter((path) => !path.endsWith('.spec.ts')),
|
|
64
|
+
template({
|
|
65
|
+
...strings,
|
|
66
|
+
...options,
|
|
67
|
+
}),
|
|
68
|
+
move(options.path),
|
|
69
|
+
])(context);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function addDeclarationToModule(options: ControllerOptions): Rule {
|
|
73
|
+
return (tree: Tree) => {
|
|
74
|
+
if (options.skipImport !== undefined && options.skipImport) {
|
|
75
|
+
return tree;
|
|
76
|
+
}
|
|
77
|
+
options.module = new ModuleFinder(tree).find({
|
|
78
|
+
name: options.name,
|
|
79
|
+
path: options.path as Path,
|
|
80
|
+
});
|
|
81
|
+
if (!options.module) {
|
|
82
|
+
return tree;
|
|
83
|
+
}
|
|
84
|
+
const content = tree.read(options.module).toString();
|
|
85
|
+
const declarator: ModuleDeclarator = new ModuleDeclarator();
|
|
86
|
+
tree.overwrite(
|
|
87
|
+
options.module,
|
|
88
|
+
declarator.declare(content, options as DeclarationOptions)
|
|
89
|
+
);
|
|
90
|
+
return tree;
|
|
91
|
+
};
|
|
92
|
+
}
|