本文整理汇总了TypeScript中@angular-devkit/schematics.SchematicContext类的典型用法代码示例。如果您正苦于以下问题:TypeScript SchematicContext类的具体用法?TypeScript SchematicContext怎么用?TypeScript SchematicContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SchematicContext类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: return
return (tree: Tree, context: SchematicContext) => {
const projectTsConfigPaths = getProjectTsConfigPaths(tree);
const tslintFixTasks: TaskId[] = [];
if (!projectTsConfigPaths.length) {
throw new Error('Could not find any tsconfig file. Please submit an issue on the Angular ' +
'Material repository that includes the name of your TypeScript configuration.');
}
// In some applications, developers will have global stylesheets which are not specified in any
// Angular component. Therefore we glob up all CSS and SCSS files outside of node_modules and
// dist. The files will be read by the individual stylesheet rules and checked.
const extraStyleFiles = globSync('!(node_modules|dist)/**/*.+(css|scss)', {absolute: true});
const tslintConfig = createTslintConfig(targetVersion, {
// Default options that can be overwritten if specified explicitly. e.g. if the
// Material update schematic wants to specify a different upgrade data.
extraStyleFiles: extraStyleFiles,
// Custom upgrade configuration options.
...upgradeConfig,
});
for (const tsconfig of projectTsConfigPaths) {
// Run the update tslint rules.
tslintFixTasks.push(context.addTask(new TslintFixTask(tslintConfig, {
silent: false,
ignoreErrors: true,
tsConfigPath: tsconfig,
})));
}
// Delete the temporary schematics directory.
context.addTask(new RunSchematicTask('ng-post-update', {}), tslintFixTasks);
};
示例2: return
return (tree: Tree, context: SchematicContext) => {
installMainPeerDependencies(tree);
const installTaskId = context.addTask(new NodePackageInstallTask());
const postInstallTaskId = context.addTask(new RunSchematicTask('post-install', options), [installTaskId]);
context.addTask(new RunSchematicTask('setup', options), [postInstallTaskId]);
};
示例3: NodePackageLinkTask
(_host: Tree, context: SchematicContext) => {
let packageTask;
if (!options.skipInstall) {
packageTask = context.addTask(new NodePackageInstallTask(options.directory));
if (options.linkCli) {
packageTask = context.addTask(
new NodePackageLinkTask('@angular/cli', options.directory),
[packageTask],
);
}
}
if (!options.skipGit) {
const commit = typeof options.commit == 'object'
? options.commit
: (!!options.commit ? {} : false);
context.addTask(
new RepositoryInitializerTask(
options.directory,
commit,
),
packageTask ? [packageTask] : [],
);
}
},
示例4: return
return (host: Tree, context: SchematicContext) => {
if (!options.skipPackageJson) {
addPackageToPackageJson(host, 'ng-zorro-antd', zorroVersion);
if (options.gestures) {
addPackageToPackageJson(host, 'hammerjs', hammerjsVersion);
}
}
const installTaskId = context.addTask(new NodePackageInstallTask());
context.addTask(new RunSchematicTask('ng-add-setup-project', options), [ installTaskId ]);
context.addTask(new RunSchematicTask('bootstrap', options));
};
示例5: return
return (host: Tree, context: SchematicContext) => {
if (host.exists('package.json')) {
const jsonStr = host.read('package.json') !.toString('utf-8');
const json = JSON.parse(jsonStr);
// If there are no dependencies, create an entry for dependencies.
const type = 'dependencies';
if (!json[type]) {
json[type] = {};
}
// If not already present, add the dependency.
const pkg = 'document-register-element';
const version = '^1.7.2';
if (!json[type][pkg]) {
json[type][pkg] = version;
}
// Write the JSON back to package.json
host.overwrite('package.json', JSON.stringify(json, null, 2));
context.logger.log('info', 'Added `document-register-element` as a dependency.');
// Install the dependency
context.addTask(new NodePackageInstallTask());
}
return host;
};
示例6: return
return (host: Tree, context: SchematicContext) => {
addPackageToPackageJson(host, 'dependencies', '@angular/cdk', materialVersion);
addPackageToPackageJson(host, 'dependencies', '@angular/material', materialVersion);
addPackageToPackageJson(host, 'dependencies', '@angular/animations', angularVersion);
context.addTask(new NodePackageInstallTask());
return host;
};
示例7: return
return (host: Tree, context: SchematicContext) => {
[
{
type: NodeDependencyType.Dev,
name: '@angular/compiler-cli',
version: latestVersions.Angular,
},
{
type: NodeDependencyType.Dev,
name: '@angular-devkit/build-angular',
version: latestVersions.DevkitBuildAngular,
},
{
type: NodeDependencyType.Dev,
name: 'typescript',
version: latestVersions.TypeScript,
},
].forEach(dependency => addPackageJsonDependency(host, dependency));
if (!options.skipInstall) {
context.addTask(new NodePackageInstallTask());
}
return host;
};
示例8: _migrateOnly
function _migrateOnly(
info: PackageInfo | undefined,
context: SchematicContext,
from: string,
to?: string,
) {
if (!info) {
return of<void>();
}
const target = info.installed;
if (!target || !target.updateMetadata.migrations) {
return of<void>(undefined);
}
const collection = (
target.updateMetadata.migrations.match(/^[./]/)
? info.name + '/'
: ''
) + target.updateMetadata.migrations;
context.addTask(new RunSchematicTask('@schematics/update', 'migrate', {
package: info.name,
collection,
from: from,
to: to || target.version,
}),
);
return of<void>(undefined);
}
示例9: return
return (tree: Tree, context: SchematicContext) => {
// Find the closest tslint.json or tslint.yaml
let dir: DirEntry | null = tree.getDir(path.substr(0, path.lastIndexOf('/')));
do {
if ((dir.subfiles as string[]).some(f => f === 'tslint.json' || f === 'tslint.yaml')) {
break;
}
dir = dir.parent;
} while (dir !== null);
if (dir === null) {
throw new SchematicsException(
'Asked to run lint fixes, but could not find a tslint.json or tslint.yaml config file.');
}
// Only include files that have been touched.
const files = tree.actions.reduce((acc: Set<string>, action) => {
const path = action.path.substr(1); // Remove the starting '/'.
if (path.endsWith('.ts') && dir && action.path.startsWith(dir.path)) {
acc.add(path);
}
return acc;
}, new Set<string>());
context.addTask(new TslintFixTask({
ignoreErrors: true,
tsConfigPath: 'tsconfig.json',
files: [...files],
}));
};
示例10: return
return (tree: Tree, context: SchematicContext) => {
const pkgPath = '/package.json';
const buffer = tree.read(pkgPath);
if (buffer == null) {
throw new SchematicsException('Could not read package.json');
}
const content = buffer.toString();
const pkg = JSON.parse(content);
if (pkg === null || typeof pkg !== 'object' || Array.isArray(pkg)) {
throw new SchematicsException('Error reading package.json');
}
const dependencyCategories = ['dependencies', 'devDependencies'];
dependencyCategories.forEach(category => {
const packageName = `@ngrx/${name}`;
if (pkg[category] && pkg[category][packageName]) {
const firstChar = pkg[category][packageName][0];
const suffix = match(firstChar, '^') || match(firstChar, '~');
// TODO: remove beta
pkg[category][packageName] = `${suffix}6.0.0`;
}
});
tree.overwrite(pkgPath, JSON.stringify(pkg, null, 2));
context.addTask(new NodePackageInstallTask());
return tree;
};