From 5b0602c915af693a802c83f6f156a97797911338 Mon Sep 17 00:00:00 2001 From: Nycto Date: Sun, 17 Nov 2013 22:00:16 -0800 Subject: [PATCH 1/4] Add grunt build --- .gitignore | 2 ++ Gruntfile.js | 23 +++++++++++++++++++++++ package.json | 9 +++++++-- 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 Gruntfile.js diff --git a/.gitignore b/.gitignore index aa75021..3b6ed46 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .idea/ *.lock *.log +node_modules +build diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..adc205b --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,23 @@ +/* global module: false */ +module.exports = function(grunt) { + "use strict"; + + // Project configuration. + grunt.initConfig({ + pkg: grunt.file.readJSON('package.json'), + + uglify: { + build: { + src: 'src/**/*.js', + dest: 'build/pen-<%= pkg.version %>.min.js' + } + } + }); + + // Plugins + grunt.loadNpmTasks('grunt-contrib-uglify'); + + // Default task(s). + grunt.registerTask('default', ['uglify']); + +}; diff --git a/package.json b/package.json index 1e76f1f..f9f6e5a 100644 --- a/package.json +++ b/package.json @@ -16,5 +16,10 @@ "license": { "type": "MIT", "url": "https://github.com/sofish/pen/blob/master/license.txt" - } -} \ No newline at end of file + }, + "devDependencies": { + "grunt": "~0.4.1", + "grunt-contrib-uglify": "~0.2.7" + }, + "readmeFilename": "README.md" +} From b9759494adf11db8885334df34bb79db30b5808c Mon Sep 17 00:00:00 2001 From: Nycto Date: Sun, 17 Nov 2013 22:09:17 -0800 Subject: [PATCH 2/4] Add jshint to build --- Gruntfile.js | 35 ++++++++++++++++++++++++++++++++++- package.json | 4 +++- src/markdown.js | 6 +++--- src/pen.js | 25 +++++++++++++------------ 4 files changed, 53 insertions(+), 17 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index adc205b..1efb6b2 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -6,18 +6,51 @@ module.exports = function(grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), + jshint: { + files: ['Gruntfile.js', 'src/**/*.js'], + options: { + globals: { 'console': false }, + bitwise: true, + camelcase: false, + curly: false, + eqeqeq: true, + forin: true, + immed: true, + indent: 2, + latedef: true, + laxcomma: true, + newcap: true, + noarg: true, + nonew: true, + noempty: true, + undef: true, + unused: true, + strict: false, + trailing: true, + maxlen: 200, + browser: true + } + }, + uglify: { build: { src: 'src/**/*.js', dest: 'build/pen-<%= pkg.version %>.min.js' } + }, + + watch: { + files: ['<%= jshint.files %>'], + tasks: ['jshint'] } }); // Plugins + grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-uglify'); + grunt.loadNpmTasks('grunt-contrib-watch'); // Default task(s). - grunt.registerTask('default', ['uglify']); + grunt.registerTask('default', ['jshint', 'uglify']); }; diff --git a/package.json b/package.json index f9f6e5a..bd68ce5 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,9 @@ }, "devDependencies": { "grunt": "~0.4.1", - "grunt-contrib-uglify": "~0.2.7" + "grunt-contrib-jshint": "~0.7.2", + "grunt-contrib-uglify": "~0.2.7", + "grunt-contrib-watch": "~0.5.3" }, "readmeFilename": "README.md" } diff --git a/src/markdown.js b/src/markdown.js index feefa7a..b8595db 100644 --- a/src/markdown.js +++ b/src/markdown.js @@ -1,5 +1,5 @@ /*! Licensed under MIT, https://github.com/sofish/pen */ -~function() { +(function() { // only works with Pen if(!this.Pen) return; @@ -67,6 +67,6 @@ }; // append to Pen - Pen.prototype.markdown = covertor; + window.Pen.prototype.markdown = covertor; -}(); \ No newline at end of file +}()); diff --git a/src/pen.js b/src/pen.js index fc0416a..60dc423 100644 --- a/src/pen.js +++ b/src/pen.js @@ -1,5 +1,6 @@ /*! Licensed under MIT, https://github.com/sofish/pen */ -~function(doc) { +/* jshint -W030, -W093, -W015 */ +(function(doc) { var Pen, FakePen, utils = {}; @@ -27,14 +28,14 @@ // shift a function utils.shift = function(key, fn, time) { - time = time || 50; - var queue = this['_shift_fn' + key], timeout = 'shift_timeout' + key, current; - queue ? queue.concat([fn, time]) : (queue = [[fn, time]]); - current = queue.pop(); - clearTimeout(this[timeout]); - this[timeout] = setTimeout(function() { - current[0](); - }, time); + time = time || 50; + var queue = this['_shift_fn' + key], timeout = 'shift_timeout' + key, current; + queue ? queue.concat([fn, time]) : (queue = [[fn, time]]); + current = queue.pop(); + clearTimeout(this[timeout]); + this[timeout] = setTimeout(function() { + current[0](); + }, time); }; // merge: make it easy to have a fallback @@ -217,7 +218,7 @@ , effects = this._effectNode(node) , menu = this._menu , linkInput = menu.querySelector('input') - , highlight + , highlight; // remove all highlights [].slice.call(menu.querySelectorAll('.active')).forEach(function(el) { @@ -332,7 +333,7 @@ Pen.prototype.destroy = function(isAJoke) { var destroy = isAJoke ? false : true - , attr = isAJoke ? 'setAttribute' : 'removeAttribute' + , attr = isAJoke ? 'setAttribute' : 'removeAttribute'; if(!isAJoke) { this._sel.removeAllRanges(); @@ -364,4 +365,4 @@ // make it accessible this.Pen = doc.getSelection ? Pen : FakePen; -}(document); +}(document)); From 60038fb668651c092850bdfbd3bd7287f40eec55 Mon Sep 17 00:00:00 2001 From: Nycto Date: Sun, 17 Nov 2013 22:11:28 -0800 Subject: [PATCH 3/4] Travis-ci build support --- .travis.yml | 6 ++++++ package.json | 3 +++ 2 files changed, 9 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..d369c5c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,6 @@ +language: node_js +node_js: + - 0.10 +before_script: + - npm install -g grunt-cli + diff --git a/package.json b/package.json index bd68ce5..6942b53 100644 --- a/package.json +++ b/package.json @@ -23,5 +23,8 @@ "grunt-contrib-uglify": "~0.2.7", "grunt-contrib-watch": "~0.5.3" }, + "scripts": { + "test": "grunt --verbose" + }, "readmeFilename": "README.md" } From 440d42e2ab85d18fc14961016e1d503f383fe327 Mon Sep 17 00:00:00 2001 From: Nycto Date: Mon, 18 Nov 2013 08:29:01 -0800 Subject: [PATCH 4/4] Add build guide --- build.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 build.md diff --git a/build.md b/build.md new file mode 100644 index 0000000..d68aaf4 --- /dev/null +++ b/build.md @@ -0,0 +1,37 @@ +How to Build +============ + +The following steps should allow you to build this project: + +1. Make sure you have the lastest version of Node.js. On Ubuntu, you might + need a custom repository: + + ``` + sudo add-apt-repository ppa:chris-lea/node.js; + sudo apt-get update; + sudo apt-get install nodejs; + sudo apt-get upgrade; + ``` + +2. Next hop into source directory where you cloned this repo. The following + commands will install grunt and all the Node dependencies: + + ``` + cd Wherever_You_Cloned/pen; + npm install; + sudo npm install -g grunt-cli; + ``` + +3. Finally, you're ready to start a build: + + ``` + grunt; + ``` + + While editing a file, you can use `watch` to automatically rebuild every + time a file is saved: + + ``` + grunt watch; + ``` +