From 59486459b2efb4c2359aea5b28dbe9c98bd60ecc Mon Sep 17 00:00:00 2001 From: George Michael Brower Date: Sat, 27 Sep 2014 16:25:12 -0400 Subject: [PATCH] saver feedback --- build/dat-gui.html | 2 +- build/dat-gui.js | 2 +- elements/dat-gui/dat-gui.js | 5 +-- gulpfile.js | 6 ++- saver/package.json | 8 +++- saver/saver.js | 81 +++++++++++++++++++++++++------------ 6 files changed, 69 insertions(+), 35 deletions(-) diff --git a/build/dat-gui.html b/build/dat-gui.html index e88d9f0..e0d5aab 100755 --- a/build/dat-gui.html +++ b/build/dat-gui.html @@ -6,7 +6,7 @@ var e,f,g,h=b.type;if("load"===h&&!b.bubbles){var i=c;i instanceof Q.Document&&( +},_register:function(){c(this.extends)&&!b(this.extends)&&console.warn("%s is attempting to extend %s, an unregistered element or one that was not registered with Polymer.",this.name,this.extends),this.register(this.name,this.extends),this.registered=!0},waitingForPrototype:function(a){return h(a)?void 0:(i(a,this),this.handleNoScript(a),!0)},handleNoScript:function(a){this.hasAttribute("noscript")&&!this.noscript&&(this.noscript=!0,Polymer(a))},waitingForResources:function(){return this._needsResources},waitingForQueue:function(){return f.enqueue(this,this.registerWhenReady,this._register)},loadResources:function(){this._needsResources=!0,this.loadStyles(function(){this._needsResources=!1,this.registerWhenReady()}.bind(this))}});e.publish(e.declaration,j),g(function(){document.body.removeAttribute("unresolved"),document.dispatchEvent(new CustomEvent("polymer-ready",{bubbles:!0}))}),document.registerElement("polymer-element",{prototype:j})}(Polymer),function(){var a=document.createElement("polymer-element");a.setAttribute("name","auto-binding"),a.setAttribute("extends","template"),a.init(),Polymer("auto-binding",{createdCallback:function(){this.syntax=this.bindingDelegate=this.makeSyntax(),Polymer.whenPolymerReady(function(){this.model=this,this.setAttribute("bind",""),this.async(function(){this.marshalNodeReferences(this.parentNode),this.fire("template-bound")})}.bind(this))},makeSyntax:function(){var a=Object.create(Polymer.api.declaration.events),b=this;a.findController=function(){return b.model};var c=new PolymerExpressions,d=c.prepareBinding;return c.prepareBinding=function(b,e,f){return a.prepareEventBinding(b,e,f)||d.call(c,b,e,f)},c}})}(); diff --git a/build/dat-gui.js b/build/dat-gui.js index cc76500..ad47ab1 100755 --- a/build/dat-gui.js +++ b/build/dat-gui.js @@ -6,7 +6,7 @@ document.write(['', +'},_register:function(){c(this.extends)&&!b(this.extends)&&console.warn("%s is attempting to extend %s, an unregistered element or one that was not registered with Polymer.",this.name,this.extends),this.register(this.name,this.extends),this.registered=!0},waitingForPrototype:function(a){return h(a)?void 0:(i(a,this),this.handleNoScript(a),!0)},handleNoScript:function(a){this.hasAttribute("noscript")&&!this.noscript&&(this.noscript=!0,Polymer(a))},waitingForResources:function(){return this._needsResources},waitingForQueue:function(){return f.enqueue(this,this.registerWhenReady,this._register)},loadResources:function(){this._needsResources=!0,this.loadStyles(function(){this._needsResources=!1,this.registerWhenReady()}.bind(this))}});e.publish(e.declaration,j),g(function(){document.body.removeAttribute("unresolved"),document.dispatchEvent(new CustomEvent("polymer-ready",{bubbles:!0}))}),document.registerElement("polymer-element",{prototype:j})}(Polymer),function(){var a=document.createElement("polymer-element");a.setAttribute("name","auto-binding"),a.setAttribute("extends","template"),a.init(),Polymer("auto-binding",{createdCallback:function(){this.syntax=this.bindingDelegate=this.makeSyntax(),Polymer.whenPolymerReady(function(){this.model=this,this.setAttribute("bind",""),this.async(function(){this.marshalNodeReferences(this.parentNode),this.fire("template-bound")})}.bind(this))},makeSyntax:function(){var a=Object.create(Polymer.api.declaration.events),b=this;a.findController=function(){return b.model};var c=new PolymerExpressions,d=c.prepareBinding;return c.prepareBinding=function(b,e,f){return a.prepareEventBinding(b,e,f)||d.call(c,b,e,f)},c}})}();', '', '', '', diff --git a/elements/dat-gui/dat-gui.js b/elements/dat-gui/dat-gui.js index 4bd1a67..efd8bed 100644 --- a/elements/dat-gui/dat-gui.js +++ b/elements/dat-gui/dat-gui.js @@ -199,11 +199,8 @@ Polymer( 'dat-gui', { serialize: function() { - // todo: return json of every controller's serialize. - var data = { - values: {}, - vars: {}, // todo + values: {} }; for ( var objectKey in this._controllersByObject ) { diff --git a/gulpfile.js b/gulpfile.js index 4e49518..cfab6fe 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -82,7 +82,7 @@ gulp.task( 'watch', [ 'lint', 'build', 'test' ], function() { } ); -//////////////////////////////////////////////// + gulp.task( 'clean', function() { return gulp.src( 'build/*' ) @@ -186,6 +186,10 @@ gulp.task( 'vulcanize', [ 'style' ], function() { } ); + +// Config +// ------------------------------- + var nib = require( 'nib' ), highlight = require( 'highlight.js' ), karma = require( 'karma' ), diff --git a/saver/package.json b/saver/package.json index 0cc6e28..c25d5b4 100644 --- a/saver/package.json +++ b/saver/package.json @@ -5,5 +5,9 @@ "saver": "saver.js" }, "main": "saver.js", - "preferGlobal": "true" -} \ No newline at end of file + "preferGlobal": "true", + "dependencies": { + "colors": "^0.6.2", + "yargs": "^1.3.1" + } +} diff --git a/saver/saver.js b/saver/saver.js index 56f2860..076ac44 100644 --- a/saver/saver.js +++ b/saver/saver.js @@ -1,36 +1,65 @@ #!/usr/bin/env node -var http = require('http'); -var fs = require('fs'); +var http = require( 'http' ); +var fs = require( 'fs' ); +var path = require( 'path' ); + +var colors = require( 'colors' ); +var argv = require( 'yargs' ).argv; + +var PORT = 7999; +var BASEPATH = process.argv[ 2 ] || './' ; +var OUTFILE = path.join( BASEPATH, argv.o || 'dat-gui.json' ); + +http.createServer( function ( req, res ) { + + switch ( req.method ) { -http.createServer(function (req, res) { - var filename = /\/([^/]+\.json)$/.exec(req.url); - if (!filename) { - filename = 'dat-gui.json'; - } else { - filename = filename[1]; - } - switch(req.method) { - case 'GET': - if (!fs.existsSync(filename)) { - res.writeHead(404); - res.end(); - return - } - res.writeHead(200, {'Content-Type': 'application/json', 'Access-Control-Allow-Origin': 'http://localhost'}); - res.end(fs.readFileSync(filename, 'utf8')); - break; case 'POST': + var data = ''; - req.on('data', function(d) {data += d;}) - req.on('end', function() { - res.writeHead(200, {'Access-Control-Allow-Origin': 'http://localhost'}); - fs.writeFileSync(filename, data); + + req.on( 'data', function( d ) { + data += d; + } ); + + req.on( 'end', function() { + + res.writeHead( 200, { 'Access-Control-Allow-Origin': 'http://localhost' } ); + fs.writeFileSync( OUTFILE, data ); + + var json = JSON.parse( data ); + var propertyCount = 0; + + for ( var i in json.values ) { + propertyCount += Object.keys( json.values[ i ] ).length; + } + + log( 'Saved ' + propertyCount + ' properties.' ); res.end(); - }) + + } ); + break; + default: - res.writeHead(404); + + res.writeHead( 405 ); res.end(); + } -}).listen(7999); + +} ).listen( PORT ); + +log( 'Running at ' + ( 'http://localhost:' + PORT ).magenta + '.' ); +log( 'Writing to ' + OUTFILE.green + '.' ); + +function log( message ) { + var d = new Date(); + var h = d.getHours() % 12; + var m = d.getMinutes(); + if ( h < 10 ) h = '0'+h; + if ( m < 10 ) m = '0'+m; + var d = h + ':' + m; + console.log( d.green + ' [ dat-gui-saver ] '.blue + message ); +} \ No newline at end of file