saver feedback

This commit is contained in:
George Michael Brower 2014-09-27 16:25:12 -04:00
parent e53005f4a1
commit 59486459b2
6 changed files with 69 additions and 35 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -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 ) {

View File

@ -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' ),

View File

@ -5,5 +5,9 @@
"saver": "saver.js"
},
"main": "saver.js",
"preferGlobal": "true"
"preferGlobal": "true",
"dependencies": {
"colors": "^0.6.2",
"yargs": "^1.3.1"
}
}

View File

@ -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);
res.end();
})
break;
default:
res.writeHead(404);
res.end();
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;
}
}).listen(7999);
log( 'Saved ' + propertyCount + ' properties.' );
res.end();
} );
break;
default:
res.writeHead( 405 );
res.end();
}
} ).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 );
}