Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return (host: Tree) => {
if (options.skipImport || !options.module) {
return host;
}
const modulePath = options.module;
let source = readIntoSourceFile(host, modulePath);
const componentPath = `/${options.path}/`
+ (options.flat ? '' : strings.dasherize(options.name) + '/')
+ strings.dasherize(options.name)
+ '.component';
const relativePath = buildRelativePath(modulePath, componentPath);
const classifiedName = strings.classify(`${options.name}Component`);
const declarationChanges = addDeclarationToModule(
source,
modulePath,
classifiedName,
relativePath);
const declarationRecorder = host.beginUpdate(modulePath);
for (const change of declarationChanges) {
if (change instanceof InsertChange) {
declarationRecorder.insertLeft(change.pos, change.toAdd);
}
}
host.commitUpdate(declarationRecorder);
if (options.export) {
// Need to refresh the AST because we overwrote the file in the host.
source = readIntoSourceFile(host, modulePath);
return host;
}
const modulePath = options.module;
let source = readIntoSourceFile(host, modulePath);
const componentPath = `/${options.path}/${options.flat ? '' : strings.dasherize(options.name) + '/'}${strings.dasherize(options.name)}.component`;
const relativePath = buildRelativePath(modulePath, componentPath);
let classifiedName = strings.classify(`${options.name}Component`);
if (options.classnameWithModule) {
const modulePrefix = getModuleClassnamePrefix(source);
if (modulePrefix) {
classifiedName = `${modulePrefix}${classifiedName}`
}
}
const declarationChanges = addDeclarationToModule(
// TODO: TypeScript version mismatch due to @schematics/angular using a different version
// than Material. Cast to any to avoid the type assignment failure.
// tslint:disable-next-line no-any
source as any,
modulePath,
classifiedName,
relativePath);
const declarationRecorder = host.beginUpdate(modulePath);
for (const change of declarationChanges) {
if (change instanceof InsertChange) {
declarationRecorder.insertLeft(change.pos, change.toAdd);
}
}
host.commitUpdate(declarationRecorder);
return (host: Tree) => {
const modulePath = `/${parsedPath.path}/${stringsExtensions.moduleFile(parsedPath.name)}.ts`;
const exampleModulePath = `/${parsedPath.path}/${stringsExtensions.componentFile(componentName)}`;
const relativePath = buildRelativePath(modulePath, exampleModulePath);
const classifiedName = stringsExtensions.componentClassName(componentName);
let source = readIntoSourceFile(host, modulePath);
const declarationChanges = addDeclarationToModule(source, modulePath, classifiedName, relativePath);
const declarationRecorder = host.beginUpdate(modulePath);
for (const change of declarationChanges) {
if (change instanceof InsertChange) {
declarationRecorder.insertLeft(change.pos, change.toAdd);
}
}
host.commitUpdate(declarationRecorder);
// Need to refresh the AST because we overwrote the file in the host.
source = readIntoSourceFile(host, modulePath);
const exportRecorder = host.beginUpdate(modulePath);
const exportChanges = addExportToModule(source, modulePath, classifiedName, relativePath);
for (const change of exportChanges) {
if (change instanceof InsertChange) {
exportRecorder.insertLeft(change.pos, change.toAdd);
return (host: Tree) => {
const source = getSourceFile(host, routingPath);
if (!source) {
return host;
}
let changes;
if (isView) {
changes = addDeclarationToModule(source, routingPath, options.componentName, options.relativePath);
} else {
changes = addImportToModule(source, routingPath, options.componentName, options.relativePath);
}
return applyChanges(host, changes, routingPath);
};
}
return (host: Tree, context: SchematicContext) => {
try {
const matButton = ['MatButtonModule', '@angular/material'];
const modulePath = getAppModulePath(host, getMainProjectPath(host, options));
const relativePath = buildRelativePath(modulePath, componentPath);
const srcPath = getSourceFile(host, modulePath);
const compName = strings.classify(`${options.name}Component`);
if (!isImported(srcPath, compName, relativePath)) {
let changes = addDeclarationToModule(srcPath, modulePath, compName, relativePath);
if (options.uiLib === 'material') {
changes = [...changes, ...addImportToModule(srcPath, modulePath, matButton[0],
matButton[1])];
}
const recorder = host.beginUpdate(modulePath);
changes.forEach((change) => {
if (change instanceof InsertChange) {
recorder.insertLeft(change.pos, change.toAdd);
}
});
host.commitUpdate(recorder);
context.logger.log('info', `✅️ Component Added to NgModule declarations`);
} else {
const componentPath = `/${options.path}/`
+ strings.dasherize(options.name) + '/'
+ strings.dasherize(options.name) + '.component';
const relativePath = buildRelativePath(modulePath, componentPath);
const declarationRecorder = tree.beginUpdate(modulePath);
const classifiedComponent = 'Dx' + widget + 'Module';
for (const change of addImportToModule(source, modulePath, classifiedComponent, 'devextreme-angular')) {
if (change instanceof InsertChange) {
declarationRecorder.insertLeft(change.pos, change.toAdd);
}
}
const classifiedName = strings.classify(options.name + 'Component');
for (const change of addDeclarationToModule(source, modulePath, classifiedName, relativePath)) {
if (change instanceof InsertChange) {
declarationRecorder.insertLeft(change.pos, change.toAdd);
}
}
tree.commitUpdate(declarationRecorder);
}
return host => {
const source = readIntoSourceFile(host, options.module);
const relativePath = buildRelativePath(options.module, options.moduleImportPath);
const declarationChanges = addDeclarationToModule(source, options.module, options.artifactName, relativePath);
const declarationRecorder = host.beginUpdate(options.module);
for (const change of declarationChanges) {
if (change instanceof InsertChange) {
declarationRecorder.insertLeft(change.pos, change.toAdd);
}
}
host.commitUpdate(declarationRecorder);
return host;
};
}