From 906f5e715ab25dccaa494c1f0e2981accf761064 Mon Sep 17 00:00:00 2001 From: "Brian J. Miller" Date: Fri, 28 Mar 2014 17:48:56 -0500 Subject: [PATCH] Switch to Grunt for building * Update npm dependencies to install grunt deps * Remove gear based build script * Improved JSHint restrictions and corrected code to match * Update Travis CI config file for new build * Bump to 0.30.0 --- .npmignore | 3 +- .travis.yml | 3 + Gruntfile.js | 113 ++++++++++++++++++++++ bower.json | 2 +- build.js | 182 ------------------------------------ build/.empty | 0 package.json | 9 +- src/Activity.js | 2 +- src/ActivityProfile.js | 6 +- src/Agent.js | 2 +- src/AgentAccount.js | 8 +- src/AgentProfile.js | 6 +- src/Context.js | 5 +- src/ContextActivities.js | 7 +- src/Environment/Browser.js | 4 +- src/Environment/Node.js | 3 +- src/InteractionComponent.js | 2 +- src/LRS.js | 6 +- src/Result.js | 5 +- src/Score.js | 5 +- src/State.js | 6 +- src/Statement.js | 18 ++-- src/StatementRef.js | 6 +- src/StatementsResult.js | 2 +- src/SubStatement.js | 16 +--- src/TinCan.js | 14 ++- src/Utils.js | 28 +++--- yuidoc.json | 2 +- 28 files changed, 187 insertions(+), 278 deletions(-) create mode 100644 Gruntfile.js delete mode 100755 build.js delete mode 100644 build/.empty diff --git a/.npmignore b/.npmignore index 9638ab5..4af7152 100644 --- a/.npmignore +++ b/.npmignore @@ -3,8 +3,7 @@ src test doc vendor -build.js -build/.empty +build/tincan-min.map .travis.yml yuidoc.json bower.json diff --git a/.travis.yml b/.travis.yml index 6e5919d..455116f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,6 @@ language: node_js node_js: - "0.10" +before_install: npm install -g grunt-cli +install: npm install +before_script: grunt build diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..c6cf8c9 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,113 @@ +/*global module:false*/ +module.exports = function(grunt) { + "use strict"; + var coreFileList = [ + "vendor/cryptojs-v3.0.2/rollups/sha1.js", + "vendor/cryptojs-v3.0.2/components/enc-base64.js", + "src/TinCan.js", + "src/Utils.js", + "src/LRS.js", + "src/AgentAccount.js", + "src/Agent.js", + "src/Group.js", + "src/Verb.js", + "src/Result.js", + "src/Score.js", + "src/InteractionComponent.js", + "src/ActivityDefinition.js", + "src/Activity.js", + "src/ContextActivities.js", + "src/Context.js", + "src/StatementRef.js", + "src/SubStatement.js", + "src/Statement.js", + "src/StatementsResult.js", + "src/State.js", + "src/ActivityProfile.js", + "src/AgentProfile.js" + ], + browserFileList = coreFileList.slice(), + nodeFileList = coreFileList.slice(); + + browserFileList.push( + "src/Environment/Browser.js" + ); + nodeFileList.push( + "src/Environment/Node.js" + ); + + // Project configuration. + grunt.initConfig({ + pkg: grunt.file.readJSON("package.json"), + + watch: { + files: ["src/**/*.js"], + tasks: ["build"], + options: { + interrupt: true + } + }, + + jshint: { + all: ["Gruntfile.js", "src/**/*.js"], + options: { + bitwise: true, + es3: true, // must use ES3 syntax (support for IE6/7/8/9) + curly: true, // Always use curlys {} + eqeqeq: true, // No more == for you, === only + forin: true, + freeze: true, + immed: true, // prohibits the use of immediate function invocations without wrapping them in parentheses + indent: 4, // force tab width of 4 spaces + latedef: true, // no setting variables before they are defined + newcap: true, // Always call constructors with a Cap + noarg: true, // prohibits arguments.caller and arguments.callee + noempty: true, // prevent empty blocks + nonbsp: true, + nonew: true, // don't allow non-captured constructor use + plusplus: true, // prevent use of ++ and -- + quotmark: "double", // require strings to be double quoted + undef: true, // prohibits the use of explicitly undeclared variables + unused: true, // Warns on unused variables + trailing: true, // Prohibits trailing whitespace + maxdepth: 6, // Max nesting of methods 6 layers deep + onevar: true, + strict: true, + globals: { + TinCan: true + } + } + }, + + concat: { + dist: { + files: { + "build/tincan.js": browserFileList, + "build/tincan-node.js": nodeFileList + }, + nonull: true + } + }, + + uglify: { + dist: { + files: { + "build/tincan-min.js": ["build/tincan.js"] + }, + options: { + sourceMap: true + } + } + } + }); + + // Load Tasks + grunt.loadNpmTasks("grunt-contrib-watch"); + grunt.loadNpmTasks("grunt-contrib-concat"); + grunt.loadNpmTasks("grunt-contrib-jshint"); + grunt.loadNpmTasks("grunt-contrib-uglify"); + + // Define tasks + grunt.registerTask("build", ["jshint", "concat", "uglify"]); + grunt.registerTask("default", "build"); +}; diff --git a/bower.json b/bower.json index 3707237..46ad62a 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "tincan", - "version": "0.22.2", + "version": "0.30.0", "homepage": "http://rusticisoftware.github.com/TinCanJS/", "authors": [ "Brian J. Miller " diff --git a/build.js b/build.js deleted file mode 100755 index a54eb4f..0000000 --- a/build.js +++ /dev/null @@ -1,182 +0,0 @@ -#!/usr/bin/env node - -var gear = require('gear'), - gearRegistry = new gear.Registry( - { - module: 'gear-lib' - } - ), - coreFileList = [ - 'src/TinCan.js' - ,'src/Utils.js' - ,'src/LRS.js' - ,'src/AgentAccount.js' - ,'src/Agent.js' - ,'src/Group.js' - ,'src/Verb.js' - ,'src/Result.js' - ,'src/Score.js' - ,'src/InteractionComponent.js' - ,'src/ActivityDefinition.js' - ,'src/Activity.js' - ,'src/ContextActivities.js' - ,'src/Context.js' - ,'src/StatementRef.js' - ,'src/SubStatement.js' - ,'src/Statement.js' - ,'src/StatementsResult.js' - ,'src/State.js' - ,'src/ActivityProfile.js' - ,'src/AgentProfile.js' - ], - browserFileList = coreFileList.slice(), - nodeFileList = coreFileList.slice(); - -browserFileList.push( - 'src/Environment/Browser.js' -); -nodeFileList.push( - 'src/Environment/Node.js' -); - -new gear.Queue( - { - registry: gearRegistry - } -) -.log("Reading") -.read(browserFileList) -.log("Linting") -.jslint( - { - config: { - white: true, - nomen: true, - passfail: false, - - // for predefined environments - devel: true, // to get console, alert defined - browser: true, - node: true, - es5: false, - - // predefined globals - predef: [ - "TinCan", "XDomainRequest" - ] - }, - callback: function (linted) { - var messages = linted.jslint || [], - counter = 0 - ; - if (messages.length) { - console.log(' ' + linted.name + ' contains ' + messages.length + ' lint errors'); - messages.forEach( - function (item) { - if (item && item.reason) { - counter += 1; - console.log(' #' + counter + ': ' + item.reason); - if (item.evidence) { - console.log(' ' + String(item.evidence).trim() + (' // line ' + item.line + ', pos ' + item.character)); - } - } - } - ) - } - else { - console.log(' ' + linted.name + ' lint free!'); - } - } - } -) -.read( - [ - 'vendor/cryptojs-v3.0.2/rollups/sha1.js', - 'vendor/cryptojs-v3.0.2/components/enc-base64.js' - ] -) -.log("Concating") -.concat() -.log("Writing raw") -.write('build/tincan.js') -.log("Minifying") -.jsminify( - { - callback: function (e) { - console.log('compression failed: ' + e.message); - }, - config: { - mangle: true, - squeeze: true, - semicolon: false, - lift_vars: true, - mangle_toplevel: true, - no_mangle_functions: true, - max_line_length: 6000 - } - } -) -.log("Writing min") -.write('build/tincan-min.js') -.run(); - -new gear.Queue( - { - registry: gearRegistry - } -) -.log("Reading") -.read(nodeFileList) -.log("Linting") -.jslint( - { - config: { - white: true, - nomen: true, - passfail: false, - - // for predefined environments - devel: true, // to get console, alert defined - node: true, - es5: false, - - // predefined globals - predef: [ - "TinCan" - ] - }, - callback: function (linted) { - var messages = linted.jslint || [], - counter = 0 - ; - if (messages.length) { - console.log(' ' + linted.name + ' contains ' + messages.length + ' lint errors'); - messages.forEach( - function (item) { - if (item && item.reason) { - counter += 1; - console.log(' #' + counter + ': ' + item.reason); - if (item.evidence) { - console.log(' ' + String(item.evidence).trim() + (' // line ' + item.line + ', pos ' + item.character)); - } - } - } - ) - } - else { - console.log(' ' + linted.name + ' lint free!'); - } - } - } -) -.read( - [ - 'vendor/cryptojs-v3.0.2/rollups/sha1.js', - 'vendor/cryptojs-v3.0.2/components/enc-base64.js' - ] -) -.log("Concating") -.concat() -.log("Writing raw") -.write('build/tincan-node.js') -.run(); diff --git a/build/.empty b/build/.empty deleted file mode 100644 index e69de29..0000000 diff --git a/package.json b/package.json index 65cd8b2..f84f64a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "tincanjs", "description": "Tin Can API Library", - "version": "0.22.2", + "version": "0.30.0", "private": false, "main": "build/tincan-node.js", "directories": { @@ -27,8 +27,11 @@ "e-learning" ], "devDependencies": { - "gear": "0.8.x", - "gear-lib": "0.8.x", + "grunt": "0.4.4", + "grunt-contrib-jshint": "0.9.2", + "grunt-contrib-watch": "0.6.1", + "grunt-contrib-concat": "0.3.0", + "grunt-contrib-uglify": "0.4.0", "qunit": "0.5.16" } } diff --git a/src/Activity.js b/src/Activity.js index 6b4ea59..938f996 100644 --- a/src/Activity.js +++ b/src/Activity.js @@ -55,7 +55,7 @@ TinCan client library /** @property LOG_SRC */ - LOG_SRC: 'Activity', + LOG_SRC: "Activity", /** @method log diff --git a/src/ActivityProfile.js b/src/ActivityProfile.js index 534a5e9..381842e 100644 --- a/src/ActivityProfile.js +++ b/src/ActivityProfile.js @@ -75,7 +75,7 @@ TinCan client library /** @property LOG_SRC */ - LOG_SRC: 'ActivityProfile', + LOG_SRC: "ActivityProfile", /** @method log @@ -94,9 +94,7 @@ TinCan client library "contents", "etag", "contentType" - ], - val - ; + ]; cfg = cfg || {}; diff --git a/src/Agent.js b/src/Agent.js index 5cc0da6..0496f80 100644 --- a/src/Agent.js +++ b/src/Agent.js @@ -202,7 +202,7 @@ TinCan client library } }, - toString: function (lang) { + toString: function () { this.log("toString"); if (this.name !== null) { diff --git a/src/AgentAccount.js b/src/AgentAccount.js index 654e78a..c830165 100644 --- a/src/AgentAccount.js +++ b/src/AgentAccount.js @@ -48,7 +48,7 @@ TinCan client library /** @property LOG_SRC */ - LOG_SRC: 'AgentAccount', + LOG_SRC: "AgentAccount", /** @method log @@ -65,9 +65,7 @@ TinCan client library directProps = [ "name", "homePage" - ], - val - ; + ]; cfg = cfg || {}; @@ -86,7 +84,7 @@ TinCan client library } }, - toString: function (lang) { + toString: function () { this.log("toString"); var result = ""; diff --git a/src/AgentProfile.js b/src/AgentProfile.js index 93a6f94..9b05d9a 100644 --- a/src/AgentProfile.js +++ b/src/AgentProfile.js @@ -75,7 +75,7 @@ TinCan client library /** @property LOG_SRC */ - LOG_SRC: 'AgentProfile', + LOG_SRC: "AgentProfile", /** @method log @@ -94,9 +94,7 @@ TinCan client library "contents", "etag", "contentType" - ], - val - ; + ]; cfg = cfg || {}; diff --git a/src/Context.js b/src/Context.js index edc5739..f005582 100644 --- a/src/Context.js +++ b/src/Context.js @@ -90,7 +90,7 @@ TinCan client library /** @property LOG_SRC */ - LOG_SRC: 'Context', + LOG_SRC: "Context", /** @method log @@ -178,8 +178,7 @@ TinCan client library "contextActivities", "statement" ], - i, - prop; + i; version = version || TinCan.versions()[0]; diff --git a/src/ContextActivities.js b/src/ContextActivities.js index 284098f..1223fd2 100644 --- a/src/ContextActivities.js +++ b/src/ContextActivities.js @@ -60,7 +60,7 @@ TinCan client library /** @property LOG_SRC */ - LOG_SRC: 'ContextActivities', + LOG_SRC: "ContextActivities", /** @method log @@ -120,7 +120,7 @@ TinCan client library } if (! (val instanceof TinCan.Activity)) { - val = typeof val === 'string' ? { id: val } : val; + val = typeof val === "string" ? { id: val } : val; val = new TinCan.Activity (val); } @@ -142,8 +142,7 @@ TinCan client library "other" ], i, - j, - prop; + j; version = version || TinCan.versions()[0]; diff --git a/src/Environment/Browser.js b/src/Environment/Browser.js index 2aede95..210b89c 100644 --- a/src/Environment/Browser.js +++ b/src/Environment/Browser.js @@ -21,6 +21,7 @@ TinCan client library @submodule TinCan.Environment.Browser **/ (function () { + /* globals window, XMLHttpRequest, XDomainRequest */ "use strict"; var LOG_SRC = "Environment.Browser", nativeRequest, @@ -364,7 +365,8 @@ TinCan client library // capabilities // TinCan.LRS.prototype._initByEnvironment = function (cfg) { - /*jslint regexp: true */ + /*jslint regexp: true, laxbreak: true */ + /* globals location */ log("_initByEnvironment", LOG_SRC); var urlParts, schemeMatches, diff --git a/src/Environment/Node.js b/src/Environment/Node.js index bcbffba..863fe0e 100644 --- a/src/Environment/Node.js +++ b/src/Environment/Node.js @@ -21,6 +21,7 @@ TinCan client library @submodule TinCan.Environment.Node **/ (function () { + /* globals require */ "use strict"; var LOG_SRC = "Environment.Node", log = TinCan.prototype.log, @@ -89,7 +90,7 @@ TinCan client library prop ; if (Object.keys(cfg.params).length > 0) { - url += '?' + querystring.stringify(cfg.params); + url += "?" + querystring.stringify(cfg.params); } xhr = new XMLHttpRequest(); diff --git a/src/InteractionComponent.js b/src/InteractionComponent.js index 82ecf4e..d252aba 100644 --- a/src/InteractionComponent.js +++ b/src/InteractionComponent.js @@ -48,7 +48,7 @@ TinCan client library /** @property LOG_SRC */ - LOG_SRC: 'InteractionComponent', + LOG_SRC: "InteractionComponent", /** @method log diff --git a/src/LRS.js b/src/LRS.js index 48f54ec..4216f81 100644 --- a/src/LRS.js +++ b/src/LRS.js @@ -731,7 +731,7 @@ TinCan client library //or endpoint (though only the former is allowed in the spec) serverRoot = TinCan.Utils.getServerRoot(this.endpoint); if (parsedURL.path.indexOf("/statements") === 0){ - parsedURL.path = this.endpoint.replace(serverRoot, '') + parsedURL.path; + parsedURL.path = this.endpoint.replace(serverRoot, "") + parsedURL.path; this.log("converting non-standard more URL to " + parsedURL.path); } @@ -926,9 +926,7 @@ TinCan client library saveState: function (key, val, cfg) { this.log("saveState"); var requestParams, - requestCfg, - requestResult - ; + requestCfg; if (typeof cfg.contentType === "undefined") { cfg.contentType = "application/octet-stream"; diff --git a/src/Result.js b/src/Result.js index 4bbc5ef..81a9c6a 100644 --- a/src/Result.js +++ b/src/Result.js @@ -72,7 +72,7 @@ TinCan client library /** @property LOG_SRC */ - LOG_SRC: 'Result', + LOG_SRC: "Result", /** @method log @@ -135,8 +135,7 @@ TinCan client library optionalObjProps = [ "score" ], - i, - prop; + i; version = version || TinCan.versions()[0]; diff --git a/src/Score.js b/src/Score.js index 4141edb..0d1ac1d 100644 --- a/src/Score.js +++ b/src/Score.js @@ -60,7 +60,7 @@ TinCan client library /** @property LOG_SRC */ - LOG_SRC: 'Score', + LOG_SRC: "Score", /** @method log @@ -105,8 +105,7 @@ TinCan client library "min", "max" ], - i, - prop; + i; version = version || TinCan.versions()[0]; diff --git a/src/State.js b/src/State.js index e602448..473bd08 100644 --- a/src/State.js +++ b/src/State.js @@ -66,7 +66,7 @@ TinCan client library /** @property LOG_SRC */ - LOG_SRC: 'State', + LOG_SRC: "State", /** @method log @@ -85,9 +85,7 @@ TinCan client library "contents", "etag", "contentType" - ], - val - ; + ]; cfg = cfg || {}; diff --git a/src/Statement.js b/src/Statement.js index c3aa53a..90cd093 100644 --- a/src/Statement.js +++ b/src/Statement.js @@ -157,7 +157,7 @@ TinCan client library /** @property LOG_SRC */ - LOG_SRC: 'Statement', + LOG_SRC: "Statement", /** @method log @@ -179,9 +179,7 @@ TinCan client library "version", "inProgress", "voided" - ], - val - ; + ]; cfg = cfg || {}; @@ -239,14 +237,10 @@ TinCan client library } } if (cfg.hasOwnProperty("target")) { - if (cfg.target instanceof TinCan.Activity - || - cfg.target instanceof TinCan.Agent - || - cfg.target instanceof TinCan.Group - || - cfg.target instanceof TinCan.SubStatement - || + if (cfg.target instanceof TinCan.Activity || + cfg.target instanceof TinCan.Agent || + cfg.target instanceof TinCan.Group || + cfg.target instanceof TinCan.SubStatement || cfg.target instanceof TinCan.StatementRef ) { this.target = cfg.target; diff --git a/src/StatementRef.js b/src/StatementRef.js index aec1d19..fd336dc 100644 --- a/src/StatementRef.js +++ b/src/StatementRef.js @@ -68,9 +68,7 @@ TinCan client library var i, directProps = [ "id" - ], - val - ; + ]; cfg = cfg || {}; @@ -85,7 +83,7 @@ TinCan client library @method toString @return {String} String representation of the statement */ - toString: function (lang) { + toString: function () { this.log("toString"); return this.id; }, diff --git a/src/StatementsResult.js b/src/StatementsResult.js index 4d03528..0c417f1 100644 --- a/src/StatementsResult.js +++ b/src/StatementsResult.js @@ -52,7 +52,7 @@ TinCan client library /** @property LOG_SRC */ - LOG_SRC: 'StatementsResult', + LOG_SRC: "StatementsResult", /** @method log diff --git a/src/SubStatement.js b/src/SubStatement.js index de7ac86..3e9654a 100644 --- a/src/SubStatement.js +++ b/src/SubStatement.js @@ -103,9 +103,7 @@ TinCan client library var i, directProps = [ "timestamp" - ], - val - ; + ]; cfg = cfg || {}; @@ -140,14 +138,10 @@ TinCan client library } } if (cfg.hasOwnProperty("target")) { - if (cfg.target instanceof TinCan.Activity - || - cfg.target instanceof TinCan.Agent - || - cfg.target instanceof TinCan.Group - || - cfg.target instanceof TinCan.SubStatement - || + if (cfg.target instanceof TinCan.Activity || + cfg.target instanceof TinCan.Agent || + cfg.target instanceof TinCan.Group || + cfg.target instanceof TinCan.SubStatement || cfg.target instanceof TinCan.StatementRef ) { this.target = cfg.target; diff --git a/src/TinCan.js b/src/TinCan.js index 44b928b..ec1a293 100644 --- a/src/TinCan.js +++ b/src/TinCan.js @@ -131,10 +131,11 @@ var TinCan; @param {String} msg Message to output */ log: function (msg, src) { + /* globals console */ if (TinCan.DEBUG && typeof console !== "undefined" && console.log) { src = src || this.LOG_SRC || "TinCan"; - console.log("TinCan." + src + ': ' + msg); + console.log("TinCan." + src + ": " + msg); } }, @@ -199,7 +200,6 @@ var TinCan; qsParams = TinCan.Utils.parseURL(url).params, lrsProps = ["endpoint", "auth"], lrsCfg = {}, - activityCfg, contextCfg, extended = null ; @@ -225,10 +225,8 @@ var TinCan; } if ( - qsParams.hasOwnProperty("activity_platform") - || - qsParams.hasOwnProperty("registration") - || + qsParams.hasOwnProperty("activity_platform") || + qsParams.hasOwnProperty("registration") || qsParams.hasOwnProperty("grouping") ) { contextCfg = {}; @@ -519,7 +517,7 @@ var TinCan; { actor: actor, verb: { - id: "http://adlnet.gov/expapi/verbs/voided" + id: "http://adlnet.gov/expapi/verbs/voided" }, target: { objectType: "StatementRef", @@ -1249,7 +1247,7 @@ var TinCan; ]; }; - /*global exports*/ + /*global module*/ // Support the CommonJS method for exporting our single global if (typeof module === "object") { module.exports = TinCan; diff --git a/src/Utils.js b/src/Utils.js index 8cba5aa..49bc3ee 100644 --- a/src/Utils.js +++ b/src/Utils.js @@ -41,11 +41,11 @@ TinCan client library Dual licensed under the MIT and GPL licenses. */ getUUID: function () { - /*jslint bitwise: true eqeq: true */ - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace( + /*jslint bitwise: true, eqeq: true */ + return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace( /[xy]/g, function (c) { - var r = Math.random() * 16|0, v = c == 'x' ? r : (r&0x3|0x8); + var r = Math.random() * 16|0, v = c == "x" ? r : (r&0x3|0x8); return v.toString(16); } ); @@ -71,20 +71,20 @@ TinCan client library tempVal = val.toString(); while (val < padder && padder > 1) { - tempVal = '0' + tempVal; + tempVal = "0" + tempVal; padder = padder / 10; } return tempVal; } - return d.getUTCFullYear() + '-' - + pad(d.getUTCMonth() + 1) + '-' - + pad(d.getUTCDate()) + 'T' - + pad(d.getUTCHours()) + ':' - + pad(d.getUTCMinutes()) + ':' - + pad(d.getUTCSeconds()) + '.' - + pad(d.getUTCMilliseconds(), 3) + 'Z'; + return d.getUTCFullYear() + "-" + + pad(d.getUTCMonth() + 1) + "-" + + pad(d.getUTCDate()) + "T" + + pad(d.getUTCHours()) + ":" + + pad(d.getUTCMinutes()) + ":" + + pad(d.getUTCSeconds()) + "." + + pad(d.getUTCMilliseconds(), 3) + "Z"; }, /** @@ -151,16 +151,16 @@ TinCan client library @private */ parseURL: function (url) { - var parts = String(url).split('?'), + var parts = String(url).split("?"), pairs, pair, i, params = {} ; if (parts.length === 2) { - pairs = parts[1].split('&'); + pairs = parts[1].split("&"); for (i = 0; i < pairs.length; i += 1) { - pair = pairs[i].split('='); + pair = pairs[i].split("="); if (pair.length === 2 && pair[0]) { params[pair[0]] = decodeURIComponent(pair[1]); } diff --git a/yuidoc.json b/yuidoc.json index b234485..9479227 100644 --- a/yuidoc.json +++ b/yuidoc.json @@ -1,5 +1,5 @@ { - "version": "0.22.2", + "version": "0.30.0", "name": "TinCanJS", "description": "Library for working with Tin Can API in JavaScript", "url": "http://rusticisoftware.github.com/TinCanJS/",