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 => {
const source = filesystem_1.readIntoSourceFile(host, options.module);
const relativePath = options.moduleImportPath
? find_module_1.buildRelativePath(options.module, options.moduleImportPath)
: undefined;
const declarationChanges = ast_utils_1.addProviderToModule(source, options.module, options.artifactName, relativePath);
const declarationRecorder = host.beginUpdate(options.module);
for (const change of declarationChanges) {
if (change instanceof change_1.InsertChange) {
declarationRecorder.insertLeft(change.pos, change.toAdd);
}
}
host.commitUpdate(declarationRecorder);
return host;
};
}
return (host) => {
if (!options.module) {
return host;
}
const modulePath = `${options.path}/${options.module}`;
const moduleSource = readIntoSourceFile(host, modulePath);
const servicePath = `${options.path}/` +
(options.flat ? '' : core_1.strings.dasherize(options.name) + '/') +
core_1.strings.dasherize(options.name) +
'.service';
const relativePath = find_module_1.buildRelativePath(modulePath, servicePath);
const classifiedName = core_1.strings.classify(`${options.name}Service`);
const providersChanges = ast_utils_1.addProviderToModule(moduleSource, modulePath, classifiedName, relativePath);
const providersRecorder = host.beginUpdate(modulePath);
for (const change of providersChanges) {
if (change instanceof change_1.InsertChange) {
providersRecorder.insertLeft(change.pos, change.toAdd);
}
}
host.commitUpdate(providersRecorder);
return host;
};
}
return host => {
const relativePath = find_module_1.buildRelativePath(options.module, options.moduleImportPath);
const source = filesystem_1.readIntoSourceFile(host, options.module);
const exportRecorder = host.beginUpdate(options.module);
const exportChanges = ast_utils_1.addExportToModule(source, options.module, core_1.strings.classify(options.artifactName), relativePath);
for (const change of exportChanges) {
if (change instanceof change_1.InsertChange) {
exportRecorder.insertLeft(change.pos, change.toAdd);
}
}
host.commitUpdate(exportRecorder);
};
}
export function buildRelativePath(from: string, to: string): string {
return originalBuildRelativePath(from, to);
}
function buildRelativeComponentPath(options: ComponentOptions, modulePath: string): string {
const componentPath =
`/${options.path}/` +
(options.flat ? '' : strings.dasherize(options.name) + '/') +
strings.dasherize(options.name) +
'.component';
return buildRelativePath(modulePath, componentPath);
}
return (host: Tree) => {
if (options.skipImport || !options.module)
return host;
const file = options.module;
const sourceFile = CodeUtils.readSourceFile(host, file);
const directivePath = `/${options.path}/`
+ (options.flat ? '' : strings.dasherize(options.name) + '/')
+ strings.dasherize(options.name)
+ '.directive';
const relativePath = buildRelativePath(options.module, directivePath);
CodeUtils.addImport(sourceFile, `${strings.classify(options.name)}Directive`, relativePath);
CodeUtils.insertInVariableArray(sourceFile, "DECLARATIONS", `${strings.classify(options.name)}Directive`);
CodeUtils.writeSourceFile(host, file, sourceFile);
return host;
};
}
return (host: Tree) => {
if (!options.module)
return host;
const file = options.module;
const sourceFile = CodeUtils.readSourceFile(host, file);
const modulePath = `/${options.path}/`
+ (options.flat ? '' : strings.dasherize(options.name) + '/')
+ strings.dasherize(options.name)
+ '.module';
const relativePath = buildRelativePath(options.module, modulePath);
CodeUtils.addImport(sourceFile, `${strings.classify(options.name)}Module`, relativePath);
CodeUtils.insertInVariableArray(sourceFile, "MODULES", `${strings.classify(options.name)}Module`);
CodeUtils.writeSourceFile(host, file, sourceFile);
return host;
};
}
function buildRelativeModulePath(options: ModuleOptions, modulePath: string): string {
const importModulePath = normalize(
`/${options.path}/` +
(options.flat ? '' : strings.dasherize(options.name) + '/') +
strings.dasherize(options.name) +
'.module'
);
return buildRelativePath(modulePath, importModulePath);
}