From 603dc44355a32cbb46741bc63bacd7e23dd950db Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Wed, 20 Jan 2016 08:10:39 -0800 Subject: [PATCH 1/2] Move scripts to tools directory --- generate-changelog.sh => tools/generate-changelog.sh | 0 release-all.sh => tools/release-all.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename generate-changelog.sh => tools/generate-changelog.sh (100%) rename release-all.sh => tools/release-all.sh (100%) diff --git a/generate-changelog.sh b/tools/generate-changelog.sh similarity index 100% rename from generate-changelog.sh rename to tools/generate-changelog.sh diff --git a/release-all.sh b/tools/release-all.sh similarity index 100% rename from release-all.sh rename to tools/release-all.sh From db897211fa1152c42cf6bb4b0b641e5c6eccfdfc Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Wed, 20 Jan 2016 12:16:24 -0800 Subject: [PATCH 2/2] Replace makefile dependency with bash script Switched to a bash script for build. Not great but make is not convenient on windows machines. Bash is everywhere and our commands are not complex. Fixes #638 --- .travis.yml | 5 +- CONTRIBUTING.md | 7 +- Makefile | 74 ----- README.md | 2 +- appveyor.yml | 22 +- build | 5 + js/test/shell-smoke-test.sh | 2 +- package.json | 2 - python/jsbeautifier/tests/shell-smoke-test.sh | 288 +++++++++--------- tools/build.sh | 101 ++++++ tools/generate-changelog.sh | 62 ++-- {test => tools}/git-status-clear.sh | 0 tools/release-all.sh | 90 ++++-- 13 files changed, 366 insertions(+), 294 deletions(-) delete mode 100644 Makefile create mode 100755 build create mode 100755 tools/build.sh rename {test => tools}/git-status-clear.sh (100%) diff --git a/.travis.yml b/.travis.yml index e046198dc..fe291502e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,10 +4,11 @@ python: - "3.2" - "3.3" - "3.4" + - "3.5" node_js: - - "0.8" + - "0.10" -script: "make" +script: "./build ci" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6d06c0200..ec66d8c25 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,10 +4,13 @@ ## Report issues If you find a bug, please report it, including environment and examples of current behavior and what you believe to be the correct behavior. The clearer your description and information, the more likely it is someone will be able to make progress on it. +## Build and test +If you run `./build full` from the root folder locally, build and tests will run and should all pass. + ## Fix issues Pull requests with fixes are totally welcome. Familiarize yourself with the folder structure and code style before you dive in. Where possible fixes should include tests to prevent future regressions in functionality. Also, if they apply and you have the ability, make fixes to both python and javascript implementations. -We use travis-ci.org to run build and test passes. If you run `make` from the root folder locally, tests will run and should all pass before your pull request will be accepted. +We use travis-ci.org to run build and test passes. If you run `./build full` from the root folder locally, tests will run and must all pass. The build may generate updated test files - commit any changes reported by `git status` after the build completes. Then create pull request. # Folders @@ -37,7 +40,7 @@ This project has been around for a while. While some parts have improved signif into disrepair and were mothballed. ### PHP -There is a out-of-date version of the beautifier available on branch `attic-php`. If you're interested +There is an out-of-date version of the beautifier available on branch `attic-php`. If you're interested in using it feel free. If you plan to enhance it, please consider joining this project, and updating this version to match current functionality. diff --git a/Makefile b/Makefile deleted file mode 100644 index 6fc39adca..000000000 --- a/Makefile +++ /dev/null @@ -1,74 +0,0 @@ - -define AVAILABLE_ACTIONS - -build: do static checking and build of js -buildp: do static checking and build of python -buildj: do static checking and build of javascript -test: test both implementations, js and python -testp: test python implementation -testj: test javascript implementation - -endef -export AVAILABLE_ACTIONS - - -.SILENT: -all: build test status - -help: - echo "$$AVAILABLE_ACTIONS" - -build: buildj buildp - -buildj: - echo Building javascript... ;\ - npm install ;\ - -buildp: - echo Building python... ;\ - pip install -e ./python - -testp: - echo Testing python implementation... - node test/generate-tests.js || exit 1;\ - cd python ;\ - python --version ;\ - ./jsbeautifier/tests/shell-smoke-test.sh - -testj: - echo Testing javascript implementation... - node test/generate-tests.js || exit 1;\ - node --version; \ - npm test - - -edit: - vim \ - js/lib/beautify.js python/jsbeautifier/__init__.py \ - js/test/beautify-tests.js python/jsbeautifier/tests/testjsbeautifier.py - -gedit: - gvim \ - js/lib/beautify.js \ - js/test/beautify-tests.js \ - python/jsbeautifier/__init__.py \ - python/jsbeautifier/tests/testjsbeautifier.py & - -tests: testj testp - -test: testj testp - -status: - test/git-status-clear.sh || exit 1 - - -gh: - git push origin master &&\ - cd gh-pages &&\ - git fetch &&\ - git checkout gh-pages &&\ - git reset --hard origin/gh-pages &&\ - git merge origin/master &&\ - git push origin gh-pages - -.PHONY: testp testj all edit tests test diff --git a/README.md b/README.md index 570244e86..76b62fb55 100644 --- a/README.md +++ b/README.md @@ -145,7 +145,7 @@ Configuration sources provided earlier in this stack will override later ones. You might notice that the CLI options and defaults hash aren't 100% correlated. Historically, the Python and JS APIs have not been 100% identical. For example, `space_before_conditional` is currently JS-only, and not addressable from the CLI script. There are a few other additional cases keeping us from 100% API-compatibility. Patches welcome! -## Directives to Ignore or Preserve sections (Javascript only) +## Directives to Ignore or Preserve sections (Javascript only) Beautifier for supports directives in comments inside the file. This allows you to tell the beautifier to preserve the formtatting of or completely ignore part of a file. diff --git a/appveyor.yml b/appveyor.yml index 63dc30bef..022709731 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -7,17 +7,20 @@ deploy: off # Test against this version of Node.js environment: - nodejs_version: "0.12" + global: + nodejs_version: "0.12" + + matrix: + - PYTHON: "C:\\Python27" + PYTHON_VERSION: "2.7.x" + PYTHON_ARCH: "32" # Install scripts. (runs after repo cloning) install: # Get the latest stable version of Node.js or io.js - ps: Install-Product node $env:nodejs_version - # install modules - - npm install - - python -m pip install -e ./python - - echo "Generating tests" - - node test/generate-tests.js + - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%" + - pip --version # Post-install test scripts. test_script: @@ -26,12 +29,7 @@ test_script: - npm --version - python --version # run tests - - echo "Testing javascript implementation" - - npm test - - echo "Testing python implementation" - - bash -c "cd python && ./jsbeautifier/tests/shell-smoke-test.sh" - - echo "Verifying git status clean" - - bash -c "./test/git-status-clear.sh" + - bash -c "./build ci" # Don't actually build. build: off diff --git a/build b/build new file mode 100755 index 000000000..ec7f3a733 --- /dev/null +++ b/build @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +REL_SCRIPT_DIR="`dirname \"$0\"`" +SCRIPT_DIR="`( cd \"$REL_SCRIPT_DIR\" && pwd )`" +$SCRIPT_DIR/tools/build.sh $* diff --git a/js/test/shell-smoke-test.sh b/js/test/shell-smoke-test.sh index 83d947d92..fcf68048f 100755 --- a/js/test/shell-smoke-test.sh +++ b/js/test/shell-smoke-test.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash REL_SCRIPT_DIR="`dirname \"$0\"`" SCRIPT_DIR="`( cd \"$REL_SCRIPT_DIR\" && pwd )`" diff --git a/package.json b/package.json index 1a37297d1..0d2c591e6 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,6 @@ "test": "js/test" }, "scripts": { - "test": "bash -c ./js/test/shell-smoke-test.sh", - "update-codemirror": "npm install codemirror && rm -rf ./web/third-party/codemirror/* && cp ./node_modules/codemirror/LICENSE ./web/third-party/codemirror/ && cp ./node_modules/codemirror/README.md ./web/third-party/codemirror/ && cp -r ./node_modules/codemirror/lib ./web/third-party/codemirror/ && mkdir -p ./web/third-party/codemirror/mode && cp -r ./node_modules/codemirror/mode/javascript ./web/third-party/codemirror/mode/ && git add -Av ./web/third-party/codemirror" }, "bugs": "https://github.com/beautify-web/js-beautify/issues", "homepage": "http://jsbeautifier.org/", diff --git a/python/jsbeautifier/tests/shell-smoke-test.sh b/python/jsbeautifier/tests/shell-smoke-test.sh index e9e498d85..a14f962b7 100755 --- a/python/jsbeautifier/tests/shell-smoke-test.sh +++ b/python/jsbeautifier/tests/shell-smoke-test.sh @@ -1,164 +1,166 @@ -#!/bin/bash +#!/usr/bin/env bash REL_SCRIPT_DIR="`dirname \"$0\"`" SCRIPT_DIR="`( cd \"$REL_SCRIPT_DIR\" && pwd )`" test_cli_common() { - echo ---------------------------------------- - echo Testing common cli behavior... - CLI_SCRIPT_NAME=${1:?missing_param} - CLI_SCRIPT=$SCRIPT_DIR/../../$CLI_SCRIPT_NAME - echo Script: $CLI_SCRIPT - - # should find the minimal help output - $CLI_SCRIPT 2>&1 | grep -q "Must define at least one file\." || { - echo "[$CLI_SCRIPT_NAME] Output should be help message." - exit 1 - } - - $CLI_SCRIPT 2> /dev/null && { - echo "[$CLI_SCRIPT_NAME (with no parameters)] Return code should be error." - exit 1 - } - - $CLI_SCRIPT -Z 2> /dev/null && { - echo "[$CLI_SCRIPT_NAME -Z] Return code for invalid parameter should be error." - exit 1 - } - - $CLI_SCRIPT -h > /dev/null || { - echo "[$CLI_SCRIPT_NAME -h] Return code should be success." - exit 1 - } - - $CLI_SCRIPT -v > /dev/null || { - echo "[$CLI_SCRIPT_NAME -v] Return code should be success." - exit 1 - } - - MISSING_FILE="$SCRIPT_DIR/../../../js/bin/missing_file" - MISSING_FILE_MESSAGE="No such file or directory" - $CLI_SCRIPT $MISSING_FILE 2> /dev/null && { - echo "[$CLI_SCRIPT_NAME $MISSING_FILE] Return code should be error." - exit 1 - } - - $CLI_SCRIPT $MISSING_FILE 2>&1 | grep -q "$MISSING_FILE_MESSAGE" || { - echo "[$CLI_SCRIPT_NAME $MISSING_FILE] Stderr should have useful message." - exit 1 - } - - if [ "`$CLI_SCRIPT $MISSING_FILE 2> /dev/null`" != "" ]; then - echo "[$CLI_SCRIPT_NAME $MISSING_FILE] Stdout should have no text." - exit 1 - fi - + echo ---------------------------------------- + echo Testing common cli behavior... + CLI_SCRIPT_NAME=${1:?missing_param} + CLI_SCRIPT=$SCRIPT_DIR/../../$CLI_SCRIPT_NAME + echo Script: $CLI_SCRIPT + + # should find the minimal help output + $CLI_SCRIPT 2>&1 | grep -q "Must define at least one file\." || { + echo "[$CLI_SCRIPT_NAME] Output should be help message." + exit 1 + } + + $CLI_SCRIPT 2> /dev/null && { + echo "[$CLI_SCRIPT_NAME (with no parameters)] Return code should be error." + exit 1 + } + + $CLI_SCRIPT -Z 2> /dev/null && { + echo "[$CLI_SCRIPT_NAME -Z] Return code for invalid parameter should be error." + exit 1 + } + + $CLI_SCRIPT -h > /dev/null || { + echo "[$CLI_SCRIPT_NAME -h] Return code should be success." + exit 1 + } + + $CLI_SCRIPT -v > /dev/null || { + echo "[$CLI_SCRIPT_NAME -v] Return code should be success." + exit 1 + } + + MISSING_FILE="$SCRIPT_DIR/../../../js/bin/missing_file" + MISSING_FILE_MESSAGE="No such file or directory" + $CLI_SCRIPT $MISSING_FILE 2> /dev/null && { + echo "[$CLI_SCRIPT_NAME $MISSING_FILE] Return code should be error." + exit 1 + } + + $CLI_SCRIPT $MISSING_FILE 2>&1 | grep -q "$MISSING_FILE_MESSAGE" || { + echo "[$CLI_SCRIPT_NAME $MISSING_FILE] Stderr should have useful message." + exit 1 + } + + if [ "`$CLI_SCRIPT $MISSING_FILE 2> /dev/null`" != "" ]; then + echo "[$CLI_SCRIPT_NAME $MISSING_FILE] Stdout should have no text." + exit 1 + fi } test_cli_js_beautify() { - echo ---------------------------------------- - echo Testing js-beautify cli behavior... - CLI_SCRIPT=$SCRIPT_DIR/../../js-beautify - - $CLI_SCRIPT $SCRIPT_DIR/../../../js/bin/js-beautify.js > /dev/null || { - echo "js-beautify output for $SCRIPT_DIR/../../../js/bin/js-beautify.js was expected succeed." - exit 1 - } - - $CLI_SCRIPT $SCRIPT_DIR/../../../js/bin/css-beautify.js > /dev/null || { - echo "js-beautify output for $SCRIPT_DIR/../../../js/bin/css-beautify.js was expected succeed." - exit 1 - } - - # On windows python automatically converts newlines to windows format - # This occurs on both pipes and files. - # As a short-term workaround, disabling these two tests on windows. - $CLI_SCRIPT $SCRIPT_DIR/../../../js/bin/js-beautify.js | diff $SCRIPT_DIR/../../../js/bin/js-beautify.js - || { - $CLI_SCRIPT $SCRIPT_DIR/../../../js/bin/js-beautify.js | diff $SCRIPT_DIR/../../../js/bin/js-beautify.js - | cat -t -e - echo "js-beautify output for $SCRIPT_DIR/../../../js/bin/js-beautify.js was expected to be unchanged." - exit 1 - } - - rm -rf /tmp/js-beautify-mkdir - $CLI_SCRIPT -o /tmp/js-beautify-mkdir/js-beautify.js $SCRIPT_DIR/../../../js/bin/js-beautify.js && diff $SCRIPT_DIR/../../../js/bin/js-beautify.js /tmp/js-beautify-mkdir/js-beautify.js || { - $CLI_SCRIPT -o /tmp/js-beautify-mkdir/js-beautify.js $SCRIPT_DIR/../../../js/bin/js-beautify.js && diff $SCRIPT_DIR/../../../js/bin/js-beautify.js /tmp/js-beautify-mkdir/js-beautify.js | cat -t -e - echo "js-beautify output for $SCRIPT_DIR/../../../js/bin/js-beautify.js should have been created in /tmp/js-beautify-mkdir/js-beautify.js." - exit 1 - } - - # ensure new line settings work - $CLI_SCRIPT -o /tmp/js-beautify-mkdir/js-beautify-n.js -e '\n' $SCRIPT_DIR/../../../js/bin/js-beautify.js - $CLI_SCRIPT -o /tmp/js-beautify-mkdir/js-beautify-rn.js -e '\r\n' /tmp/js-beautify-mkdir/js-beautify-n.js - - diff -q /tmp/js-beautify-mkdir/js-beautify-n.js /tmp/js-beautify-mkdir/js-beautify-rn.js && { - diff /tmp/js-beautify-mkdir/js-beautify-n.js /tmp/js-beautify-mkdir/js-beautify-rn.js | cat -t -e - echo "js-beautify output for /tmp/js-beautify-mkdir/js-beautify-n.js and /tmp/js-beautify-mkdir/js-beautify-rn.js was expected to be different." - exit 1 - } - - $CLI_SCRIPT /tmp/js-beautify-mkdir/js-beautify-n.js | diff -q /tmp/js-beautify-mkdir/js-beautify-n.js - || { - echo "js-beautify output for /tmp/js-beautify-mkdir/js-beautify-n.js was expected to be unchanged." - exit 1 - } - - $CLI_SCRIPT --eol 'auto' /tmp/js-beautify-mkdir/js-beautify-rn.js | diff -q /tmp/js-beautify-mkdir/js-beautify-rn.js - || { - echo "js-beautify output for /tmp/js-beautify-mkdir/js-beautify-rn.js was expected to be unchanged." - exit 1 - } - - # ensure unchanged files are not overwritten - $CLI_SCRIPT -o /tmp/js-beautify-mkdir/js-beautify.js $SCRIPT_DIR/../../../js/bin/js-beautify.js - cp -p /tmp/js-beautify-mkdir/js-beautify.js /tmp/js-beautify-mkdir/js-beautify-old.js - touch /tmp/js-beautify-mkdir/js-beautify.js - sleep 2 - touch /tmp/js-beautify-mkdir/js-beautify-old.js - $CLI_SCRIPT -r /tmp/js-beautify-mkdir/js-beautify.js && test /tmp/js-beautify-mkdir/js-beautify.js -nt /tmp/js-beautify-mkdir/js-beautify-old.js && { - echo "js-beautify should not replace unchanged file /tmp/js-beautify-mkdir/js-beautify.js when using -r" - exit 1 - } - - $CLI_SCRIPT -o /tmp/js-beautify-mkdir/js-beautify.js /tmp/js-beautify-mkdir/js-beautify.js && test /tmp/js-beautify-mkdir/js-beautify.js -nt /tmp/js-beautify-mkdir/js-beautify-old.js && { - echo "js-beautify should not replace unchanged file /tmp/js-beautify-mkdir/js-beautify.js when using -o and same file name" - exit 1 - } - - $CLI_SCRIPT -o /tmp/js-beautify-mkdir/js-beautify.js /tmp/js-beautify-mkdir/js-beautify-old.js && test /tmp/js-beautify-mkdir/js-beautify.js -nt /tmp/js-beautify-mkdir/js-beautify-old.js && { - echo "js-beautify should not replace unchanged file /tmp/js-beautify-mkdir/js-beautify.js when using -o and different file name" - exit 1 - } - - $CLI_SCRIPT $SCRIPT_DIR/../../../js/bin/css-beautify.js | diff -q $SCRIPT_DIR/../../../js/bin/css-beautify.js - && { - echo "js-beautify output for $SCRIPT_DIR/../../../js/bin/css-beautify.js was expected to be different." - exit 1 - } - + echo ---------------------------------------- + echo Testing js-beautify cli behavior... + CLI_SCRIPT=$SCRIPT_DIR/../../js-beautify + + $CLI_SCRIPT $SCRIPT_DIR/../../../js/bin/js-beautify.js > /dev/null || { + echo "js-beautify output for $SCRIPT_DIR/../../../js/bin/js-beautify.js was expected succeed." + exit 1 + } + + $CLI_SCRIPT $SCRIPT_DIR/../../../js/bin/css-beautify.js > /dev/null || { + echo "js-beautify output for $SCRIPT_DIR/../../../js/bin/css-beautify.js was expected succeed." + exit 1 + } + + # On windows python automatically converts newlines to windows format + # This occurs on both pipes and files. + # As a short-term workaround, disabling these two tests on windows. + $CLI_SCRIPT $SCRIPT_DIR/../../../js/bin/js-beautify.js | diff $SCRIPT_DIR/../../../js/bin/js-beautify.js - || { + $CLI_SCRIPT $SCRIPT_DIR/../../../js/bin/js-beautify.js | diff $SCRIPT_DIR/../../../js/bin/js-beautify.js - | cat -t -e + echo "js-beautify output for $SCRIPT_DIR/../../../js/bin/js-beautify.js was expected to be unchanged." + exit 1 + } + + rm -rf /tmp/js-beautify-mkdir + $CLI_SCRIPT -o /tmp/js-beautify-mkdir/js-beautify.js $SCRIPT_DIR/../../../js/bin/js-beautify.js && diff $SCRIPT_DIR/../../../js/bin/js-beautify.js /tmp/js-beautify-mkdir/js-beautify.js || { + $CLI_SCRIPT -o /tmp/js-beautify-mkdir/js-beautify.js $SCRIPT_DIR/../../../js/bin/js-beautify.js && diff $SCRIPT_DIR/../../../js/bin/js-beautify.js /tmp/js-beautify-mkdir/js-beautify.js | cat -t -e + echo "js-beautify output for $SCRIPT_DIR/../../../js/bin/js-beautify.js should have been created in /tmp/js-beautify-mkdir/js-beautify.js." + exit 1 + } + + # ensure new line settings work + $CLI_SCRIPT -o /tmp/js-beautify-mkdir/js-beautify-n.js -e '\n' $SCRIPT_DIR/../../../js/bin/js-beautify.js + $CLI_SCRIPT -o /tmp/js-beautify-mkdir/js-beautify-rn.js -e '\r\n' /tmp/js-beautify-mkdir/js-beautify-n.js + + diff -q /tmp/js-beautify-mkdir/js-beautify-n.js /tmp/js-beautify-mkdir/js-beautify-rn.js && { + diff /tmp/js-beautify-mkdir/js-beautify-n.js /tmp/js-beautify-mkdir/js-beautify-rn.js | cat -t -e + echo "js-beautify output for /tmp/js-beautify-mkdir/js-beautify-n.js and /tmp/js-beautify-mkdir/js-beautify-rn.js was expected to be different." + exit 1 + } + + $CLI_SCRIPT /tmp/js-beautify-mkdir/js-beautify-n.js | diff -q /tmp/js-beautify-mkdir/js-beautify-n.js - || { + echo "js-beautify output for /tmp/js-beautify-mkdir/js-beautify-n.js was expected to be unchanged." + exit 1 + } + + $CLI_SCRIPT --eol 'auto' /tmp/js-beautify-mkdir/js-beautify-rn.js | diff -q /tmp/js-beautify-mkdir/js-beautify-rn.js - || { + echo "js-beautify output for /tmp/js-beautify-mkdir/js-beautify-rn.js was expected to be unchanged." + exit 1 + } + + # ensure unchanged files are not overwritten + $CLI_SCRIPT -o /tmp/js-beautify-mkdir/js-beautify.js $SCRIPT_DIR/../../../js/bin/js-beautify.js + cp -p /tmp/js-beautify-mkdir/js-beautify.js /tmp/js-beautify-mkdir/js-beautify-old.js + touch /tmp/js-beautify-mkdir/js-beautify.js + sleep 2 + touch /tmp/js-beautify-mkdir/js-beautify-old.js + $CLI_SCRIPT -r /tmp/js-beautify-mkdir/js-beautify.js && test /tmp/js-beautify-mkdir/js-beautify.js -nt /tmp/js-beautify-mkdir/js-beautify-old.js && { + echo "js-beautify should not replace unchanged file /tmp/js-beautify-mkdir/js-beautify.js when using -r" + exit 1 + } + + $CLI_SCRIPT -o /tmp/js-beautify-mkdir/js-beautify.js /tmp/js-beautify-mkdir/js-beautify.js && test /tmp/js-beautify-mkdir/js-beautify.js -nt /tmp/js-beautify-mkdir/js-beautify-old.js && { + echo "js-beautify should not replace unchanged file /tmp/js-beautify-mkdir/js-beautify.js when using -o and same file name" + exit 1 + } + + $CLI_SCRIPT -o /tmp/js-beautify-mkdir/js-beautify.js /tmp/js-beautify-mkdir/js-beautify-old.js && test /tmp/js-beautify-mkdir/js-beautify.js -nt /tmp/js-beautify-mkdir/js-beautify-old.js && { + echo "js-beautify should not replace unchanged file /tmp/js-beautify-mkdir/js-beautify.js when using -o and different file name" + exit 1 + } + + $CLI_SCRIPT $SCRIPT_DIR/../../../js/bin/css-beautify.js | diff -q $SCRIPT_DIR/../../../js/bin/css-beautify.js - && { + echo "js-beautify output for $SCRIPT_DIR/../../../js/bin/css-beautify.js was expected to be different." + exit 1 + } } test_smoke_js_beautify() { - echo ---------------------------------------- - echo Testing beautify functionality... - PYTHON=python $SCRIPT_DIR/../../js-beautify-test || exit 1 + echo ---------------------------------------- + echo Testing beautify functionality... + PYTHON=python $SCRIPT_DIR/../../js-beautify-test || exit 1 } test_perf_js_beautify() { - echo ---------------------------------------- - echo Testing beautify performance... - # PYTHON=python $SCRIPT_DIR/../../js-beautify-profile || exit 1 - python $SCRIPT_DIR/test-perf-jsbeautifier.py || exit 1 - + echo ---------------------------------------- + echo Testing beautify performance... + # PYTHON=python $SCRIPT_DIR/../../js-beautify-profile || exit 1 + python $SCRIPT_DIR/test-perf-jsbeautifier.py || exit 1 } -#test_cli_common css-beautify -#test_cli_common html-beautify -test_cli_common js-beautify -test_cli_js_beautify -test_smoke_js_beautify -test_perf_js_beautify +main() { + #test_cli_common css-beautify + #test_cli_common html-beautify + test_cli_common js-beautify + + test_cli_js_beautify + test_smoke_js_beautify + test_perf_js_beautify + + echo ---------------------------------------- + echo $0 - PASSED. + echo ---------------------------------------- +} -echo ---------------------------------------- -echo $0 - PASSED. -echo ---------------------------------------- +(main $*) diff --git a/tools/build.sh b/tools/build.sh new file mode 100755 index 000000000..a7ecfb378 --- /dev/null +++ b/tools/build.sh @@ -0,0 +1,101 @@ +#!/usr/bin/env bash + +REL_SCRIPT_DIR="`dirname \"$0\"`" +SCRIPT_DIR="`( cd \"$REL_SCRIPT_DIR\" && pwd )`" + +build_help() +{ + echo "build.sh " + echo " full - build and test of all implementations" + echo " all - build of both implementations" + echo " js - build of javascript" + echo " py - build of python" + echo " alltest - test both implementations, js and python" + echo " pytest - test python implementation" + echo " jstest - test javascript implementation" +} + +build_ci() +{ + build_full + build_git_status +} + +build_full() +{ + build_all + build_alltest +} + +build_all() +{ + build_py + build_js +} + +build_py() +{ + echo Building python module... + pip install -e ./python || exit 1 +} + +build_js() +{ + echo Building javascript... + npm install || exit 1 +} + +build_alltest() +{ + build_jstest + build_pytest +} + +build_pytest() +{ + echo Testing python implementation... + node test/generate-tests.js || exit 1 + cd python + python --version + ./jsbeautifier/tests/shell-smoke-test.sh || exit 1 +} + +build_jstest() +{ + echo Testing javascript implementation... + node test/generate-tests.js || exit 1 + node --version + ./js/test/shell-smoke-test.sh || exit 1 +} + +build_git_status() +{ + $SCRIPT_DIR/git-status-clear.sh || exit 1 +} + +build_update-codemirror() +{ + rm -rf node_modules/codemirror + npm install codemirror + rm -rf ./web/third-party/codemirror/* + cp ./node_modules/codemirror/LICENSE ./web/third-party/codemirror/ + cp ./node_modules/codemirror/README.md ./web/third-party/codemirror/ + cp -r ./node_modules/codemirror/lib ./web/third-party/codemirror/ + mkdir -p ./web/third-party/codemirror/mode + cp -r ./node_modules/codemirror/mode/javascript ./web/third-party/codemirror/mode/ + git add -Av ./web/third-party/codemirror +} + +main() { + cd $SCRIPT_DIR/.. + local ACTION + ACTION=build_${1:-full} + if [ -n "$(type -t $ACTION)" ] && [ "$(type -t $ACTION)" = "function" ]; then + $ACTION + else + build_help + fi + +} + +(main $*) diff --git a/tools/generate-changelog.sh b/tools/generate-changelog.sh index 0703bcdbb..d0dcebeef 100755 --- a/tools/generate-changelog.sh +++ b/tools/generate-changelog.sh @@ -1,28 +1,40 @@ -#!/bin/bash +#!/usr/bin/env bash + +REL_SCRIPT_DIR="`dirname \"$0\"`" +SCRIPT_DIR="`( cd \"$REL_SCRIPT_DIR\" && pwd )`" + # based on https://gist.github.com/joelittlejohn/5937573 # -if [ "$#" -ne 1 ]; then - echo "Usage: ./generate-changelog.sh user/repo" - exit 1 -fi - -IFS=$'\n' -echo "# Changelog" > CHANGELOG.md - -for m in $(curl -s "https://api.github.com/repos/$1/milestones?state=closed" | jq -c '.[] | [.title, .number, .description]' | sort -r); do - mid=$(echo $m | sed 's/\[".*",\(.*\),".*"\]/\1/') - title=$(echo $m | sed 's/\["\(.*\)",.*,".*"\]/\1/') - - echo "Processing milestone: $title..." - echo $m | sed 's/\["\(.*\)",.*\]/## \1/' >> CHANGELOG.md - echo "" >> CHANGELOG.md - echo '### Description' >> CHANGELOG.md - echo $m | sed 's/\[".*",.*,"\(.*\)"\]/\1/' | sed -e 's/\\"/"/g' | sed -e 's/\\r\\n/\\n/g' | sed -e 's/\\n/\'$'\n/g' >> CHANGELOG.md - echo "" >> CHANGELOG.md - echo '### Closed Issues' >> CHANGELOG.md - for i in $(curl -s "https://api.github.com/repos/$1/issues?milestone=$mid&state=closed" | jq -c '.[] | [.html_url, .number, .title]'); do - echo $i | sed 's/\["\(.*\)",\(.*\),\"\(.*\)\"\]/* \3 ([#\2](\1))/' | sed 's/\\"/"/g' >> CHANGELOG.md + +main() +{ + cd $SCRIPT_DIR/.. + + if [ "$#" -ne 1 ]; then + echo "Usage: ./generate-changelog.sh user/repo" + exit 1 + fi + + IFS=$'\n' + echo "# Changelog" > CHANGELOG.md + + for m in $(curl -s "https://api.github.com/repos/$1/milestones?state=closed" | jq -c '.[] | [.title, .number, .description]' | sort -r); do + mid=$(echo $m | sed 's/\[".*",\(.*\),".*"\]/\1/') + title=$(echo $m | sed 's/\["\(.*\)",.*,".*"\]/\1/') + + echo "Processing milestone: $title..." + echo $m | sed 's/\["\(.*\)",.*\]/## \1/' >> CHANGELOG.md + echo "" >> CHANGELOG.md + echo '### Description' >> CHANGELOG.md + echo $m | sed 's/\[".*",.*,"\(.*\)"\]/\1/' | sed -e 's/\\"/"/g' | sed -e 's/\\r\\n/\\n/g' | sed -e 's/\\n/\'$'\n/g' >> CHANGELOG.md + echo "" >> CHANGELOG.md + echo '### Closed Issues' >> CHANGELOG.md + for i in $(curl -s "https://api.github.com/repos/$1/issues?milestone=$mid&state=closed" | jq -c '.[] | [.html_url, .number, .title]'); do + echo $i | sed 's/\["\(.*\)",\(.*\),\"\(.*\)\"\]/* \3 ([#\2](\1))/' | sed 's/\\"/"/g' >> CHANGELOG.md + done + echo "" >> CHANGELOG.md + echo "" >> CHANGELOG.md done - echo "" >> CHANGELOG.md - echo "" >> CHANGELOG.md -done +} + +(main $*) diff --git a/test/git-status-clear.sh b/tools/git-status-clear.sh similarity index 100% rename from test/git-status-clear.sh rename to tools/git-status-clear.sh diff --git a/tools/release-all.sh b/tools/release-all.sh index 62681c03b..736de8e35 100755 --- a/tools/release-all.sh +++ b/tools/release-all.sh @@ -1,32 +1,58 @@ -#!/bin/bash - -NEW_VERSION=$1 - -git checkout master - -./generate-changelog.sh beautify-web/js-beautify || exit 1 -git commit -am "Update Changelog for $NEW_VERSION" - -# python -git clean -xfd || exit 1 -echo "__version__ = '$NEW_VERSION'" > python/jsbeautifier/__version__.py -git commit -am "Python $NEW_VERSION" -cd python -python setup.py register -python setup.py sdist bdist_wininst upload -cd .. -git push - -# node -git clean -xfd -npm version $NEW_VERSION -npm publish . -git push -git push --tags - -# web -git clean -xfd -git checkout gh-pages && git fetch && git merge origin/master && git push || exit 1 - -git checkout master - +#!/usr/bin/env bash + +REL_SCRIPT_DIR="`dirname \"$0\"`" +SCRIPT_DIR="`( cd \"$REL_SCRIPT_DIR\" && pwd )`" + +generate_changelog() +{ + ./generate-changelog.sh beautify-web/js-beautify || exit 1 + git commit -am "Update Changelog for $NEW_VERSION" +} + +release_python() +{ + git clean -xfd || exit 1 + echo "__version__ = '$NEW_VERSION'" > python/jsbeautifier/__version__.py + git commit -am "Python $NEW_VERSION" + cd python + python setup.py register + python setup.py sdist bdist_wininst upload + git push +} + +release_node() +{ + git clean -xfd || exit 1 + npm version $NEW_VERSION + npm publish . + git push + git push --tags +} + +release_web() +{ + local ORIGINAL_BRANCH + ORIGINAL_BRANCH=$(git branch | grep '[*] .*' | awk '{print $2}') + git clean -xfd || exit 1 + git fetch || exit 1 + git checkout gh-pages && git reset --hard origin/gh-pages || exit 1 + git merge origin/master && git push || exit 1 + git checkout $ORIGINAL_BRANCH +} + +main() +{ + cd $SCRIPT_DIR/.. + + local NEW_VERSION=$1 + NEW_VERSION=$1 + + git checkout master + + generate_changelog + (release_python) + release_node + release_web +} + +(main $*)