回路図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はすでに存在します。回路図ワークフローが失敗しました。上記を参照。
この例外をキャッチして管理するにはどうすればよいですか?
2つのオプションがあります:
--force
回路図コマンドでオプションを使用して、既存のすべてのファイルを強制的に上書きします。 ng g @custom/my-schematics:rule --force
const templateSource = apply(url('./files'), [
forEach((fileEntry: FileEntry) => {
if (tree.exists(fileEntry.path)) {
console.log('File already exists, but it\'s ok');
return null;
}
return fileEntry;
})
]);
return chain([
mergeWith(templateSource)
]);
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加