本文整理汇总了TypeScript中@angular-devkit/schematics.schematic函数的典型用法代码示例。如果您正苦于以下问题:TypeScript schematic函数的具体用法?TypeScript schematic怎么用?TypeScript schematic使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了schematic函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: return
return (host: Tree, context: SchematicContext) => {
if (!options.name) {
throw new SchematicsException(`Invalid options, "name" is required.`);
}
const prefix = options.prefix || 'lib';
validateProjectName(options.name);
// If scoped project (i.e. "@foo/bar"), convert projectDir to "foo/bar".
const projectName = options.name;
const packageName = strings.dasherize(projectName);
let scopeName = null;
if (/^@.*\/.*/.test(options.name)) {
const [scope, name] = options.name.split('/');
scopeName = scope.replace(/^@/, '');
options.name = name;
}
const workspace = getWorkspace(host);
const newProjectRoot = workspace.newProjectRoot;
const scopeFolder = scopeName ? strings.dasherize(scopeName) + '/' : '';
const folderName = `${scopeFolder}${strings.dasherize(options.name)}`;
const projectRoot = `${newProjectRoot}/${folderName}`;
const distRoot = `dist/${folderName}`;
const sourceDir = `${projectRoot}/src/lib`;
const relativePathToWorkspaceRoot = projectRoot.split('/').map(x => '..').join('/');
const templateSource = apply(url('./files'), [
template({
...strings,
...options,
packageName,
projectRoot,
distRoot,
relativePathToWorkspaceRoot,
prefix,
}),
// TODO: Moving inside `branchAndMerge` should work but is bugged right now.
// The __projectRoot__ is being used meanwhile.
// move(projectRoot),
]);
return chain([
branchAndMerge(mergeWith(templateSource)),
addAppToWorkspaceFile(options, workspace, projectRoot, projectName),
options.skipPackageJson ? noop() : addDependenciesToPackageJson(),
options.skipTsConfig ? noop() : updateTsConfig(packageName, distRoot),
schematic('module', {
name: options.name,
commonModule: false,
flat: true,
path: sourceDir,
project: options.name,
}),
schematic('component', {
name: options.name,
selector: `${prefix}-${options.name}`,
inlineStyle: true,
inlineTemplate: true,
flat: true,
path: sourceDir,
export: true,
project: options.name,
}),
schematic('service', {
name: options.name,
flat: true,
path: sourceDir,
project: options.name,
}),
(_tree: Tree, context: SchematicContext) => {
if (!options.skipPackageJson && !options.skipInstall) {
context.addTask(new NodePackageInstallTask());
}
},
]);
};
示例2: function
export default function (options: NgNewOptions): Rule {
if (!options.name) {
throw new SchematicsException(`Invalid options, "name" is required.`);
}
if (!options.directory) {
options.directory = options.name;
}
const workspaceOptions: WorkspaceOptions = {
name: options.name,
version: options.version,
newProjectRoot: options.newProjectRoot || 'projects',
};
const applicationOptions: ApplicationOptions = {
projectRoot: '',
name: options.name,
inlineStyle: options.inlineStyle,
inlineTemplate: options.inlineTemplate,
prefix: options.prefix,
viewEncapsulation: options.viewEncapsulation,
routing: options.routing,
style: options.style,
skipTests: options.skipTests,
skipPackageJson: false,
};
return chain([
mergeWith(
apply(empty(), [
schematic('workspace', workspaceOptions),
schematic('application', applicationOptions),
move(options.directory || options.name),
]),
),
(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] : [],
);
}
},
]);
}
示例3: schematic
.map(name => schematic(name, options)),
示例4: return
return (host: Tree, context: SchematicContext) => {
if (!options.name) {
throw new SchematicsException(`Invalid options, "name" is required.`);
}
validateProjectName(options.name);
const prefix = options.prefix || 'app';
const appRootSelector = `${prefix}-root`;
const componentOptions = {
inlineStyle: options.inlineStyle,
inlineTemplate: options.inlineTemplate,
spec: !options.skipTests,
styleext: options.style,
viewEncapsulation: options.viewEncapsulation,
};
const workspace = getWorkspace(host);
let newProjectRoot = workspace.newProjectRoot;
let appDir = `${newProjectRoot}/${options.name}`;
let sourceRoot = `${appDir}/src`;
let sourceDir = `${sourceRoot}/app`;
let relativePathToWorkspaceRoot = appDir.split('/').map(x => '..').join('/');
const rootInSrc = options.projectRoot !== undefined;
if (options.projectRoot !== undefined) {
newProjectRoot = options.projectRoot;
appDir = `${newProjectRoot}/src`;
sourceRoot = appDir;
sourceDir = `${sourceRoot}/app`;
relativePathToWorkspaceRoot = relative(normalize('/' + sourceRoot), normalize('/'));
if (relativePathToWorkspaceRoot === '') {
relativePathToWorkspaceRoot = '.';
}
}
const tsLintRoot = appDir;
const e2eOptions: E2eOptions = {
name: `${options.name}-e2e`,
relatedAppName: options.name,
rootSelector: appRootSelector,
projectRoot: newProjectRoot ? `${newProjectRoot}/${options.name}-e2e` : 'e2e',
};
return chain([
addAppToWorkspaceFile(options, workspace),
options.skipPackageJson ? noop() : addDependenciesToPackageJson(),
mergeWith(
apply(url('./files/src'), [
template({
utils: strings,
...options,
'dot': '.',
relativePathToWorkspaceRoot,
}),
move(sourceRoot),
])),
mergeWith(
apply(url('./files/root'), [
template({
utils: strings,
...options,
'dot': '.',
relativePathToWorkspaceRoot,
rootInSrc,
}),
move(appDir),
])),
mergeWith(
apply(url('./files/lint'), [
template({
utils: strings,
...options,
tsLintRoot,
relativePathToWorkspaceRoot,
prefix,
}),
// TODO: Moving should work but is bugged right now.
// The __tsLintRoot__ is being used meanwhile.
// Otherwise the tslint.json file could be inside of the root folder and
// this block and the lint folder could be removed.
])),
schematic('module', {
name: 'app',
commonModule: false,
flat: true,
routing: options.routing,
routingScope: 'Root',
path: sourceDir,
project: options.name,
}),
schematic('component', {
name: 'app',
selector: appRootSelector,
flat: true,
path: sourceDir,
skipImport: true,
project: options.name,
...componentOptions,
}),
mergeWith(
apply(url('./other-files'), [
componentOptions.inlineTemplate ? filter(path => !path.endsWith('.html')) : noop(),
//.........这里部分代码省略.........
示例5: generatePlayground
export function generatePlayground(): Rule {
return chain([
schematic('playground-module', {}),
schematic('playground-components', {}),
]);
}
示例6: async
return async (host: Tree) => {
if (!options.name) {
throw new SchematicsException(`Invalid options, "name" is required.`);
}
const prefix = options.prefix || 'lib';
validateProjectName(options.name);
// If scoped project (i.e. "@foo/bar"), convert projectDir to "foo/bar".
const projectName = options.name;
const packageName = strings.dasherize(projectName);
let scopeName = null;
if (/^@.*\/.*/.test(options.name)) {
const [scope, name] = options.name.split('/');
scopeName = scope.replace(/^@/, '');
options.name = name;
}
const workspace = await getWorkspace(host);
const newProjectRoot = workspace.extensions.newProjectRoot as (string | undefined) || '';
const scopeFolder = scopeName ? strings.dasherize(scopeName) + '/' : '';
const folderName = `${scopeFolder}${strings.dasherize(options.name)}`;
const projectRoot = join(normalize(newProjectRoot), folderName);
const distRoot = `dist/${folderName}`;
const sourceDir = `${projectRoot}/src/lib`;
const templateSource = apply(url('./files'), [
applyTemplates({
...strings,
...options,
packageName,
projectRoot,
distRoot,
relativePathToWorkspaceRoot: relativePathToWorkspaceRoot(projectRoot),
prefix,
angularLatestVersion: latestVersions.Angular.replace('~', '').replace('^', ''),
folderName,
}),
move(projectRoot),
]);
return chain([
mergeWith(templateSource),
addAppToWorkspaceFile(options, projectRoot, projectName),
options.skipPackageJson ? noop() : addDependenciesToPackageJson(),
options.skipTsConfig ? noop() : updateTsConfig(packageName, distRoot),
schematic('module', {
name: options.name,
commonModule: false,
flat: true,
path: sourceDir,
project: options.name,
}),
schematic('component', {
name: options.name,
selector: `${prefix}-${options.name}`,
inlineStyle: true,
inlineTemplate: true,
flat: true,
path: sourceDir,
export: true,
project: options.name,
}),
schematic('service', {
name: options.name,
flat: true,
path: sourceDir,
project: options.name,
}),
options.lintFix ? applyLintFix(sourceDir) : noop(),
(_tree: Tree, context: SchematicContext) => {
if (!options.skipPackageJson && !options.skipInstall) {
context.addTask(new NodePackageInstallTask());
}
},
]);
};