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
14 lines (11 loc) · 749 Bytes
/
build-flow.js
File metadata and controls
14 lines (11 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
const fs = require('fs');
let dir = `${__dirname}/../`;
let index = fs.readFileSync(dir + '/node/index.d.ts', 'utf8');
index = '// @flow\n' + index;
index = index.replace(/export interface (.*?) \{((?:.|\n)*?)\}/g, 'export type $1 = {|$2|};');
index = index.replace(/export declare function/g, 'declare export function');
index = index.replace("Omit<TransformOptions, 'code'>", "$Rest<TransformOptions, {|code: TransformOptions['code']|}>");
let targets = fs.readFileSync(dir + '/node/targets.d.ts', 'utf8');
targets = targets.replace(/export interface (.*?) \{((?:.|\n)*?)\}/g, 'export type $1 = {|$2|};');
index = index.replace(/import type \{\s*Targets\s*\} from '.\/targets';/, targets);
fs.writeFileSync(dir + '/node/index.js.flow', index);