MCPcopy
hub / github.com/angular/angular-cli / addImportToNgModule

Function addImportToNgModule

packages/schematics/angular/module/index.ts:53–82  ·  view source on GitHub ↗
(options: ModuleOptions)

Source from the content-addressed store, hash-verified

51}
52
53function addImportToNgModule(options: ModuleOptions): Rule {
54 return (host: Tree) => {
55 if (!options.module) {
56 return host;
57 }
58
59 const modulePath = options.module;
60
61 const sourceText = host.readText(modulePath);
62 const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
63
64 const relativePath = buildRelativeModulePath(options, modulePath);
65 const changes = addImportToModule(
66 source,
67 modulePath,
68 strings.classify(`${options.name}Module`),
69 relativePath,
70 );
71
72 const recorder = host.beginUpdate(modulePath);
73 for (const change of changes) {
74 if (change instanceof InsertChange) {
75 recorder.insertLeft(change.pos, change.toAdd);
76 }
77 }
78 host.commitUpdate(recorder);
79
80 return host;
81 };
82}
83
84function addRouteDeclarationToNgModule(
85 options: ModuleOptions,

Callers 1

index.tsFile · 0.85

Calls 6

addImportToModuleFunction · 0.90
buildRelativeModulePathFunction · 0.85
readTextMethod · 0.65
beginUpdateMethod · 0.65
insertLeftMethod · 0.65
commitUpdateMethod · 0.65

Tested by

no test coverage detected