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() { serialize: function() {
// todo: return json of every controller's serialize.
var data = { var data = {
values: {}, values: {}
vars: {}, // todo
}; };
for ( var objectKey in this._controllersByObject ) { for ( var objectKey in this._controllersByObject ) {

View File

@ -82,7 +82,7 @@ gulp.task( 'watch', [ 'lint', 'build', 'test' ], function() {
} ); } );
////////////////////////////////////////////////
gulp.task( 'clean', function() { gulp.task( 'clean', function() {
return gulp.src( 'build/*' ) return gulp.src( 'build/*' )
@ -186,6 +186,10 @@ gulp.task( 'vulcanize', [ 'style' ], function() {
} ); } );
// Config
// -------------------------------
var nib = require( 'nib' ), var nib = require( 'nib' ),
highlight = require( 'highlight.js' ), highlight = require( 'highlight.js' ),
karma = require( 'karma' ), karma = require( 'karma' ),

View File

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

View File

@ -2,35 +2,64 @@
var http = require( 'http' ); var http = require( 'http' );
var fs = require( 'fs' ); 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 ) { http.createServer( function ( req, res ) {
var filename = /\/([^/]+\.json)$/.exec(req.url);
if (!filename) {
filename = 'dat-gui.json';
} else {
filename = filename[1];
}
switch ( req.method ) { 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': case 'POST':
var data = ''; var data = '';
req.on('data', function(d) {data += d;})
req.on( 'data', function( d ) {
data += d;
} );
req.on( 'end', function() { req.on( 'end', function() {
res.writeHead( 200, { 'Access-Control-Allow-Origin': 'http://localhost' } ); res.writeHead( 200, { 'Access-Control-Allow-Origin': 'http://localhost' } );
fs.writeFileSync(filename, data); fs.writeFileSync( OUTFILE, data );
res.end();
}) var json = JSON.parse( data );
break; var propertyCount = 0;
default:
res.writeHead(404); for ( var i in json.values ) {
res.end(); propertyCount += Object.keys( json.values[ i ] ).length;
}
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 );
} }
}).listen(7999);