diff --git a/.travis.yml b/.travis.yml index b593232e..d947aff1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,24 @@ sudo: required dist: trusty -language: node_js -node_js: - - "stable" branches: # Only build master and tagged versions, i.e. not feature branches; feature # branches already get built after opening a pull request. only: - master - /^v\d+\.\d+(\.\d+)?(-\S*)?$/ -before_install: +language: node_js +node_js: + - "stable" +env: + - PATH=$HOME/bin:$PATH PURS_VERSION=v0.12.3 PSC_PACKAGE_VERSION=v0.5.1 +install: + - mkdir -p $HOME/bin + - wget -O $HOME/bin/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$PURS_VERSION/linux64.tar.gz + - tar -xvf $HOME/bin/purescript.tar.gz -C $HOME/bin --strip-components 1 purescript/purs + - wget -O $HOME/bin/psc-package.tar.gz https://github.com/purescript/psc-package/releases/download/$PSC_PACKAGE_VERSION/linux64.tar.gz + - tar -xvf $HOME/bin/psc-package.tar.gz -C $HOME/bin --strip-components 1 psc-package/psc-package + - chmod -R a+x $HOME/bin - travis_retry npm install -g bower - - wget -q -O - https://github.com/purescript/psc-package/releases/download/v0.2.2/linux64.tar.gz | sudo tar xzf - -C /usr/local/bin --strip-components 1 psc-package/psc-package script: + - npm install - npm test diff --git a/appveyor.yml b/appveyor.yml index f7cd96c2..41c94539 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,8 @@ # Test against this version of Node.js environment: nodejs_version: "10" + purs_version: "v0.12.3" + psc_package_version: "v0.5.1" # Only build master and tagged versions, i.e. not feature branches; feature # branches already get built after opening a pull request. @@ -23,14 +25,13 @@ cache: install: - ps: Install-Product node $env:nodejs_version x64 - npm install -g bower - - npm install - set PATH=%PATH%;C:\tools - - pushd C:\tools & curl -opsc-package.tar.gz -L https://github.com/purescript/psc-package/releases/download/v0.2.2/win64.tar.gz & 7z e psc-package.tar.gz & 7z e psc-package.tar psc-package/psc-package.exe & popd + - pushd C:\tools & curl -opsc-package.tar.gz -L https://github.com/purescript/psc-package/releases/download/%psc_package_version%/win64.tar.gz & 7z e psc-package.tar.gz & 7z e psc-package.tar psc-package/psc-package.exe & popd + - pushd C:\tools & curl -opurescript.tar.gz -L https://github.com/purescript/purescript/releases/download/%purs_version%/win64.tar.gz & 7z e purescript.tar.gz & 7z e purescript.tar purescript/purs.exe & popd # Post-install test scripts. test_script: - - node --version - - npm --version + - npm install - npm run test # "build" means "build using the project or solution file", which we don't diff --git a/package.json b/package.json index 398a0913..eda75af3 100644 --- a/package.json +++ b/package.json @@ -33,14 +33,15 @@ "engines": { "node": ">= 4" }, - "config": { - "psc_build_version": "v0.12.1", - "psc_test_version": "v0.12.1" - }, "scripts": { - "prepare": "node scripts.js prepare", - "test": "node scripts.js test", - "build": "node scripts.js build" + "prepare": "bower install && npm run build", + "test": "npm run test:unit && npm run test:integration", + "build": "npm run lint && npm run compile && npm run bundle", + "lint": "jshint src", + "compile": "psa -c \"src/**/*.purs\" \"test/**/*.purs\" \"bower_components/purescript-*/src/**/*.purs\" --censor-lib --censor-codes=ImplicitImport,HidingImport", + "bundle": "purs bundle \"output/*/*.js\" --output pulp.js --module Main --main Main", + "test:unit": "purs bundle \"output/*/*.js\" --output unit-tests.js --module Test.Main --main Test.Main && node unit-tests.js", + "test:integration": "mocha test-js --require babel/register" }, "dependencies": { "browserify": "^16.2.3", @@ -69,7 +70,6 @@ "jshint": "^2.9.7", "mkdirp": "^0.5.1", "mocha": "^5.2.0", - "psvm": "^0.1.6", "purescript-psa": "^0.7.3", "semver": "^5.6.0", "touch": "^3.1.0" diff --git a/scripts.js b/scripts.js deleted file mode 100644 index d50b71eb..00000000 --- a/scripts.js +++ /dev/null @@ -1,127 +0,0 @@ -// Pulp build scripts -// -// Sometimes we need to use one version of the PureScript compiler to compile -// Pulp with, and a different version to test with. For example, this is -// usually necessary after a compiler release with breaking changes, because -// the PureScript libraries which Pulp depends on will not yet have been -// updated. -// -// This script enables us to switch versions of psc for different build -// scripts, via psvm (https://github.com/ThomasCrvsr/psvm-js). -const child_process = require("child_process"); -const mkdirp = require("mkdirp"); -const path = require("path"); - -const scripts = { - "lint": "jshint src", - "compile": "psa -c \"src/**/*.purs\" \"test/**/*.purs\" \"bower_components/purescript-*/src/**/*.purs\" --censor-lib --censor-codes=ImplicitImport,HidingImport", - "bundle": "purs bundle \"output/*/*.js\" --output pulp.js --module Main --main Main", - "test:unit": "purs bundle \"output/*/*.js\" --output unit-tests.js --module Test.Main --main Test.Main && node unit-tests.js", - "test:integration": "mocha test-js --require babel/register" -}; - -const subcommand = process.argv[2]; -const restArgs = process.argv.slice(3); - -if (!subcommand) { - console.error("Expected a subcommand."); - console.error("Usage: "); - console.error(" node scripts.js [build|test|prepare]"); - process.exit(1); -} - -switch (subcommand) { - case "build": - build(); - break; - case "test": - test(); - break; - case "prepare": - prepare(); - break; - default: - throw new Error("Unrecognised subcommand: " + subcommand); - break; -} - -function build() { - spawnSync("psvm use " + getConfig("psc_build_version")); - ["lint", "compile", "bundle"].forEach(execScript); -} - -function test() { - spawnSync("psvm use " + getConfig("psc_test_version")); - // TODO: unit tests don't work on Windows yet - if (process.platform !== "win32") { - execScript("test:unit"); - } - execScript("test:integration"); -} - -function prepare() { - ensurePscVersionsInstalled(); - spawnSync("bower install"); - build(); -} - -// Construct and return an environment to run subcommands in. -// -// We set the PSVM_HOME environment variable to ensure that psvm only installs -// stuff in the current directory. -function getSubcommandEnv() { - var env = Object.assign({}, process.env); - env.PSVM_HOME = path.join(__dirname, ".psvm"); - prependPath(env, path.join(env.PSVM_HOME, "current", "bin")); - return env; -} - -function execScript(script) { - spawnSync(scripts[script] + " " + restArgs.join(" ")); -} - - -function prependPath(env, newDirectory) { - const pathVar = process.platform === "win32" ? "Path" : "PATH"; - env[pathVar] = newDirectory + path.delimiter + env[pathVar]; -} - -function ensurePscVersionsInstalled() { - var subcommandEnv = getSubcommandEnv(); - - const versions = ['psc_build_version', 'psc_test_version'].map(getConfig); - - versions.forEach((version) => { - if (!subcommandEnv.GITHUB_API_TOKEN) { - console.error("Warning: GitHub API token not set."); - } - spawnSync("psvm install " + version); - }); -} - -function getConfig(variable) { - var result = process.env['npm_package_config_' + variable]; - if (result) { - return result; - } else { - throw new Error("Missing configuration: " + variable); - } -} - -function spawnSync(command, opts) { - opts = opts || {}; - console.log(">> " + command); - var result = child_process.spawnSync(command, { - cwd: process.cwd(), - env: getSubcommandEnv(), - stdio: ["inherit", opts.quiet ? "pipe" : "inherit", "inherit"], - encoding: "utf-8", - shell: true - }); - - if (result.status !== 0) { - throw new Error("shell command exited with: " + result.status); - } - - return result.stdout; -}