···
const { promisify } = require('util');
const { compiler, beautify } = require('flowgen');
15
+
const cwd = process.cwd();
const writeFile = promisify(fs.writeFile);
17
+
const readFile = promisify(fs.readFile);
const preamble = '// @flow\n\n';
18
-
const gen = async () => {
19
-
const cwd = process.cwd();
20
+
const genEntry = async () => {
21
+
let entry = await readFile(path.resolve(cwd, 'index.js.flow'), { encoding: 'utf8' });
21
-
const input = await globby([
23
+
entry = entry.replace(/.\/src/g, '../src');
25
+
const outputCJS = path.resolve(cwd, 'dist/wonka.js.flow');
26
+
const outputES = path.resolve(cwd, 'dist/wonka.es.js.flow');
28
+
return Promise.all([
29
+
writeFile(outputCJS, entry, { encoding: 'utf8' }),
30
+
writeFile(outputES, entry, { encoding: 'utf8' })
34
+
const gen = async () => {
35
+
const input = await globby(['src/*.d.ts', 'src/**/*.d.ts'], {
···
const filepath = path.dirname(fullpath);
const newpath = path.join(filepath, basename + '.js.flow');
45
-
return writeFile(newpath, preamble + flowdef, {
56
+
// Fix incorrect imports
57
+
const fixedFlowdef = flowdef.replace(/^import \{/g, 'import type {');
59
+
return writeFile(newpath, preamble + fixedFlowdef, {
50
-
return Promise.all(write);
64
+
return Promise.all([...write, genEntry()]);
56
-
console.error(err.message);
72
+
console.error(err.message);