本文整理汇总了TypeScript中@angular-devkit/schematics.Tree.delete方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Tree.delete方法的具体用法?TypeScript Tree.delete怎么用?TypeScript Tree.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular-devkit/schematics.Tree
的用法示例。
在下文中一共展示了Tree.delete方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: return
return (tree: Tree, context: SchematicContext) => {
for (let file of options.deleteFiles) {
tree.delete(file);
}
context.addTask(new RunSchematicTask('ng-post-post-update', {}));
};
示例2: return
return (host: Tree, context: SchematicContext) => {
const oldConfigPath = getConfigPath(host);
const configPath = normalize('angular.json');
context.logger.info(`Updating configuration`);
const config: JsonObject = {
'$schema': './node_modules/@angular/cli/lib/config/schema.json',
version: 1,
newProjectRoot: 'projects',
projects: extractProjectsConfig(oldConfig, host, logger),
};
const defaultProject = extractDefaultProject(oldConfig);
if (defaultProject !== null) {
config.defaultProject = defaultProject;
}
const cliConfig = extractCliConfig(oldConfig);
if (cliConfig !== null) {
config.cli = cliConfig;
}
const schematicsConfig = extractSchematicsConfig(oldConfig);
if (schematicsConfig !== null) {
config.schematics = schematicsConfig;
}
const targetsConfig = extractTargetsConfig(oldConfig);
if (targetsConfig !== null) {
config.architect = targetsConfig;
}
context.logger.info(`Removing old config file (${oldConfigPath})`);
host.delete(oldConfigPath);
context.logger.info(`Writing config file (${configPath})`);
host.create(configPath, JSON.stringify(config, null, 2));
return host;
};
示例3: return
return (host: Tree, context: SchematicContext) => {
if (host.exists(npmrc)) {
host.delete(npmrc);
}
if (options.type === 'remove') {
return ;
}
host.create(npmrc, `sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
phantomjs_cdnurl=https://npm.taobao.org/mirrors/phantomjs/
electron_mirror=https://npm.taobao.org/mirrors/electron/
registry=https://registry.npm.taobao.org`);
};
示例4: overwriteFile
export function overwriteFile(
host: Tree,
filePath: string,
sourcePath?: string,
overwrite = false,
): Tree {
const isExists = host.exists(filePath);
if (overwrite || isExists) {
try {
const buffer = fs.readFileSync(sourcePath);
const content = buffer ? buffer.toString('utf-8') : '';
if (overwrite) {
if (isExists) {
host.delete(filePath);
}
host.create(filePath, content);
} else {
host.overwrite(filePath, content);
}
} catch {}
}
return host;
}
示例5: return
return (tree: Tree) => {
const source = tree.read(polyfillPath);
if (!source) {
return;
}
// normalize line endings to increase hash match chances
const content = source.toString().replace(/\r\n|\r/g, '\n');
// Check if file is unmodified, if so then replace and return
const hash = createHash('md5');
hash.update(content);
const digest = hash.digest('hex');
if (knownPolyfillHashes.includes(digest)) {
// Replace with new project polyfills file
// This removes the need to parse and also updates all included comments
// mergeWith overwrite doesn't work so clear out existing file
tree.delete(polyfillPath);
return mergeWith(
apply(url('../../application/files/src'), [
filter(path => path === '/polyfills.ts.template'),
move('/polyfills.ts.template', polyfillPath),
]),
MergeStrategy.Overwrite,
);
}
if (!content.includes('core-js')) {
// no action required if no mention of core-js
return;
}
const sourceFile = ts.createSourceFile(polyfillPath,
content,
ts.ScriptTarget.Latest,
true,
);
const imports = sourceFile.statements
.filter(s => s.kind === ts.SyntaxKind.ImportDeclaration) as ts.ImportDeclaration[];
if (imports.length === 0) { return; }
// Start the update of the file.
const recorder = tree.beginUpdate(polyfillPath);
const applicationPolyfillsStart = content.indexOf(applicationPolyfillsHeader);
const browserPolyfillsStart = content.indexOf(browserPolyfillsHeader);
let addHeader = false;
for (const i of imports) {
const module = ts.isStringLiteral(i.moduleSpecifier) && i.moduleSpecifier.text;
// We do not want to remove imports which are after the "APPLICATION IMPORTS" header.
if (module && toDrop[module] && applicationPolyfillsStart > i.getFullStart()) {
recorder.remove(i.getFullStart(), i.getFullWidth());
if (i.getFullStart() <= browserPolyfillsStart) {
addHeader = true;
}
}
}
// We've removed the header since it's part of the JSDoc of the nodes we dropped
if (addHeader) {
recorder.insertLeft(0, header);
}
tree.commitUpdate(recorder);
};
示例7: tryAddFile
export function tryAddFile(host: Tree, path: string, content: string) {
if (host.exists(path)) {
host.delete(path);
}
host.create(path, content);
}
示例8: return
return (tree: Tree, context: SchematicContext) => {
tree.delete(options.deletePath);
context.addTask(new RunSchematicTask('ng-post-post-update', {}));
};