diff options
| -rw-r--r-- | README.md | 4 | ||||
| -rw-r--r-- | gulpfile.js | 90 | ||||
| -rw-r--r-- | package.json | 6 | ||||
| -rw-r--r-- | sample_config.json | 3 | ||||
| -rw-r--r-- | src/app.html | 3 | ||||
| -rw-r--r-- | src/index.html | 3 | ||||
| -rw-r--r-- | src/profile.html | 5 | ||||
| -rw-r--r-- | src/projects.html | 5 |
8 files changed, 92 insertions, 27 deletions
@@ -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/gulpfile.js b/gulpfile.js index 612decf6..941b1119 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,21 +1,65 @@ +/** + * Build file for the frontend codebase of OpenDC. + * + * Usage: + * $ 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 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'); /** - * STYLES + * 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 configInput = argv.config; + + if (configInput === undefined) { + gulpUtil.log(gulpUtil.colors.red('Config file argument missing\n'), 'Usage:\n' + + ' $ gulp --config=config.json'); + throw new Exception(); + } + + try { + 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(); + } +} + + +/** + * Stylesheet task. */ const stylesRootDir = './src/styles/'; const stylesDestDir = './build/styles/'; @@ -34,7 +78,7 @@ gulp.task('styles', function () { /** - * SCRIPTS + * Script task. */ const scriptsRootDir = './src/scripts/'; const scriptsDestDir = './build/scripts/'; @@ -46,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() @@ -59,7 +103,7 @@ gulp.task('scripts', function () { /** - * TYPESCRIPT DEFINITIONS + * TypeScript definitions. */ gulp.task("typings", function () { return gulp.src("./typings.json") @@ -69,7 +113,7 @@ gulp.task("typings", function () { /** - * HTML + * HTML task. */ const htmlRootDir = './src/'; const htmlDestDir = './build/'; @@ -80,7 +124,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})); @@ -88,7 +135,7 @@ gulp.task('html', function () { /** - * IMAGES + * Images task. */ const imagesRootDir = './src/img/'; const imagesDestDir = './build/img/'; @@ -103,7 +150,7 @@ gulp.task('images', function () { /** - * CLEAN + * Clean task. */ gulp.task('clean', function () { return del(['./build']); @@ -111,7 +158,7 @@ gulp.task('clean', function () { /** - * BOWER + * Bower task. */ gulp.task('bower', function () { return bower({cmd: 'install'}, ['--allow-root']) @@ -120,17 +167,30 @@ 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 () { + try { + getConfigFile(); + } catch (error) { + return; + } + runSequence('clean', 'typings', 'styles', 'bower', 'scripts', 'html', 'images'); }); /** - * WATCH + * 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 c45fcd9e..f0ab12b6 100644 --- a/package.json +++ b/package.json @@ -20,17 +20,21 @@ "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", + "gulp-util": "^3.0.8", "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" 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" +} 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 @@ <html lang="en"> <head> <meta charset="UTF-8"> - <meta name="google-signin-client_id" - content="184853849394-v89e96desio4dub3360vg32p1l4r3jqd.apps.googleusercontent.com"> + <meta name="google-signin-client_id" content="GOOGLE_OAUTH_CLIENT_ID"> <title>OpenDC</title> 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 @@ <meta property="og:locale" content="en_US"> <!-- Google Sign-in --> - <meta name="google-signin-client_id" - content="184853849394-v89e96desio4dub3360vg32p1l4r3jqd.apps.googleusercontent.com"> + <meta name="google-signin-client_id" content="GOOGLE_OAUTH_CLIENT_ID"> <!-- Set viewport --> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> 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 @@ <html lang="en"> <head> <meta charset="UTF-8"> - <meta name="google-signin-client_id" - content="184853849394-v89e96desio4dub3360vg32p1l4r3jqd.apps.googleusercontent.com"> + <meta name="google-signin-client_id" content="GOOGLE_OAUTH_CLIENT_ID"> <title>OpenDC - Profile</title> @@ -60,4 +59,4 @@ <script src="https://apis.google.com/js/platform.js?onload=gapiSigninButton" async defer></script> </body> -</html>
\ No newline at end of file +</html> 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 @@ <html lang="en"> <head> <meta charset="UTF-8"> - <meta name="google-signin-client_id" - content="184853849394-v89e96desio4dub3360vg32p1l4r3jqd.apps.googleusercontent.com"> + <meta name="google-signin-client_id" content="GOOGLE_OAUTH_CLIENT_ID"> <title>OpenDC - Projects</title> @@ -91,4 +90,4 @@ <script src="https://apis.google.com/js/platform.js?onload=gapiSigninButton" async defer></script> </body> -</html>
\ No newline at end of file +</html> |
