Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return (tree: Tree): Tree => {
const module = new ModuleFinder(tree).find({
name: 'core',
path: join('.' as Path, project || '.', 'src/app/core/') as Path,
});
if (!module) {
return tree;
}
const config = existsConfigModule(tree, project || '.');
let fileContent: string | undefined = tree.read(module)!.toString('utf-8');
if (fileContent!.includes('TypeOrmModule.forRoot')) {
return tree;
}
if (!config) {
return (tree: Tree) => {
const modulePosiblePath = join(options.path! as Path, '../..');
const moduleName = strings.classify(basename(modulePosiblePath) + '-module');
const module = new ModuleFinder(tree).find({
name: moduleName,
path: modulePosiblePath,
});
if (!module) {
return tree;
}
let content = tree.read(module)!.toString();
content = addImports(content, strings.classify(options.name), './model');
content = addImports(content, 'TypeOrmModule', '@nestjs/typeorm');
tree.overwrite(
module,
formatTsFile(addTypeormFeatureToModule(content, moduleName, strings.classify(options.name))),
);
function addMailerToCoreModule(path: string, tree: Tree, existsConfig: boolean) {
const core = new ModuleFinder(tree).find({
name: 'core',
path: join(path as Path, 'src/app/core') as Path,
});
if (!core) {
return;
}
let coreContent: string | undefined = tree.read(core)!.toString();
if (coreContent.includes('MailerModule')) {
return;
}
if (existsConfig) {
coreContent = addImports(coreContent, 'ConfigurationService', './configuration/services');
coreContent = addToModuleDecorator(
export function existsConfigModule(tree: Tree, path: string): boolean {
const config = new ModuleFinder(tree).find({
name: 'configuration',
path: join('.' as Path, path || '.', 'src/app/core/configuration') as Path,
});
return !!config && basename(config) === 'configuration.module.ts';
}
return (tree: Tree) => {
const module = new ModuleFinder(tree).find({
name: 'app',
path: (project + '/src/app/') as Path,
});
if (!module) {
return tree;
}
const fileContent = addToModuleDecorator(
tree.read(module)!.toString('utf-8'),
'AppModule',
'./core/core.module',
'CoreModule',
'imports',
false,
);
return (tree: Tree): Tree => {
const moduleName = strings.classify(basename(modulePath as Path) + '-module');
const module = new ModuleFinder(tree).find({
name: basename(modulePath as Path),
path: modulePath as Path,
});
if (!module) {
return tree;
}
const fileContent = addToModuleDecorator(
tree.read(module)!.toString('utf-8'),
moduleName,
'./controllers',
strings.classify(controllerName) + 'Controller',
'controllers',
false,
);
return (tree: Tree): Tree => {
const module = new ModuleFinder(tree).find({
name: 'core',
path: join('.' as Path, project || '.', 'src/app/core/') as Path,
});
if (!module) {
return tree;
}
let fileContent = addToModuleDecorator(
tree.read(module)!.toString('utf-8'),
'CoreModule',
'./auth/auth.module',
'AuthModule',
'imports',
true,
);
return (tree: Tree): Tree => {
const moduleName = strings.classify(basename(modulePath as Path) + '-module');
const module = new ModuleFinder(tree).find({
name: basename(modulePath as Path),
path: modulePath as Path,
});
if (!module) {
return tree;
}
let fileContent = addToModuleDecorator(
tree.read(module)!.toString('utf-8'),
moduleName,
'./services',
strings.classify(crudName) + 'CrudService',
'providers',
false,
);
return (tree: Tree): Tree => {
const moduleName = strings.classify(basename(modulePath as Path) + '-module');
const module = new ModuleFinder(tree).find({
name: basename(modulePath as Path),
path: modulePath as Path,
});
if (!module) {
return tree;
}
const fileContent = addToModuleDecorator(
tree.read(module)!.toString('utf-8'),
moduleName,
'./services',
strings.classify(serviceName) + 'Service',
'providers',
false,
);