Skip to content

Commit

Permalink
fix(cli:module): fix missing comma (#1428)
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk authored Jan 15, 2022
1 parent 794c569 commit c3dba05
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions schematics/module/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,17 @@ function addRoutingModuleToTop(options: ModuleSchema): Rule {
}
const recorder = tree.beginUpdate(modulePath);
const moduleName = strings.classify(`${options.name}Module`);
const code = `{ path: '${options.name}', loadChildren: () => import('./${options.name}/${options.name}.module').then((m) => m.${moduleName}) },`;
let pos = childrenNode.parent.end;
const validLines = childrenNode.parent
.getText()
.trim()
.split('\n')
.map(v => v.trim())
.filter(v => v.length > 1 && !v.startsWith('//'));
const comma = validLines.pop()?.endsWith(',') === false ? ', ' : '';
const code = `${comma} { path: '${options.name}', loadChildren: () => import('./${options.name}/${options.name}.module').then((m) => m.${moduleName}) }`;
// Insert it just before the `]`.
recorder.insertRight(--pos, code);
recorder.insertRight(pos - 1, code);
tree.commitUpdate(recorder);
return tree;
};
Expand Down

0 comments on commit c3dba05

Please sign in to comment.