Cha*_*man 2 angular-cli angular angular-schematics
我目前正在尝试创建自己的自定义 Angular Schematics。我有以下内容:
import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
// You don't have to export the function as default. You can also have more than one rule factory
// per file.
export function pxSchematics(options: any): Rule {
return (tree: Tree, _context: SchematicContext) => {
tree.create(options.name || 'hello', 'world');
return tree;
};
}
Run Code Online (Sandbox Code Playgroud)
它只是创建一个带有“hello world”的文件。我将如何更改树的文件路径,以便它在自定义目录中输出文件?谢谢。
您可以只指定所需的路径:
import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
import { normalize } from "@angular-devkit/core";
export function pxSchematics(options: any): Rule {
return (tree: Tree, _context: SchematicContext) => {
tree.create(options.name || normalize('sorts/hello'), 'world');
return tree;
};
}
Run Code Online (Sandbox Code Playgroud)