From db9cba928bba0cca7aa12cef0762b4c2a4b3dec2 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 9 Jul 2014 12:34:29 -0700 Subject: [PATCH] clean up pipes --- bin/build-style.js | 5 ++--- bin/{stringify.js => fuzz-colors.js} | 2 +- bin/fuzz-style.js | 24 ------------------------ bin/minify.js | 15 +++++++++++++++ bin/package.json | 1 - bin/parse.js | 28 ---------------------------- 6 files changed, 18 insertions(+), 57 deletions(-) rename bin/{stringify.js => fuzz-colors.js} (88%) delete mode 100755 bin/fuzz-style.js create mode 100755 bin/minify.js delete mode 100755 bin/parse.js diff --git a/bin/build-style.js b/bin/build-style.js index 0d8d09ade..9e131e05a 100755 --- a/bin/build-style.js +++ b/bin/build-style.js @@ -2,10 +2,9 @@ 'use strict'; var load = require('./load-style.js'); -var JSONStream = require('JSONStream'); -var stringify = require('./stringify'); +var minify = require('./minify'); var mkdirp = require('./mkdirp.js'); load(process.argv[2]) - .pipe(stringify()) + .pipe(minify()) .pipe(mkdirp(process.argv[3])); diff --git a/bin/stringify.js b/bin/fuzz-colors.js similarity index 88% rename from bin/stringify.js rename to bin/fuzz-colors.js index c65a54ed1..c3a64f9ac 100755 --- a/bin/stringify.js +++ b/bin/fuzz-colors.js @@ -23,4 +23,4 @@ module.exports = function() { }); }; -// if (!module.parent) module.exports().pipe(process.stdout); +if (!module.parent) process.stdin.pipe(module.exports()).pipe(process.stdout); diff --git a/bin/fuzz-style.js b/bin/fuzz-style.js deleted file mode 100755 index 79fe7e1cc..000000000 --- a/bin/fuzz-style.js +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env node -'use strict'; - -var concat = require('concat-stream'); -var fuzzer = require('fuzzer'); -fuzzer.seed(0); - -var read = process.stdin; -var write = concat(function(buffer) { - var json = JSON.parse(buffer); - - json.constants = Object.keys(json.constants).reduce(function(obj, key, index) { - var value = json.constants[key]; - if (typeof value === 'string') { - obj[key] = fuzzer.mutate.string(value); - } - return obj; - }, {}); - - var data = JSON.stringify(json); - process.stdout.write(data); -}); - -read.pipe(write); diff --git a/bin/minify.js b/bin/minify.js new file mode 100755 index 000000000..253b34001 --- /dev/null +++ b/bin/minify.js @@ -0,0 +1,15 @@ +#!/usr/bin/env node +'use strict'; + +var through = require('through2'); + +module.exports = function() { + return through.obj(function(chunk, env, callback) { + var json = JSON.parse(chunk.toString()); + var data = JSON.stringify(json); + this.push(data); + callback(); + }); +}; + +if (!module.parent) process.stdin.pipe(module.exports()).pipe(process.stdout); diff --git a/bin/package.json b/bin/package.json index bb8783d99..4a428bde6 100644 --- a/bin/package.json +++ b/bin/package.json @@ -2,7 +2,6 @@ "name": "llmr-native", "version": "0.0.1", "dependencies": { - "concat-stream": "^1.4.6", "fuzzer": "^0.2.0", "glsl-optimizer": "git://github.com/kkaefer/glsl-optimizer.git#amalgamation", "mkdirp": "^0.5.0" diff --git a/bin/parse.js b/bin/parse.js deleted file mode 100755 index 15aad1016..000000000 --- a/bin/parse.js +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env node -'use strict'; - -var concat = require('concat-stream'); -var through = require('through2'); -var fuzzer = require('fuzzer'); -fuzzer.seed(0); - -module.exports = function() { - var read = through(); - var write = concat(function(buffer) { - var json = JSON.parse(buffer); - - json.constants = Object.keys(json.constants).reduce(function(obj, key, index) { - var value = json.constants[key]; - if (typeof value === 'string') { - obj[key] = fuzzer.mutate.string(value); - } - return obj; - }, {}); - - var data = JSON.stringify(json); - process.stdout.write(data); - }); - read.pipe(write); -}; - -// if (!module.parent) module.exports().pipe(process.stdout);