@ngneat/transloco
Version:
The internationalization (i18n) library for Angular
23 lines (19 loc) • 751 B
text/typescript
import { Rule, Tree, SchematicContext, externalSchematic } from '@angular-devkit/schematics';
import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators';
export default function(options): Rule {
return (host: Tree, context: SchematicContext) => {
const template = `<ng-template transloco let-t>
<h1> {{ t('title') }} </h1>
</ng-template>
`;
const cmpRule = externalSchematic('@schematics/angular', 'component', options);
const tree$ = (cmpRule(host, context) as Observable<Tree>).pipe(
tap(tree => {
const templatePath = tree.actions.find(action => !!action.path.match(/component.html/)).path;
tree.overwrite(templatePath, template);
})
);
return tree$;
};
}