From e84f5e67df43e5ba475df0da3e2e09530f924393 Mon Sep 17 00:00:00 2001 From: Mike Bland Date: Mon, 29 May 2017 13:34:00 -0400 Subject: [PATCH 1/2] setup: Add `setup karma`+browser-only Windows mode Getting Redis set up on Windows is kind of a non-starter, and live-server doesn't behave as desired. Plus it's nice to have the Karma setup in a separate subcommand for all platforms. --- scripts/lib/setup | 14 +++++++++ scripts/setup | 72 +++++++++++++++++++++++++------------------ scripts/setup.d/karma | 35 +++++++++++++++++++++ 3 files changed, 91 insertions(+), 30 deletions(-) create mode 100644 scripts/lib/setup create mode 100644 scripts/setup.d/karma diff --git a/scripts/lib/setup b/scripts/lib/setup new file mode 100644 index 0000000..16c4bd3 --- /dev/null +++ b/scripts/lib/setup @@ -0,0 +1,14 @@ +#! /usr/bin/env bash +# +# Functions and variables shared across setup scripts + +export URLP_PLATFORM="${URLP_PLATFORM:-$(node -e \ + 'console.log(process.platform)')}" + +urlp.npm_install() { + if [[ "$URLP_PLATFORM" == 'win32' ]]; then + npm install -s --no-progress "$@" >/dev/null 2>&1 + else + npm install "$@" + fi +} diff --git a/scripts/setup b/scripts/setup index 0563081..95659f5 100755 --- a/scripts/setup +++ b/scripts/setup @@ -2,11 +2,13 @@ # # Runs first-time setup commands for a freshly-cloned repository +. "$_GO_USE_MODULES" 'setup' + urlp.check_for_prerequisite_tools() { if ! command -v node >/dev/null; then @go.printf 'Please install Node.js before continuing.\n' >&2 return 1 - elif ! command -v redis-server >/dev/null; then + elif [[ "$URLP_PLATFORM" != 'win32' ]] && ! command -v redis-server >/dev/null; then @go.printf 'Please install redis-server before continuing.\n' >&2 return 1 fi @@ -14,34 +16,47 @@ urlp.check_for_prerequisite_tools() { urlp.install_required_tools() { if ! command -v phantomjs >/dev/null; then - npm install phantomjs-prebuilt + @go.log_command urlp.npm_install phantomjs-prebuilt fi } urlp.install_optional_tools() { - local karma_dependencies=('karma-browserify' - 'karma-chai' - 'karma-chrome-launcher' - 'karma-detect-browsers' - 'karma-edge-launcher' - 'karma-firefox-launcher' - 'karma-ie-launcher' - 'karma-mocha' - 'karma-mocha-reporter' - 'karma-opera-launcher' - 'karma-phantomjs-launcher' - 'karma-safari-launcher' - 'karma-sinon' - 'watchify') - if [[ "$CI" != 'true' ]] && command -v karma >/dev/null; then - if ! karma --help >/dev/null 2>&1; then - npm install karma - fi - npm install "${karma_dependencies[@]}" + @go.log_command @go setup karma fi } +urlp.setup_windows() { + local result='0' + + @go.log INFO 'Setting up browser-only development with Karma on Windows...' + if ! @go.log_command @go setup karma; then + result='1' + fi + if ! @go.log_command @go lint; then + result='1' + fi + if ! KARMA_SINGLE_RUN='true' @go.log_command karma start; then + result='1' + fi + return "$result" +} + +urlp.setup_full() { + local result='0' + + if ! @go.log_command urlp.install_optional_tools; then + result='1' + fi + if ! @go.log_command @go lint; then + result='1' + fi + if ! @go.log_command @go test --coverage; then + result='1' + fi + return "$result" +} + urlp.setup() { local result='0' @@ -53,20 +68,17 @@ urlp.setup() { @go.log_command urlp.check_for_prerequisite_tools if [[ -z "$CI" ]]; then - @go.log_command npm install + @go.log_command urlp.npm_install fi @go.log_command urlp.install_required_tools @go.critical_section_end - if ! @go.log_command urlp.install_optional_tools; then - result='1' - fi - if ! @go.log_command @go lint; then - result='1' - fi - if ! @go.log_command @go test --coverage; then - result='1' + if [[ "$URLP_PLATFORM" == 'win32' ]]; then + @go.log_command urlp.setup_windows + else + @go.log_command urlp.setup_full fi + result="$?" if [[ "$result" -eq '0' ]]; then @go.log FINISH 'Project setup completed successfully.' diff --git a/scripts/setup.d/karma b/scripts/setup.d/karma new file mode 100644 index 0000000..f396a45 --- /dev/null +++ b/scripts/setup.d/karma @@ -0,0 +1,35 @@ +#! /usr/bin/env bash +# +# Sets up the Karma JavaScript browser test runner + +. "$_GO_USE_MODULES" 'setup' + +_urlp_setup_karma() { + local karma_dependencies=('karma-browserify' + 'karma-chai' + 'karma-chrome-launcher' + 'karma-detect-browsers' + 'karma-edge-launcher' + 'karma-firefox-launcher' + 'karma-ie-launcher' + 'karma-mocha' + 'karma-mocha-reporter' + 'karma-opera-launcher' + 'karma-phantomjs-launcher' + 'karma-safari-launcher' + 'karma-sinon' + 'watchify') + + if ! command -v karma>/dev/null && + ! @go.log_command urlp.npm_install -g karma-cli; then + @go.printf 'Failed to install karma-cli globally; %s\n' \ + 'please make sure you have the necessary permissions and try again.' >&2 + return 1 + elif ! karma --help >/dev/null 2>&1; then + karma_dependencies+=('karma') + fi + + @go.log_command urlp.npm_install "${karma_dependencies[@]}" +} + +_urlp_setup_karma "$@" From 2597a09cc13e49c371961aabc103be297b55d119 Mon Sep 17 00:00:00 2001 From: Mike Bland Date: Mon, 29 May 2017 14:14:55 -0400 Subject: [PATCH 2/2] ./go: Disable MSYS2 POSIX path conversion This was causing paths to get mangled for `./go test browser`, which launches live-server. For more details, see: https://github.com/mbland/go-script-bash/issues/176 --- go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/go b/go index 3139bbc..a274882 100755 --- a/go +++ b/go @@ -32,6 +32,13 @@ fi export PATH="node_modules/.bin:$PATH" +# Keep this until the following is resolved: +# https://github.com/mbland/go-script-bash/issues/176 +if [[ "$OSTYPE" == 'msys' ]]; then + export MSYS_NO_PATHCONV='true' + export MSYS2_ARG_CONV_EXCL='*' +fi + if [[ -t 1 || -n "$TRAVIS" ]]; then _GO_LOG_FORMATTING='true' fi