├── .gitignore ├── examples ├── intro-outro │ ├── src │ │ ├── intro.js │ │ ├── outro.js │ │ └── random.js │ ├── dist │ │ ├── jquery.ba-random.min.js │ │ └── jquery.ba-random.js │ └── plugin.json ├── multiple-plugins │ ├── src │ │ ├── not-random.js │ │ └── random.js │ ├── jqbuild.json │ ├── dist │ │ ├── jquery.ba-random.min.js │ │ ├── jquery.ba-notrandom.min.js │ │ ├── jquery.ba-random.js │ │ └── jquery.ba-notrandom.js │ └── plugin.json ├── custom-banner │ ├── src │ │ └── random.js │ ├── dist │ │ ├── jquery.ba-random.min.js │ │ └── jquery.ba-random.js │ └── plugin.json └── debug │ ├── dist │ ├── jquery.ba-random.min.js │ └── jquery.ba-random.js │ ├── src │ └── random.js │ └── plugin.json ├── lib ├── jqbuild │ ├── pkginfo.js │ ├── lint.js │ ├── minify.js │ ├── help.js │ ├── file.js │ ├── log.js │ ├── cli.js │ ├── defaults.js │ └── util.js └── jqbuild.js ├── bin └── jqbuild ├── package.json ├── LICENSE-MIT ├── README.md └── LICENSE-GPL /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | -------------------------------------------------------------------------------- /examples/intro-outro/src/intro.js: -------------------------------------------------------------------------------- 1 | (function($) { 2 | -------------------------------------------------------------------------------- /examples/intro-outro/src/outro.js: -------------------------------------------------------------------------------- 1 | }(jQuery)); 2 | -------------------------------------------------------------------------------- /lib/jqbuild/pkginfo.js: -------------------------------------------------------------------------------- 1 | require('pkginfo')(module); 2 | -------------------------------------------------------------------------------- /bin/jqbuild: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('../lib/jqbuild'); 3 | -------------------------------------------------------------------------------- /examples/multiple-plugins/src/not-random.js: -------------------------------------------------------------------------------- 1 | // PLEASE, don't ever do this. 2 | Math['random'] = function() { 3 | return 0 4 | }; 5 | -------------------------------------------------------------------------------- /examples/intro-outro/src/random.js: -------------------------------------------------------------------------------- 1 | $.fn.random = function(selector) { 2 | var elems = selector ? this.filter(selector) : this; 3 | return this.pushStack(elems.eq(Math.floor(Math.random() * elems.length))); 4 | }; 5 | -------------------------------------------------------------------------------- /examples/multiple-plugins/jqbuild.json: -------------------------------------------------------------------------------- 1 | { 2 | "banner": "// This banner will be used for all plugins in plugin.json!\n// {{.label}} - v{{.versions[0].version}}\n// {{.copyright}}; Licensed {{.license.join(', ')}}" 3 | } 4 | 5 | 6 | -------------------------------------------------------------------------------- /examples/custom-banner/src/random.js: -------------------------------------------------------------------------------- 1 | (function($) { 2 | 3 | $.fn.random = function(selector) { 4 | var elems = selector ? this.filter(selector) : this; 5 | return this.pushStack(elems.eq(Math.floor(Math.random() * elems.length))); 6 | }; 7 | 8 | }(jQuery)); 9 | -------------------------------------------------------------------------------- /examples/multiple-plugins/src/random.js: -------------------------------------------------------------------------------- 1 | (function($) { 2 | 3 | $.fn.random = function(selector) { 4 | var elems = selector ? this.filter(selector) : this; 5 | return this.pushStack(elems.eq(Math.floor(Math.random() * elems.length))); 6 | }; 7 | 8 | }(jQuery)); 9 | -------------------------------------------------------------------------------- /examples/custom-banner/dist/jquery.ba-random.min.js: -------------------------------------------------------------------------------- 1 | // jQuery Random - v0.1.0 - http://benalman.com/ 2 | // Copyright (c) 2011 Ben Alman; Licensed MIT, GPL 3 | (function($){$.fn.random=function(a){var b=a?this.filter(a):this;return this.pushStack(b.eq(Math.floor(Math.random()*b.length)))}})(jQuery) -------------------------------------------------------------------------------- /examples/intro-outro/dist/jquery.ba-random.min.js: -------------------------------------------------------------------------------- 1 | // jQuery Random - v0.1.0 - 6/13/2011 2 | // http://benalman.com/ 3 | // Copyright (c) 2011 Ben Alman; Licensed MIT, GPL 4 | (function($){$.fn.random=function(a){var b=a?this.filter(a):this;return this.pushStack(b.eq(Math.floor(Math.random()*b.length)))}})(jQuery) -------------------------------------------------------------------------------- /examples/multiple-plugins/dist/jquery.ba-random.min.js: -------------------------------------------------------------------------------- 1 | // This banner will be used for all plugins in plugin.json! 2 | // jQuery Random - v0.1.0 3 | // Copyright (c) 2011 Ben Alman; Licensed MIT, GPL 4 | (function($){$.fn.random=function(a){var b=a?this.filter(a):this;return this.pushStack(b.eq(Math.floor(Math.random()*b.length)))}})(jQuery) -------------------------------------------------------------------------------- /examples/debug/dist/jquery.ba-random.min.js: -------------------------------------------------------------------------------- 1 | // jQuery Random - v0.1.0 - 6/13/2011 2 | // http://benalman.com/ 3 | // Copyright (c) 2011 Ben Alman; Licensed MIT, GPL 4 | (function($){$.fn.random=function(a){debugger;var b=a?this.filter(a):this,c=b.length,d=Math.floor(Math.random()*c),e=b.eq(d);console.log(c,d,e);return this.pushStack(e)}})(jQuery) -------------------------------------------------------------------------------- /examples/multiple-plugins/dist/jquery.ba-notrandom.min.js: -------------------------------------------------------------------------------- 1 | // This banner will be used for all plugins in plugin.json! 2 | // jQuery NOT Random - v0.1.0 3 | // Copyright (c) 2011 Ben Alman; Licensed MIT, GPL 4 | Math.random=function(){return 0},function($){$.fn.random=function(a){var b=a?this.filter(a):this;return this.pushStack(b.eq(Math.floor(Math.random()*b.length)))}}(jQuery) -------------------------------------------------------------------------------- /examples/debug/src/random.js: -------------------------------------------------------------------------------- 1 | (function($) { 2 | 3 | $.fn.random = function(selector) { 4 | debugger; 5 | var elems = selector ? this.filter(selector) : this; 6 | var len = elems.length; 7 | var i = Math.floor(Math.random() * len); 8 | var elem = elems.eq(i); 9 | console.log(len, i, elem); 10 | return this.pushStack(elem); 11 | }; 12 | 13 | }(jQuery)); 14 | -------------------------------------------------------------------------------- /examples/custom-banner/dist/jquery.ba-random.js: -------------------------------------------------------------------------------- 1 | // jQuery Random - v0.1.0 - http://benalman.com/ 2 | // Copyright (c) 2011 Ben Alman; Licensed MIT, GPL 3 | 4 | (function($){ 5 | 6 | $.fn.random = function(selector) { 7 | var elems = selector ? this.filter(selector) : this; 8 | return this.pushStack(elems.eq(Math.floor(Math.random() * elems.length))); 9 | }; 10 | 11 | }(jQuery)); 12 | -------------------------------------------------------------------------------- /examples/intro-outro/dist/jquery.ba-random.js: -------------------------------------------------------------------------------- 1 | // jQuery Random - v0.1.0 - 6/13/2011 2 | // http://benalman.com/ 3 | // Copyright (c) 2011 Ben Alman; Licensed MIT, GPL 4 | 5 | (function($){ 6 | 7 | $.fn.random = function(selector) { 8 | var elems = selector ? this.filter(selector) : this; 9 | return this.pushStack(elems.eq(Math.floor(Math.random() * elems.length))); 10 | }; 11 | 12 | }(jQuery)); 13 | -------------------------------------------------------------------------------- /examples/multiple-plugins/dist/jquery.ba-random.js: -------------------------------------------------------------------------------- 1 | // This banner will be used for all plugins in plugin.json! 2 | // jQuery Random - v0.1.0 3 | // Copyright (c) 2011 Ben Alman; Licensed MIT, GPL 4 | 5 | (function($) { 6 | 7 | $.fn.random = function(selector) { 8 | var elems = selector ? this.filter(selector) : this; 9 | return this.pushStack(elems.eq(Math.floor(Math.random() * elems.length))); 10 | }; 11 | 12 | }(jQuery)); 13 | -------------------------------------------------------------------------------- /examples/multiple-plugins/dist/jquery.ba-notrandom.js: -------------------------------------------------------------------------------- 1 | // This banner will be used for all plugins in plugin.json! 2 | // jQuery NOT Random - v0.1.0 3 | // Copyright (c) 2011 Ben Alman; Licensed MIT, GPL 4 | 5 | // PLEASE, don't ever do this. 6 | Math['random'] = function() { 7 | return 0 8 | }; 9 | 10 | (function($) { 11 | 12 | $.fn.random = function(selector) { 13 | var elems = selector ? this.filter(selector) : this; 14 | return this.pushStack(elems.eq(Math.floor(Math.random() * elems.length))); 15 | }; 16 | 17 | }(jQuery)); 18 | -------------------------------------------------------------------------------- /examples/debug/dist/jquery.ba-random.js: -------------------------------------------------------------------------------- 1 | // jQuery Random - v0.1.0 - 6/13/2011 2 | // http://benalman.com/ 3 | // Copyright (c) 2011 Ben Alman; Licensed MIT, GPL 4 | 5 | // SOURCE: src/random.js 6 | 7 | (function($) { 8 | 9 | $.fn.random = function(selector) { 10 | debugger; 11 | var elems = selector ? this.filter(selector) : this; 12 | var len = elems.length; 13 | var i = Math.floor(Math.random() * len); 14 | var elem = elems.eq(i); 15 | console.log(len, i, elem); 16 | return this.pushStack(elem); 17 | }; 18 | 19 | }(jQuery)); 20 | -------------------------------------------------------------------------------- /examples/debug/plugin.json: -------------------------------------------------------------------------------- 1 | { 2 | "jquery-random": { 3 | "label": "jQuery Random", 4 | "description": "Filter the current set down to a single random element.", 5 | "dist": { 6 | "dev": "dist/jquery.ba-random.js", 7 | "prod": "dist/jquery.ba-random.min.js" 8 | }, 9 | "license": ["MIT", "GPL"], 10 | "copyright": "Copyright (c) 2011 Ben Alman", 11 | "homeurl": "http://benalman.com/", 12 | "versions": [ 13 | { "version": "0.1.0" } 14 | ], 15 | "jqbuild": { 16 | "config": { 17 | "debug": true 18 | }, 19 | "src": [ 20 | "src/random.js" 21 | ] 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /examples/intro-outro/plugin.json: -------------------------------------------------------------------------------- 1 | { 2 | "jquery-random": { 3 | "label": "jQuery Random", 4 | "description": "Filter the current set down to a single random element.", 5 | "dist": { 6 | "dev": "dist/jquery.ba-random.js", 7 | "prod": "dist/jquery.ba-random.min.js" 8 | }, 9 | "license": ["MIT", "GPL"], 10 | "copyright": "Copyright (c) 2011 Ben Alman", 11 | "homeurl": "http://benalman.com/", 12 | "versions": [ 13 | { "version": "0.1.0" } 14 | ], 15 | "jqbuild": { 16 | "config": { 17 | "prelint": false 18 | }, 19 | "src": [ 20 | "src/intro.js", 21 | "src/random.js", 22 | "src/outro.js" 23 | ] 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /examples/custom-banner/plugin.json: -------------------------------------------------------------------------------- 1 | { 2 | "jquery-random": { 3 | "label": "jQuery Random", 4 | "description": "Filter the current set down to a single random element.", 5 | "dist": { 6 | "dev": "dist/jquery.ba-random.js", 7 | "prod": "dist/jquery.ba-random.min.js" 8 | }, 9 | "license": ["MIT", "GPL"], 10 | "copyright": "Copyright (c) 2011 Ben Alman", 11 | "homeurl": "http://benalman.com/", 12 | "versions": [ 13 | { "version": "0.1.0" } 14 | ], 15 | "jqbuild": { 16 | "config": { 17 | "banner": "// {{.label}} - v{{.versions[0].version}} - {{.homeurl}}\n// {{.copyright}}; Licensed {{.license.join(', ')}}" 18 | }, 19 | "src": [ 20 | "src/random.js" 21 | ] 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jqbuild", 3 | "version": "0.1.0", 4 | "description": "A command line build tool for jQuery plugins.", 5 | "keywords": [ 6 | "cli", 7 | "cowboy", 8 | "jquery", 9 | "plugin" 10 | ], 11 | "homepage": "http://github.com/cowboy/node-jqbuild", 12 | "author": "\"Cowboy\" Ben Alman (http://benalman.com/)", 13 | "repository": { 14 | "type": "git", 15 | "url": "http://github.com/cowboy/node-jqbuild.git" 16 | }, 17 | "dependencies": { 18 | "colors": "~0.5.0", 19 | "dateformat": "1.0.1-1.2.3", 20 | "jshint": "~0.2.2", 21 | "nopt": "~1.0.5", 22 | "pkginfo": "~0.2.1", 23 | "uglify-js": "~1.0.2", 24 | "zlib": "~1.0.2" 25 | }, 26 | "bin": "./bin/jqbuild", 27 | "engines": { 28 | "node": ">= 0.4.0" 29 | }, 30 | "preferGlobal": true 31 | } -------------------------------------------------------------------------------- /lib/jqbuild/lint.js: -------------------------------------------------------------------------------- 1 | var colors = require('colors'); 2 | var log = require('./log'); 3 | var util = require('./util'); 4 | 5 | var jshint = require('jshint').JSHINT; 6 | 7 | // Validate with JSHint. 8 | exports.jshint = function(src, config) { 9 | //console.log(config.jshint); 10 | log.write('Validating with JSHint...'); 11 | var opts = util.merge({}, config.jshint); 12 | if ( config.debug ) { 13 | opts.devel = true; 14 | opts.debug = true; 15 | } 16 | //console.log(config); 17 | //console.log(src); 18 | //console.log(opts); 19 | var passed = jshint(src, opts); 20 | //console.log(jshint.errors); 21 | if ( passed ) { 22 | log.ok(); 23 | } else { 24 | log.error(); 25 | log.indent(function() { 26 | jshint.errors.forEach(function(e) { 27 | if ( !e ) { return; } 28 | var str = e.evidence ? e.evidence.inverse + ' <- ' : ''; 29 | log.error('[L' + e.line + ':C' + e.character + '] ' + str + e.reason); 30 | }); 31 | }); 32 | } 33 | return passed; 34 | } -------------------------------------------------------------------------------- /lib/jqbuild/minify.js: -------------------------------------------------------------------------------- 1 | var colors = require('colors'); 2 | var log = require('./log'); 3 | 4 | var uglifyjs = require('uglify-js'); 5 | 6 | var Buffer = require('buffer').Buffer; 7 | var zlib = require('zlib'); 8 | 9 | // Minify with UglifyJS. 10 | // From https://github.com/mishoo/UglifyJS 11 | exports.uglify = function(src, config) { 12 | log.write('Minifying with UglifyJS...') 13 | var jsp = uglifyjs.parser; 14 | var pro = uglifyjs.uglify; 15 | var ast; 16 | 17 | try { 18 | ast = jsp.parse(src); 19 | ast = pro.ast_mangle(ast, config.mangle || {}); 20 | ast = pro.ast_squeeze(ast, config.squeeze || {}); 21 | src = pro.gen_code(ast, config.codegen || {}); 22 | log.ok(); 23 | return src; 24 | } catch(e) { 25 | log.error(); 26 | log.indent(function() { 27 | log.error('[L' + e.line + ':C' + e.col + '] ' + e.message + ' (position: ' + e.pos + ')'); 28 | }) 29 | return false; 30 | } 31 | }; 32 | 33 | // Return deflated src input. 34 | exports.gzip = function(src) { 35 | return zlib.deflate(new Buffer(src)); 36 | }; 37 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 "Cowboy" Ben Alman 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /examples/multiple-plugins/plugin.json: -------------------------------------------------------------------------------- 1 | { 2 | "jquery-random": { 3 | "label": "jQuery Random", 4 | "description": "Filter the current set down to a single random element.", 5 | "dist": { 6 | "dev": "dist/jquery.ba-random.js", 7 | "prod": "dist/jquery.ba-random.min.js" 8 | }, 9 | "license": ["MIT", "GPL"], 10 | "copyright": "Copyright (c) 2011 Ben Alman", 11 | "homeurl": "http://benalman.com/", 12 | "versions": [ 13 | { "version": "0.1.0" } 14 | ], 15 | "jqbuild": { 16 | "config": {}, 17 | "src": [ 18 | "src/random.js" 19 | ] 20 | } 21 | }, 22 | "jquery-not-random": { 23 | "label": "jQuery NOT Random", 24 | "description": "Filter the current set down to a single NON random element.", 25 | "dist": { 26 | "dev": "dist/jquery.ba-notrandom.js", 27 | "prod": "dist/jquery.ba-notrandom.min.js" 28 | }, 29 | "license": ["MIT", "GPL"], 30 | "copyright": "Copyright (c) 2011 Ben Alman", 31 | "homeurl": "http://benalman.com/", 32 | "versions": [ 33 | { "version": "0.1.0" } 34 | ], 35 | "jqbuild": { 36 | "config": { 37 | "jshint": { 38 | "sub": true, 39 | "asi": true 40 | } 41 | }, 42 | "src": [ 43 | "src/not-random.js", 44 | "src/random.js" 45 | ] 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /lib/jqbuild/help.js: -------------------------------------------------------------------------------- 1 | var pkg = require('./pkginfo'); 2 | var cli = require('./cli'); 3 | var log = require('./log'); 4 | var util = require('./util'); 5 | 6 | var arr = [ 7 | ' ' + pkg.description, 8 | ' ' + pkg.homepage, 9 | '## Usage:', 10 | ' jqbuild [options] [action] [plugins]', 11 | '## Options:' 12 | ]; 13 | 14 | Object.keys(cli._options).forEach(function(long) { 15 | var str; 16 | var opt = cli._options[long]; 17 | if ( opt.desc ) { 18 | str = eval(util.ghettoTmpl(opt, (opt.short ? ' -{{.short}},' : ' ') + ' --{{long}} {{.desc}}')); 19 | arr.push(log.pad(20, / (-\S,| ) --\S+/g, str)); 20 | } 21 | }); 22 | 23 | arr.push( 24 | '', 25 | ' Any listed option with a ' + '*'.green + ' can be set for all plugins in jqbuild.json, or on a', 26 | ' per-plugin basis in plugin.json. Any option can be negated on the command line', 27 | ' using --no-optname (false) and un-negated using --optname (true).', 28 | '', 29 | ' Options are overridden in this order: 1) internal defaults, 2) jqbuild.json,', 30 | ' 3) --config jqbuild.json file, 4) plugin.json, 5) command line flags.', 31 | '## Actions:' 32 | ); 33 | 34 | Object.keys(cli._actions).forEach(function(action) { 35 | var str = eval(util.ghettoTmpl(cli._actions, ' <{{action}}> {{.' + action + '}}')); 36 | arr.push(log.pad(10, /<.*?>/g, str)); 37 | }); 38 | 39 | log.writelns(arr); 40 | 41 | process.exit(); 42 | 'defaults', 'local', plbuild.config, 'conf', cli.opts -------------------------------------------------------------------------------- /lib/jqbuild/file.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'); 2 | var path = require('path'); 3 | var util = require('./util'); 4 | var log = require('./log'); 5 | 6 | // Read a file. 7 | exports.read = function(filepath) { 8 | var src; 9 | log.write('Reading ' + filepath + '...'); 10 | try { 11 | src = fs.readFileSync(filepath, 'UTF-8'); 12 | log.ok(); 13 | return src; 14 | } catch(e) { 15 | log.error(); 16 | log.indent(function() { 17 | log.error(e.message); 18 | }); 19 | return false; 20 | } 21 | }; 22 | 23 | // Write a file. 24 | exports.write = function(filepath, contents, opts) { 25 | if ( opts.nowrite ) { 26 | log.writeln('Not'.underline + ' writing ' + filepath + ' (dry run).'); 27 | return true; 28 | } 29 | log.write('Writing ' + filepath + '...'); 30 | try { 31 | fs.writeFileSync(filepath, contents, 'UTF-8'); 32 | log.ok(); 33 | return true; 34 | } catch(e) { 35 | log.error(); 36 | log.indent(function() { 37 | log.error(e); 38 | }); 39 | } 40 | }; 41 | 42 | // Read and parse a JSON file. 43 | exports.readJson = function(filepath, errmsg, opts) { 44 | opts = util.merge({pretty: filepath}, opts); 45 | var result = {}; 46 | var reading = log.write.bind(null, 'Reading ' + opts.pretty + '...'); 47 | if ( filepath ) { 48 | opts.silent || reading(); 49 | if ( path.existsSync(filepath) ) { 50 | try { 51 | result = JSON.parse(fs.readFileSync(filepath, 'UTF-8')); 52 | opts.silent && reading(); 53 | log.ok(); 54 | //opts.silent || log.ok(); 55 | } catch(e) { 56 | opts.silent && reading(); 57 | log.error(); 58 | log.error(e.message); 59 | errmsg && log.error(errmsg); 60 | result = false; 61 | } 62 | } else if ( opts.required ) { 63 | opts.silent && reading(); 64 | log.error(); 65 | log.error('Error reading file ' + opts.pretty + '.'); 66 | errmsg && log.error(errmsg); 67 | result = false; 68 | } 69 | } 70 | return result; 71 | }; 72 | -------------------------------------------------------------------------------- /lib/jqbuild/log.js: -------------------------------------------------------------------------------- 1 | var errors = exports.errors = []; 2 | 3 | // Strip colors from colorized strings. 4 | var uncolorRe = new RegExp('\033\\[\\d+m', 'g'); 5 | var uncolor = exports.uncolor = function(str) { 6 | return str.replace(uncolorRe, ''); 7 | }; 8 | 9 | // String padding stuff. 10 | var pad = exports.pad = function(n, re, str) { 11 | var p = Array(n + 1).join(' '); 12 | return str.replace(/\n/g, '\n' + p).replace(re, function(s) { 13 | return s + p.substr(uncolor(s).length + 1); 14 | }); 15 | }; 16 | 17 | // Increase/decrease indentation. 18 | var indent = exports.indent = function(n) { 19 | if ( indent.i == null ) { indent.i = 0; } 20 | if ( typeof n == 'function' ) { 21 | indent.i++; n(); indent.i--; 22 | } else if ( n === 0 ) { 23 | indent.i = 0; 24 | } else { 25 | indent.i += n; 26 | } 27 | }; 28 | 29 | // Error. 30 | var error = exports.error = function(txt) { 31 | if ( txt ) { 32 | errors.push(txt); 33 | writeln('>> '.red + txt); 34 | } else { 35 | write('ERROR'.red + '\n', true); 36 | } 37 | }; 38 | 39 | // Ok. 40 | var ok = exports.ok = function(txt) { 41 | if ( txt ) { 42 | writeln('>> '.green + txt); 43 | } else { 44 | write('OK'.green + '\n', true); 45 | } 46 | }; 47 | 48 | // Write some text, without a linefeed, indenting if necessary. 49 | var write = exports.write = function(txt, noindent) { 50 | var i = indent.i || 0; 51 | var prefix = Array(i + 1).join(' '); 52 | process.stdout.write((noindent ? '' : prefix) + (txt || '')); 53 | }; 54 | 55 | // Write some text, with a linefeed. 56 | var writeln = exports.writeln = function(txt) { 57 | write(txt); 58 | write('\n'); 59 | }; 60 | 61 | // Write many lines of text. 62 | var writelns = exports.writelns = function(a) { 63 | var b = typeof a == 'string' ? Array.prototype.slice.call(arguments) : a; 64 | b.forEach(function(line) { 65 | writeln(line 66 | .replace(/\*$/g, function(s) { return s.green; }) 67 | .replace(/^## (.+)/g, function(_, s) { return '\n' + s.underline.cyan + '\n'; }) 68 | .replace(/ --[\w-]+| -\w/g, function(s) { return s.yellow; }) 69 | .replace(/<(\w+)>/g, function(_, s) { return s.yellow; }) 70 | ); 71 | }); 72 | }; 73 | -------------------------------------------------------------------------------- /lib/jqbuild/cli.js: -------------------------------------------------------------------------------- 1 | var nopt = require('nopt'); 2 | var path = require('path'); 3 | 4 | // Acceptable --xxx or -x CLI flags. 5 | var options = exports._options = { 6 | banner: { 7 | short: 'b', 8 | desc: 'Specify an alternate top banner template.*', 9 | type: String 10 | }, 11 | config: { 12 | short: 'c', 13 | desc: 'Specify a custom jqbuild.json config file.', 14 | type: String 15 | }, 16 | debug: { 17 | short: 'd', 18 | desc: 'Allow console, alert, etc in lint (JSHint "devel"). Also \nwrites debugging comments into built "dev" scripts.*', 19 | type: Boolean 20 | }, 21 | force: { 22 | short: 'f', 23 | desc: 'A way to force your way past errors. Want a suggestion?\nDon\'t use this option, fix your errors.*', 24 | type: Boolean 25 | }, 26 | help: { 27 | short: 'h', 28 | desc: 'Display this help text.', 29 | type: Boolean 30 | }, 31 | pluginjson: { 32 | short: 'p', 33 | desc: 'Specify an alternate plugin.json file.', 34 | type: path 35 | }, 36 | prelint: { 37 | desc: 'Lint both before and after concatenation. To lint only AFTER\nconcatentation, use --no-prelint.*', 38 | type: Boolean 39 | }, 40 | version: { 41 | short: 'v', // TODO: implement 42 | desc: '', 43 | type: Boolean 44 | }, 45 | write: { 46 | desc: 'Write files. For a dry run, use --no-write.*', 47 | type: Boolean 48 | } 49 | }; 50 | 51 | // Acceptable actions. 52 | var actions = exports._actions = { 53 | make: 'Validate code (JSHint) and build (concat, add banner) distribution .js\nfiles (UglifyJS). This is the default action if none is specified.'/*, 54 | init: 'Generate sample dirs, files and plugin.json.\n(additional options needed??)'*/ 55 | }; 56 | 57 | // Parse `options` into a form that nopt can handle. 58 | var keys = Object.keys(options); 59 | var known = {}; 60 | keys.forEach(function(k) { known[k] = options[k].type; }); 61 | var aliases = {}; 62 | keys.forEach(function(k) { var s = options[k].short; if ( s ) { aliases[s] = '--' + k; } }); 63 | var parsed = nopt(known, aliases, process.argv, 2); 64 | //console.dir(parsed); process.exit(); 65 | 66 | var args = exports.args = parsed.argv.remain; 67 | delete parsed.argv; 68 | var opts = exports.opts = parsed; 69 | var action = exports.action = args[0] in actions ? args.shift() : Object.keys(actions)[0]; 70 | //console.dir(opts); console.dir(action); console.dir(args); process.exit(); 71 | -------------------------------------------------------------------------------- /lib/jqbuild/defaults.js: -------------------------------------------------------------------------------- 1 | // If you use a custom jqbuild.json file, it will have this exact same structure 2 | // except that it will need to be valid JSON (ie. no comments, no string concat) 3 | // and should only contain the keys you wish to override. 4 | // 5 | // If you only have one plugin, or want per-plugin settings, you may specify 6 | // these settings in a "config" key under the "jqbuild" key in that plugin's 7 | // JSON data. 8 | // 9 | // Per-plugin configuration options will override options set in jqbuild.json. 10 | 11 | module.exports = { 12 | // Options that have a non-falsy default value: 13 | "banner": "// {{.label}} - v{{.versions[0].version}} - {{dateFormat(now, 'm/d/yyyy')}}\n" 14 | + "// {{.homeurl}}\n" 15 | + "// {{.copyright}}; Licensed {{.license.join(', ')}}", 16 | "pluginjson": "plugin.json", 17 | "prelint": true, 18 | "write": true, 19 | // Non-string/boolean options, like the following, can only be overridden in 20 | // jqbuild.json or plugin.json: 21 | // 22 | // These are the default JSHint options I recommend. See jshint.com for more 23 | // information. 24 | "jshint": { 25 | // Force curly braces. 26 | "curly": true, 27 | // Allow == null 28 | "eqnull": true, 29 | // Allow for in without hasOwnProperty check (jQuery assumes that nothing 30 | // has been added to Object.prototype anyways, so it"s a moot point). 31 | "forin": true, 32 | // Require IIFEs to be wrapped in (). 33 | "immed": true, 34 | // Constructor functions must be capitalized. 35 | "newcap": true, 36 | // No arguments.caller and arguments.callee. Use NFEs instead. 37 | "noarg": true, 38 | // All non-global vars must be defined before they are used. 39 | "undef": true, 40 | // Allow browser globals, such as window, document, etc. 41 | "browser": true, 42 | // Only the jQuery global var is allowed, as $ will causes issues in 43 | // noConflict scenarios. Use an IIFE instead of JSHint"s 'jquery' option! 44 | "predef": ["jQuery"] 45 | }, 46 | // These are the default Uglify-JS options I recommend. See the docs at 47 | // https://github.com/mishoo/UglifyJS/ for more information. 48 | "uglify": { 49 | // Options passed to ast_mangle(). 50 | "mangle": { 51 | // Don"t mangle $, because it looks cool. 52 | "except": ["$"] 53 | }, 54 | // Options passed to ast_squeeze(). 55 | "squeeze": {}, 56 | // Options passed to gen_code(). 57 | "codegen": {} 58 | } 59 | }; -------------------------------------------------------------------------------- /lib/jqbuild/util.js: -------------------------------------------------------------------------------- 1 | // Ghetto fabulous template system for replacing values in strings. If {{.foo}} 2 | // or {{.bar[0].baz}} is encountered (leading . or ( or [ char), attempt to 3 | // access properties of data object like `data.foo` or `data.bar[0].baz`. 4 | // Alternately, if {{foo}} or {{bar("baz")}} is encountered (no leading dot), 5 | // simply evaluate `foo` or `bar("baz")`. If an error occurs, return empty 6 | // string. Oh yeah, you have to pass the result of ghettoTmpl to eval. :) 7 | // https://gist.github.com/1020250 8 | exports.ghettoTmpl = function(data, str) { 9 | __ghettoTmpldata = data; 10 | __ghettoTmplstr = str; 11 | return "__ghettoTmplstr.replace(/\\{\\{(([.[(])?.*?)\\}\\}/g, function(_, str, dot) {" 12 | + "return eval('try{' + (dot ? '__ghettoTmpldata' : '') + str + '}catch(e){\"\"}');" 13 | + "})"; 14 | }; 15 | 16 | // Optionally-recursive merge. Note: not smart enough to ignore non-plain 17 | // objects! Works pretty much like jQuery.extend(), except that any explicitly 18 | // set, null/undefined property value will have its property deleted outright. 19 | exports.merge = function merge() { 20 | var args = Array.prototype.slice.call(arguments); 21 | var deep = typeof args[0] == 'boolean' && args.shift(); 22 | var result = args.shift(); 23 | args.forEach(function(obj) { 24 | obj != null && Object.keys(obj).forEach(function(key) { 25 | var val = obj[key]; 26 | var empty; 27 | if ( val == null ) { 28 | delete result[key]; 29 | } else if ( deep && typeof val == 'object' ) { 30 | empty = val instanceof Array ? [] : {}; 31 | result[key] = merge(true, typeof result[key] == 'object' ? result[key] : empty, val); 32 | } else { 33 | result[key] = val; 34 | } 35 | }); 36 | }) 37 | return result; 38 | }; 39 | 40 | /*function mergeTests() { 41 | var o; 42 | o = merge(true, {}, {a: 1, b: 0, c: {x: 1}}, {b: 2, c: {y: 2}}) // { a: 1, b: 2, c: { x: 1, y: 2 } } 43 | console.log(o); 44 | o = merge(true, {}, {a: 1, b: 0, c: {x: 1}}, null, {b: 2, c: null}) // { a: 1, b: 2 } 45 | console.log(o); 46 | o = merge(true, {}, {a: 1, b: 0, c: {x: 1}}, undefined, {b: 2, c: undefined}) // { a: 1, b: 2 } 47 | console.log(o); 48 | o = merge(false, {}, {a: 1, b: 0, c: {x: 1}}, {b: 2, c: {y: 2}}) // { a: 1, b: 2, c: { y: 2 } } 49 | console.log(o); 50 | o = merge(false, {}, {a: 1, b: 0, c: {x: 1}}, null, {b: 2, c: null}) // { a: 1, b: 2 } 51 | console.log(o); 52 | o = merge(false, {}, {a: 1, b: 0, c: {x: 1}}, undefined, {b: 2, c: undefined}) // { a: 1, b: 2 } 53 | console.log(o); 54 | }*/ 55 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # jqbuild 2 | 3 | A command line build tool for jQuery plugins. 4 | 5 | _(coming soon)_ 6 | 7 | ## Installation 8 | 9 | npm install -g jqbuild 10 | 11 | ## Usage 12 | 13 | $ jqbuild --help 14 | jqbuild v0.1.0 by "Cowboy" Ben Alman 15 | 16 | A command line build tool for jQuery plugins. 17 | http://github.com/cowboy/node-jqbuild 18 | 19 | Usage: 20 | 21 | jqbuild [options] [action] [plugins] 22 | 23 | Options: 24 | 25 | -b, --banner Specify an alternate top banner template.* 26 | -c, --config Specify a custom jqbuild.json config file. 27 | -d, --debug Allow console, alert, etc in lint (JSHint "devel"). Also 28 | writes debugging comments into built "dev" scripts.* 29 | -f, --force A way to force your way past errors. Want a suggestion? 30 | Don't use this option, fix your errors.* 31 | -h, --help Display this help text. 32 | -p, --pluginjson Specify an alternate plugin.json file. 33 | --prelint Lint both before and after concatenation. To lint only AFTER 34 | concatentation, use --no-prelint.* 35 | --write Write files. For a dry run, use --no-write.* 36 | 37 | Any listed option with a * can be set for all plugins in jqbuild.json, or on a 38 | per-plugin basis in plugin.json. Any option can be negated on the command line 39 | using --no-optname (false) and un-negated using --optname (true). 40 | 41 | Options are overridden in this order: 1) internal defaults, 2) jqbuild.json, 42 | 3) --config jqbuild.json file, 4) plugin.json, 5) command line flags. 43 | 44 | Actions: 45 | 46 | make Validate code (JSHint) and build (concat, add banner) distribution .js 47 | files (UglifyJS). This is the default action if none is specified. 48 | 49 | ## Examples 50 | 51 | Look in the examples folder for sample plugin.json and jqbuild.json files, as well as sample directory structures. 52 | 53 | _Note: the plugin.json format shown here has NOT yet been finalized, so it will very likely change!_ 54 | 55 | ## Sample output 56 | 57 | $ jqbuild 58 | jqbuild v0.1.0 by "Cowboy" Ben Alman 59 | 60 | CONFIG 61 | Reading jqbuild.json...OK 62 | Reading plugin.json...OK 63 | 64 | PLUGIN jQuery Random (jquery-random) 65 | Reading src/random.js...OK 66 | Validating with JSHint...OK 67 | Minifying with UglifyJS...OK 68 | Writing dist/jquery.ba-random.min.js...OK 69 | Compressed size: 217 bytes gzipped (276 bytes minified). 70 | Writing dist/jquery.ba-random.js...OK 71 | Uncompressed size: 345 bytes. 72 | 73 | PLUGIN jQuery NOT Random (jquery-not-random) 74 | Reading src/not-random.js...OK 75 | Validating with JSHint...OK 76 | Reading src/random.js...OK 77 | Validating with JSHint...OK 78 | Concatenating 2 scripts...OK 79 | Validating with JSHint...OK 80 | Minifying with UglifyJS...OK 81 | Writing dist/jquery.ba-notrandom.min.js...OK 82 | Compressed size: 230 bytes gzipped (311 bytes minified). 83 | Writing dist/jquery.ba-notrandom.js...OK 84 | Uncompressed size: 425 bytes. 85 | 86 | >> All done! 87 | 88 | ## Release History 89 | Nothing yet... 90 | 91 | ## License 92 | Copyright (c) 2011 "Cowboy" Ben Alman 93 | Dual licensed under the MIT and GPL licenses. 94 | 95 | -------------------------------------------------------------------------------- /lib/jqbuild.js: -------------------------------------------------------------------------------- 1 | // Return a path relative to the jqbuild module root. 2 | var path = require('path'); 3 | var rpath = path.join.bind(null, __dirname, '..'); 4 | //require.paths.unshift(rpath('lib')); // REMOVE? 5 | 6 | var now = new Date; 7 | 8 | var colors = require('colors'); 9 | var dateFormat = require('dateformat'); 10 | 11 | var pkg = require('./jqbuild/pkginfo'); 12 | var cli = require('./jqbuild/cli'); 13 | var log = require('./jqbuild/log'); 14 | var file = require('./jqbuild/file'); 15 | var util = require('./jqbuild/util'); 16 | var lint = require('./jqbuild/lint'); 17 | var minify = require('./jqbuild/minify'); 18 | 19 | // Output some version info, etc at the very start. 20 | log.writeln((pkg.name + ' v' + pkg.version + ' by ' + pkg.author.replace(/<.*/, '')).cyan); 21 | 22 | // Only output version if --version specified. 23 | cli.opts.version && process.exit(); 24 | 25 | log.writeln(); 26 | 27 | // Usage info (can be displayed with --help). 28 | cli.opts.help && require('./jqbuild/help'); 29 | 30 | // Read and parse all specified config options. 31 | log.writeln('CONFIG'.cyan); 32 | log.indent(1); 33 | 34 | var jqbuild = {}; 35 | 36 | // Config options. 37 | jqbuild.config = { 38 | // Base config. All boolean defaults are false (see the `options` object). 39 | defaults: require('./jqbuild/defaults'), 40 | 41 | // Parse ~/.jqbuild, if it exists. BAD IDEA?? 42 | local: file.readJson('jqbuild.json', 43 | 'The jqbuild.json file is invalid or cannot be read.', 44 | {silent: true}) || fatality(), 45 | 46 | // Parse --config jqbuild.json, if it exists. 47 | conf: file.readJson(cli.opts.config, 48 | 'The specified config file is invalid or cannot be read.', 49 | {required: true}) || fatality(), 50 | 51 | // Merge configs. 52 | merge: function() { 53 | var args = Array.prototype.slice.call(arguments); 54 | return util.merge.apply(null, [true, {}].concat(args.map(function(v) { 55 | return typeof v == 'string' ? jqbuild.config[v] : v; 56 | }))); 57 | }, 58 | }; 59 | 60 | // Parse plugin.json file 61 | var pluginjson = jqbuild.config.merge('defaults', 'local', 'conf', cli.opts).pluginjson; 62 | jqbuild.plugins = file.readJson(pluginjson, 63 | 'A valid plugin.json file is required. Use --help for more information.', 64 | {required: true, pretty: 'plugin.json'}) || fatality(); 65 | 66 | log.indent(-1); 67 | 68 | // Iterate over all plugins. 69 | var keys = cli.args.length ? cli.args : Object.keys(jqbuild.plugins); 70 | 71 | if ( !keys.length ) { 72 | log.writeln(); 73 | log.error('No plugins found in plugin.json.'); 74 | fatality(); 75 | } 76 | 77 | keys.forEach(function(name) { 78 | var dev, prod, gzip, min, linterror; 79 | var errlen = log.errors.length; 80 | var plugin = jqbuild.plugins[name]; 81 | log.writeln(); 82 | log.writeln(('PLUGIN ' + (plugin ? plugin.label : '???') + ' (' + name + ')').cyan); 83 | if ( !plugin ) { 84 | log.indent(function() { 85 | log.error('PLUGIN ' + name + ' not found!'); 86 | }); 87 | return; 88 | } 89 | log.indent(1); 90 | // Get plugin-specific jqbuild data. 91 | var plbuild = plugin.jqbuild || {}; 92 | // Merge config data. 93 | var config = jqbuild.config.merge('defaults', 'local', plbuild.config, 'conf', cli.opts); 94 | //console.dir(config); 95 | // Build banner from plugin metadata. 96 | var banner = eval(util.ghettoTmpl(plugin, typeof config.banner == 'string' ? config.banner : '')); 97 | if ( banner ) { banner += '\n'; } 98 | 99 | // Iterate through sources, concatenating.. 100 | if ( !plbuild.src || !plbuild.src.length ) { 101 | log.error('No "src" files defined in plugin.json.'); 102 | log.indent(-1); 103 | return; 104 | } 105 | 106 | var src = plbuild.src.map(function(path) { 107 | var src = file.read(path); 108 | if ( src === false ) { return; } 109 | // Don't lint if --no-prelint was set, in cases where source files contain 110 | // and intro.js + outro.js, for example. 111 | if ( config.prelint ) { 112 | log.indent(function() { 113 | linterror = !lint.jshint(src, config) || linterror; 114 | }); 115 | } 116 | // If --debug was set, prepend a comment before each source file. 117 | if ( config.debug ) { 118 | src = '// SOURCE: ' + path + '\n\n' + src; 119 | } 120 | return src; 121 | }).join('\n'); 122 | 123 | if ( linterror ) { 124 | if ( plbuild.src.length >= 2 ) { 125 | log.error('Errors were encountered. To disable pre-concat lint, use --no-prelint.'); 126 | } 127 | } else if ( log.errors.length > errlen ) { 128 | log.error('Errors were encountered.'); 129 | log.indent(-1); 130 | return; 131 | } 132 | 133 | // Dev (uncompressed) version. 134 | dev = banner + '\n' + src; 135 | 136 | // Only mention concatenation or lint here if 2+ scripts were concatenated! 137 | if ( plbuild.src.length >= 2 ) { 138 | log.write('Concatenating ' + plbuild.src.length + ' scripts...'); 139 | src ? log.ok() : log.error(); 140 | log.indent(function() { 141 | linterror = !lint.jshint(dev, config) || linterror; 142 | }); 143 | } 144 | 145 | // If errors have occurred, abort unless --force used. 146 | if ( log.errors.length > errlen ) { 147 | if ( config.force ) { 148 | log.error('Errors were encountered, --force was used. Continuing.'); 149 | } else { 150 | log.error('Errors were encountered, aborting build. Use --force to build regardless.'); 151 | log.indent(-1); 152 | return; 153 | } 154 | } 155 | 156 | // Write out distribution versions. 157 | if ( plugin.dist && (plugin.dist.prod || plugin.dist.dev) ) { 158 | if ( plugin.dist.prod ) { 159 | // Minify 160 | min = minify.uglify(src, config.uglify); 161 | if ( min !== false ) { 162 | // Production (compressed) version. 163 | prod = banner + min; 164 | // Length of gzipped production version. 165 | gzip = minify.gzip(prod).length + ''; 166 | // Write production version. 167 | if ( file.write(plugin.dist.prod, prod, {nowrite: !config.write}) ) { 168 | // Some useful information. 169 | log.indent(function() { 170 | log.writeln('Compressed size: ' + gzip.yellow + ' bytes gzipped (' + (prod.length + '').yellow + ' bytes minified).'); 171 | }); 172 | } 173 | } 174 | } 175 | if ( plugin.dist.dev ) { 176 | // Write dev version. 177 | if ( file.write(plugin.dist.dev, dev, {nowrite: !config.write}) ) { 178 | log.indent(function() { 179 | log.writeln('Uncompressed size: ' + (dev.length + '').yellow + ' bytes.'); 180 | }); 181 | } 182 | } 183 | } else { 184 | log.error('No distribution files defined in plugin.json, nothing to build!'); 185 | } 186 | log.indent(-1); 187 | }); 188 | 189 | // Was everything successful? 190 | log.indent(0); 191 | log.writeln(); 192 | if ( log.errors.length ) { 193 | // Whoops? 194 | log.error('Done, but with errors.'); 195 | process.exit(2); 196 | } else { 197 | // Everything finished up A-OK. 198 | log.ok('All done!'); 199 | process.exit(0); 200 | } 201 | 202 | // Something really bad happened. 203 | function fatality() { 204 | log.indent(0); 205 | log.writeln(); 206 | log.error('An unrecoverable error occurred, exiting.'); 207 | process.exit(1); 208 | } 209 | -------------------------------------------------------------------------------- /LICENSE-GPL: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. --------------------------------------------------------------------------------