From d521fbbd2ce366cb0153f48e473b071a87dfad4d Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Wed, 10 May 2017 15:15:41 -0400 Subject: [PATCH] chore(CLI): minify Etcher CLI code (#1401) UglifyJS v3 was recently released, which includes support for compressing ES6 code. This commit introduces the following changes: - Add a boolean `-m` option to `concatenate-javascript.sh`, which when set, will minify the final concatenated JavaScript file - Install `uglify-es` in the CI servers See: https://news.ycombinator.com/item?id=14285179 See: https://github.com/mishoo/UglifyJS2/tree/harmony Signed-off-by: Juan Cruz Viotti --- Makefile | 2 +- scripts/build/concatenate-javascript.sh | 11 ++++++++++- scripts/build/docker/Dockerfile-i686 | 1 + scripts/build/docker/Dockerfile-x86_64 | 1 + scripts/build/docker/Dockerfile.template | 1 + scripts/ci/appveyor-install.bat | 2 +- scripts/ci/travis-install.sh | 2 +- 7 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index dda0d038..e61d6836 100644 --- a/Makefile +++ b/Makefile @@ -247,7 +247,7 @@ $(BUILD_DIRECTORY)/$(APPLICATION_NAME)-cli-$(TARGET_PLATFORM)-$(APPLICATION_VERS $(BUILD_DIRECTORY)/$(APPLICATION_NAME)-cli-$(TARGET_PLATFORM)-$(APPLICATION_VERSION)-$(TARGET_ARCH).js: \ $(BUILD_DIRECTORY)/$(APPLICATION_NAME)-cli-$(TARGET_PLATFORM)-$(APPLICATION_VERSION)-$(TARGET_ARCH)-app \ | $(BUILD_DIRECTORY) - ./scripts/build/concatenate-javascript.sh -e $" echo " -o " + echo " -m minify" exit 1 } ARGV_ENTRY_POINT="" ARGV_OUTPUT="" +ARGV_MINIFY=false -while getopts ":e:o:" option; do +while getopts ":e:o:m" option; do case $option in e) ARGV_ENTRY_POINT=$OPTARG ;; o) ARGV_OUTPUT=$OPTARG ;; + m) ARGV_MINIFY=true ;; *) usage ;; esac done @@ -48,3 +52,8 @@ if [ -z "$ARGV_ENTRY_POINT" ] || [ -z "$ARGV_OUTPUT" ]; then fi "$BROWSERIFY" "$ARGV_ENTRY_POINT" --node --outfile "$ARGV_OUTPUT" + +if [ "$ARGV_MINIFY" == "true" ]; then + uglifyjs --compress --output "$ARGV_OUTPUT.MIN" -- "$ARGV_OUTPUT" + mv "$ARGV_OUTPUT.MIN" "$ARGV_OUTPUT" +fi diff --git a/scripts/build/docker/Dockerfile-i686 b/scripts/build/docker/Dockerfile-i686 index a2033b5f..f41486b7 100644 --- a/scripts/build/docker/Dockerfile-i686 +++ b/scripts/build/docker/Dockerfile-i686 @@ -34,6 +34,7 @@ RUN add-apt-repository ppa:ubuntu-toolchain-r/test \ RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - \ && apt-get install -y nodejs RUN npm config set spin=false +RUN npm install -g uglify-es@3.0.3 # Python RUN pip install codespell==1.9.2 awscli cpplint diff --git a/scripts/build/docker/Dockerfile-x86_64 b/scripts/build/docker/Dockerfile-x86_64 index c69668d1..711ebdbf 100644 --- a/scripts/build/docker/Dockerfile-x86_64 +++ b/scripts/build/docker/Dockerfile-x86_64 @@ -34,6 +34,7 @@ RUN add-apt-repository ppa:ubuntu-toolchain-r/test \ RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - \ && apt-get install -y nodejs RUN npm config set spin=false +RUN npm install -g uglify-es@3.0.3 # Python RUN pip install codespell==1.9.2 awscli cpplint diff --git a/scripts/build/docker/Dockerfile.template b/scripts/build/docker/Dockerfile.template index c77b1555..11be29df 100644 --- a/scripts/build/docker/Dockerfile.template +++ b/scripts/build/docker/Dockerfile.template @@ -34,6 +34,7 @@ RUN add-apt-repository ppa:ubuntu-toolchain-r/test \ RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - \ && apt-get install -y nodejs RUN npm config set spin=false +RUN npm install -g uglify-es@3.0.3 # Python RUN pip install codespell==1.9.2 awscli cpplint diff --git a/scripts/ci/appveyor-install.bat b/scripts/ci/appveyor-install.bat index bd62ddf0..c01ff338 100755 --- a/scripts/ci/appveyor-install.bat +++ b/scripts/ci/appveyor-install.bat @@ -20,7 +20,7 @@ IF "%APPVEYOR_REPO_BRANCH%"=="" ( ) call npm config set spin=false -call npm install -g npm@4.4.4 +call npm install -g npm@4.4.4 uglify-es@3.0.3 call choco install nsis -version 2.51 call choco install jq diff --git a/scripts/ci/travis-install.sh b/scripts/ci/travis-install.sh index f5a828ff..57b3507c 100755 --- a/scripts/ci/travis-install.sh +++ b/scripts/ci/travis-install.sh @@ -35,7 +35,7 @@ else ./scripts/build/check-dependency.sh make ./scripts/build/check-dependency.sh npm - npm install -g npm@3.10.10 + npm install -g npm@3.10.10 uglify-es@3.0.3 npm config set spin=false pip install codespell==1.9.2 awscli cpplint