Created
July 12, 2014 21:26
-
-
Save kentcdodds/eb4e6610e5cbd48aa98e to your computer and use it in GitHub Desktop.
Loading Scripts for AngularJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var _ = require('lodash-node'); | |
var glob = require('glob'); | |
var address = require('address'); | |
module.exports = function(env) { | |
'use strict'; | |
var topScripts = [ | |
'bower_components/angular/angular.js' | |
]; | |
if (/local/.test(env)) { | |
topScripts.push('non_bower_components/MinFaker.js'); | |
} | |
var styles = _.union([ | |
'non_bower_components/bootstrap-theme.min.css', | |
'bower_components/font-awesome/css/font-awesome.min.css', | |
'bower_components/toastr/toastr.min.css' | |
], | |
getFilesInPath('public/styles/*.css', 'public/')); | |
var scripts = _.union([ | |
// non angular related stuff | |
'bower_components/jquery/dist/jquery.js', | |
'bower_components/lodash/dist/lodash.js', | |
'bower_components/moment/moment.js', | |
'bower_components/toastr/toastr.min.js', | |
'bower_components/firebase/firebase.js', | |
'bower_components/firebase-simple-login/firebase-simple-login.js', | |
// extra angular stuff from the core team | |
// angular-ui | |
'bower_components/angular-ui-router/release/angular-ui-router.js', | |
'bower_components/angular-bootstrap/ui-bootstrap-tpls.js', | |
// other angular mods | |
'non_bower_components/Scope.SafeApply.min.js', | |
'bower_components/angularfire/angularfire.js' | |
], | |
// diviggle stuff | |
// common components first | |
getSection('components/dv.common/constants'), | |
getSection('components/dv.common/services'), | |
getSection('components/dv.common/models'), | |
getSection('components/dv.common/filters'), | |
getSection('components/dv.common/directives'), | |
getSection('components/dv.common'), | |
// web components | |
getSection('components/dv.web/constants'), | |
getSection('components/dv.web/directives'), | |
getSection('components/dv.web/services'), | |
getSection('components/dv.web')); | |
var data = { | |
onDev: false, | |
BASE_URL: 'http://www.diviggle.com/', | |
FBAPI: 'https://diviggle.firebaseio.com/', | |
topScripts: topScripts, | |
stylesheets: styles, | |
scripts: scripts, | |
resourcePrefix: '/' | |
}; | |
if (/local/.test(env)) { | |
data.onDev = true; | |
data.BASE_URL = 'http://localhost:8000/'; | |
data.FBAPI = 'https://diviggle.firebaseio.com/'; | |
scripts.push('one-off/long-errors.js'); | |
} | |
return data; | |
// FUNCTIONS | |
function getFilesInPath(pattern, removePrefix) { | |
var files = glob.sync(pattern); | |
if (removePrefix) { | |
_.each(files, function (file, num) { | |
files[num] = file.substring(removePrefix.length); | |
}); | |
} | |
return files; | |
} | |
function getSection(name) { | |
var prefix = 'public/'; | |
var appJs = getFilesInPath(prefix + name + '/app.js', prefix); | |
var otherJsFiles = getFilesInPath(prefix + name + '/**/*.js', prefix); | |
return _.union(appJs, otherJsFiles); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(grunt) { | |
'use strict'; | |
// Project configuration. | |
grunt.initConfig({ | |
jade: { | |
local: { | |
options: { | |
data: function() { | |
return require('./jade/getIndexData')('local'); | |
} | |
}, | |
files: { | |
'public/index.html': ['jade/index.jade'] | |
} | |
} | |
}, | |
watch: { | |
jade: { | |
files: ['jade/index.jade', 'Gruntfile.js', 'jade/getIndexData.js'], //Unfortunately, I haven't found a way to watch for file adds/removes... | |
tasks: 'jade' | |
} | |
} | |
}); | |
grunt.loadNpmTasks('grunt-contrib-jade'); | |
grunt.loadNpmTasks('grunt-contrib-watch'); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This file is generated from index.jade | |
doctype html | |
html(lang="en", ng-app="dv.web", ng-controller="MainCtrl", ng-class="{'auth': authenticated, 'anon': !authenticated, 'small-screen': smallScreen}") | |
head | |
// create global DV object | |
script. | |
window.DV = {}; | |
window.DV.BASE_URL = '#{BASE_URL}'; | |
window.DV.FBAPI = '#{FBAPI}'; | |
window.DV.onDev = #{onDev}; | |
if onDev | |
script. | |
console.log('on development'); | |
script. | |
(function() { | |
var htmlElement = document.getElementsByTagName('html')[0]; | |
var background = 'components/dv.common/images/login-backgrounds/bg' + Math.floor(Math.random() * 19) + '.jpg'; | |
htmlElement.style.background = 'url("' + background + '") no-repeat center center fixed'; | |
htmlElement.style['background-size'] = 'cover'; | |
})(); | |
meta(charset="utf-8") | |
meta(http-equiv="X-UA-Compatible", content="IE=edge,chrome=1") | |
title(ng-bind="title") Diviggle | |
meta(name="viewport", content="height=device-height, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no") | |
// load stylsheets | |
for href in stylesheets | |
link(rel="stylesheet", href="#{resourcePrefix}#{href}") | |
// load critical scripts | |
for script in topScripts | |
script(src="#{resourcePrefix}#{script}") | |
body | |
div(ui-view) | |
// load other scripts | |
for script in scripts | |
script(src="#{resourcePrefix}#{script}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment