From 9212569028fb67907e2579377d53d9562cab9b44 Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Mon, 17 Nov 2014 23:47:39 +0100 Subject: [PATCH 1/4] browserify pvz & provide biojs snippets --- Gruntfile.js | 40 +++++++++++ build-tools/end.frag.txt | 4 +- build-tools/start.frag.txt | 6 +- index.js | 2 + package.json | 45 ++++++++++--- snippets/example-0.js | 134 +++++++++++++++++++++++++++++++++++++ 6 files changed, 218 insertions(+), 13 deletions(-) create mode 100644 index.js create mode 100644 snippets/example-0.js diff --git a/Gruntfile.js b/Gruntfile.js index 4151281..a3d39ae 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -170,4 +170,44 @@ module.exports = function(grunt) { grunt.registerTask('build', ['build_x', 'copy:dist', 'copy:dist-examples', 'jsdoc']); + + var browserify = require("browserify"); + var mkdirp = require("mkdirp"); + var fs = require("fs"); + + grunt.registerTask('browserify', 'Browserifies the source', function(){ + // task is async + var done = this.async(); + + // create tmp dir + mkdirp("build"); + + var packageConfig = require("./package.json"); + + // local test build + var outFile = 'build/pviz.local.js'; + var wsExport = fs.createWriteStream(outFile); + wsExport.on('finish', function () { + console.log("patching amd"); + fs.readFile(outFile, "utf8", function(err,data){ + // patch the AMD output - this is VERY ugly (but works) + // first patch: backbone-amd needs to be instantiated in via AMD + //data = data.replace(/if \(typeof exports !== 'undefined'\) {\s+?\n\s+\/\/ Node\/CommonJS, no need for jQuery in that case\./, "if (typeof exportsNotDefined !== 'undefined') {"); + data = data.replace(/if \(typeof exports !== 'undefined'\) {\s+?\/\/ Node\/CommonJS, no need for jQuery in that case\./, "if (typeof exportsNotDefined !== 'undefined') {"); + + // second patch: somehow there is sth. wrong with the backbone version and its + // router + data = data.replace("_.bindAll(this, 'checkUrl');", "//_.bindAll(this, 'checkUrl');"); + + console.log("patching finished"); + fs.writeFile(outFile,data, function(){ + done(); + }); + }); + }); + + var b = browserify({debug: false,hasExports: true, insertGlobalVars: []}); + b.add('./index.js', {expose: packageConfig.name }); + b.bundle().pipe(wsExport); + }); }; diff --git a/build-tools/end.frag.txt b/build-tools/end.frag.txt index 28ccfd8..a890c9f 100644 --- a/build-tools/end.frag.txt +++ b/build-tools/end.frag.txt @@ -2,5 +2,5 @@ //this snippet. Ask almond to synchronously require the //module value for 'main' here and return it as the //value to use for the public API for the built file. - return require('PVizExport'); -})); \ No newline at end of file + return requirejs('PVizExport'); +})); diff --git a/build-tools/start.frag.txt b/build-tools/start.frag.txt index 44bc6fb..4c43cdb 100644 --- a/build-tools/start.frag.txt +++ b/build-tools/start.frag.txt @@ -36,11 +36,13 @@ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. //see this AMD call, not the internal modules in //the closure below. define(factory); - } else { + } else if(typeof exports !== "undefined"){ + module.exports = factory(); + }else { //Browser globals case. Just assign the //result to a property on the global. root.pviz = factory(); } }(this, function () { //almond, and your modules will be inlined here - \ No newline at end of file + diff --git a/index.js b/index.js new file mode 100644 index 0000000..f3c83b1 --- /dev/null +++ b/index.js @@ -0,0 +1,2 @@ +_ = require("underscore"); +module.exports = require("./build/pviz-bundle.js"); diff --git a/package.json b/package.json index 9bde3e9..6adef89 100644 --- a/package.json +++ b/package.json @@ -1,20 +1,47 @@ { "name": "pviz", "version": "0.1.10", - "dependencies": {}, + "repository": { + "type": "git", + "url": "github.com/genentech/pviz" + }, + "dependencies": { + "underscore": "^1.4.4" + }, "devDependencies": { + "biojs-sniper": "^0.1.0", + "bower": "~1.2.8", + "browserify": "^6.3.2", "grunt": "~0.4.2", + "grunt-bower-requirejs": "~0.8.0", + "grunt-cli": "~0.1.11", + "grunt-contrib-clean": "~0.5.0", + "grunt-contrib-concat": "~0.3.0", + "grunt-contrib-copy": "~0.4.1", "grunt-contrib-jshint": "~0.7.2", "grunt-contrib-uglify": "~0.2.7", "grunt-contrib-watch": "~0.5.3", - "bower": "~1.2.8", - "grunt-bower-requirejs": "~0.8.0", "grunt-devserver": "~0.5.0", + "grunt-jsdoc": "^0.5.6", "grunt-requirejs": "~0.4.0", - "grunt-contrib-concat": "~0.3.0", - "grunt-cli": "~0.1.11", - "grunt-contrib-copy": "~0.4.1", - "grunt-contrib-clean": "~0.5.0", - "grunt-jsdoc": "^0.5.6" - } + "mkdirp": "^0.5.0" + }, + "scripts": { + "prepublish": "bower install && grunt build browserify" + }, + "main": "./index.js", + "sniper": { + "js": [ + "/build/pviz.local.js" + ], + "css": [ + "/src/css/pviz-core.css" + ], + "first": "example-0" + }, + "keywords": [ + "feature", + "annotation", + "biojs" + ] } diff --git a/snippets/example-0.js b/snippets/example-0.js new file mode 100644 index 0000000..7ca6ab7 --- /dev/null +++ b/snippets/example-0.js @@ -0,0 +1,134 @@ +var pviz = require("pviz"); + +//define the model, a sequence entry with an explicit sequence +var seq = 'MELAALCRWGLLLALLPPGAASTQVCTGTDMKLRLPASPETHLDMLRHLYQGCQVVQGNLELTYLPTNASLSFLQDIQEVQGYVLIAHNQVRQVPLQRLRIVRGTQLFEDNYALAVLDNGDPLNNTTPVTGASPGGLRELQLRSLTEILKGGVLIQRNPQLCYQDTILWKDIFHKNNQLA'; +var seqEntry = new pviz.SeqEntry({ + sequence : seq +}); + +/* + * thefined the view, in a backbone.js fashion + * model: that's the model, who would have guessed + * el: a selector to the target where to insert the view (size and so will be inherited) + * + * .render(): call the rendering + * + * NB: even though the features are not yet added to the model, the view will be recomputed at the end of any feature addition. + * This is to take into account asynchroncity, when data comes from several remote sources + */ +new pviz.SeqEntryAnnotInteractiveView({ + model : seqEntry, + el : yourDiv +}).render(); + +/* we can add featureswith properties + * group: features will be grouped together on this property. they might no be displayed on the same line, but feature with different grous cannot be on the same line + * type: within group, property can have different types + * text: to be displayed or use wherever you want + * start: initial position, starting at 0 + * end: last position of the feature (including), starting at 0 + * + * NB: the explicit loading of features could be replaced by a JSON call. But for the sake of a standalone example, ajax does not work with file queries + d3.tsv('example-features.tsv', function(err, data) { + seqEntry.addFeatures(data); + }); + */ +seqEntry.addFeatures([{ + category : 'ptms', + type : 'mickey', + start : 20, + end : 20, + count : 10 +}, { + category : 'ptms', + type : 'mickey', + start : 22, + end : 22, + count : 3 +}, { + category : 'ptms', + type : 'mickey', + start : 40, + end : 40, + count : 10, + improbable : true //!! an option attribute +}, { + category : 'ptms', + type : 'mickey', + start : 50, + end : 50, + count : 2 +}, { + category : 'regions', + type : 'topological domain', + text : 'extra cellular', + start : 22, + end : 650 +}, { + category : 'secondary structure', + type : 'beta_strand', + start : 24, + end : 26 +}, { + category : 'secondary structure', + type : 'helix', + start : 38, + end : 49 +}, { + category : 'secondary structure', + type : 'beta_strand', + start : 53, + end : 57 +}, { + category : 'secondary structure', + type : 'beta_strand', + start : 59, + end : 63 +}, { + category : 'secondary structure', + type : 'helix', + start : 71, + end : 73 +}, { + category : 'secondary structure', + type : 'beta_strand', + start : 78, + end : 81 +}, { + category : 'secondary structure', + type : 'beta_strand', + start : 83, + end : 87 +}, { + category : 'secondary structure', + type : 'beta_strand', + start : 91, + end : 94 +}, { + category : 'secondary structure', + type : 'turn', + start : 108, + end : 110 +}, { + category : 'secondary structure', + type : 'beta_strand', + start : 111, + end : 116 +}, { + category : 'secondary structure', + type : 'turn', + start : 129, + end : 131 +}, { + category : 'secondary structure', + type : 'beta_strand', + start : 138, + end : 140 +}, { + category : 'secondary structure', + type : 'beta_strand', + start : 150, + end : 155 +}]); + + From 3e81489a2a8d21fa5efc4b80824e44c3365f8b75 Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Mon, 17 Nov 2014 23:50:27 +0100 Subject: [PATCH 2/4] sniper as npm task --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 6adef89..74b5045 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,8 @@ "mkdirp": "^0.5.0" }, "scripts": { - "prepublish": "bower install && grunt build browserify" + "prepublish": "bower install && grunt build browserify", + "sniper": "biojs-sniper ." }, "main": "./index.js", "sniper": { From 32c200acb87c6071e22b38c0cb147c01f12aeceb Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Sat, 22 Nov 2014 04:44:15 +0100 Subject: [PATCH 3/4] updated grunt task to push the modified library to dist --- Gruntfile.js | 37 +++++++++++++++++++++++-------------- index.js | 2 +- package.json | 4 ++-- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index a3d39ae..2036830 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -175,20 +175,12 @@ module.exports = function(grunt) { var mkdirp = require("mkdirp"); var fs = require("fs"); - grunt.registerTask('browserify', 'Browserifies the source', function(){ - // task is async + grunt.registerTask('patch-pviz', 'Makes pviz work for node', function(){ var done = this.async(); - - // create tmp dir - mkdirp("build"); - - var packageConfig = require("./package.json"); - - // local test build - var outFile = 'build/pviz.local.js'; - var wsExport = fs.createWriteStream(outFile); - wsExport.on('finish', function () { - console.log("patching amd"); + console.log("patching amd"); + + var outFile = 'dist/pviz-bundle.js'; + var modFile = 'dist/pviz.mod.js'; fs.readFile(outFile, "utf8", function(err,data){ // patch the AMD output - this is VERY ugly (but works) // first patch: backbone-amd needs to be instantiated in via AMD @@ -200,14 +192,31 @@ module.exports = function(grunt) { data = data.replace("_.bindAll(this, 'checkUrl');", "//_.bindAll(this, 'checkUrl');"); console.log("patching finished"); - fs.writeFile(outFile,data, function(){ + fs.writeFile(modFile,data, function(){ done(); }); }); + }); + + grunt.registerTask('build-browser', function(){ + // task is async + var done = this.async(); + + // create tmp dir + mkdirp("build"); + + var packageConfig = require("./package.json"); + + // local test build + var outFile = 'build/pviz.local.js'; + var wsExport = fs.createWriteStream(outFile); + wsExport.on('finish', function () { + done(); }); var b = browserify({debug: false,hasExports: true, insertGlobalVars: []}); b.add('./index.js', {expose: packageConfig.name }); b.bundle().pipe(wsExport); }); + grunt.registerTask('browserify', ['build_x','copy:dist', 'patch-pviz','build-browser']); }; diff --git a/index.js b/index.js index f3c83b1..13d1cdc 100644 --- a/index.js +++ b/index.js @@ -1,2 +1,2 @@ _ = require("underscore"); -module.exports = require("./build/pviz-bundle.js"); +module.exports = require("./dist/pviz.mod.js"); diff --git a/package.json b/package.json index 74b5045..3d230aa 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "pviz", - "version": "0.1.10", + "version": "0.1.12-1", "repository": { "type": "git", - "url": "github.com/genentech/pviz" + "url": "github.com/greenify/pviz" }, "dependencies": { "underscore": "^1.4.4" From 23ed244b52ee95b6fd7553193d6ba773a03bed73 Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Sat, 22 Nov 2014 04:47:09 +0100 Subject: [PATCH 4/4] added description to the package.gson --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 3d230aa..92ffb0c 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,10 @@ { "name": "pviz", - "version": "0.1.12-1", + "version": "0.1.12-2", + "description": "pViz.js is a protein sequence features viewer for modern browsers", "repository": { "type": "git", - "url": "github.com/greenify/pviz" + "url": "github.com/genentech/pviz" }, "dependencies": { "underscore": "^1.4.4"