Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,27 @@ Install with [npm](https://npmjs.org/package/gulp-purescript)
npm install gulp-purescript --save-dev
```

## Binaries

This plugin requires that the PureScript binaries first be installed. The binaries may be installed using the [purescript](https://www.npmjs.com/package/purescript) NPM package or as described on the PureScript [installation](https://github.com/purescript/purescript/wiki/Language-Guide:-Getting-Started#installation) section of the GitHub wiki.

## Example

```js
var gulp = require('gulp')
, purescript = require('gulp-purescript')
;
var gulp = require('gulp');

var purescript = require('gulp-purescript');

gulp.task('purescript', function(){
return (
gulp.src('src/**/*.purs.hs').
pipe(purescript.psc({noPrelude: true})).
pipe(gulp.dest('dist/'))
);
return gulp.src('src/**/*.purs').
pipe(purescript.psc({noPrelude: true})).
pipe(gulp.dest('build'));
});
```

## API

Refer to the PureScript [usage](http://docs.purescript.org/en/latest/start.html#compiler-usage) section for additional details on the behaviour of each option below.
Refer to the PureScript [compiler usage](https://github.com/purescript/purescript/wiki/Language-Guide:-Getting-Started#compiler-usage) section of the Github wiki for additional details on the behaviour of each option below.

### purescript.psc(options)

Expand Down
137 changes: 80 additions & 57 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ var logalot = require('logalot');

var multipipe = require('multipipe');

var resolveBin = require('resolve-bin');

var options = require('./options');

var pluginName = 'gulp-purescript';
var packageJson = require('./package.json');

var pluginName = packageJson.name;

var purescriptPackage = 'purescript';

var psciFilename = '.psci';

Expand All @@ -38,16 +44,24 @@ var PluginError = gutil.PluginError;

var File = gutil.File;

function runCommand(cmd, args, k) {
var err = [ 'Failed to find ' + gutil.colors.magenta(cmd), 'in your path.'
, 'Please ensure that ' + gutil.colors.magenta(cmd)
, 'is available on your system.' ].join(' ');
function resolve(cmd, callback) {
var err = 'Failed to find ' + gutil.colors.cyan(cmd) + '. Please ensure it is available on your system.';

var that = this;
resolveBin(purescriptPackage, {executable: cmd}, function(e, bin){
if (!e) callback(null, bin);
else {
which(cmd, function(e){
if (e) callback(err);
else callback(null, cmd);
});
}
});
}

which(cmd, function(e){
if (e) that.emit('error', new PluginError(pluginName, err));
else k(child_process.spawn(cmd, args));
function execute(cmd, args, callback) {
resolve(cmd, function(e, bin){
if (e) callback(new PluginError(pluginName, e));
else callback(null, child_process.spawn(bin, args));
});
}

Expand Down Expand Up @@ -102,21 +116,24 @@ function psc(opts) {

var buffere = new Buffer(0);

runCommand.apply(this, [options.psc.cmd, args, function(cmd){
cmd.stdout.on('data', function(stdout){buffero = Buffer.concat([buffero, new Buffer(stdout)]);});

cmd.stderr.on('data', function(stderr){buffere = Buffer.concat([buffere, new Buffer(stderr)]);});

cmd.on('close', function(code){
if (code !== 0) callback(new PluginError(pluginName, buffere.toString()));
else {
callback(null, new File({
path: output,
contents: buffero
}));
}
});
}]);
execute(options.psc.cmd, args, function(e, cmd){
if (e) callback(e);
else {
cmd.stdout.on('data', function(stdout){buffero = Buffer.concat([buffero, new Buffer(stdout)]);});

cmd.stderr.on('data', function(stderr){buffere = Buffer.concat([buffere, new Buffer(stderr)]);});

cmd.on('close', function(code){
if (code !== 0) callback(new PluginError(pluginName, buffere.toString()));
else {
callback(null, new File({
path: output,
contents: buffero
}));
}
});
}
});
}

return multipipe(collectPaths(), through2.obj(transform));
Expand All @@ -130,24 +147,27 @@ function pscMake(opts) {

var buffere = new Buffer(0);

runCommand.apply(this, [options.pscMake.cmd, args, function(cmd){
cmd.stdout.on('data', function(stdout){buffero = Buffer.concat([buffero, new Buffer(stdout)]);});

cmd.stderr.on('data', function(stderr){buffere = Buffer.concat([buffere, new Buffer(stderr)]);});

cmd.on('close', function(code){
var message =
function() { return [ gutil.colors.cyan(options.pscMake.cmd)
, buffero.toString()
, buffere.toString() ].join('\n') };

if (code !== 0) callback(new PluginError(pluginName, message()));
else {
if (isVerbose) logalot.info(message());
callback();
}
});
}]);
execute(options.pscMake.cmd, args, function(e, cmd){
if (e) callback(e);
else {
cmd.stdout.on('data', function(stdout){buffero = Buffer.concat([buffero, new Buffer(stdout)]);});

cmd.stderr.on('data', function(stderr){buffere = Buffer.concat([buffere, new Buffer(stderr)]);});

cmd.on('close', function(code){
var message =
function() { return [ gutil.colors.cyan(options.pscMake.cmd)
, buffero.toString()
, buffere.toString() ].join('\n') };

if (code !== 0) callback(new PluginError(pluginName, message()));
else {
if (isVerbose) logalot.info(message());
callback();
}
});
}
});
};

return multipipe(collectPaths(), through2.obj(transform));
Expand All @@ -161,21 +181,24 @@ function pscDocs(opts) {

var buffere = new Buffer(0);

runCommand.apply(this, [options.pscDocs.cmd, args, function(cmd){
cmd.stdout.on('data', function(stdout){buffero = Buffer.concat([buffero, new Buffer(stdout)]);});

cmd.stderr.on('data', function(stderr){buffere = Buffer.concat([buffere, new Buffer(stderr)]);});

cmd.on('close', function(code){
if (code !== 0) callback(new PluginError(pluginName, buffere.toString()));
else {
callback(null, new File({
path: '.',
contents: buffero
}));
}
});
}]);
execute(options.pscDocs.cmd, args, function(e, cmd){
if (e) callback(e);
else {
cmd.stdout.on('data', function(stdout){buffero = Buffer.concat([buffero, new Buffer(stdout)]);});

cmd.stderr.on('data', function(stderr){buffere = Buffer.concat([buffere, new Buffer(stderr)]);});

cmd.on('close', function(code){
if (code !== 0) callback(new PluginError(pluginName, buffere.toString()));
else {
callback(null, new File({
path: '.',
contents: buffero
}));
}
});
}
});
}

return multipipe(collectPaths(), through2.obj(transform));
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"logalot": "^2.1.0",
"minimist": "^1.1.1",
"multipipe": "^0.1.2",
"resolve-bin": "^0.3.0",
"through2": "^0.6.3",
"which": "^1.0.9"
},
Expand Down