Jason Jean 716bb44254
feat(core): migrate library to devkit (#4512)
* migrate lint

* feat(core): migrate library to devkit
2021-01-13 16:57:19 -05:00

25 lines
650 B
TypeScript

import { JsxEmit, ScriptTarget, transpile } from 'typescript';
import { Tree } from '@nrwl/tao/src/shared/tree';
/**
* Rename and transpile any new typescript files created to javascript files
*/
export function toJS(tree: Tree) {
for (const c of tree.listChanges()) {
if (
(c.path.endsWith('.ts') || c.path.endsWith('tsx')) &&
c.type === 'CREATE'
) {
tree.write(
c.path,
transpile(c.content.toString('utf-8'), {
allowJs: true,
jsx: JsxEmit.Preserve,
target: ScriptTarget.ESNext,
})
);
tree.rename(c.path, c.path.replace(/\.tsx?$/, '.js'));
}
}
}