JSPM

  • Created
  • Published
  • Downloads 222
  • Score
    100M100P100Q70731F
  • License MIT

Build a PureScript binary from source

Package Exports

  • build-purescript

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (build-purescript) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

build-purescript

NPM version Build Status Build status Coverage Status

A Node.js module to build a PureScript binary from source

const {execFile} = require('child_process');
const buildPurescript = require('build-purescript');

buildPurescript('/path/to/dir').subscribe({
  complete() {
    execFile('/path/to/dir/purs', ['--help'], (err, stdout) => {
      stdout.toString(); //=> 'Usage: purs COMMAND\n  The PureScript compiler and tools ...'
    });
  }
});

Installation

Make sure stack command is installed in your $PATH, then install build-purescript via npm CLI.

npm install build-purescript

API

const buildPurescript = require('build-purescript');

buildPurescript(dir [, options])

dir: string (a directory path where the PureScript binary will be built)
options: Object
Return: Observable (zenparsing's implementation)

When the Observable is subscribed, it starts to download PureScript source from the GitHub repository, build it and successively send progress as objects to its Observer.

Progress object

Each progress object has id property with one of these values:

download

Sent to the Observer while downloading and extracting the PureScript source archive.

entry and response properties are derived from dl-tar.

{
  id: 'download',
  entry: {
    bytes: <number>,
    header: <Object>
  },
  response: {
    bytes: <number>,
    headers: <Object>
  }
}
download:complete

Sent to the Observer when the PureScript source is completely downloaded.

setup

Sent to the Observer while running stack setup command.

command property is the command currently running, and output property is each line of stderr.

{
  id: 'setup',
  command 'stack setup ...',
  output: <string>
}
setup:complete

Sent to the Observer when stack setup command exits with code 0.

build

Sent to the Observer while running stack install command.

command property is the command currently running, and output property is each line of stderr.

{
  id: 'setup',
  command 'stack install ...',
  output: <string>
}
build:complete

Sent to the Observer when stack install command exits with code 0.

downloadPurescript('my/dir')
.filter(({id}) => id.endsWith(':complete'))
.forEach(({id}) => console.log(`${id.replace(':complete', '')}`))
.then(() => console.log('\nCompleted.'));
✓ download
✓ setup
✓ build

Completed.

Errors

Each error passed to the Observer have id property that indicates which step the error occurred at.

// When your machine have no network connection
buildPureScript('.').subscribe({
  error(err) {
    err.message; //=> 'getaddrinfo ENOTFOUND github.com github.com:443'
    err.id; //=> 'download'
  }
});

// When the `stack` command is not installed
buildPureScript('.').subscribe({
  error(err) {
    err.message; //=> '`stack` command is not found in your PATH ...'
    err.id; //=> 'setup'
  }
});

Options

Options are directly passed to the underlying donwload-purescript-source and spawn-stack. Also you can use the following:

sourceDir

Type: string
Default: require('unique-temp-dir')()

A path where the PureScript source is downloaded. If nothing exists in this path, a temporary directory will be created.

args

Type: Array<string>

Additional command-line arguments passed to stack setup and stack install.

Note that --local-bin-path is automatically set to the first argument of buildPurescript.

License

Copyright (c) 2017 Shinnosuke Watanabe

Licensed under the MIT License.