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) => {
const workspace = getWorkspace(host);
const project = getProjectFromWorkspace(workspace, options.project);
const appModulePath = getAppModulePath(host, getProjectMainFile(project));
if (options.animations) {
// In case the project explicitly uses the NoopAnimationsModule, we should print a warning
// message that makes the user aware of the fact that we won't automatically set up
// animations. If we would add the BrowserAnimationsModule while the NoopAnimationsModule
// is already configured, we would cause unexpected behavior and runtime exceptions.
if (hasNgModuleImport(host, appModulePath, noopAnimationsModuleName)) {
return console.warn(
chalk.red(
`Could not set up "${chalk.bold(browserAnimationsModuleName)}" ` +
`because "${chalk.bold(noopAnimationsModuleName)}" is already imported. Please ` +
`manually set up browser animations.`
)
);
}
return (host: Tree) => {
const workspace = getWorkspace(host);
const project = getProjectFromWorkspace(workspace, options.project);
const appModulePath = getAppModulePath(host, getProjectMainFile(project));
if (options.animations) {
if (hasNgModuleImport(host, appModulePath, noopAnimationsModuleName)) {
console.warn(chalk.red(`Could not set up "${chalk.bold(browserAnimationsModuleName)}" ` +
`because "${chalk.bold(noopAnimationsModuleName)}" is already imported. Please manually ` +
`set up browser animations.`));
return;
}
addModuleImportToRootModule(host, browserAnimationsModuleName,
'@angular/platform-browser/animations', project);
} else if (!hasNgModuleImport(host, appModulePath, browserAnimationsModuleName)) {
// Do not add the NoopAnimationsModule module if the project already explicitly uses
// the BrowserAnimationsModule.
addModuleImportToRootModule(host, noopAnimationsModuleName,
return (host: Tree, context: SchematicContext) => {
const workspace = getWorkspace(host);
const project = getProjectFromWorkspace(workspace, options.project);
const appModulePath = getAppModulePath(host, getProjectMainFile(project));
if (options.animations) {
// In case the project explicitly uses the NoopAnimationsModule, we should print a warning
// message that makes the user aware of the fact that we won't automatically set up
// animations. If we would add the BrowserAnimationsModule while the NoopAnimationsModule
// is already configured, we would cause unexpected behavior and runtime exceptions.
if (hasNgModuleImport(host, appModulePath, noopAnimationsModuleName)) {
context.logger.error(
`Could not set up "${browserAnimationsModuleName}" ` +
`because "${noopAnimationsModuleName}" is already imported.`);
context.logger.info(`Please manually set up browser animations.`);
return;
}
addModuleImportToRootModule(host, browserAnimationsModuleName,
'@angular/platform-browser/animations', project);
function getAppModule(host: Tree, mainPath: string): { appModulePath: string; appModuleFile: string; } {
const appModulePath = getAppModulePath(host, mainPath);
if (!host.exists(appModulePath)) {
throw new SchematicsException(`Can't find AppModule`);
}
const appModuleFile = (host.read(appModulePath) as Buffer).toString('utf-8');
return { appModulePath, appModuleFile };
}
return (host: Tree) => {
const workspace = getWorkspace(host);
const project = getProjectFromWorkspace(workspace, options.project) as WorkspaceProject;
const appModulePath = getAppModulePath(host, getProjectMainFile(project));
for (const module in modulesMap) {
addModuleImportToApptModule(host, module, modulesMap[ module ],
project, appModulePath, options);
}
return host;
};
}
export function addModuleImportToRootModule(host: Tree, moduleName: string, src: string, project: WorkspaceProject) {
const modulePath = getAppModulePath(host, getProjectMainFile(project));
addModuleImportToModule(host, modulePath, moduleName, src);
}
return (host: Tree, context: SchematicContext) => {
const workspace = getWorkspace(host);
const project = workspace.projects[projectName || workspace.defaultProject!];
const buildOptions = getProjectTargetOptions(project, 'build');
const modulePath = getAppModulePath(host, buildOptions.main);
const moduleSource = getSourceFile(host, modulePath);
const changes = addImportToModule(
moduleSource,
modulePath,
'FontAwesomeModule',
'@fortawesome/angular-fontawesome',
);
const recorder = host.beginUpdate(modulePath);
changes.forEach((change) => {
if (change instanceof InsertChange) {
recorder.insertLeft(change.pos, change.toAdd);
}
});
host.commitUpdate(recorder);
context.addTask(new TslintFixTask(modulePath, {}));
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) {
return (tree: Tree, _context: SchematicContext) => {
const workspace = getWorkspace(tree);
const project = workspace.projects[workspace.defaultProject];
const modulePath = getAppModulePath(tree, getProjectMainFile(project));
const moduleSource = getSourceFile(tree, modulePath);
const changes = addImportToModule(moduleSource, modulePath, 'AngularCesiumModule.forRoot()', 'angular-cesium')
.concat(addImportToModule(moduleSource, modulePath, 'AngularCesiumWidgetsModule', 'angular-cesium'));
const recorder = tree.beginUpdate(modulePath);
changes.forEach((change) => {
if (change instanceof InsertChange) {
recorder.insertLeft(change.pos, change.toAdd);
}
});
tree.commitUpdate(recorder);
return tree;
};
export function addModuleImportToRootModule(
host: Tree,
moduleName: string,
src: string,
project: WorkspaceProject,
isModuleImport: boolean = true
) {
const modulePath = getAppModulePath(host, getProjectMainFile(project));
addModuleImportToModule(host, modulePath, moduleName, src, isModuleImport);
}