Skip to content

Commit

Permalink
Navbar updates and massive refactor of build system
Browse files Browse the repository at this point in the history
Using ngconstant module now to build constants into app in a more structured manner.
Templating is no longer required!

Updated the website's headers, footers, and other styles to match site new wide style.
Additionally added a new login widget to show the user's name and profile pic.
  • Loading branch information
atruskie committed Aug 15, 2015
1 parent fb481d0 commit 62ab956
Show file tree
Hide file tree
Showing 43 changed files with 841 additions and 648 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@ bin/
es6/
vendor/
src/assets/temp
.sass-cache
.sass-cache
*.generated*
111 changes: 85 additions & 26 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ module.exports = function (grunt) {
_ = require("lodash"),
sass = require("./node_modules/grunt-sass/node_modules/node-sass");

var _invalidateRequireCacheForFile = function(filePath){
delete require.cache[path.resolve(filePath)];
};

var requireNoCache = function(filePath){
_invalidateRequireCacheForFile(filePath);
return require(filePath);
};

/**
* Load required Grunt tasks. These are installed based on the versions listed
Expand All @@ -27,6 +35,7 @@ module.exports = function (grunt) {
grunt.loadNpmTasks("grunt-html2js");
grunt.loadNpmTasks("grunt-contrib-connect");
grunt.loadNpmTasks("grunt-babel");
grunt.loadNpmTasks("grunt-ng-constant");

/**
* Load in our build configuration file.
Expand Down Expand Up @@ -73,18 +82,18 @@ module.exports = function (grunt) {

if (development) {
grunt.log.ok("Development build selected");
userConfig.build_configs.current = userConfig.build_configs.development;
userConfig.build_configs.current = userConfig.build_configs.environments.development;
userConfig.build_configs.current.key = "development";
}
if (staging) {
grunt.log.ok("Staging build selected");
userConfig.build_configs.current = userConfig.build_configs.staging;
userConfig.build_configs.current = userConfig.build_configs.environments.staging;
userConfig.build_configs.current.key = "staging";
userConfig.usePhantomJs = true;
}
if (production) {
grunt.log.ok("Production build selected");
userConfig.build_configs.current = userConfig.build_configs.production;
userConfig.build_configs.current = userConfig.build_configs.environments.production;
userConfig.build_configs.current.key = "production";
userConfig.usePhantomJs = true;
}
Expand Down Expand Up @@ -177,6 +186,41 @@ module.exports = function (grunt) {
}
},

/**
* The `ngconstant` task allows us to embed environment settings as
* angular constant/value modules. We thus can avoid the need for templating
* javascript files.
*/
ngconstant: {
options: {
name: "bawApp.configuration",
serializerOptions: {
indent: " ",
quote: "\"",
no_trailing_comma: true
},
constants: function () {
var bc = grunt.config("build_configs"),
constantsFiles = grunt.config("constants_files"),
appEnvironment = _.merge({}, bc.current, bc.values);

var result = {
"conf.environment": appEnvironment
};

Object.keys(constantsFiles).forEach(function(key) {
var constantsModule = requireNoCache(constantsFiles[key]);

result[key] = constantsModule(appEnvironment);
});

return result;
},
dest: "src/baw.environment.generated.js"
},
build: {}
},

/**
* The `copy` task just copies files from A to B. We use it here to copy
* our project assets (images, fonts, etc.) and javascripts into
Expand Down Expand Up @@ -233,19 +277,19 @@ module.exports = function (grunt) {
},
build_appjs: {
options: {
process: 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.indexOf(bc.configFile) >= 0) {

// then process as template!
return grunt.template.process(content, {data: bc});
}

return content;
}
//process: 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.indexOf(bc.configFile) >= 0) {
//
// // then process as template!
// return grunt.template.process(content, {data: bc});
// }
//
// return content;
//}
},
files: [
{
Expand Down Expand Up @@ -293,7 +337,7 @@ module.exports = function (grunt) {
transpile_appjs: {
files: [
{
src: [ "<%= app_files.js %>", "<%= app_files.jsunit %>"],
src: ["<%= app_files.js %>", "<%= app_files.jsunit %>"],
dest: "<%= es6_dir %>",
cwd: ".",
expand: true,
Expand Down Expand Up @@ -338,6 +382,7 @@ module.exports = function (grunt) {
});
}()),
"buildConfig/module.prefix",
// "<%= build_dir %>/src/**/*generated.js",
"<%= build_dir %>/src/**/*.js",
"<%= html2js.app.dest %>",
"<%= html2js.common.dest %>",
Expand Down Expand Up @@ -373,11 +418,11 @@ module.exports = function (grunt) {
sassReal: {
options: {
functions: {
"image-url($img)": function(img, done) {
"image-url($img)": function (img, done) {
var cwd = process.cwd(),
bd = userConfig.build_dir,
imgPath = path.join(cwd, bd, "assets/img", img.getValue()),
// equivalent to "<%= build_configs.current.siteDir %>assets/img"
// equivalent to "<%= build_configs.current.siteDir %>assets/img"
sassPath = path.join(cwd, bd, "assets/styles"),
fullPath = path.join(
//userConfig.build_configs.current.siteDir,
Expand Down Expand Up @@ -414,7 +459,7 @@ module.exports = function (grunt) {
/**
* `jshint` defines the rules of our linter as well as which files we
* should check. This file, all javascript sources, and all our unit tests
* are linted based on the policies listed in `options`. But we can also
* are linted based on the policies listed in `.jshintrc`. But we can also
* specify exclusionary patterns by prefixing them with an exclamation
* point (!); this is useful when code comes from a third party but is
* nonetheless inside `src/`.
Expand All @@ -424,7 +469,8 @@ module.exports = function (grunt) {
jshintrc: ".jshintrc"
},
src: [
"<%= app_files.js %>"
"<%= app_files.js %>",
"!src/**/*.generated.js"
],
test: [
"<%= app_files.jsunit %>"
Expand Down Expand Up @@ -498,6 +544,7 @@ module.exports = function (grunt) {
dir: "<%= build_dir %>",
src: [
"<%= vendor_files.js %>",
//"<%= build_dir %>/src/**/*generated.js",
"<%= build_dir %>/src/**/*.js",
"<%= html2js.common.dest %>",
"<%= html2js.app.dest %>",
Expand Down Expand Up @@ -532,6 +579,7 @@ module.exports = function (grunt) {
"<%= vendor_files.js %>",
"<%= html2js.app.dest %>",
"<%= html2js.common.dest %>",
//"<%= build_dir %>/src/**/*generated.js",
"<%= test_files.js %>"
]
}
Expand Down Expand Up @@ -635,12 +683,22 @@ module.exports = function (grunt) {
*/
jssrc: {
files: [
"!src/**/*.generated.js",
"<%= app_files.js %>"
],
// recent modification: files are copied before unit tests are run!
tasks: ["jshint:src", "babel:transpile_appjs", "copy:build_appjs", "karma:unit:run" ]
tasks: ["jshint:src", "ngconstant:build", "babel:transpile_appjs", "copy:build_appjs", "karma:unit:run"]
},

jssrc2: {
files: [
"<%= app_files.specialjs %>",
],
// recent modification: files are copied before unit tests are run!
tasks: ["jshint:src", "ngconstant:build", "babel:transpile_appjs", "copy:build_appjs", "karma:unit:run"]
},


/**
* When assets are changed, copy them. Note that this will *not* copy new
* files, so this is probably not very useful.
Expand Down Expand Up @@ -721,7 +779,8 @@ module.exports = function (grunt) {
grunt.registerTask("build", [
"clean", "html2js", "jshint", "sass:build",
"concat:build_css", "copy:build_app_assets", "copy:build_vendor_assets",
"babel:transpile_appjs", "copy:build_appjs", "copy:build_vendorjs", "index:build", "karmaconfig",
"ngconstant:build", "babel:transpile_appjs", "copy:build_appjs",
"copy:build_vendorjs", "index:build", "karmaconfig",
"karma:continuous"
]);

Expand Down Expand Up @@ -777,7 +836,8 @@ module.exports = function (grunt) {
scripts: jsFiles,
styles: cssFiles,
mainStyle: mainCss,
version: grunt.config("pkg.version")
version: grunt.config("pkg.version"),
year: (new Date()).getFullYear()
}
});
}
Expand Down Expand Up @@ -814,8 +874,7 @@ module.exports = function (grunt) {
}



} else if(isSlashedA) {
} else if (isSlashedA) {
return 1;
} else if (isSlashedB) {
return -1;
Expand Down
10 changes: 9 additions & 1 deletion buildConfig/build.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ module.exports = {
*/
build_configs: require("./environmentSettings.json"),

constants_files: {
"conf.paths": "./src/baw.paths.nobuild.js",
"conf.constants": "./src/baw.constants.nobuild.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
Expand All @@ -31,8 +35,12 @@ module.exports = {
* app's unit tests.
*/
app_files: {
js: ["src/**/*.js", "!src/**/*.spec.js", "!src/assets/**/*.js"],
js: ["src/**/*.js",
"!src/**/*.spec.js",
"!src/assets/**/*.js",
"!src/**/*.nobuild.js"],
jsunit: ["src/**/*.spec.js"],
specialjs: ["src/**/*.nobuild.js"],

atpl: ["src/app/**/*.tpl.html"],
ctpl: ["src/common/**/*.tpl.html", "src/components/**/*.tpl.html"],
Expand Down
63 changes: 39 additions & 24 deletions buildConfig/environmentSettings.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
{
"keys": {
"googleMaps": ""
},
"configFile": "src/baw.configuration.tpl.js",
"development": {
"apiRoot": "http://staging.ecosounds.org",
"siteRoot": "http://localhost:8080",
"siteDir": "/",
"ga": {
"trackingId": ""
}
},
"staging": {
"apiRoot": "http://staging.EXAMPLE.org",
"siteRoot": "http://staging.EXAMPLE.org/system/listen_to",
"siteDir": "/system/listen_to/",
"ga": {
"trackingId": "<<PLACEHOLDER>>"
"environments" : {
"development": {
"apiRoot": "http://staging.ecosounds.org",
"siteRoot": "http://localhost:8080",
"siteDir": "/",
"ga": {
"trackingId": ""
}
},
"staging": {
"apiRoot": "http://staging.EXAMPLE.org",
"siteRoot": "http://staging.EXAMPLE.org/system/listen_to",
"siteDir": "/system/listen_to/",
"ga": {
"trackingId": "<<PLACEHOLDER>>"
}
},
"production": {
"apiRoot": "http://production.EXAMPLE.org",
"siteRoot": "http://production.EXAMPLE.org/system/listen_to",
"siteDir": "/system/listen_to/",
"ga": {
"trackingId": "<<PLACEHOLDER>>"
}
}
},
"production": {
"apiRoot": "http://production.EXAMPLE.org",
"siteRoot": "http://production.EXAMPLE.org/system/listen_to",
"siteDir": "/system/listen_to/",
"ga": {
"trackingId": "<<PLACEHOLDER>>"
"values": {
"keys": {
"googleMaps": ""
},
"brand": {
"name": "<<brand name here>>",
"title": "<<brand name here>> | Bioacoustic Workbench"
},
"content": {
"research": [
{
"innerText": "Example",
"url": "http://www.EXAMPLE.org/awebpage"
}
]
}
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"grunt-conventional-changelog": "^3.0",
"grunt-html2js": "~0.3.2",
"grunt-karma": "^0.12",
"grunt-ng-constant": "^1.1.0",
"grunt-sass": "^1.0.0",
"karma": "^0.13",
"karma-chrome-launcher": "~0.2",
Expand Down
Loading

0 comments on commit 62ab956

Please sign in to comment.