summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorMike Morris <michael.patrick.morris@gmail.com>2014-07-08 18:28:00 -0700
committerMike Morris <michael.patrick.morris@gmail.com>2014-07-08 18:28:00 -0700
commitab36059fdada88e91d8cb88434287d226db3b73e (patch)
tree0a6ad9df270415fd78f0e772c24c583c835e26ea /bin
parentbc30a9b8cda6e150ae77c8b0f4da24d1aae5b970 (diff)
downloadqtlocation-mapboxgl-ab36059fdada88e91d8cb88434287d226db3b73e.tar.gz
try breaking up build-style pipeline into pipeable files
Diffstat (limited to 'bin')
-rwxr-xr-xbin/build-style.js14
-rwxr-xr-x[-rw-r--r--]bin/fuzz-style.js32
-rwxr-xr-xbin/load-style.js15
-rwxr-xr-x[-rw-r--r--]bin/mkdirp.js102
-rw-r--r--bin/package.json4
-rwxr-xr-xbin/parse.js28
-rwxr-xr-xbin/stringify.js26
-rwxr-xr-x[-rw-r--r--]bin/style.json (renamed from bin/style.js)6
8 files changed, 106 insertions, 121 deletions
diff --git a/bin/build-style.js b/bin/build-style.js
index 9b931c8112..0d8d09adeb 100755
--- a/bin/build-style.js
+++ b/bin/build-style.js
@@ -1,11 +1,11 @@
#!/usr/bin/env node
'use strict';
-var path = require('path');
-var fs = require('fs');
-var mkdirp = require('./mkdirp');
-var data = JSON.stringify(require(path.join(process.cwd(), process.argv[2])));
+var load = require('./load-style.js');
+var JSONStream = require('JSONStream');
+var stringify = require('./stringify');
+var mkdirp = require('./mkdirp.js');
-var out_path = path.join(process.argv[3], 'bin/style.min.js');
-mkdirp.sync(path.dirname(out_path));
-fs.writeFileSync(out_path, data);
+load(process.argv[2])
+ .pipe(stringify())
+ .pipe(mkdirp(process.argv[3]));
diff --git a/bin/fuzz-style.js b/bin/fuzz-style.js
index 8dae68e4a3..79fe7e1cc8 100644..100755
--- a/bin/fuzz-style.js
+++ b/bin/fuzz-style.js
@@ -1,24 +1,24 @@
#!/usr/bin/env node
'use strict';
+var concat = require('concat-stream');
var fuzzer = require('fuzzer');
-var path = require('path');
-var fs = require('fs');
-var mkdirp = require('./mkdirp');
-var json = require(path.join(process.cwd(), process.argv[2]));
-
fuzzer.seed(0);
-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 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);
+ var data = JSON.stringify(json);
+ process.stdout.write(data);
+});
-var out_path = path.join(process.argv[3], 'bin/style-fuzzed.min.js');
-mkdirp.sync(path.dirname(out_path));
-fs.writeFileSync(out_path, data);
+read.pipe(write);
diff --git a/bin/load-style.js b/bin/load-style.js
new file mode 100755
index 0000000000..48aa6ecc47
--- /dev/null
+++ b/bin/load-style.js
@@ -0,0 +1,15 @@
+#!/usr/bin/env node
+'use strict';
+
+var fs = require('fs');
+var path = require('path');
+var brfs = require('brfs');
+
+module.exports = function(file) {
+ var fromFile = file && file !== '-';
+ var rs = fromFile ? fs.createReadStream(file) : process.stdin;
+ var fpath = fromFile ? file : path.join(process.cwd(), '-');
+ return rs.pipe(brfs(fpath));
+};
+
+if (!module.parent) module.exports(process.argv[2]).pipe(process.stdout);
diff --git a/bin/mkdirp.js b/bin/mkdirp.js
index a1742b2069..25b3234ef7 100644..100755
--- a/bin/mkdirp.js
+++ b/bin/mkdirp.js
@@ -1,97 +1,13 @@
+#!/usr/bin/env node
+'use strict';
+
var path = require('path');
+var mkdirp = require('mkdirp');
var fs = require('fs');
-module.exports = mkdirP.mkdirp = mkdirP.mkdirP = mkdirP;
-
-function mkdirP (p, opts, f, made) {
- if (typeof opts === 'function') {
- f = opts;
- opts = {};
- }
- else if (!opts || typeof opts !== 'object') {
- opts = { mode: opts };
- }
-
- var mode = opts.mode;
- var xfs = opts.fs || fs;
-
- if (mode === undefined) {
- mode = 0777 & (~process.umask());
- }
- if (!made) made = null;
-
- var cb = f || function () {};
- p = path.resolve(p);
-
- xfs.mkdir(p, mode, function (er) {
- if (!er) {
- made = made || p;
- return cb(null, made);
- }
- switch (er.code) {
- case 'ENOENT':
- mkdirP(path.dirname(p), opts, function (er, made) {
- if (er) cb(er, made);
- else mkdirP(p, opts, cb, made);
- });
- break;
-
- // In the case of any other error, just see if there's a dir
- // there already. If so, then hooray! If not, then something
- // is borked.
- default:
- xfs.stat(p, function (er2, stat) {
- // if the stat fails, then that's super weird.
- // let the original error be the failure reason.
- if (er2 || !stat.isDirectory()) cb(er, made)
- else cb(null, made);
- });
- break;
- }
- });
-}
-
-mkdirP.sync = function sync (p, opts, made) {
- if (!opts || typeof opts !== 'object') {
- opts = { mode: opts };
- }
-
- var mode = opts.mode;
- var xfs = opts.fs || fs;
-
- if (mode === undefined) {
- mode = 0777 & (~process.umask());
- }
- if (!made) made = null;
-
- p = path.resolve(p);
-
- try {
- xfs.mkdirSync(p, mode);
- made = made || p;
- }
- catch (err0) {
- switch (err0.code) {
- case 'ENOENT' :
- made = sync(path.dirname(p), opts, made);
- sync(p, opts, made);
- break;
-
- // In the case of any other error, just see if there's a dir
- // there already. If so, then hooray! If not, then something
- // is borked.
- default:
- var stat;
- try {
- stat = xfs.statSync(p);
- }
- catch (err1) {
- throw err0;
- }
- if (!stat.isDirectory()) throw err0;
- break;
- }
- }
-
- return made;
+module.exports = function(out) {
+ mkdirp.sync(path.dirname(out));
+ return fs.createWriteStream(out);
};
+
+if (!module.parent) process.stdin.pipe(module.exports(process.argv[2]));
diff --git a/bin/package.json b/bin/package.json
index 0eefafd26a..bb8783d99c 100644
--- a/bin/package.json
+++ b/bin/package.json
@@ -2,7 +2,9 @@
"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"
+ "glsl-optimizer": "git://github.com/kkaefer/glsl-optimizer.git#amalgamation",
+ "mkdirp": "^0.5.0"
}
}
diff --git a/bin/parse.js b/bin/parse.js
new file mode 100755
index 0000000000..15aad10166
--- /dev/null
+++ b/bin/parse.js
@@ -0,0 +1,28 @@
+#!/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);
diff --git a/bin/stringify.js b/bin/stringify.js
new file mode 100755
index 0000000000..c65a54ed19
--- /dev/null
+++ b/bin/stringify.js
@@ -0,0 +1,26 @@
+#!/usr/bin/env node
+'use strict';
+
+var through = require('through2');
+var fuzzer = require('fuzzer');
+fuzzer.seed(0);
+
+module.exports = function() {
+ return through.obj(function(chunk, env, callback) {
+ var json = JSON.parse(chunk.toString());
+
+ 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);
+ this.push(data);
+ callback();
+ });
+};
+
+// if (!module.parent) module.exports().pipe(process.stdout);
diff --git a/bin/style.js b/bin/style.json
index 21cca2af34..4044e45626 100644..100755
--- a/bin/style.js
+++ b/bin/style.json
@@ -1,6 +1,4 @@
-"use strict";
-
-module.exports = {
+{
"version": 3,
"sprite": "https://www.mapbox.com/mapbox-gl-styles/sprites/outdoors",
"glyphs": "https://mapbox.s3.amazonaws.com/gl-glyphs-256/{{fontstack}}/{{range}}.pbf",
@@ -2473,4 +2471,4 @@ module.exports = {
}
}
}]
-};
+}