Skip to content

Commit

Permalink
create gen-flow-files and flow:coverage scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards1211 committed Oct 12, 2016
1 parent 437dd17 commit 51307d7
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[ignore]
<PROJECT_ROOT>/lib/.*

[include]
./src
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
coverage
.nyc_output
test
scripts
node_modules
.babelrc
.eslintrc
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
"lint:fix": "eslint --fix src test",
"lint:watch": "esw --watch src test",
"flow": "flow",
"flow:coverage": "for file in src/*.js; do echo $file; flow coverage $file; done",
"flow:watch": "flow-watch --ignore lib/ --ignore node_modules/ --watch .flowconfig --watch src/ --watch scripts/ --watch test/",
"gen-flow-files": "babel-node scripts/gen-flow-files.js",
"build": "rimraf lib && babel src --out-dir lib",
"test": "mocha $npm_package_config_mocha",
"coverage": "NODE_ENV=coverage nyc --reporter=lcov --reporter=text mocha $npm_package_config_mocha",
"prepublish": "npm run lint && flow && npm run coverage && rimraf lib && babel src --out-dir lib",
"prepublish": "npm run lint && flow && npm run coverage && npm run build && npm run gen-flow-files",
"postpublish": "git tag -a v$npm_package_version -m v$npm_package_version && git push origin v$npm_package_version"
},
"config": {
Expand Down Expand Up @@ -53,11 +56,13 @@
"babel-runtime": "^6.11.6",
"chai": "^3.5.0",
"coveralls": "^2.11.14",
"es6-promisify": "^5.0.0",
"eslint": "^3.7.0",
"eslint-config-andy": "github:jedwards1211/eslint-config-andy#2.0.0-beta7",
"eslint-watch": "^2.1.14",
"flow-bin": "^0.33.0",
"flow-watch": "^1.0.0",
"glob": "^7.1.1",
"istanbul": "^0.4.5",
"mocha": "^3.1.0",
"nyc": "^8.3.0",
Expand Down
14 changes: 14 additions & 0 deletions scripts/asyncScript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @flow

async function asyncScript(run: () => Promise<*>, options?: {exitOnSuccess?: boolean} = {}): Promise<any> {
try {
const result = await run()
if (options.exitOnSuccess !== false) process.exit(0)
else return result
} catch (error) {
console.error(error.stack) // eslint-disable-line no-console
process.exit(1)
}
}

export default asyncScript
22 changes: 22 additions & 0 deletions scripts/gen-flow-files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// @flow

import glob from 'glob'
import {exec} from 'child_process'
import path from 'path'
import fs from 'fs'
import flow from 'flow-bin'
import asyncScript from './asyncScript'
import promisify from 'es6-promisify'

const src = path.resolve(__dirname, '..', 'src')
const lib = path.resolve(__dirname, '..', 'lib')

asyncScript(async () => {
const files = await promisify(glob)(path.join(src, '**', '*.js'))
await Promise.all(files.map(async file => {
const stdout = await promisify(exec)(`${flow} gen-flow-files ${file}`)
const outfile = path.join(lib, path.relative(src, file)) + '.flow'
await promisify(fs.writeFile)(outfile, stdout, 'utf8')
console.log('wrote', outfile)
}))
})

0 comments on commit 51307d7

Please sign in to comment.