Skip to content

Commit

Permalink
Fix script.js spawnSync issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
chexxor committed Mar 12, 2017
1 parent 65396ab commit 30a9b88
Showing 1 changed file with 41 additions and 13 deletions.
54 changes: 41 additions & 13 deletions scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,36 @@ const mkdirp = require("mkdirp");
const path = require("path");

const scripts = {
"lint": "jshint src",
"compile": "psa -c \"src/**/*.purs\" \"bower_components/purescript-*/src/**/*.purs\" --censor-lib --censor-codes=ImplicitImport,HidingImport",
"bundle": "psc-bundle \"output/*/*.js\" --output pulp.js --module Main --main Main",
"test": "mocha test-js --require babel/register",
"lint": {
cmd: "jshint",
args: ["src"]
},
"compile": {
cmd: "psa",
args: [
"-c",
"src/**/*.purs",
"bower_components/purescript-*/src/**/*.purs",
"--censor-lib",
"--censor-codes=ImplicitImport,HidingImport"
]
},
"bundle": {
cmd: "psc-bundle",
args: [
"output/*/*.js",
"--output", "pulp.js",
"--module", "Main",
"--main", "Main"
]
},
"test": {
cmd: "mocha",
args: [
"test-js",
"--require", "babel/register"
]
},
};

const subcommand = process.argv[2];
Expand Down Expand Up @@ -45,18 +71,18 @@ switch (subcommand) {
}

function build() {
spawnSync("psvm use " + getConfig("psc_build_version"));
spawnSync("psvm", ["use", getConfig("psc_build_version")]);
["lint", "compile", "bundle"].forEach(execScript);
}

function test() {
spawnSync("psvm use " + getConfig("psc_test_version"));
spawnSync("psvm", ["use", getConfig("psc_test_version")]);
execScript("test");
}

function prepublish() {
ensurePscVersionsInstalled();
spawnSync("bower install");
spawnSync("bower", ["install"]);
build();
}

Expand All @@ -72,7 +98,7 @@ function getSubcommandEnv() {
}

function execScript(script) {
spawnSync(scripts[script] + " " + restArgs.join(" "));
spawnSync(scripts[script].cmd, scripts[script].args, restArgs);
}


Expand All @@ -87,7 +113,7 @@ function ensurePscVersionsInstalled() {
const versions = ['psc_build_version', 'psc_test_version'].map(getConfig);

versions.forEach((version) => {
spawnSync("psvm install " + version);
spawnSync("psvm", ["install", version]);
});
}

Expand All @@ -100,10 +126,10 @@ function getConfig(variable) {
}
}

function spawnSync(command, opts) {
function spawnSync(command, args, opts) {
opts = opts || {};
console.log(">> " + command);
var result = child_process.spawnSync(command, {
console.log(">> " + command + " " + args.join(" "));
var result = child_process.spawnSync(command, args, {
cwd: process.cwd(),
env: getSubcommandEnv(),
stdio: ["inherit", opts.quiet ? "pipe" : "inherit", "inherit"],
Expand All @@ -112,7 +138,9 @@ function spawnSync(command, opts) {
});

if (result.status !== 0) {
throw new Error("shell command exited with: " + result.status);
throw new Error("shell command exited with: " + result.status
+ "\n"
+ result.error);
}

return result.stdout;
Expand Down

0 comments on commit 30a9b88

Please sign in to comment.