forked from parcel-bundler/lightningcss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-flow.js
More file actions
18 lines (15 loc) · 1.06 KB
/
build-flow.js
File metadata and controls
18 lines (15 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
const fs = require('fs');
const { compiler, beautify } = require('flowgen');
let dir = `${__dirname}/../`;
let contents = fs.readFileSync(dir + '/node/index.d.ts', 'utf8').replace('`${PropertyStart}${string}`', 'string');
contents = contents.replace(/`.*`/g, 'string');
contents = contents.replace(/(string & \{\})/g, 'string');
let index = beautify(compiler.compileDefinitionString(contents, { inexact: false, interfaceRecords: true }));
index = index.replace('{ code: any }', '{| code: any |}');
index = index.replace(/from "(.*?)";/g, 'from "$1.js.flow";');
// This Exclude type isn't right at all, but idk how to get it working for real...
fs.writeFileSync(dir + '/node/index.js.flow', '// @flow\n\ntype Exclude<A, B> = A;\n' + index)
let ast = beautify(compiler.compileDefinitionFile(dir + '/node/ast.d.ts', { inexact: false }));
fs.writeFileSync(dir + '/node/ast.js.flow', '// @flow\n\n' + ast)
let targets = beautify(compiler.compileDefinitionFile(dir + '/node/targets.d.ts', { inexact: false }));
fs.writeFileSync(dir + '/node/targets.js.flow', '// @flow\n\n' + targets)