本文整理匯總了TypeScript中@schematics/angular/utility/config.getWorkspacePath函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript getWorkspacePath函數的具體用法?TypeScript getWorkspacePath怎麽用?TypeScript getWorkspacePath使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了getWorkspacePath函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: return
return (host: Tree, context: SchematicContext) => {
const workspacePath = getWorkspacePath(host);
if (!workspacePath) {
return;
}
host.create(
`${workspacePath}.bak`, '// This is a backup file of the original angular.json. ' +
'This file is needed in case you want to revert to the workflow without Bazel.\n\n' +
host.read(workspacePath));
};
示例2: addResetCss
export function addResetCss(host: Tree): boolean {
const config = getWorkspace(host);
const project = config.projects[config.defaultProject] as WorkspaceProject<ProjectType.Application>;
let addPackage;
const styleExts = ['scss', 'sass', 'css', 'less', 'styl'];
const styleExt = styleExts.find(ext => host.exists(path.posix.join(project.sourceRoot, `styles.${ext}`)));
if (!styleExt) {
return false;
}
const stylesFile = path.posix.join(project.sourceRoot, `styles.${styleExt}`);
switch (styleExt) {
case 'sass':
case 'scss':
let content = host.read(stylesFile).toString();
if (content.indexOf(`~minireset.css/minireset`) === -1) {
content = scssImport + content;
host.overwrite(stylesFile, content);
addPackage = resetPackage;
}
break;
case 'css':
case 'less':
case 'styl':
if (!project.architect ||
!project.architect.build ||
project.projectType !== ProjectType.Application) {
return false;
}
if (project.architect.build.options.styles) {
project.architect.build.options.styles =
[cssImport, ...project.architect.build.options.styles];
} else {
project.architect.build.options.styles = [cssImport];
}
host.overwrite(getWorkspacePath(host), JSON.stringify(config, null, 2));
addPackage = resetPackage;
break;
default:
break;
}
if (addPackage) {
const targetFile = 'package.json';
if (host.exists(targetFile)) {
const pkgJson = JSON.parse(host.read(targetFile).toString());
pkgJson.dependencies = Object.assign({}, addPackage, pkgJson.dependencies);
host.overwrite(targetFile, JSON.stringify(pkgJson, null, 2) + '\n');
return true;
}
}
return false;
}