Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

flow-status-webpack-plugin

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flow-status-webpack-plugin - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

126

index.js

@@ -1,71 +0,91 @@

var colors = require('colors'),
shell = require('shelljs');
var shell = require('shelljs');
function isFunction(x) {
return Object.prototype.toString.call(x) == '[object Function]';
}
function FlowStatusWebpackPlugin(options) {
this.options = options || {};
this.options = options || {};
}
FlowStatusWebpackPlugin.prototype.apply = function(compiler) {
var options = this.options,
flowArgs = options.flowArgs || '',
flow = options.binaryPath || 'flow',
firstRun = true,
waitingForFlow = false;
var options = this.options;
var flowArgs = options.flowArgs || '';
var flow = options.binaryPath || 'flow';
var failOnError = options.failOnError || false;
var firstRun = true;
var waitingForFlow = false;
function startFlow(cb) {
if (options.restartFlow === false) {
cb();
} else {
shell.exec(flow + ' stop', function() {
shell.exec(flow + ' start ' + flowArgs, cb);
});
}
function startFlow(cb) {
if (options.restartFlow === false) {
cb();
} else {
shell.exec(flow + ' stop', {silent: true}, function() {
shell.exec(flow + ' start ' + flowArgs, {silent: true}, cb);
});
}
}
function startFlowIfFirstRun(compiler, cb) {
if (firstRun) {
firstRun = false;
startFlow(cb);
function startFlowIfFirstRun(compiler, cb) {
if (firstRun) {
firstRun = false;
startFlow(cb);
}
else {
cb();
}
}
function flowStatus (successCb, errorCb) {
if (!waitingForFlow) {
waitingForFlow = true;
// this will start a flow server if it was not running
shell.exec(flow + ' status --color always', {silent: true}, function(code, stdout, stderr) {
var hasErrors = code !== 0;
var cb = hasErrors ? errorCb : successCb
waitingForFlow = false;
if (isFunction(cb)) {
cb(stdout, stderr)
}
else {
cb();
}
});
}
}
// restart flow if interfacesPath was provided regardless
// of whether webpack is in normal or watch mode
compiler.plugin('run', startFlowIfFirstRun);
compiler.plugin('watch-run', startFlowIfFirstRun);
var flowError = null
function flowStatus() {
if (!waitingForFlow) {
waitingForFlow = true;
function checkItWreckIt (compiler, cb) {
startFlowIfFirstRun(compiler, function () {
flowStatus(function success () {
cb()
}, function error (stdout) {
flowError = new Error(stdout)
// Here we don't pass error to callback because
// webpack-dev-middleware would just throw it
// and cause webpack dev server to exit with
// an error status code. Obviously, having to restart
// the development webpack server after every flow
// check error would be too annoying.
cb()
})
})
}
// this will start a flow server if it was not running
shell.exec(flow + ' status --color always', {silent: true}, function(code, stdout, stderr) {
var hasErrors = code !== 0;
compiler.plugin('run', checkItWreckIt);
compiler.plugin('watch-run', checkItWreckIt);
if (hasErrors) {
console.log('\n----------------'.red);
console.log('Flow has errors!');
console.log('----------------\n'.red);
} else if (options.quietSuccess !== true) {
console.log('\n-----------------------------'.green);
console.log('Everything is fine with Flow!');
console.log('-----------------------------\n'.green);
}
if (options.quietSuccess !== true || hasErrors) {
console.log(stdout);
}
console.error(stderr);
waitingForFlow = false;
});
}
// If there are flow errors, fail the build before compilation starts.
compiler.plugin('compilation', function (compilation) {
if (flowError) {
if (failOnError === true) {
compilation.errors.push(flowError);
}
flowError = null;
}
// When Webpack compilation is done, we should run Flow Status.
compiler.plugin('done', flowStatus);
});
};
module.exports = FlowStatusWebpackPlugin;
{
"name": "flow-status-webpack-plugin",
"version": "0.1.5",
"version": "0.1.6",
"author": "Diego Durli <dgodurli@gmail> (https://github.com/diegodurli)",
"dependencies": {
"colors": "^1.1.2",
"shelljs": "^0.6.0"

@@ -8,0 +7,0 @@ },

Flow Status Webpack Plugin
==========================
[![npm version](https://img.shields.io/npm/v/flow-status-webpack-plugin.svg?style=flat-square)](https://www.npmjs.com/package/flow-status-webpack-plugin) [![npm downloads](https://img.shields.io/npm/dm/flow-status-webpack-plugin.svg?style=flat-square)](https://www.npmjs.com/package/flow-status-webpack-plugin)
This [webpack](http://webpack.github.io/) plugin will automatically start a [Flow](http://flowtype.org/) server (or restart if one is running) when webpack starts up, and run `flow status` after each webpack build. Still experimental.

@@ -33,10 +31,2 @@

It will generate an output like this:
![Flow has no errors](http://i.imgur.com/GX2xg8J.png?1)
or, in case of some error:
![Flow has errors](http://i.imgur.com/4cnu50c.png?1)
Configuration

@@ -90,5 +80,3 @@ -------------

If you don't want the plugin to display a message on success, pass
`quietSuccess: true`:
If you want the plugin to fail the build if the code doesn't type check, pass `failOnError = true`, and include the `NoErrorsPlugin`:
```js

@@ -100,4 +88,5 @@ var FlowStatusWebpackPlugin = require('flow-status-webpack-plugin');

plugins: [
new webpack.NoErrorsPlugin(),
new FlowStatusWebpackPlugin({
quietSuccess: true
failOnError: true
})

@@ -108,4 +97,5 @@ ]

License
-------
This plugin is released under the [MIT License](https://opensource.org/licenses/MIT).
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc