flow-status-webpack-plugin
Advanced tools
Comparing version 0.1.6 to 0.1.7
30
index.js
var shell = require('shelljs'); | ||
function noop() {} | ||
function isFunction(x) { | ||
return Object.prototype.toString.call(x) == '[object Function]'; | ||
} | ||
function FlowStatusWebpackPlugin(options) { | ||
@@ -18,2 +14,4 @@ this.options = options || {}; | ||
var failOnError = options.failOnError || false; | ||
var onSuccess = options.onSuccess || noop; | ||
var onError = options.onError || noop; | ||
var firstRun = true; | ||
@@ -42,3 +40,3 @@ var waitingForFlow = false; | ||
function flowStatus (successCb, errorCb) { | ||
function flowStatus(successCb, errorCb) { | ||
if (!waitingForFlow) { | ||
@@ -50,8 +48,6 @@ waitingForFlow = true; | ||
var hasErrors = code !== 0; | ||
var cb = hasErrors ? errorCb : successCb | ||
var cb = hasErrors ? errorCb : successCb; | ||
waitingForFlow = false; | ||
if (isFunction(cb)) { | ||
cb(stdout, stderr) | ||
} | ||
cb(stdout, stderr); | ||
}); | ||
@@ -63,8 +59,12 @@ } | ||
function checkItWreckIt (compiler, cb) { | ||
function checkItWreckIt(compiler, cb) { | ||
startFlowIfFirstRun(compiler, function () { | ||
flowStatus(function success () { | ||
cb() | ||
}, function error (stdout) { | ||
flowError = new Error(stdout) | ||
flowStatus(function success(stdout) { | ||
onSuccess(stdout); | ||
cb(); | ||
}, function error(stdout) { | ||
onError(stdout); | ||
flowError = new Error(stdout); | ||
// Here we don't pass error to callback because | ||
@@ -71,0 +71,0 @@ // webpack-dev-middleware would just throw it |
{ | ||
"name": "flow-status-webpack-plugin", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"author": "Diego Durli <dgodurli@gmail> (https://github.com/diegodurli)", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -80,2 +80,3 @@ Flow Status Webpack Plugin | ||
If you want the plugin to fail the build if the code doesn't type check, pass `failOnError = true`, and include the `NoErrorsPlugin`: | ||
```js | ||
@@ -95,5 +96,23 @@ var FlowStatusWebpackPlugin = require('flow-status-webpack-plugin'); | ||
If you want to perform an action on successful/failed Flow checks, use the `onSucess`/`onError` callbacks: | ||
```js | ||
var FlowStatusWebpackPlugin = require('flow-status-webpack-plugin'); | ||
var notifier = require('node-notifier'); | ||
module.exports = { | ||
... | ||
plugins: [ | ||
new webpack.NoErrorsPlugin(), | ||
new FlowStatusWebpackPlugin({ | ||
onSuccess: function(stdout) { notifier.notify({ title: 'Flow', message: 'Flow is happy!' }); }, | ||
onError: function(stdout) { notifier.notify({ title: 'Flow', message: 'Flow is sad!' }); } | ||
}) | ||
] | ||
} | ||
``` | ||
License | ||
------- | ||
This plugin is released under the [MIT License](https://opensource.org/licenses/MIT). |
7238
117