diff --git a/Gruntfile.js b/Gruntfile.js index ad61089d..de0a9318 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -24,11 +24,53 @@ module.exports = function (grunt) { grunt.loadNpmTasks('grunt-html2js'); grunt.loadNpmTasks('grunt-contrib-connect'); + /** * Load in our build configuration file. */ var userConfig = require('./build.config.js'); + + /** + * Process the build option. + */ + var development = grunt.option('development') === true, + staging = grunt.option('staging') === true, + production = grunt.option('production') === true, + sumBuildOptions = development + staging + production; + + // if none set, set default to prod + if (sumBuildOptions === 0) { + if (grunt.cli.tasks && grunt.cli.tasks.length > 0) { + grunt.log.writeln("No build option selected, setting default to ***development***"); + development = true; + } + else { + grunt.log.writeln("No build option selected and no task given, setting default to ***production***"); + production = true; + } + sumBuildOptions = 1; + } + + if (sumBuildOptions !== 1) { + grunt.log.error("More than one build option set! cannot have multiple build options."); + throw "More than one build option set! cannot have multiple build options."; + } + + if (development) { + grunt.log.ok("Development build selected"); + userConfig.build_configs.current = userConfig.build_configs.development; + } + if (staging) { + grunt.log.ok("Staging build selected"); + userConfig.build_configs.current = userConfig.build_configs.staging; + } + if (production) { + grunt.log.ok("Production build selected"); + userConfig.build_configs.current = userConfig.build_configs.production; + } + + /** * This is the configuration object Grunt uses to give each plugin its * instructions. @@ -126,6 +168,21 @@ module.exports = function (grunt) { ] }, build_appjs: { + options : { + processContent : function(content, srcPath) { + // if srcPath contain .tpl.js + // for now since the angular templates use tpl as well, + // we'll cheat and just use a direct file reference + var bc = grunt.config('build_configs'); + if (srcPath === bc.configFile) { + + // then process as template! + return grunt.template.process(content, {data: bc}); + } + + return content; + } + }, files: [ { src: [ '<%= app_files.js %>' ], @@ -625,6 +682,7 @@ module.exports = function (grunt) { }; + grunt.initConfig(grunt.util._.extend(taskConfig, userConfig)); /** @@ -698,6 +756,7 @@ module.exports = function (grunt) { process: function (contents, path) { return grunt.template.process(contents, { data: { + build_configs: grunt.config('build_configs'), scripts: jsFiles, styles: cssFiles, mainStyle: mainCss, diff --git a/README.md b/README.md index 5d0da6e3..8d361ecb 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ cd to your cloned directory and then $ grunt watch -and browse to the karma tab first `localhost:` (see output for port number), then `localhost:8080`. +and browse to the karma tab first `localhost:` (see output for port number), then `localhost:8080` after the karma unit tests have run. To add new bower packages @@ -27,9 +27,23 @@ You'll need to configure `build.config.js` when adding any new grunt packages to ## To build: - $ grunt compile + $ grunt and copy the artefacts from the `/bin` directory. +The `grunt` runner will accept three build options that will rewrite important variables. + + - development: `$ grunt --development` + - staging: `$ grunt --staging` + - production (the default): `$ grunt --production` + +These variables are configured in `build_configs.js`. + +--- +# Licence +Apache License, Version 2.0 + +--- + Based off the [ng-boilerplate](https://github.com/ngbp/ng-boilerplate) library. \ No newline at end of file diff --git a/build.config.js b/build.config.js index 72cb8e04..9a1e7b11 100644 --- a/build.config.js +++ b/build.config.js @@ -1,88 +1,109 @@ +var appConfigFile = 'src/baw.configuration.tpl.js'; + /** * This file/module contains all configuration for the build process. */ module.exports = { - /** - * The `build_dir` folder is where our projects are compiled during - * development and the `compile_dir` folder is where our app resides once it's - * completely built. - */ - build_dir: 'build', - compile_dir: 'bin', + /** + * The `build_dir` folder is where our projects are compiled during + * development and the `compile_dir` folder is where our app resides once it's + * completely built. + */ + build_dir: 'build', + compile_dir: 'bin', + + build_configs: { + configFile: appConfigFile, + development: { + apiRoot: "http://staging.ecosounds.org", + siteRoot: "localhost:8080", + siteDir: "/" + }, + staging: { + apiRoot: "http://staging.ecosounds.org", + siteRoot: "http://staging.ecosounds.org/system/listen_to", + siteDir: "/system/listen_to/" + }, + production: { + apiRoot: "http://ecosounds.org", + siteRoot: "http://ecosounds.org/????", + siteDir: "????" + } + }, + + /** + * This is a collection of file patterns that refer to our app code (the + * stuff in `src/`). These file paths are used in the configuration of + * build tasks. `js` is all project javascript, less tests. `ctpl` contains + * our reusable components' (`src/common`) template HTML files, while + * `atpl` contains the same, but for our app's code. `html` is just our + * main HTML file, `less` is our main stylesheet, and `unit` contains our + * app's unit tests. + */ + app_files: { + js: [ 'src/**/*.js', '!src/**/*.spec.js', '!src/assets/**/*.js' ], + jsunit: [ 'src/**/*.spec.js' ], - /** - * This is a collection of file patterns that refer to our app code (the - * stuff in `src/`). These file paths are used in the configuration of - * build tasks. `js` is all project javascript, less tests. `ctpl` contains - * our reusable components' (`src/common`) template HTML files, while - * `atpl` contains the same, but for our app's code. `html` is just our - * main HTML file, `less` is our main stylesheet, and `unit` contains our - * app's unit tests. - */ - app_files: { - js: [ 'src/**/*.js', '!src/**/*.spec.js', '!src/assets/**/*.js' ], - jsunit: [ 'src/**/*.spec.js' ], - - coffee: [ 'src/**/*.coffee', '!src/**/*.spec.coffee' ], - coffeeunit: [ 'src/**/*.spec.coffee' ], + coffee: [ 'src/**/*.coffee', '!src/**/*.spec.coffee' ], + coffeeunit: [ 'src/**/*.spec.coffee' ], - atpl: [ 'src/app/**/*.tpl.html' ], - ctpl: [ 'src/common/**/*.tpl.html' ], + atpl: [ 'src/app/**/*.tpl.html' ], + ctpl: [ 'src/common/**/*.tpl.html' ], - html: [ 'src/index.html'], - sass: [ 'src/sass/application.scss' ] - //less: 'src/less/main.less' - }, + html: [ 'src/index.html'], + sass: [ 'src/sass/application.scss' ] + //less: 'src/less/main.less' + }, - /** - * This is a collection of files used during testing only. - */ - test_files: { - js: [ - 'vendor/angular-mocks/angular-mocks.js' - ] - }, + /** + * This is a collection of files used during testing only. + */ + test_files: { + js: [ + 'vendor/angular-mocks/angular-mocks.js' + ] + }, - /** - * This is the same as `app_files`, except it contains patterns that - * reference vendor code (`vendor/`) that we need to place into the build - * process somewhere. While the `app_files` property ensures all - * standardized files are collected for compilation, it is the user's job - * to ensure non-standardized (i.e. vendor-related) files are handled - * appropriately in `vendor_files.js`. - * - * The `vendor_files.js` property holds files to be automatically - * concatenated and minified with our project source files. - * - * The `vendor_files.css` property holds any CSS files to be automatically - * included in our app. - * - * The `vendor_files.assets` property holds any assets to be copied along - * with our app's assets. This structure is flattened, so it is not - * recommended that you use wildcards. - */ - vendor_files: { - js: [ - 'vendor/jquery/jquery.js', - // TODO: THIS IS TERRIBLE! REMOVE UI ASAP... OR AT LEAST ONLY INCLUDE RELEVANT COMPONENTS - 'vendor/jquery-ui/ui/jquery-ui.js', - 'vendor/momentjs/moment.js', - 'vendor/angular/angular.js', - 'vendor/angular-route/angular-route.js', - 'vendor/angular-resource/angular-resource.js', - 'vendor/angular-bootstrap/ui-bootstrap-tpls.min.js', - 'vendor/placeholders/angular-placeholders-0.0.1-SNAPSHOT.min.js', - 'vendor/angular-ui-router/release/angular-ui-router.js', - 'vendor/angular-ui-utils/modules/route/route.js', - // TODO: the following line is dodgy and bloats the app - 'vendor/angular-ui-utils/modules/**/*.js', '!vendor/angular-ui-utils/modules/**/*Spec.js', - 'vendor/modernizr/modernizr.js', - 'vendor/underscore/underscore.js' - ], - css: [ - 'vendor/hint.css/hint.css' - ], - assets: [ - ] - } + /** + * This is the same as `app_files`, except it contains patterns that + * reference vendor code (`vendor/`) that we need to place into the build + * process somewhere. While the `app_files` property ensures all + * standardized files are collected for compilation, it is the user's job + * to ensure non-standardized (i.e. vendor-related) files are handled + * appropriately in `vendor_files.js`. + * + * The `vendor_files.js` property holds files to be automatically + * concatenated and minified with our project source files. + * + * The `vendor_files.css` property holds any CSS files to be automatically + * included in our app. + * + * The `vendor_files.assets` property holds any assets to be copied along + * with our app's assets. This structure is flattened, so it is not + * recommended that you use wildcards. + */ + vendor_files: { + js: [ + 'vendor/jquery/jquery.js', + // TODO: THIS IS TERRIBLE! REMOVE UI ASAP... OR AT LEAST ONLY INCLUDE RELEVANT COMPONENTS + 'vendor/jquery-ui/ui/jquery-ui.js', + 'vendor/momentjs/moment.js', + 'vendor/angular/angular.js', + 'vendor/angular-route/angular-route.js', + 'vendor/angular-resource/angular-resource.js', + 'vendor/angular-bootstrap/ui-bootstrap-tpls.min.js', + 'vendor/placeholders/angular-placeholders-0.0.1-SNAPSHOT.min.js', + 'vendor/angular-ui-router/release/angular-ui-router.js', + 'vendor/angular-ui-utils/modules/route/route.js', + // TODO: the following line is dodgy and bloats the app + 'vendor/angular-ui-utils/modules/**/*.js', '!vendor/angular-ui-utils/modules/**/*Spec.js', + 'vendor/modernizr/modernizr.js', + 'vendor/underscore/underscore.js' + ], + css: [ + 'vendor/hint.css/hint.css' + ], + assets: [ + ] + } }; diff --git a/src/app/listen/listen.js b/src/app/listen/listen.js index 022daea1..c3cd5686 100644 --- a/src/app/listen/listen.js +++ b/src/app/listen/listen.js @@ -76,7 +76,7 @@ angular.module('bawApp.listen', []) } $scope.model.media.availableImageFormats[imgKeys[0]].url = - paths.joinFragments(paths.api.root, $scope.model.media.availableImageFormats[imgKeys[0]].url); + paths.joinFragments(paths.api.root, $scope.model.media.availableImageFormats[imgKeys[0]].url); $scope.model.media.spectrogram = $scope.model.media.availableImageFormats[imgKeys[0]]; //$scope.model.media.spectrogramBaseUrl.format($scope.model.media); + "?" + authToken; @@ -236,15 +236,26 @@ angular.module('bawApp.listen', []) stepBy = CHUNK_DURATION_SECONDS; } + var baseLink = {recordingId: recordingId}; + if (linkType === "previous") { + var lowerBound = ($routeParams.start - stepBy); + if (lowerBound === 0) { + baseLink.end = lowerBound + stepBy; + } + else if (lowerBound > 0) { + baseLink.start = lowerBound; + baseLink.end = lowerBound + stepBy; + } + else { + // noop + } + var uriPrev = $url.formatUri( paths.site.ngRoutes.listen, - { - recordingId: recordingId, - start: ($routeParams.start - stepBy), - end: ($routeParams.end - stepBy) - }); + baseLink); return uriPrev; + } else if (linkType === "next") { var uriNext = $url.formatUri( @@ -258,7 +269,8 @@ angular.module('bawApp.listen', []) } throw "Invalid link type specified in createNavigationHref"; - }; + } + ; $scope.clearSelected = function () { //$scope.model.selectedAudioEvents.length = 0; @@ -347,4 +359,5 @@ angular.module('bawApp.listen', []) } - }]); + }]) +; diff --git a/src/app/paths.js b/src/baw.configuration.tpl.js similarity index 97% rename from src/app/paths.js rename to src/baw.configuration.tpl.js index cf2b50b9..b988eef3 100644 --- a/src/app/paths.js +++ b/src/baw.configuration.tpl.js @@ -12,7 +12,7 @@ angular.module('bawApp.configuration', []) var paths = { api: { - root: "http://staging.ecosounds.org", + root: "<%= current.apiRoot %>", routes: { project: "/projects/{projectId}", site: "/projects/{projectId}/sites/{siteId}", @@ -43,7 +43,7 @@ angular.module('bawApp.configuration', []) } }, site: { - root: "localhost:8080", + root: "<%= current.siteRoot %>", // The following intentionally are not prefixed with a '/' files: { error404: 'error/error_404.tpl.html', diff --git a/src/index.html b/src/index.html index fa7ab00d..c31fd865 100644 --- a/src/index.html +++ b/src/index.html @@ -10,10 +10,10 @@ <% styles.forEach( function ( file ) { %> <% }); %> - + <% scripts.forEach( function ( file ) { %> - + <% }); %>