From 2ddbc41de85a63555058c227c9cfa0343627875a Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Wed, 25 Jan 2017 22:09:39 +0100 Subject: Add NPM dependencies for GAuth replace action --- package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index c45fcd9e..35f4790c 100644 --- a/package.json +++ b/package.json @@ -20,17 +20,20 @@ "gulp-notify": "^2.2.0", "gulp-processhtml": "^1.1.0", "gulp-rename": "^1.2.2", + "gulp-replace": "^0.5.4", "gulp-typings": "^2.0.4", "jquery": "^3.1.0", "jquery-mousewheel": "^3.1.13", "jquery.easing": "^1.4.1", "less": "^2.7.1", + "run-sequence": "^1.2.2", "socket.io-client": "^1.4.8", "tsify": "^2.0.2", "tslint": "^3.10.2", "typescript": "^2.1.4", "typings": "^1.3.2", - "vinyl-source-stream": "^1.1.0" + "vinyl-source-stream": "^1.1.0", + "yargs": "^6.6.0" }, "devDependencies": { "jasmine-core": "^2.4.1" -- cgit v1.2.3 From 3461ffcca100c105a81a16de4355806f0628e6a6 Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Wed, 25 Jan 2017 22:10:22 +0100 Subject: Replace GAuth client ID in HTMLs with placeholder --- src/app.html | 3 +-- src/index.html | 3 +-- src/profile.html | 5 ++--- src/projects.html | 5 ++--- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/app.html b/src/app.html index c267a354..5b652b6c 100644 --- a/src/app.html +++ b/src/app.html @@ -2,8 +2,7 @@ - + OpenDC diff --git a/src/index.html b/src/index.html index 03806513..37e039c1 100644 --- a/src/index.html +++ b/src/index.html @@ -19,8 +19,7 @@ - + diff --git a/src/profile.html b/src/profile.html index 23a1f5a3..9691f827 100644 --- a/src/profile.html +++ b/src/profile.html @@ -2,8 +2,7 @@ - + OpenDC - Profile @@ -60,4 +59,4 @@ - \ No newline at end of file + diff --git a/src/projects.html b/src/projects.html index c829ae00..5ac8d64c 100644 --- a/src/projects.html +++ b/src/projects.html @@ -2,8 +2,7 @@ - + OpenDC - Projects @@ -91,4 +90,4 @@ - \ No newline at end of file + -- cgit v1.2.3 From e99093c9d98f7fab16c5958d7e538a6de00ea701 Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Wed, 25 Jan 2017 22:19:35 +0100 Subject: Clean up gulpfile.js --- gulpfile.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 612decf6..325bc8b7 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,5 +1,14 @@ +/** + * Build file for the frontend codebase of OpenDC. + * + * Usage: + * $ gulp config.json # for a single build + * $ gulp watch config.json # to run once, watch for changes, and rebuild when something changed + */ + 'use strict'; +const runSequence = require('run-sequence'); const gulp = require('gulp'); const notify = require('gulp-notify'); const source = require('vinyl-source-stream'); @@ -15,7 +24,7 @@ const bower = require('gulp-bower'); /** - * STYLES + * Stylesheet task. */ const stylesRootDir = './src/styles/'; const stylesDestDir = './build/styles/'; @@ -34,7 +43,7 @@ gulp.task('styles', function () { /** - * SCRIPTS + * Script task. */ const scriptsRootDir = './src/scripts/'; const scriptsDestDir = './build/scripts/'; @@ -59,7 +68,7 @@ gulp.task('scripts', function () { /** - * TYPESCRIPT DEFINITIONS + * TypeScript definitions. */ gulp.task("typings", function () { return gulp.src("./typings.json") @@ -69,7 +78,7 @@ gulp.task("typings", function () { /** - * HTML + * HTML task. */ const htmlRootDir = './src/'; const htmlDestDir = './build/'; @@ -88,7 +97,7 @@ gulp.task('html', function () { /** - * IMAGES + * Images task. */ const imagesRootDir = './src/img/'; const imagesDestDir = './build/img/'; @@ -103,7 +112,7 @@ gulp.task('images', function () { /** - * CLEAN + * Clean task. */ gulp.task('clean', function () { return del(['./build']); @@ -111,7 +120,7 @@ gulp.task('clean', function () { /** - * BOWER + * Bower task. */ gulp.task('bower', function () { return bower({cmd: 'install'}, ['--allow-root']) @@ -120,15 +129,15 @@ gulp.task('bower', function () { /** - * DEFAULT TASK + * Default build task. */ -gulp.task('default', ['clean', 'typings'], function () { - gulp.start('styles', 'bower', 'scripts', 'html', 'images'); +gulp.task('default', function () { + runSequence('clean', 'typings', 'styles', 'bower', 'scripts', 'html', 'images'); }); /** - * WATCH + * Watch task. */ gulp.task('watch', ['default'], function () { gulp.watch(stylesRootDir + '**/*.less', ['styles']); -- cgit v1.2.3 From 875a9c9e55b929eb29aac31b46b3f6b0108737d1 Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Wed, 25 Jan 2017 22:56:28 +0100 Subject: Add config file option to gulp build process --- gulpfile.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++------ package.json | 1 + 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 325bc8b7..fb7605cc 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,27 +2,55 @@ * Build file for the frontend codebase of OpenDC. * * Usage: - * $ gulp config.json # for a single build - * $ gulp watch config.json # to run once, watch for changes, and rebuild when something changed + * $ gulp --config=config.json # for a single build + * $ gulp watch --config=config.json # to run once, watch for changes, and rebuild when something changed */ 'use strict'; -const runSequence = require('run-sequence'); +const argv = require('yargs').argv; + const gulp = require('gulp'); const notify = require('gulp-notify'); +const gulpUtil = require('gulp-util'); +const rename = require('gulp-rename'); +const replace = require('gulp-replace'); +const del = require('del'); +const runSequence = require('run-sequence'); const source = require('vinyl-source-stream'); const es = require('event-stream'); const less = require('gulp-less'); const browserify = require('browserify'); const tsify = require('tsify'); const gulpTypings = require("gulp-typings"); -const rename = require('gulp-rename'); const processHTML = require('gulp-processhtml'); -const del = require('del'); const bower = require('gulp-bower'); +/** + * Checks whether the configuration file is specified and reads its contents. + * + * @throws an Exception if the config file could not be found or read (logs appropriately to the console) + * @returns {Object} the config file contents. + */ +function getConfigFile() { + const configFilePath = argv.config; + + if (configFilePath === undefined) { + gulpUtil.log(gulpUtil.colors.red('Config file argument missing\n'), "Usage:\n" + + " $ gulp --config=config.json"); + throw new Exception(); + } + + try { + return require('./' + configFilePath); + } catch (error) { + gulpUtil.log(gulpUtil.colors.red('Config file could not be read'), error); + throw new Exception(); + } +} + + /** * Stylesheet task. */ @@ -89,7 +117,10 @@ const htmlFilePaths = htmlFileNames.map(function (fileName) { }); gulp.task('html', function () { + const configFile = getConfigFile(); + return gulp.src(htmlFilePaths) + .pipe(replace('GOOGLE_OAUTH_CLIENT_ID', configFile.GOOGLE_OAUTH_CLIENT_ID)) .pipe(processHTML()) .pipe(gulp.dest(htmlDestDir)) .pipe(notify({message: 'HTML task complete', onLast: true})); @@ -132,6 +163,11 @@ gulp.task('bower', function () { * Default build task. */ gulp.task('default', function () { + try { + getConfigFile(); + } catch (error) { + return; + } runSequence('clean', 'typings', 'styles', 'bower', 'scripts', 'html', 'images'); }); @@ -139,7 +175,15 @@ gulp.task('default', function () { /** * Watch task. */ -gulp.task('watch', ['default'], function () { +gulp.task('watch', function () { + try { + getConfigFile(); + } catch (error) { + return; + } + + runSequence('default'); + gulp.watch(stylesRootDir + '**/*.less', ['styles']); gulp.watch(scriptsRootDir + '**/*.ts', ['scripts']); gulp.watch(htmlRootDir + '**/*.html', ['html']); diff --git a/package.json b/package.json index 35f4790c..f0ab12b6 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "gulp-rename": "^1.2.2", "gulp-replace": "^0.5.4", "gulp-typings": "^2.0.4", + "gulp-util": "^3.0.8", "jquery": "^3.1.0", "jquery-mousewheel": "^3.1.13", "jquery.easing": "^1.4.1", -- cgit v1.2.3 From f9fbf70170421fc5e02b95923ff137e0234cad69 Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Wed, 25 Jan 2017 23:06:18 +0100 Subject: Improve gulp config option handling --- gulpfile.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index fb7605cc..941b1119 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -34,16 +34,23 @@ const bower = require('gulp-bower'); * @returns {Object} the config file contents. */ function getConfigFile() { - const configFilePath = argv.config; + const configInput = argv.config; - if (configFilePath === undefined) { - gulpUtil.log(gulpUtil.colors.red('Config file argument missing\n'), "Usage:\n" + - " $ gulp --config=config.json"); + if (configInput === undefined) { + gulpUtil.log(gulpUtil.colors.red('Config file argument missing\n'), 'Usage:\n' + + ' $ gulp --config=config.json'); throw new Exception(); } try { - return require('./' + configFilePath); + let configFilePath; + if (configInput.indexOf('/') === -1) { + configFilePath = './' + configInput; + } else { + configFilePath = configInput; + } + + return require(configFilePath); } catch (error) { gulpUtil.log(gulpUtil.colors.red('Config file could not be read'), error); throw new Exception(); @@ -83,7 +90,7 @@ const scriptsFilePaths = scriptsFileNames.map(function (fileName) { }); gulp.task('scripts', function () { - var tasks = scriptsFilePaths.map(function (entry, index) { + const tasks = scriptsFilePaths.map(function (entry, index) { return browserify({entries: [entry]}) .plugin(tsify, {insertGlobals: true}) .bundle() -- cgit v1.2.3 From edbef77114dfde33524dccb22d27144570299372 Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Thu, 26 Jan 2017 13:41:13 +0100 Subject: Add config instructions to README --- README.md | 4 +++- sample_config.json | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 sample_config.json diff --git a/README.md b/README.md index 22a173ae..84ed0e99 100644 --- a/README.md +++ b/README.md @@ -14,5 +14,7 @@ Run the following commands from this directory to fetch dependencies and compile ``` $ yarn -$ gulp +$ gulp --config=config.json ``` + +**Note:** You need to replace `config.json` with the name / path of a real config file. This config file can be created by making a copy of the `sample_config.json` template and replacing the entries with your setup data. Make sure not to check this new config file into the VCS, as it is unique to each deployment situation. diff --git a/sample_config.json b/sample_config.json new file mode 100644 index 00000000..628476ed --- /dev/null +++ b/sample_config.json @@ -0,0 +1,3 @@ +{ + "GOOGLE_OAUTH_CLIENT_ID": "the-google-oauth-client-id" +} -- cgit v1.2.3