From 898cfc9965aa44f87151771493e47aa8af4737ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Tue, 4 Feb 2020 13:47:21 +0100 Subject: [PATCH 1/2] MOBILE-3333 travis: Do not edit config.js on AOT --- .travis.yml | 3 +- scripts/aot.sh | 81 -------------------------------------------------- scripts/ci.sh | 79 ++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 77 insertions(+), 86 deletions(-) delete mode 100755 scripts/aot.sh diff --git a/.travis.yml b/.travis.yml index 4e41b34b3..60d343646 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -sudo: required +os: linux dist: bionic group: edge @@ -23,4 +23,3 @@ script: after_success: - scripts/ci.sh - \ No newline at end of file diff --git a/scripts/aot.sh b/scripts/aot.sh deleted file mode 100755 index 7c705744b..000000000 --- a/scripts/aot.sh +++ /dev/null @@ -1,81 +0,0 @@ -#!/bin/bash -source "scripts/functions.sh" - -print_title "NPM packages list" - -# List first level of installed libraries so we can check the installed versions. -npm list --depth=0 - -if [ "$TRAVIS_BRANCH" == 'master' ] && [ ! -z $GIT_TOKEN ] && [ "$TRAVIS_REPO_SLUG" == 'moodlehq/moodleapp' ]; then - print_title "Update langpacks" - cd scripts - ./update_lang.sh - cd .. - - print_title "Update generated lang files" - git remote set-url origin https://$GIT_TOKEN@github.com/$TRAVIS_REPO_SLUG.git - git fetch -q origin - git add -A src/assets/lang - git add */en.json - git add src/config.json - git commit -m 'Update lang files [ci skip]' - - print_title "Update Licenses" - npm install -g license-checker - - jq --version - license-checker --json --production --relativeLicensePath > licenses.json - jq 'del(.[].path)' licenses.json > licenses_old.json - mv licenses_old.json licenses.json - licenses=`jq -r 'keys[]' licenses.json` - echo "{" > licensesurl.json - first=1 - for license in $licenses; do - obj=`jq --arg lic $license '.[$lic]' licenses.json` - licensePath=`echo $obj | jq -r '.licenseFile'` - file="" - if [[ ! -z "$licensePath" ]] || [[ "$licensePath" != "null" ]]; then - file=$(basename $licensePath) - if [ $first -eq 1 ] ; then - first=0 - echo "\"$license\" : { \"licenseFile\" : \"$file\"}" >> licensesurl.json - else - echo ",\"$license\" : { \"licenseFile\" : \"$file\"}" >> licensesurl.json - fi - fi - done - echo "}" >> licensesurl.json - - jq -s '.[0] * .[1]' licenses.json licensesurl.json > licenses_old.json - mv licenses_old.json licenses.json - rm licensesurl.json - - git add licenses.json - git commit -m 'Update licenses [ci skip]' - - git push origin HEAD:$TRAVIS_BRANCH -fi - -print_title "AOT Compilation" -sed -ie $'s~throw new Error("No ResourceLoader.*~url = "templates/" + url;\\\nvar resolve;\\\nvar reject;\\\nvar promise = new Promise(function (res, rej) {\\\nresolve = res;\\\nreject = rej;\\\n});\\\nvar xhr = new XMLHttpRequest();\\\nxhr.open("GET", url, true);\\\nxhr.responseType = "text";\\\nxhr.onload = function () {\\\nvar response = xhr.response || xhr.responseText;\\\nvar status = xhr.status === 1223 ? 204 : xhr.status;\\\nif (status === 0) {\\\nstatus = response ? 200 : 0;\\\n}\\\nif (200 <= status \&\& status <= 300) {\\\nresolve(response);\\\n}\\\nelse {\\\nreject("Failed to load " + url);\\\n}\\\n};\\\nxhr.onerror = function () { reject("Failed to load " + url); };\\\nxhr.send();\\\nreturn promise;\\\n~g' node_modules/@angular/platform-browser-dynamic/esm5/platform-browser-dynamic.js -sed -ie "s/context\.isProd || hasArg('--minifyJs')/hasArg('--minifyJs')/g" node_modules/@ionic/app-scripts/dist/util/config.js -sed -ie "s/context\.isProd || hasArg('--optimizeJs')/hasArg('--optimizeJs')/g" node_modules/@ionic/app-scripts/dist/util/config.js -npm run ionic:build -- --prod - - -if [ $TRAVIS_BRANCH == 'integration' ] || [ $TRAVIS_BRANCH == 'master' ] || [ $TRAVIS_BRANCH == 'desktop' ] ; then - if [ ! -z $GIT_ORG_PRIVATE ] && [ ! -z $GIT_TOKEN ] ; then - if [ "$TRAVIS_REPO_SLUG" == 'moodlehq/moodleapp' ]; then - print_title "Mirror repository" - git remote add mirror https://$GIT_TOKEN@github.com/$GIT_ORG_PRIVATE/moodleapp.git - git fetch -q mirror - git push -f mirror HEAD:$TRAVIS_BRANCH - git push mirror --tags - else - print_title "Run scripts" - git clone --depth 1 https://$GIT_TOKEN@github.com/$GIT_ORG_PRIVATE/apps-scripts.git ../scripts - cp ../scripts/build.sh scripts/ - ./scripts/build.sh - fi - fi -fi diff --git a/scripts/ci.sh b/scripts/ci.sh index a8aaec045..b2ef17ebd 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -1,8 +1,81 @@ #!/bin/bash +source "scripts/functions.sh" -if [ $TRAVIS_EVENT_TYPE == 'cron' ] ; then +if [ "$TRAVIS_EVENT_TYPE" == 'cron' ] ; then # Tests scripts. - echo 'CRON NOT IMPLEMENTED YET' + print_error 'CRON NOT IMPLEMENTED YET' else - ./scripts/aot.sh + if [ -z $GIT_ORG_PRIVATE ] || [ -z $GIT_TOKEN ]; then + print_error "Env vars not correctly defined" + exit 1 + fi + + # List first level of installed libraries so we can check the installed versions. + print_title "NPM packages list" + npm list --depth=0 + + if [ "$TRAVIS_REPO_SLUG" == 'moodlehq/moodleapp' ]; then + if [ "$TRAVIS_BRANCH" == 'master' ]; then + print_title "Update langpacks" + cd scripts + ./update_lang.sh + cd .. + + print_title "Update generated lang files" + git remote set-url origin https://$GIT_TOKEN@github.com/$TRAVIS_REPO_SLUG.git + git fetch -q origin + git add -A src/assets/lang + git add */en.json + git add src/config.json + git commit -m 'Update lang files [ci skip]' + + print_title "Update Licenses" + npm install -g license-checker + + jq --version + license-checker --json --production --relativeLicensePath > licenses.json + jq 'del(.[].path)' licenses.json > licenses_old.json + mv licenses_old.json licenses.json + licenses=`jq -r 'keys[]' licenses.json` + echo "{" > licensesurl.json + first=1 + for license in $licenses; do + obj=`jq --arg lic $license '.[$lic]' licenses.json` + licensePath=`echo $obj | jq -r '.licenseFile'` + file="" + if [[ ! -z "$licensePath" ]] || [[ "$licensePath" != "null" ]]; then + file=$(basename $licensePath) + if [ $first -eq 1 ] ; then + first=0 + echo "\"$license\" : { \"licenseFile\" : \"$file\"}" >> licensesurl.json + else + echo ",\"$license\" : { \"licenseFile\" : \"$file\"}" >> licensesurl.json + fi + fi + done + echo "}" >> licensesurl.json + + jq -s '.[0] * .[1]' licenses.json licensesurl.json > licenses_old.json + mv licenses_old.json licenses.json + rm licensesurl.json + + git add licenses.json + git commit -m 'Update licenses [ci skip]' + + git push origin HEAD:$TRAVIS_BRANCH + fi + + if [ "$TRAVIS_BRANCH" == 'integration' ] || [ "$TRAVIS_BRANCH" == 'master' ] || [ "$TRAVIS_BRANCH" == 'desktop' ] ; then + print_title "Mirror repository" + git remote add mirror https://$GIT_TOKEN@github.com/$GIT_ORG_PRIVATE/moodleapp.git + git fetch -q mirror + git push -f mirror HEAD:$TRAVIS_BRANCH + git push mirror --tags + fi + elif [ "$TRAVIS_REPO_SLUG" == "$GIT_ORG_PRIVATE/moodleapp" ]; then + print_title "Run scripts" + git clone --depth 1 https://$GIT_TOKEN@github.com/$GIT_ORG_PRIVATE/apps-scripts.git ../scripts + cp ../scripts/build.sh scripts/ + ./scripts/build.sh + fi fi From 7c2fbdb84355d1d79d631d0b8706efc22c15afd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Tue, 4 Feb 2020 13:47:41 +0100 Subject: [PATCH 2/2] MOBILE-3333 gulp: Minimize HTML templates --- gulpfile.js | 9 +++- package-lock.json | 124 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 3 files changed, 133 insertions(+), 1 deletion(-) diff --git a/gulpfile.js b/gulpfile.js index e90e7bad4..0a4596073 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -9,7 +9,8 @@ var gulp = require('gulp'), flatten = require('gulp-flatten'), npmPath = require('path'), concat = require('gulp-concat'), - bufferFrom = require('buffer-from') + htmlmin = require('gulp-htmlmin'), + bufferFrom = require('buffer-from'), exec = require('child_process').exec, license = '' + '// (C) Copyright 2015 Moodle Pty Ltd.\n' + @@ -293,6 +294,12 @@ gulp.task('copy-component-templates', function(done) { gulp.src(templatesSrc, { allowEmpty: true }) .pipe(flatten()) + // Check options here: https://github.com/kangax/html-minifier + .pipe(htmlmin({ + collapseWhitespace: true, + removeComments: true, + caseSensitive: true + })) .pipe(gulp.dest(templatesDest)) .on('end', done); }); diff --git a/package-lock.json b/package-lock.json index 2a05110de..171a78d48 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2359,6 +2359,16 @@ "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==" }, + "camel-case": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/camel-case/-/camel-case-3.0.0.tgz", + "integrity": "sha1-yjw2iKTpzzpM2nd9xNy8cTJJz3M=", + "dev": true, + "requires": { + "no-case": "^2.2.0", + "upper-case": "^1.1.1" + } + }, "camelcase": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-2.1.1.tgz", @@ -6952,6 +6962,37 @@ "through2": "^2.0.0" } }, + "gulp-htmlmin": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/gulp-htmlmin/-/gulp-htmlmin-5.0.1.tgz", + "integrity": "sha512-ASlyDPZOSKjHYUifYV0rf9JPDflN9IRIb8lw2vRqtYMC4ljU3zAmnnaVXwFQ3H+CfXxZSUesZ2x7jrnPJu93jA==", + "dev": true, + "requires": { + "html-minifier": "^3.5.20", + "plugin-error": "^1.0.1", + "through2": "^2.0.3" + }, + "dependencies": { + "arr-diff": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/arr-diff/-/arr-diff-4.0.0.tgz", + "integrity": "sha1-1kYQdP6/7HHn4VI1dhoyml3HxSA=", + "dev": true + }, + "plugin-error": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/plugin-error/-/plugin-error-1.0.1.tgz", + "integrity": "sha512-L1zP0dk7vGweZME2i+EeakvUNqSrdiI3F91TwEoYiGrAfUXmVv6fJIq4g82PAXxNsWOp0J7ZqQy/3Szz0ajTxA==", + "dev": true, + "requires": { + "ansi-colors": "^1.0.1", + "arr-diff": "^4.0.0", + "arr-union": "^3.1.0", + "extend-shallow": "^3.0.2" + } + } + } + }, "gulp-rename": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/gulp-rename/-/gulp-rename-1.3.0.tgz", @@ -7164,6 +7205,12 @@ "minimalistic-assert": "^1.0.1" } }, + "he": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", + "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", + "dev": true + }, "hmac-drbg": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", @@ -7189,6 +7236,47 @@ "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.6.0.tgz", "integrity": "sha512-lIbgIIQA3lz5XaB6vxakj6sDHADJiZadYEJB+FgA+C4nubM1NwcuvUr9EJPmnH1skZqpqUzWborWo8EIUi0Sdw==" }, + "html-minifier": { + "version": "3.5.21", + "resolved": "https://registry.npmjs.org/html-minifier/-/html-minifier-3.5.21.tgz", + "integrity": "sha512-LKUKwuJDhxNa3uf/LPR/KVjm/l3rBqtYeCOAekvG8F1vItxMUpueGd94i/asDDr8/1u7InxzFA5EeGjhhG5mMA==", + "dev": true, + "requires": { + "camel-case": "3.0.x", + "clean-css": "4.2.x", + "commander": "2.17.x", + "he": "1.2.x", + "param-case": "2.1.x", + "relateurl": "0.2.x", + "uglify-js": "3.4.x" + }, + "dependencies": { + "commander": { + "version": "2.17.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.17.1.tgz", + "integrity": "sha512-wPMUt6FnH2yzG95SA6mzjQOEKUU3aLaDEmzs1ti+1E9h+CsrZghRlqEM/EJ4KscsQVG8uNN4uVreUeT8+drlgg==", + "dev": true + }, + "uglify-js": { + "version": "3.4.10", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.4.10.tgz", + "integrity": "sha512-Y2VsbPVs0FIshJztycsO2SfPk7/KAF/T72qzv9u5EpQ4kB2hQoHlhNQTsNyy6ul7lQtqJN/AoWeS23OzEiEFxw==", + "dev": true, + "requires": { + "commander": "~2.19.0", + "source-map": "~0.6.1" + }, + "dependencies": { + "commander": { + "version": "2.19.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.19.0.tgz", + "integrity": "sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg==", + "dev": true + } + } + } + } + }, "http-errors": { "version": "1.6.3", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz", @@ -8213,6 +8301,12 @@ "signal-exit": "^3.0.0" } }, + "lower-case": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/lower-case/-/lower-case-1.1.4.tgz", + "integrity": "sha1-miyr0bno4K6ZOkv31YdcOcQujqw=", + "dev": true + }, "lowercase-keys": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-1.0.1.tgz", @@ -8894,6 +8988,15 @@ "resolved": "https://registry.npmjs.org/nl.kingsquare.cordova.background-audio/-/nl.kingsquare.cordova.background-audio-1.0.1.tgz", "integrity": "sha1-Gx1NzaijXAx/x5UzN7FzsUtPmGA=" }, + "no-case": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/no-case/-/no-case-2.3.2.tgz", + "integrity": "sha512-rmTZ9kz+f3rCvK2TD1Ue/oZlns7OGoIWP4fc3llxxRXlOkHKoWPPWJOfFYpITabSow43QJbRIoHQXtt10VldyQ==", + "dev": true, + "requires": { + "lower-case": "^1.1.1" + } + }, "node-abi": { "version": "2.4.3", "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-2.4.3.tgz", @@ -9617,6 +9720,15 @@ "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.6.tgz", "integrity": "sha512-lQe48YPsMJAig+yngZ87Lus+NF+3mtu7DVOBu6b/gHO1YpKwIj5AWjZ/TOS7i46HD/UixzWb1zeWDZfGZ3iYcg==" }, + "param-case": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/param-case/-/param-case-2.1.1.tgz", + "integrity": "sha1-35T9jPZTHs915r75oIWPvHK+Ikc=", + "dev": true, + "requires": { + "no-case": "^2.2.0" + } + }, "parent-module": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", @@ -10341,6 +10453,12 @@ "rc": "^1.0.1" } }, + "relateurl": { + "version": "0.2.7", + "resolved": "https://registry.npmjs.org/relateurl/-/relateurl-0.2.7.tgz", + "integrity": "sha1-VNvzd+UUQKypCkzSdGANP/LYiKk=", + "dev": true + }, "remove-bom-buffer": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/remove-bom-buffer/-/remove-bom-buffer-3.0.0.tgz", @@ -12189,6 +12307,12 @@ } } }, + "upper-case": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/upper-case/-/upper-case-1.1.3.tgz", + "integrity": "sha1-9rRQHC7EzdJrp4vnIilh3ndiFZg=", + "dev": true + }, "uri-js": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", diff --git a/package.json b/package.json index 520c2a203..ffb20574f 100644 --- a/package.json +++ b/package.json @@ -133,6 +133,7 @@ "gulp-clip-empty-files": "^0.1.2", "gulp-concat": "^2.6.1", "gulp-flatten": "^0.4.0", + "gulp-htmlmin": "^5.0.1", "gulp-rename": "^1.3.0", "gulp-slash": "^1.1.3", "lodash.template": "^4.5.0",