Skip to content

Commit

Permalink
updated npm tasks to include env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
asifaminb committed Jun 26, 2020
1 parent d7a57b1 commit 435aa98
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 25 deletions.
33 changes: 16 additions & 17 deletions gulp/common-tasks/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down Expand Up @@ -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',
Expand All @@ -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}`)));
};
};
43 changes: 41 additions & 2 deletions gulp/release-tasks/files.js
Original file line number Diff line number Diff line change
@@ -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}/**/*`,
Expand Down Expand Up @@ -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];
Expand All @@ -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}`))
Expand Down
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 435aa98

Please sign in to comment.