Mirror: 馃帺 A tiny but capable push & pull stream library for TypeScript and Flow
1import { resolve, basename, dirname, join } from 'path'; 2import { writeFileSync } from 'fs'; 3import { sync as glob } from 'glob'; 4import { compiler, beautify } from 'flowgen'; 5 6function flowTypings() { 7 return { 8 name: 'flow-typings', 9 async writeBundle() { 10 const cwd = process.cwd(); 11 for (const file of glob('dist/types/**/*.d.ts')) { 12 const fullpath = resolve(cwd, file); 13 const flowdef = beautify(compiler.compileDefinitionFile(fullpath)); 14 const name = basename(fullpath, '.d.ts'); 15 const filepath = dirname(fullpath); 16 const newpath = join(filepath, name + '.js.flow'); 17 const definition = flowdef.replace(/import/g, 'import type'); 18 writeFileSync(newpath, '// @flow\n\n' + definition); 19 } 20 }, 21 }; 22} 23 24export default flowTypings;