In a text file which has the line beginning with the “declarations:” string,
replace “declarations” with “imports”,
replace “AppComponent” or “NxWelcomeComponent” with “”,
parse the result string to get the individual string separated by comma “,”,
and get their related import strings from above.
e.g.
in:
import { RouterModule } from '@angular/router';
import { ScrollDirective } from './directives/scroll.directive';
import { TestComponent } from './test';
import { Test2 } from './test2';
@NgModule({
declarations: [AppComponent, NxWelcomeComponent, ScrollDirective, TestComponent, Test2],
})
Expected out:
import { ScrollDirective } from './directives/scroll.directive';
import { TestComponent } from './test';
import { Test2 } from './test2';
imports: [ScrollDirective, TestComponent, Test2],
I tried:
test.awk:
/declarations:/ {str=$0; sub("declarations", "imports", str) ; sub("AppComponent,", "", str) ; sub("NxWelcomeComponent,", "", str) }
/import/ { importbuf[++arrindex]=$0}
END {
for (i in importbuf) {
print importbuf[i]
}
print str
}
awk -f test.awk in