【发布时间】:2021-07-09 16:30:04
【问题描述】:
我的库中有一个字体文件夹,我想在安装过程中或安装后使用 Angular Schematics 将其复制到 Angular 应用程序(更具体地说是src/asset 文件夹)。在 package.json 中运行一个简单的 cp 脚本不是一种选择。到目前为止,这是我的工厂:
export function addFonts(_options: any): Rule {
return (tree: Tree, _context: SchematicContext) => {
const workspaceConfigBuffer = tree.read('angular.json');
if (!workspaceConfigBuffer) {
throw new SchematicsException('Not an Angular CLI workspace');
}
const workspace = JSON.parse(workspaceConfigBuffer.toString());
const projectName = workspace.defaultProject;
const project = workspace.projects[projectName];
const defaultProjectPath = `${project.sourceRoot}/${
project.projectType === 'application' ? 'app' : 'lib'
}`;
const rawFontDir = tree.getDir(`${defaultProjectPath}/assets`);
const results: string[] = [];
tree.getDir('node_modules/@myNgLib/font-styles/fonts').visit(filePath => {
results.push(filePath);
});
results.map(result => {
const copyFonts = apply(url(`${result}`), [move(`${rawFontDir}`)]);
console.log(rawFontDir);
return mergeWith(copyFonts);
});
return tree;
};
}
看来我没有更改树中的任何内容,因为当我运行它时,我收到消息Nothing to be done。有人可以帮忙吗?
【问题讨论】:
标签: angular angular-schematics