本文整理汇总了TypeScript中@angular-devkit/schematics.apply函数的典型用法代码示例。如果您正苦于以下问题:TypeScript apply函数的具体用法?TypeScript apply怎么用?TypeScript apply使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了apply函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: addFilesToRoot
function addFilesToRoot(options: ApplicationOptions) {
return chain([
mergeWith(
apply(url('./files/src'), [
options.i18n ? noop() : filter(p => p.indexOf('i18n') === -1),
options.form ? noop() : filter(p => p.indexOf('json-schema') === -1),
template({
utils: strings,
...options,
dot: '.',
VERSION,
ZORROVERSION,
}),
move(appSourceRoot),
]),
),
mergeWith(
apply(url('./files/root'), [
options.i18n ? noop() : filter(p => p.indexOf('i18n') === -1),
options.form ? noop() : filter(p => p.indexOf('json-schema') === -1),
template({
utils: strings,
...options,
dot: '.',
VERSION,
ZORROVERSION,
}),
move('/'),
]),
),
]);
}
示例2: return
return (host: Tree, context: SchematicContext) => {
const workspace = getWorkspace(host);
if (!options.project) {
throw new SchematicsException('Option "project" is required.');
}
const project = workspace.projects[options.project];
if (project.projectType !== 'application') {
throw new SchematicsException(`PWA requires a project type of "application".`);
}
const assetPath = join(project.root as Path, 'src', 'assets');
const sourcePath = join(project.root as Path, 'src');
options.title = options.title || options.project;
const templateSource = apply(url('./files/assets'), [
template({
...options,
}),
move(assetPath),
]);
return chain([
addServiceWorker(options),
branchAndMerge(chain([
mergeWith(templateSource),
])),
mergeWith(apply(url('./files/root'), [
template({...options}),
move(sourcePath),
])),
updateIndexFile(options),
addManifestToAssetsConfig(options),
])(host, context);
};
示例3: return
return (tree: Tree, context: SchematicContext) => {
if (!options.name) {
throw new SchematicsException('name option is required.');
}
let collectionPath: Path | undefined;
try {
const packageJsonContent = tree.read('/package.json');
if (packageJsonContent) {
const packageJson = JSON.parse(packageJsonContent.toString('utf-8'));
if ('schematics' in packageJson) {
const p = normalize(packageJson['schematics']);
if (tree.exists(p)) {
collectionPath = p;
}
}
}
} catch (_) {
}
let source = apply(url('./schematic-files'), [
applyTemplates({
...options as object,
coreVersion,
schematicsVersion,
dot: '.',
camelize: strings.camelize,
dasherize: strings.dasherize,
}),
]);
// Simply create a new schematic project.
if (!collectionPath) {
collectionPath = normalize('/' + options.name + '/src/collection.json');
source = apply(url('./project-files'), [
applyTemplates({
...options as object,
coreVersion,
schematicsVersion,
dot: '.',
camelize: strings.camelize,
dasherize: strings.dasherize,
}),
mergeWith(source),
move(options.name),
]);
context.addTask(new NodePackageInstallTask(options.name));
}
return chain([
mergeWith(source),
addSchematicToCollectionJson(collectionPath, strings.dasherize(options.name), {
description: 'A blank schematic.',
factory: './' + strings.dasherize(options.name) + '/index#' +
strings.camelize(options.name),
}),
]);
};
示例4: async
return async (host: Tree, context: SchematicContext) => {
const workspace = await getWorkspace(host);
const clientProject = workspace.projects.get(options.clientProject);
if (!clientProject || clientProject.extensions.projectType !== 'application') {
throw new SchematicsException(`Universal requires a project type of "application".`);
}
const clientBuildTarget = clientProject.targets.get('build');
if (!clientBuildTarget) {
throw targetBuildNotFoundError();
}
const clientBuildOptions =
(clientBuildTarget.options || {}) as unknown as BrowserBuilderOptions;
const outDir = getTsConfigOutDir(host, clientBuildOptions.tsConfig);
const clientTsConfig = normalize(clientBuildOptions.tsConfig);
const tsConfigExtends = basename(clientTsConfig);
// this is needed because prior to version 8, tsconfig might have been in 'src'
// and we don't want to break the 'ng add @nguniversal/express-engine schematics'
const rootInSrc = clientProject.root === '' && clientTsConfig.includes('src/');
const tsConfigDirectory = join(normalize(clientProject.root), rootInSrc ? 'src' : '');
if (!options.skipInstall) {
context.addTask(new NodePackageInstallTask());
}
const templateSource = apply(url('./files/src'), [
applyTemplates({
...strings,
...options as object,
stripTsExtension: (s: string) => s.replace(/\.ts$/, ''),
}),
move(join(normalize(clientProject.root), 'src')),
]);
const rootSource = apply(url('./files/root'), [
applyTemplates({
...strings,
...options as object,
stripTsExtension: (s: string) => s.replace(/\.ts$/, ''),
outDir,
tsConfigExtends,
rootInSrc,
}),
move(tsConfigDirectory),
]);
return chain([
mergeWith(templateSource),
mergeWith(rootSource),
addDependencies(),
updateConfigFile(options, tsConfigDirectory),
wrapBootstrapCall(clientBuildOptions.main),
addServerTransition(options, clientBuildOptions.main, clientProject.root),
]);
};
示例5: return
return (host: Tree, context: SchematicContext) => {
if (options.module) {
options.module = findModuleFromOptions(host, options);
}
const templateSource = apply(url('./files'), [
options.spec ? noop() : filter(path => !path.endsWith('__spec.ts')),
template({
...stringUtils,
'if-flat': (s: string) =>
stringUtils.group(
options.flat ? '' : s,
options.group ? 'effects' : ''
),
...(options as object),
dot: () => '.',
}),
move(sourceDir),
]);
return chain([
branchAndMerge(
chain([
filter(
path =>
path.endsWith('.module.ts') &&
!path.endsWith('-routing.module.ts')
),
addImportToNgModule(options),
mergeWith(templateSource),
])
),
])(host, context);
};
示例6: return
return (host: Tree, context: SchematicContext) => {
options.path = getProjectPath(host, options);
const parsedPath = parseName(options.path, options.name);
options.name = parsedPath.name;
options.path = parsedPath.path;
const templateSource = apply(url('./files'), [
options.spec ? noop() : filter(path => !path.endsWith('__spec.ts')),
template({
'if-flat': (s: string) =>
stringUtils.group(
options.flat ? '' : s,
options.group ? 'actions' : ''
),
...stringUtils,
...(options as object),
dot: () => '.',
} as any),
move(parsedPath.path),
]);
return chain([branchAndMerge(chain([mergeWith(templateSource)]))])(
host,
context
);
};