Skip to content

Commit

Permalink
fix: pass through flow options
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards1211 committed Oct 31, 2019
1 parent 1d325cd commit 73c65b4
Show file tree
Hide file tree
Showing 11 changed files with 662 additions and 123 deletions.
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules
.eslintrc
.flowconfig
.travis.yml
test
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

51 changes: 51 additions & 0 deletions createNodemonArgs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@


module.exports = function createNodemonArgs(argv) {
var options = []
var args = []
var stopSlurping = false
for (var i = 0; i < argv.length; i++) {
if (stopSlurping) {
args.push(argv[i])
continue
}
switch (argv[i]) {
case '-e':
case '--ext':
case '-w':
case '--watch':
case '-i':
case '--ignore':
case '--delay':
case '--signal':
options.push(argv[i])
options.push(argv[++i])
break
case '-q':
case '--quiet':
case '-L':
case '--legacy-watch':
case '-V':
case '--verbose':
options.push(argv[i])
break
case '--':
stopSlurping = true
break
default:
args.push(argv[i])
}
}
if (!options.length) {
options.push(
'--ignore', 'node_modules/',
'--watch', '*.js',
'--watch', '*.jsx',
'--watch', '*.js.flow',
'--watch', '.flowconfig',
'--ext', 'js,mjs,jsx,json'
)
}
if (args.length) args.unshift('--')
return options.concat([require.resolve('./runFlow')], args)
}
16 changes: 16 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env node

'use strict'

var spawn = require('cross-spawn')
var createNodemonArgs = require('./createNodemonArgs')

spawn(
process.execPath,
[
require.resolve('nodemon/bin/nodemon'),
].concat(createNodemonArgs(process.argv.slice(2))),
{
stdio: 'inherit'
}
)
22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
"name": "flow-watch",
"version": "1.1.4",
"description": "clear the console and run flow on file changes",
"main": "src/flow-watch.js",
"main": "./index.js",
"bin": {
"flow-watch": "./src/flow-watch.js"
"flow-watch": "./index.js"
},
"scripts": {
"lint": "eslint src test",
"lint:fix": "eslint --fix src test",
"flow": "flow",
"flow:watch": "node src/flow-watch.js",
"test": "mocha $npm_package_config_mocha",
"prepublish": "npm run lint && flow",
"lint": "eslint *.js test",
"lint:fix": "eslint --fix *.js test",
"flow:watch": "node ./index.js",
"test": "mocha",
"test:watch": "mocha --watch",
"prepublishOnly": "npm run lint && npm test",
"postpublish": "git tag -a v$npm_package_version -m v$npm_package_version && git push origin v$npm_package_version"
},
"keywords": [
Expand All @@ -22,12 +22,14 @@
"author": "Andy Edwards",
"license": "MIT",
"devDependencies": {
"chai": "^4.2.0",
"eslint": "^3.7.0",
"flow-bin": "^0.41.0"
"flow-bin": "^0.41.0",
"mocha": "^6.2.2"
},
"dependencies": {
"cross-spawn": "^6.0.3",
"nodemon": "^1.18.6"
"nodemon": "^1.19.4"
},
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions src/runFlow.js → runFlow.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /usr/bin/env node
// @flow
'use strict'

var flow
try {
Expand All @@ -15,4 +15,4 @@ if (process.stdout.isTTY && !process.env.FLOW_WATCH_NO_CLEAR_CONSOLE) {
process.stdout.write('\u001b[3J')
}

require('cross-spawn')(flow, {stdio: 'inherit'})
require('cross-spawn')(flow, process.argv.slice(2), {stdio: 'inherit'})
26 changes: 0 additions & 26 deletions src/flow-watch.js

This file was deleted.

5 changes: 5 additions & 0 deletions test/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"env": {
"mocha": true
}
}
48 changes: 48 additions & 0 deletions test/createNodemonArgs.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict'

var createNodemonArgs = require('../createNodemonArgs')
var expect = require('chai').expect

describe('createNodemonArgs', function () {
it('with no input args', function () {
expect(createNodemonArgs([])).to.deep.equal([
'--ignore', 'node_modules/',
'--watch', '*.js',
'--watch', '*.jsx',
'--watch', '*.js.flow',
'--watch', '.flowconfig',
'--ext', 'js,mjs,jsx,json',
require.resolve('../runFlow')
])
})
it('with no nodemon-specific input args', function () {
expect(createNodemonArgs(['--foo'])).to.deep.equal([
'--ignore', 'node_modules/',
'--watch', '*.js',
'--watch', '*.jsx',
'--watch', '*.js.flow',
'--watch', '.flowconfig',
'--ext', 'js,mjs,jsx,json',
require.resolve('../runFlow'),
'--',
'--foo'
])
})
it('with nodemon-specific input args', function () {
expect(createNodemonArgs(['--watch', '*.js.flow', '--foo'])).to.deep.equal([
'--watch', '*.js.flow',
require.resolve('../runFlow'),
'--',
'--foo'
])
})
it('with nodemon-specific input args and --', function () {
expect(createNodemonArgs(['--watch', '*.js.flow', '--', '--verbose', '--foo'])).to.deep.equal([
'--watch', '*.js.flow',
require.resolve('../runFlow'),
'--',
'--verbose',
'--foo'
])
})
})
1 change: 1 addition & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--reporter spec
Loading

0 comments on commit 73c65b4

Please sign in to comment.