Skip to content

Commit

Permalink
Move all build related boilerplate into separate npm module
Browse files Browse the repository at this point in the history
  • Loading branch information
vlizard committed Aug 12, 2014
1 parent 1c551a3 commit 47b7db2
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 397 deletions.
28 changes: 0 additions & 28 deletions .jshintrc

This file was deleted.

241 changes: 2 additions & 239 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,241 +1,4 @@
module.exports = function(grunt) {
"use strict";

var shared = require("./grunt/lib.js").init(grunt);

grunt.loadTasks("grunt/tasks");
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-concat");
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("sphere");

grunt.registerTask("default", ["check-environment:" + shared.config("env"), "jshint", "clean:all", "build"]);

var sources = {
"js": [
"app.js",
"controls/**/*.js",
"third-party/**/*.js",
"dashboard.js",
"dashboard/*.js",
"dashboard/**/*.js"
],
"images": [
"images/**"
],
"demo": [
"demo.html",
"demo-dev.html"
]
};

var config = {
"dirs": {
"build": "build",
"dest": "web",
"dist": "web"
},
"sources": sources,
"pkg": grunt.file.readJSON("package.json"),
"banner":
"/**\n" +
" * Copyright 2012-<%= grunt.template.today(\"UTC:yyyy\") %> <%= pkg.author.name %>.\n" +
" * Licensed under the Apache License, Version 2.0 (the \"License\");\n" +
" * you may not use this file except in compliance with the License.\n" +
" * You may obtain a copy of the License at\n" +
" *\n" +
" * http://www.apache.org/licenses/LICENSE-2.0\n" +
" *\n" +
" * Unless required by applicable law or agreed to in writing, software\n" +
" * distributed under the License is distributed on an \"AS IS\" BASIS,\n" +
" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" +
" * See the License for the specific language governing permissions and\n" +
" * limitations under the License.\n" +
" *\n" +
" * Version: <%= pkg.version %> (<%= grunt.template.today(\"UTC:yyyy-mm-dd HH:MM:ss Z\") %>)\n" +
" */\n",
"clean": {
"build": [
"<%= dirs.build %>/*"
],
"plugins": [
"<%= dirs.build %>/plugins"
],
"all": [
"<%= dirs.dist %>/*",
"<%= clean.build %>"
]
},
"wrap": {
"options": {
"header": [
"(function(jQuery) {",
"var $ = jQuery;",
""
],
"footer": [
"})(Echo.jQuery);"
]
},
"third-party": {
"files": [{
"expand": true,
"cwd": "<%= dirs.build %>",
"src": ["third-party/*"]
}]
}
},
"copy": {
"js": {
"src": "<%= sources.js %>",
"dest": "<%= dirs.build %>/"
},
"third-party": {
"src": "third-party/*.js",
"dest": "<%= dirs.build %>/"
},
"images": {
"src": "<%= sources.images %>",
"dest": "<%= dirs.build %>/"
},
"demo": {
"src": "<%= sources.demo %>",
"dest": "<%= dirs.build %>/"
},
"manifest": {
"src": "app-manifest.json",
"dest": "<%= dirs.build %>/"
},
"build": {
"options": {
"processContent": shared.replacePlaceholdersOnCopy,
"processContentExclude": "**/*.{png,jpg,jpeg,gif}"
},
"files": [{
"expand": true,
"cwd": "<%= dirs.build %>",
"src": ["**"],
"dest": "<%= dirs.dest %>"
}]
}
},
"concat": {
"options": {
"stripBanners": true,
"banner": "<%= banner %>"
},
"dashboard": {
"src": [
"<%= dirs.build %>/dashboard.js",
"<%= dirs.build%>/dashboard/list.js",
"<%= dirs.build%>/dashboard/item.js",
"<%= dirs.build%>/dashboard/**/*.js"
],
"dest": "<%= dirs.build %>/dashboard.js"
},
"app": {
"src": [
"<%= dirs.build %>/app.js",
"<%= dirs.build %>/controls/*.js",
"<%= dirs.build %>/third-party/**/*.js",
"<%= dirs.build %>/plugins/*.js"
],
"dest": "<%= dirs.build %>/app.js"
}
},
"uglify": {
"options": {
"report": grunt.option("verbose") ? "gzip" : "min"
},
"js": {
"files": [{
"expand": true,
"cwd": "<%= dirs.build %>",
"src": "<%= sources.js %>",
"dest": "<%= dirs.build %>"
}]
}
},
"jshint": {
"options": {
"jshintrc": ".jshintrc",
"ignores": ["third-party/**/*.js"]
},
"grunt": ["Gruntfile.js", "grunt/**/*.js"],
"sources": ["<%= sources.js %>"]
},
"release": {
"options": {
"environment": shared.config("env"),
"debug": shared.config("debug"),
"configFile": "config/release.json",
"location": shared.config("env") === "staging" ? "sandbox" : "cdn",
"remoteRoot": shared.config("env") === "staging" ? "/staging" : "",
"purgeTitle": "<%= pkg.name %>",
"purgePaths": [
"/apps/echo/topic-radar/v<%= pkg.versions.stable %>/"
]
},
"regular": {
"options": {
"deployTargets": {
"all": {
"src": "**",
"cwd": "<%= dirs.dist %>/",
"dest": "<%= release.options.remoteRoot %>/apps/echo/topic-radar/v<%= pkg.versions.stable %>/"
}
}
}
},
"purge": {
"options": {
"skipBuild": true
}
}
},
"watch": {
"src": {
"files": [
"<%= sources.js %>",
"<%= sources.demo %>",
"Gruntfile.js",
"grunt/**"
],
"tasks": ["default"],
"options": {
"interrupt": true
}
}
},
"check-environment": {
"options": {
"list": shared.config("environments")
}
},
"init-environment": {
"options": {
"list": shared.config("environments")
}
}
};
grunt.initConfig(config);

var parts = grunt.config("pkg.version").split(".");
grunt.config("pkg.versions", {
"stable": parts.join("."),
"latest": parts[0] + "." + parts[1]
});

function assembleEnvConfig() {
var env = shared.config("env");
var envFilename = "config/environments/" + env + ".json";
if (!grunt.file.exists(envFilename)) return;
var config = grunt.file.readJSON(envFilename);
config.packageVersions = grunt.config("pkg.versions");
grunt.config("envConfig", config);
}
assembleEnvConfig();
'use strict';
require('cloudapp-boilerplate')(grunt);
};
Empty file added grunt/config/.gitkeep
Empty file.
26 changes: 26 additions & 0 deletions grunt/config/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
options: {
tasks: {
dev: [
'copy:third-party',
'wrap',
'copy:js',
'concat',
'clean:plugins'
],
min: [
'copy:third-party',
'wrap',
'copy:js',
'uglify',
'concat',
'clean:plugins'
],
'final': [
'copy:demo',
'copy:images',
'copy:manifest'
]
}
}
};
5 changes: 5 additions & 0 deletions grunt/config/clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
plugins: [
'<%= dirs.build %>/plugins'
]
};
18 changes: 18 additions & 0 deletions grunt/config/concat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
dashboard: {
src: [
'<%= dirs.build %>/dashboard.js',
'<%= dirs.build %>/dashboard/list.js',
'<%= dirs.build %>/dashboard/item.js',
'<%= dirs.build %>/dashboard/**/*.js'
]
},
app: {
src: [
'<%= dirs.build %>/app.js',
'<%= dirs.build %>/controls/*.js',
'<%= dirs.build %>/third-party/*.js',
'<%= dirs.build %>/plugins/*.js'
]
}
};
5 changes: 5 additions & 0 deletions grunt/config/jshint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
options: {
ignores: ['<%= dirs.src %>/third-party/**/*.js']
}
};
5 changes: 5 additions & 0 deletions grunt/config/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
options: {
path: '/apps/echo/topic-radar'
}
};
15 changes: 15 additions & 0 deletions grunt/config/sources.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"js": [
"app.js",
"controls/**/*.js",
"third-party/**/*.js",
"dashboard.js",
"dashboard/**/*.js"
],
"images": [
"images/**"
],
"demo": [
"demo/**"
]
}
19 changes: 19 additions & 0 deletions grunt/config/wrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
options: {
header: [
'(function(jQuery) {',
'var $ = jQuery;',
''
],
footer: [
'})(Echo.jQuery);'
]
},
'third-party': {
files: [{
expand: true,
cwd: '<%= dirs.build %>',
src: ['third-party/*']
}]
}
};
Loading

0 comments on commit 47b7db2

Please sign in to comment.