diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6fb03dea9688d9872faa0ae5afbe1bfa13a9cc19..efae92580682e8f552518ed5b84dc61cd14484d2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,7 +13,7 @@ build: # only for official releases - if: $CI_COMMIT_TAG =~ /\A\d+\.\d+\.\d+\z/ script: - - ./compile.sh --ci + - ./compile.sh --ci --minify artifacts: paths: - bin/FC_pregmod.html diff --git a/compile.sh b/compile.sh index 84b4ee732756fba715c638794adbeac572de3b6e..48aa0183ed18650ae8f5ac2e223d8d40d3c094ed 100755 --- a/compile.sh +++ b/compile.sh @@ -14,6 +14,7 @@ Options: -s, --sanity Run sanityCheck -q, --quiet Suppress terminal output -t, --themes Generate theme files + -m, --minify Minify output files --ci CI mode HelpText } @@ -42,10 +43,13 @@ function compile() { echoMessage "x64 arch" if [ "$(uname -s)" = "Darwin" ]; then TWEEGO_EXE="./devTools/tweeGo/tweego_osx64" + MINIFY_EXE="./devTools/minify/minify_darwin_amd64" elif [ "$OSTYPE" = "msys" ]; then TWEEGO_EXE="./devTools/tweeGo/tweego_win64" + MINIFY_EXE="./devTools/minify/minify_win_amd64" else TWEEGO_EXE="./devTools/tweeGo/tweego_nix64" + MINIFY_EXE="./devTools/minify/minify_linux_amd64" fi ;; x86 | i[3-6]86) @@ -70,21 +74,25 @@ function compile() { # Find and insert current commit if [[ "$ci" ]]; then - COMMIT=$CI_COMMIT_SHORT_SHA - elif [[ -d .git ]]; then - COMMIT=$(git rev-parse --short HEAD) - if [[ "$usehash" ]]; then + COMMIT=$CI_COMMIT_SHORT_SHA + elif [[ -d .git ]]; then + COMMIT=$(git rev-parse --short HEAD) + if [[ "$usehash" ]]; then file="bin/FC_pregmod_${COMMIT}.html" fi fi + if [[ "$minify" ]]; then + final_file=$file + file="bin/tmp.html" + fi if [[ "$COMMIT" ]]; then - printf "App.Version.commitHash = '%s';\n" ${COMMIT} > src/002-config/fc-version.js.commitHash.js - fi + printf "App.Version.commitHash = '%s';\n" "${COMMIT}" > src/002-config/fc-version.js.commitHash.js + fi devTools/concatFiles.sh js/ '*.js' bin/fc.js devTools/concatFiles.sh css/ '*.css' bin/fc.css - $TWEEGO_EXE -o $file --module=bin/fc.js --module=bin/fc.css --head resources/raster/favicon/arcologyVector.html src/ || build_failed="true" + $TWEEGO_EXE -o "$file" --module=bin/fc.js --module=bin/fc.css --head resources/raster/favicon/arcologyVector.html src/ || build_failed="true" rm -f bin/fc.js rm -f bin/fc.css if [ "$build_failed" = "true" ]; then @@ -92,7 +100,20 @@ function compile() { exit 1 fi - if [[ "$ci" || -d .git ]]; then + if [[ "$minify" ]]; then + if [[ "$MINIFY_EXE" ]]; then + # SC license is inside an HTML comment, so keep them. + # eval depends on local variables, so don't modify them (Config, Engine, ...) + $MINIFY_EXE --html-keep-comments --js-keep-var-names "$file" > "$final_file" + rm -f "$file" + else + echoError "Minification only available on amd64 systems." + mv "$file" "$final_file" + fi + file=$final_file + fi + + if [[ "$ci" || -d .git ]]; then rm src/002-config/fc-version.js.commitHash.js fi echoMessage "Saved to $file." @@ -121,12 +142,15 @@ else -q | --quiet) output=/dev/null ;; - -t | --themes) - themes="true" - ;; - --ci) - ci="true" - ;; + -t | --themes) + themes="true" + ;; + -m | --minify) + minify="true" + ;; + --ci) + ci="true" + ;; *) echoError "Unknown argument $1." displayHelp @@ -154,13 +178,13 @@ fi # compile themes if [[ "$themes" ]]; then - ( - cd themes/ || exit - for D in *; do - if [ -d "${D}" ]; then - ../devTools/concatFiles.sh "${D}"/ '*.css' ../bin/"${D}".css - fi - done - ) - echoMessage "Themes compiled at $(date +%T)" + ( + cd themes/ || exit + for D in *; do + if [ -d "${D}" ]; then + ../devTools/concatFiles.sh "${D}"/ '*.css' ../bin/"${D}".css + fi + done + ) + echoMessage "Themes compiled at $(date +%T)" fi diff --git a/devTools/minify/LICENSE b/devTools/minify/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..41677de41ec1ddfe9c8558cad4466816b9b2195f --- /dev/null +++ b/devTools/minify/LICENSE @@ -0,0 +1,22 @@ +Copyright (c) 2015 Taco de Wolff + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the "Software"), to deal in the Software without + restriction, including without limitation the rights to use, + copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following + conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/devTools/minify/README.md b/devTools/minify/README.md new file mode 100644 index 0000000000000000000000000000000000000000..e1ebf4fc9619fffa62142222b37fa33af9c740db --- /dev/null +++ b/devTools/minify/README.md @@ -0,0 +1,183 @@ +# Minify [](https://gitter.im/tdewolff/minify?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + +**[Download binaries](https://github.com/tdewolff/minify/releases) for Windows, Linux and macOS** + +Minify is a CLI implementation of the minify [library package](https://github.com/tdewolff/minify). + +## Installation +Make sure you have [Go](http://golang.org/) and [Git](http://git-scm.com/) installed. + +Run the following command + + mkdir $HOME/src + cd $HOME/src + git clone https://github.com/tdewolff/minify.git + cd minify + make install + +and the `minify` command will be in `$GOPATH/bin` or `$HOME/go/bin`. + +If you do not have `make`, instead run the following lines to install `minify` and enable bash tab completion: + + go install ./cmd/minify + source minify_bash_tab_completion + +### Arch Linux +Using `yay`: + +``` +yay -Syu minify +``` + +[Minify in AUR](https://aur.archlinux.org/packages/minify/) + +### FreeBSD +``` +pkg install minify +``` + +### MacOS +Using Homebrew: + +``` +brew install tdewolff/tap/minify +``` + +[Brew tap](https://github.com/tdewolff/homebrew-tap/) + +### Ubuntu +Update the package index: + +``` +sudo apt-get update +``` + +Install minify deb package: +``` +sudo apt-get install minify +``` + +## Usage + Usage: minify [options] [input] + + Options: + -a, --all Minify all files, including hidden files and files in hidden directories + -b, --bundle Bundle files by concatenation into a single file + --cpuprofile string Export CPU profile + --css-precision int Number of significant digits to preserve in numbers, 0 is all (default 0) + -h, --help Show usage + --html-keep-comments Preserve all comments + --html-keep-conditional-comments Preserve all IE conditional comments + --html-keep-default-attrvals Preserve default attribute values + --html-keep-document-tags Preserve html, head and body tags + --html-keep-end-tags Preserve all end tags + --html-keep-quotes Preserve quotes around attribute values + --html-keep-whitespace Preserve whitespace characters but still collapse multiple into one + --js-precision int Number of significant digits to preserve in numbers, 0 is all (default 0) + --js-keep-var-names Preserve original variable names + --json-precision int Number of significant digits to preserve in numbers, 0 is all (default 0) + -l, --list List all accepted filetypes + --match string Filename pattern matching using regular expressions + --memprofile string Export memory profile + --mime string Mimetype (eg. text/css), optional for input filenames, has precedence over --type + -o, --output string Output file or directory (must have trailing slash), leave blank to use stdout + -p, --preserve-links Copy symbolic links without dereferencing and without minifying the referenced file (only with --sync) + -r, --recursive Recursively minify directories + --svg-precision int Number of significant digits to preserve in numbers, 0 is all (default 0) + -s, --sync Copy all files to destination directory and minify when filetype matches + --type string Filetype (eg. css), optional for input filenames + --url string URL of file to enable URL minification + -v, --verbose Verbose + --version Version + -w, --watch Watch files and minify upon changes + --xml-keep-whitespace Preserve whitespace characters but still collapse multiple into one + + Input: + Files or directories, leave blank to use stdin + +### Types + + css text/css + htm text/html + html text/html + js application/javascript + json application/json + svg image/svg+xml + xml text/xml + +## Examples +Minify **index.html** to **index-min.html**: +```sh +$ minify -o index-min.html index.html +``` + +Minify **index.html** to standard output (leave `-o` blank): +```sh +$ minify index.html +``` + +Normally the mimetype is inferred from the extension, to set the mimetype explicitly: +```sh +$ minify --type=html -o index-min.tpl index.tpl +``` + +You need to set the type or the mimetype option when using standard input: +```sh +$ minify --mime=application/javascript < script.js > script-min.js + +$ cat script.js | minify --type=js > script-min.js +``` + +### Directories +You can also give directories as input, and these directories can be minified recursively. + +Minify files in the current working directory to **out/** (no subdirectories): +```sh +$ minify -o out/ * +``` + +Minify files recursively in **src/**: +```sh +$ minify -r -o out/ src +``` + +Minify only javascript files in **src/**: +```sh +$ minify -r -o out/ --match=\.js src +``` + +### Concatenate +When multiple inputs are given and the output is either standard output or a single file, it will concatenate the files together if you use the bundle option. + +Concatenate **one.css** and **two.css** into **style.css**: +```sh +$ minify -b -o style.css one.css two.css +``` + +Concatenate all files in **styles/** into **style.css**: +```sh +$ minify -r -b -o style.css styles +``` + +You can also use `cat` as standard input to concatenate files and use gzip for example: +```sh +$ cat one.css two.css three.css | minify --type=css | gzip -9 -c > style.css.gz +``` + +### Watching +To watch file changes and automatically re-minify you can use the `-w` or `--watch` option. + +Minify **style.css** to itself and watch changes: +```sh +$ minify -w -o style.css style.css +``` + +Minify and concatenate **one.css** and **two.css** to **style.css** and watch changes: +```sh +$ minify -w -o style.css one.css two.css +``` + +Minify files in **src/** and subdirectories to **out/** and watch changes: +```sh +$ minify -w -r -o out/ src +``` diff --git a/devTools/minify/minify_darwin_amd64 b/devTools/minify/minify_darwin_amd64 new file mode 100644 index 0000000000000000000000000000000000000000..2bf7fb8e7be5086188c8a0a8f84173110ffc65f5 Binary files /dev/null and b/devTools/minify/minify_darwin_amd64 differ diff --git a/devTools/minify/minify_linux_amd64 b/devTools/minify/minify_linux_amd64 new file mode 100755 index 0000000000000000000000000000000000000000..82d92126f98f62c9f6c10653df5c0eaef8048f10 Binary files /dev/null and b/devTools/minify/minify_linux_amd64 differ diff --git a/devTools/minify/minify_win_amd64.exe b/devTools/minify/minify_win_amd64.exe new file mode 100644 index 0000000000000000000000000000000000000000..e9948aef52854bed38acbb09b10c6d9323d50d4d Binary files /dev/null and b/devTools/minify/minify_win_amd64.exe differ