diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index e07b628..0000000 --- a/.jshintrc +++ /dev/null @@ -1,28 +0,0 @@ -{ - "es3": true, - "eqeqeq": true, - "expr": true, - "forin": true, - "immed": true, - "latedef": true, - "newcap": true, - "noarg": true, - "nonew": false, - "smarttabs": true, - "strict": true, - "sub": true, - "trailing": true, - "undef": true, - "unused": "vars", - "browser": true, - "scripturl": true, - "jquery": true, - "devel": true, - "laxbreak": true, - "node": true, - "globals": { - "Echo": false, - "Backplane": false, - "janrain": false - } -} diff --git a/Gruntfile.js b/Gruntfile.js index d55a39b..e001631 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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); }; diff --git a/grunt/config/.gitkeep b/grunt/config/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/grunt/config/build.js b/grunt/config/build.js new file mode 100644 index 0000000..6f70922 --- /dev/null +++ b/grunt/config/build.js @@ -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' + ] + } + } +}; diff --git a/grunt/config/clean.js b/grunt/config/clean.js new file mode 100644 index 0000000..0eeaf02 --- /dev/null +++ b/grunt/config/clean.js @@ -0,0 +1,5 @@ +module.exports = { + plugins: [ + '<%= dirs.build %>/plugins' + ] +}; diff --git a/grunt/config/concat.js b/grunt/config/concat.js new file mode 100644 index 0000000..44cea21 --- /dev/null +++ b/grunt/config/concat.js @@ -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' + ] + } +}; diff --git a/grunt/config/jshint.js b/grunt/config/jshint.js new file mode 100644 index 0000000..28aac28 --- /dev/null +++ b/grunt/config/jshint.js @@ -0,0 +1,5 @@ +module.exports = { + options: { + ignores: ['<%= dirs.src %>/third-party/**/*.js'] + } +}; diff --git a/grunt/config/release.js b/grunt/config/release.js new file mode 100644 index 0000000..215868f --- /dev/null +++ b/grunt/config/release.js @@ -0,0 +1,5 @@ +module.exports = { + options: { + path: '/apps/echo/topic-radar' + } +}; diff --git a/grunt/config/sources.json b/grunt/config/sources.json new file mode 100644 index 0000000..ca2b5b6 --- /dev/null +++ b/grunt/config/sources.json @@ -0,0 +1,15 @@ +{ + "js": [ + "app.js", + "controls/**/*.js", + "third-party/**/*.js", + "dashboard.js", + "dashboard/**/*.js" + ], + "images": [ + "images/**" + ], + "demo": [ + "demo/**" + ] +} diff --git a/grunt/config/wrap.js b/grunt/config/wrap.js new file mode 100644 index 0000000..02bc961 --- /dev/null +++ b/grunt/config/wrap.js @@ -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/*'] + }] + } +}; diff --git a/grunt/lib.js b/grunt/lib.js deleted file mode 100644 index 3f60635..0000000 --- a/grunt/lib.js +++ /dev/null @@ -1,68 +0,0 @@ -var initialized = false; -var data = { - // if this value is true no actual release will be performed, - // to enable debug mode execute `grunt release -d=1` - "debug": false, - // execute `grunt release --env=production` for actual release - "env": "development", - "environments": ["development", "test", "staging", "production"], - // flag is set to true when we execute release task - "release": false -}; -var child_process = require("child_process"); -var _ = require("lodash"); - -exports.init = function(grunt) { - "use strict"; - - var exports = {}; - - exports.config = function(key, value) { - if (typeof arguments[1] !== "undefined") { - return grunt.util.namespace.set(data, key, value); - } else { - return grunt.util.namespace.get(data, key); - } - }; - - exports.exec = function(command, callback) { - grunt.log.subhead(command.yellow); - child_process.exec(command, function(err, stdout, stderr) { - if (err) { - grunt.fail.fatal(err); - } - if (stderr) { - grunt.log.writeln(stderr); - } - callback(stdout, stderr); - }); - }; - - grunt.template.addDelimiters("configPlaceholder", "{%", "%}"); - exports.replacePlaceholdersOnCopy = function(text) { - // return text as is if there are no placeholders - if (!/{%=/.test(text)) return text; - // we set the last parameter value to "init" because we want different - // placeholders not to mix up with default ones ( {%=x%} instead of <%=x%> ) - return grunt.template.process(text, { - "data": grunt.config("envConfig"), - "delimiters": "configPlaceholder" - }); - }; - - if (!initialized) { - initialized = true; - exports.config("debug", !!grunt.option("debug")); - var env = grunt.option("env"); - if (!_.contains(exports.config("environments"), env)) { - env = "development"; - } - exports.config("env", env); - grunt.log.writeln(""); - grunt.log.writeln("DEBUG mode is " + (exports.config("debug") ? "ON".green : "OFF".red)); - grunt.log.writeln("Working in the " + (env === "production" ? "PRODUCTION".red : env.toUpperCase().green) + " environment"); - grunt.log.writeln(""); - } - - return exports; -}; diff --git a/grunt/tasks/.gitkeep b/grunt/tasks/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/grunt/tasks/build.js b/grunt/tasks/build.js deleted file mode 100644 index d25ae52..0000000 --- a/grunt/tasks/build.js +++ /dev/null @@ -1,52 +0,0 @@ -module.exports = function(grunt) { - "use strict"; - - var shared = require("../lib.js").init(grunt); - - grunt.registerTask("build", "Go through all stages of building some target/system", function(stage) { - var tasks = []; - if (!stage) { - tasks = ["build:dev"]; - if (shared.config("env") !== "development") { - tasks.push("build:min"); - } - tasks.push("build:final"); - grunt.task.run(tasks); - return; - } - grunt.config("dirs.dest", "<%= dirs.dist %>" + (stage === "dev" ? "/dev" : "")); - switch(stage) { - case "dev": - tasks = [ - "copy:third-party", - "wrap", - "copy:js", - "concat", - "clean:plugins" - ]; - break; - case "min": - tasks = [ - "copy:third-party", - "wrap", - "copy:js", - "uglify", - "concat", - "clean:plugins" - ]; - break; - case "final": - tasks = [ - "copy:demo", - "copy:images", - "copy:manifest" - ]; - break; - } - tasks = tasks.concat([ - "copy:build", - "clean:build" - ]); - grunt.task.run(tasks); - }); -}; diff --git a/package.json b/package.json index 5dae504..1551364 100644 --- a/package.json +++ b/package.json @@ -24,16 +24,7 @@ }, "dependencies": { "grunt": "^0.4.5", - "grunt-contrib-clean": "^0.5.0", - "grunt-contrib-concat": "^0.4.0", - "grunt-contrib-copy": "^0.5.0", - "grunt-contrib-jshint": "^0.10.0", - "grunt-contrib-uglify": "^0.5.0", - "lodash": "^2.4.1", - "sphere": "^0.2.2" - }, - "devDependencies": { - "grunt-contrib-watch": "^0.6.1" + "cloudapp-boilerplate": "^0.1.0" }, "private": true }