【发布时间】:2020-06-23 17:03:40
【问题描述】:
我正在设法将一些文件从原理图files 目录复制到主项目目标文件夹:
function addTplFiles(path: string): Source {
// copy templates
return apply(url('./files'), [
move(path as string)
]);
}
export function ngAdd(options: ISchema): Rule {
return (host: Tree/*, context: SchematicContext*/) => {
// get the workspace config of the consuming project
// i.e. angular.json file
const workspace = getWorkspace(host);
// identify the project config which is using our library
// or default to the default project in consumer workspace
const project = getProjectFromWorkspace(
workspace,
options.project || workspace.defaultProject
);
const projectType = project.projectType === 'application' ? 'app' : 'lib';
const path = (options.path === undefined) ? `${project.sourceRoot}/${projectType}` : options.path;
const templateSource = addTplFiles(project.sourceRoot || '');
// return updated tree
try {
return chain([
mergeWith(templateSource)
]);
} catch (e) {
return host;
}
};
代码运行良好,除非文件已经在主应用项目中:
错误! src/assets/i18n/en.json 已经存在。错误! src/assets/i18n/it.json 已经存在。原理图工作流程失败。 见上文。
我怎样才能捕捉和管理这个异常?
【问题讨论】:
标签: angular angular-schematics