Skip to content

Commit

Permalink
Generate flow types next to implementation (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
z0isch committed Mar 28, 2022
1 parent 3979baf commit deab1f0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
12 changes: 12 additions & 0 deletions dist/index.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@flow
declare export {
maybe,
fromJust,
fromMaybe,
catMaybes,
mapMaybes,
mmap,
mthen,
mEffect,
asHTMLAttributeValue,
} from "./maybe";
3 changes: 1 addition & 2 deletions flow/maybe.js → dist/maybe.js.flow
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare module '@freckle/maybe' {
//@flow
declare export function maybe<I, O>(
defaultValue: () => O,
f: (v: I) => O,
Expand Down Expand Up @@ -28,4 +28,3 @@ declare export function mEffect<V>(
effect: (v: V) => void
): void;
declare export function asHTMLAttributeValue<T>(value?: T | null): T | void;
}
31 changes: 18 additions & 13 deletions gen-flow.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
const {beautify, compiler} = require('flowgen')
const fs = require('fs')
const glob = require('glob')
const path = require('path')

const flowdef = beautify(compiler.compileDefinitionFile('./dist/maybe.d.ts'))
fs.writeFile(
'./flow/maybe.js',
`declare module '@freckle/maybe' \{
${flowdef}\}
`,
e => {
if (e) console.error(e)
else {
console.log('Flow types written')
}
}
)
glob('./dist/**/*.d.ts', {}, (err, files) => {
if (err) console.error(err)
files.forEach(f => {
const flowdef = beautify(compiler.compileDefinitionFile(f))
const p = path.parse(f)
const name = /(.*).d/.exec(p.name)[1]
fs.writeFile(
`${p.dir}/${name}.js.flow`,
`//@flow
${flowdef}`,
e => {
if (e) console.error(e)
}
)
})
})

0 comments on commit deab1f0

Please sign in to comment.