Skip to content

Commit

Permalink
Modded gruntfile to process baw.configuration.tpl.js
Browse files Browse the repository at this point in the history
Added options to grunt file that allow automatic rewriting of configuration files and path references for different environements.

Fixed a few bugs with the previous link on the listen page.
  • Loading branch information
atruskie committed Oct 8, 2013
1 parent a272cef commit 5d0b812
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 92 deletions.
59 changes: 59 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 %>' ],
Expand Down Expand Up @@ -625,6 +682,7 @@ module.exports = function (grunt) {

};


grunt.initConfig(grunt.util._.extend(taskConfig, userConfig));

/**
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cd to your cloned directory and then

$ grunt watch

and browse to the karma tab first `localhost:<port>` (see output for port number), then `localhost:8080`.
and browse to the karma tab first `localhost:<port>` (see output for port number), then `localhost:8080` after the karma unit tests have run.

To add new bower packages

Expand All @@ -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.
177 changes: 99 additions & 78 deletions build.config.js
Original file line number Diff line number Diff line change
@@ -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: [
]
}
};
29 changes: 21 additions & 8 deletions src/app/listen/listen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -258,7 +269,8 @@ angular.module('bawApp.listen', [])
}

throw "Invalid link type specified in createNavigationHref";
};
}
;

$scope.clearSelected = function () {
//$scope.model.selectedAudioEvents.length = 0;
Expand Down Expand Up @@ -347,4 +359,5 @@ angular.module('bawApp.listen', [])
}


}]);
}])
;
4 changes: 2 additions & 2 deletions src/app/paths.js → src/baw.configuration.tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down Expand Up @@ -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',
Expand Down
Loading

0 comments on commit 5d0b812

Please sign in to comment.