From 435aa98c68603fdc8a8861d4a18947d08b455303 Mon Sep 17 00:00:00 2001 From: asifamingov Date: Fri, 26 Jun 2020 10:14:34 +1000 Subject: [PATCH] updated npm tasks to include env variable --- gulp/common-tasks/js.js | 33 ++++++++++++++-------------- gulp/release-tasks/files.js | 43 +++++++++++++++++++++++++++++++++++-- package.json | 11 +++++----- 3 files changed, 62 insertions(+), 25 deletions(-) diff --git a/gulp/common-tasks/js.js b/gulp/common-tasks/js.js index b9a5b19a0..3fa08116c 100644 --- a/gulp/common-tasks/js.js +++ b/gulp/common-tasks/js.js @@ -7,6 +7,15 @@ module.exports = function (gulp, plugins, config, webpack, destFolder, type = 'b let src = [ `${config.basepath.src}/assets/_project/_blocks/qg-main.js`, ]; + const cdnLink = function () { + if (process.env.NODE_ENV === 'prod') { + return `https://static.qgov.net.au/assets/${config.versionName}`; + } else if (process.env.NODE_ENV === 'test') { + return `https://test-static.qgov.net.au/assets/${config.versionName}`; + } else { + return `/assets/${config.versionName}`; + } + }; //.concat(config.build.excludes); remove excludes let dest = { base: `${config.basepath.build}`, @@ -39,23 +48,13 @@ module.exports = function (gulp, plugins, config, webpack, destFolder, type = 'b loader: 'webpack-replace', query: { search: '{{CDN}}', - replace: process.env.NODE_ENV === 'prod' ? `https://static.qgov.net.au/assets/${config.versionName}` : `/assets/${config.versionName}`, + replace: cdnLink(), }, }, { test: /\.json$/, loader: 'json-loader', }, - { - test: /\.js$/, - exclude: /(node_modules)/, - loader: 'webpack-replace', - }, - { - test: /\.js$/, - exclude: /(node_modules)/, - loader: 'webpack-replace', - }, ], }, devtool: 'source-map', @@ -75,11 +74,11 @@ module.exports = function (gulp, plugins, config, webpack, destFolder, type = 'b // } return gulp.src(src) - .pipe(webpack(webpackSettings)) - .pipe(plugins.if(typeof destFolder[0] !== 'undefined', gulp.dest(`${dest.base}/${destFolder[0]}/${dest.ext}`))) - .pipe(plugins.if(typeof destFolder[1] !== 'undefined', gulp.dest(`${dest.base}/${destFolder[1]}/${dest.ext}`))) - .pipe(plugins.if(typeof destFolder[2] !== 'undefined', gulp.dest(`${dest.base}/${destFolder[2]}/${dest.ext}`))) - .pipe(plugins.if(typeof destFolder[3] !== 'undefined', gulp.dest(`${dest.base}/${destFolder[3]}/${dest.ext}`))) - .pipe(plugins.if(typeof destFolder[4] !== 'undefined', gulp.dest(`${dest.base}/${destFolder[4]}/${dest.ext}`))); + .pipe(webpack(webpackSettings)) + .pipe(plugins.if(typeof destFolder[0] !== 'undefined', gulp.dest(`${dest.base}/${destFolder[0]}/${dest.ext}`))) + .pipe(plugins.if(typeof destFolder[1] !== 'undefined', gulp.dest(`${dest.base}/${destFolder[1]}/${dest.ext}`))) + .pipe(plugins.if(typeof destFolder[2] !== 'undefined', gulp.dest(`${dest.base}/${destFolder[2]}/${dest.ext}`))) + .pipe(plugins.if(typeof destFolder[3] !== 'undefined', gulp.dest(`${dest.base}/${destFolder[3]}/${dest.ext}`))) + .pipe(plugins.if(typeof destFolder[4] !== 'undefined', gulp.dest(`${dest.base}/${destFolder[4]}/${dest.ext}`))); }; }; diff --git a/gulp/release-tasks/files.js b/gulp/release-tasks/files.js index 3caee7bad..1dbed862a 100644 --- a/gulp/release-tasks/files.js +++ b/gulp/release-tasks/files.js @@ -1,5 +1,18 @@ const cssnano = require('cssnano'); +const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); module.exports = function (gulp, plugins, config, es, webpack, path, banner) { + let src = [ + `${config.basepath.src}/assets/_project/_blocks/qg-main.js`, + ]; + const cdnLink = function () { + if (process.env.NODE_ENV === 'prod') { + return `https://static.qgov.net.au/assets/${config.versionName}`; + } else if (process.env.NODE_ENV === 'test') { + return `https://test-static.qgov.net.au/assets/${config.versionName}`; + } else { + return `/assets/${config.versionName}`; + } + }; return function () { const target = [ `${config.basepath.build}/**/*`, @@ -47,7 +60,7 @@ module.exports = function (gulp, plugins, config, es, webpack, path, banner) { .pipe(gulp.dest(`${config.basepath.release}/template-local-ssi/assets/includes-local/`)), //JS task - gulp.src(`${config.basepath.build}/assets/${config.versionName}/latest/js/*.js`, { dot: true }) + gulp.src(src, { dot: true }) .pipe(plugins.foreach(function (stream, file) { let filename = path.basename(file.path); let destPath = file.path.split(file.base)[1].split(filename)[0]; @@ -56,7 +69,33 @@ module.exports = function (gulp, plugins, config, es, webpack, path, banner) { output: { filename: filename, }, - plugins: [new webpack.optimize.UglifyJsPlugin()], + module: { + loaders: [{ + test: /\.js$/, + exclude: /(node_modules)/, + loader: 'babel-loader', + query: { + presets: ['es2015'], + }, + }, + { + test: /\.js$/, + exclude: /(node_modules)/, + loader: 'webpack-replace', + query: { + search: '{{CDN}}', + replace: cdnLink(), + }, + }, + { + test: /\.json$/, + loader: 'json-loader', + }, + ], + }, + plugins: [ + new UglifyJsPlugin(), + ], }, webpack)) .pipe(plugins.insert.prepend(banner)) .pipe(gulp.dest(`${config.basepath.release}/template-local-ssi/assets/${config.versionName}/latest/js/${destPath}`)) diff --git a/package.json b/package.json index e23a4c307..d17e47773 100644 --- a/package.json +++ b/package.json @@ -16,17 +16,16 @@ "test": "jest", "postbuild": "gulp clean-redundant-build", "prerelease": "gulp clean-release", - "release": "export NODE_ENV=prod && npm run build && gulp release && node gulp/release-tasks/node-template-flatten.js && gulp replace-links", + "release": "npm run build && gulp release && node gulp/release-tasks/node-template-flatten.js && gulp replace-links", "postrelease": "gulp clean-redundant-release", "start": "npm run build && gulp watch", "watch": "gulp watch", - "publish-npm": "export NODE_ENV=prod && gulp wt-clean && gulp wt-clone && gulp wt-sync && gulp wt-updateVersion && gulp wt-npm && gulp wt-add && gulp wt-commit && gulp wt-tag && gulp wt-push", - "publish-test": "export NODE_ENV=test && gulp wt-clean && gulp wt-clone && gulp wt-sync && gulp wt-branch && gulp wt-updateVersion && gulp wt-add && gulp wt-commit && gulp wt-push", + "publish-npm": "export NODE_ENV=prod && npm run release && gulp wt-clean && gulp wt-clone && gulp wt-sync && gulp wt-updateVersion && gulp wt-npm && gulp wt-add && gulp wt-commit && gulp wt-tag && gulp wt-push", + "publish-test": "export NODE_ENV=test && npm run release && gulp wt-clean && gulp wt-clone && gulp wt-sync && gulp wt-branch && gulp wt-updateVersion && gulp wt-add && gulp wt-commit && gulp wt-push", "create-swe-release": "gulp swe-add && gulp swe-tag && gulp swe-commit && gulp swe-push", - "publish-cdn": "gulp cdn-clean && gulp cdn-clone && gulp cdn-transfer && gulp cdn-add && gulp cdn-commit && gulp cdn-push", + "publish-cdn": "export NODE_ENV=prod && npm run release && gulp cdn-clean && gulp cdn-clone && gulp cdn-transfer && gulp cdn-add && gulp cdn-commit && gulp cdn-push", "prepublish": "npm run release", - "publish-npm-cdn": "npm run publish-npm && npm run publish-cdn", - "publish-test-cdn": "npm run release && export NODE_ENV=test && gulp cdn-clean && gulp cdn-clone && gulp cdn-transfer && gulp cdn-branch && gulp cdn-add && gulp cdn-commit && gulp cdn-push", + "publish-test-cdn": "export NODE_ENV=test && npm run release && export NODE_ENV=test && gulp cdn-clean && gulp cdn-clone && gulp cdn-transfer && gulp cdn-branch && gulp cdn-add && gulp cdn-commit && gulp cdn-push", "postpublish": "gulp clean-publish" }, "authors": "Queensland Government",