flow-status-webpack-plugin
Advanced tools
Comparing version 0.1.0 to 0.1.1
60
index.js
@@ -5,25 +5,38 @@ const colors = require('colors'); | ||
function FlowStatusWebpackPlugin(options) { | ||
const interfaces = options && options.interfacesPath ? ' --lib ' + options.interfacesPath : ''; | ||
// Developer may change some interface configuration between each | ||
// file save. To avoid any configuration not being properly sent | ||
// over to Flow server, we should stop it and start it again. | ||
shell.exec('flow stop', {silent: true}, () => { | ||
shell.exec('flow start' + interfaces, {silent: true}, (code) => { | ||
this.flow_server_running = code === 0; | ||
}); | ||
}); | ||
this.options = options || {}; | ||
} | ||
FlowStatusWebpackPlugin.prototype.apply = function(compiler) { | ||
var _this = this; | ||
const options = this.options; | ||
const flowArgs = options.flowArgs || ''; | ||
// When Webpack compilation is done, we should run Flow Status. | ||
compiler.plugin('done', function() { | ||
function startFlow(cb) { | ||
shell.exec('flow stop', () => { | ||
shell.exec('flow start ' + flowArgs, () => cb()); | ||
}); | ||
} | ||
// For now it's a week test, but since this plugin is not handling | ||
// all kind of errors for now, it will work. | ||
if (_this.flow_server_running) { | ||
var firstRun = true; | ||
function startFlowIfFirstRun(compiler, cb) { | ||
if (firstRun) { | ||
firstRun = false; | ||
startFlow(cb); | ||
} | ||
else { | ||
cb(); | ||
} | ||
} | ||
shell.exec('flow status', {silent: true}, (code, stdout) => { | ||
// 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 waitingForFlow = false; | ||
function flowStatus() { | ||
if (!waitingForFlow) { | ||
waitingForFlow = true; | ||
// this will start a flow server if it was not running | ||
shell.exec('flow status --color always', {silent: true}, (code, stdout, stderr) => { | ||
const hasErrors = code !== 0; | ||
@@ -35,3 +48,2 @@ | ||
console.log('----------------\n'.red); | ||
console.log(stdout.red); | ||
} else { | ||
@@ -41,9 +53,15 @@ console.log('\n-----------------------------'.green); | ||
console.log('-----------------------------\n'.green); | ||
console.log(stdout.green); | ||
} | ||
console.log(stdout); | ||
console.error(stderr); | ||
waitingForFlow = false; | ||
}); | ||
} | ||
}); | ||
} | ||
// When Webpack compilation is done, we should run Flow Status. | ||
compiler.plugin('done', flowStatus); | ||
}; | ||
module.exports = FlowStatusWebpackPlugin; | ||
module.exports = FlowStatusWebpackPlugin; |
{ | ||
"name": "flow-status-webpack-plugin", | ||
"version": "0.1.0", | ||
"author": { | ||
"email": "dgodurli@gmail", | ||
"name": "Diego Durli", | ||
"url": "https://github.com/diegodurli" | ||
}, | ||
"version": "0.1.1", | ||
"author": "Diego Durli <dgodurli@gmail> (https://github.com/diegodurli)", | ||
"dependencies": { | ||
@@ -23,9 +19,16 @@ "colors": "^1.1.2", | ||
"maintainers": [ | ||
{ | ||
"name": "diegodurli", | ||
"email": "dgodurli@gmail.com" | ||
} | ||
"diegodurli <dgodurli@gmail.com>" | ||
], | ||
"optionalDependencies": {}, | ||
"readmeFilename": "README.md" | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/diegodurli/flow-status-webpack-plugin.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/diegodurli/flow-status-webpack-plugin/issues" | ||
}, | ||
"homepage": "https://github.com/diegodurli/flow-status-webpack-plugin#readme" | ||
} |
Flow Status Webpack Plugin | ||
========================== | ||
This [webpack](http://webpack.github.io/) plugin will start a [Flow](http://flowtype.org/) server and run `flow status` on each webpack build. Still experimental. | ||
[![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. | ||
If you have any idea on how to get it better, you're welcome to contribute! | ||
@@ -20,3 +22,3 @@ | ||
``` | ||
```js | ||
var FlowStatusWebpackPlugin = require('flow-status-webpack-plugin'); | ||
@@ -43,5 +45,5 @@ | ||
In case you have [Flow Interfaces](http://flowtype.org/docs/third-party.html#_) and you're not using a `.flowconfig` file, you need to specify a path to your interfaces directory, otherwise flow will not be able to identify (and use) those interfaces. | ||
If you want to pass additional command-line arguments to `flow start`, you can pass a `flowArgs` option to the plugin: | ||
``` | ||
```js | ||
var FlowStatusWebpackPlugin = require('flow-status-webpack-plugin'); | ||
@@ -53,3 +55,3 @@ | ||
new FlowStatusWebpackPlugin({ | ||
interfacesPath: 'path/to/interfaces/directory' | ||
flowArgs: '--lib path/to/interfaces/directory' | ||
}) | ||
@@ -56,0 +58,0 @@ ] |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
5701
5
52
0
61
0