Skip to content

Commit

Permalink
add support for concatenated production js (coffee not updated yet); …
Browse files Browse the repository at this point in the history
…add test spec and helper; fix paths
  • Loading branch information
ahamid committed Sep 18, 2012
1 parent 8d8fade commit 7843508
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 56 deletions.
4 changes: 2 additions & 2 deletions grunt.js
Expand Up @@ -9,7 +9,7 @@ module.exports = function(grunt) {
prefix: "{%="
},
js: {
src: ["tasks/project/root/tasks/**/*.js" ],
src: ["tasks/init/project/root/app/js/**/*.js" ],
dest: 'tmp/js',
variables: { " js_safe_name %}": '__tmp_app' },
prefix: "{%="
Expand Down Expand Up @@ -121,7 +121,7 @@ module.exports = function(grunt) {
// Default task.
grunt.registerTask("build:coffee", "replace:coffee coffeelint coffee lint");
grunt.registerTask("build:js", "replace:js lint");
grunt.registerTask("diffjs", "exec:diffjs");
grunt.registerTask("diffjs", "replace:js replace:coffee coffee exec:diffjs");
grunt.registerTask("gen_js_proj", "clean:js_proj generate_js_proj");
grunt.registerTask("gen_cs_proj", "clean:cs_proj generate_cs_proj");
grunt.registerTask("test_js_proj", "gen_js_proj exec:js_proj_jasmine");
Expand Down
2 changes: 1 addition & 1 deletion tasks/init/project/root/app/coffee/files.coffee
@@ -1,4 +1,4 @@
# {%= name %} dependecies
# {%= js_safe_name %} {%= name %} dependecies
files = [
# vendor
"js/vendor/jquery.min"
Expand Down
1 change: 1 addition & 0 deletions tasks/init/project/root/app/coffee/templates.coffee
@@ -0,0 +1 @@
# {%= js_safe_name %}
99 changes: 58 additions & 41 deletions tasks/init/project/root/app/js/files.js
Expand Up @@ -3,44 +3,61 @@ if (typeof {%= js_safe_name %} === "undefined") {
var {%= js_safe_name %} = this.{%= js_safe_name %} = {};
}

// {%= name %} dependecies
{%= js_safe_name %}.files = [
// vendor
"js/vendor/jquery.min.js",
"js/vendor/jquery.mobile.router.min.js",
"js/vendor/underscore-min.js",
"js/vendor/backbone.js",
"js/templates.js",

// config
"js/config/config.js",
"js/config/envs/dev.js",

// add your app dependecies here

// helpers
"js/helpers/render.js",

// models

// collections

// views

// app
"js/router.js",
"js/app.js",
"js/init.js",

// load jquery mobile last
"js/vendor/jquery.mobile-1.1.0.min.js"
];

// load all
if (typeof $script !== "undefined") {
$script.order({%= js_safe_name %}.files);
}

if (typeof exports !== 'undefined') {
module.exports = {%= js_safe_name %}.files;
}
(function(app) {

function getUrlParams () {
var vars = {};
window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value.split("#")[0];
});
return vars;
}

// {%= name %} dependecies
app.files = function files(env) {
if (!env) env = "dev";

if (env == "prod") {
return "asset/app.js";
} else return [
// vendor
"js/vendor/jquery.min.js",
"js/vendor/jquery.mobile.router.min.js",
"js/vendor/underscore-min.js",
"js/vendor/backbone.js",
"js/templates.js",

// config
"js/config/config.js",
"js/config/envs/" + env + ".js",

// add your app dependecies here

// helpers
"js/helpers/render.js",

// models

// collections

// views

// app
"js/router.js",
"js/app.js",
"js/init.js",

// load jquery mobile last
"js/vendor/jquery.mobile-1.1.0.js"
];
};

// load all
if (typeof $script !== "undefined") {
$script.order(app.files(getUrlParams().env || "dev"));
}

if (typeof exports !== 'undefined') {
module.exports = app.files;
}
})({%= js_safe_name %})
28 changes: 16 additions & 12 deletions tasks/init/project/root/grunt.js
Expand Up @@ -4,24 +4,28 @@ var path = require('path');

module.exports = function (grunt) {

function resolve_js_files() {
function all_js() {
try {
return require('./app/js/files.js').map(function (file) {
if (file == "js/config/envs/dev.js") {
file = "js/config/envs/prod.js";
}
return require('./app/js/files.js')().map(function (file) {
return "app/" + file;
});
} catch (e) {
return []
}
}

function app_js() {
return grunt.utils._.reject(all_js(), function(path) {
return path.lastIndexOf("app/js/vendor/", 0) === 0 ||
path.lastIndexOf("phonegap/", 0) === 0;
});
}

// load js paths
var cfgPath = "tasks/cfg";
var jsFiles = resolve_js_files();
var jsFiles = all_js();

jsFiles.unshift('phonegap/iphone/www/cordova-1.7.0.js');
//jsFiles.unshift('phonegap/iphone/www/cordova-1.7.0.js');

var cfg = {
js: {
Expand Down Expand Up @@ -56,7 +60,7 @@ module.exports = function (grunt) {
},

lint: {
files: '<config:js.files>'
files: app_js()
},

jshint: {
Expand Down Expand Up @@ -95,12 +99,12 @@ module.exports = function (grunt) {

jasmine: {
src: '<config:js.files>',
specs : [ '**/*_spec.js' ],
helpers : 'spec/unit/helpers/**/*.js'
specs : [ 'specs/unit/*_spec.js' ],
helpers : 'specs/unit/helpers/**/*.js'
},

jasmine_node: {
project_root: "spec/integration",
project_root: "specs/integration",
},

// tasks configs
Expand Down Expand Up @@ -164,6 +168,6 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-coffeelint');
grunt.loadNpmTasks('grunt-jasmine-runner');
grunt.loadNpmTasks('grunt-jasmine-node');
grunt.registerTask('default', 'coffeelint coffee jst mincss tmplmin');
grunt.registerTask('default', 'coffeelint coffee jst mincss tmplmin concat');
grunt.registerTask('test', 'default jasmine-server')
}
5 changes: 5 additions & 0 deletions tasks/init/project/root/specs/unit/helpers/uihelper.js
@@ -0,0 +1,5 @@
$(function () {
// jquery.mobile adds this element to jasmine runner which makes
// specs invisibile so just hide it
$('.ui-page-active, .ui-loader').hide();
});
5 changes: 5 additions & 0 deletions tasks/init/project/root/specs/unit/script_load_spec.js
@@ -0,0 +1,5 @@
describe("script loading", function() {
it("app namespace should be present", function() {
expect(test_project_js).toBeDefined();
})
});

0 comments on commit 7843508

Please sign in to comment.