diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/build-fixtures.js | 22 | ||||
-rwxr-xr-x | bin/build-shaders.js | 2 | ||||
-rwxr-xr-x | bin/build-style.js | 10 | ||||
-rwxr-xr-x | bin/fuzz-colors.js | 26 | ||||
-rwxr-xr-x | bin/fuzz-functions.js | 27 | ||||
-rwxr-xr-x | bin/fuzz-layers.js | 23 | ||||
-rwxr-xr-x | bin/load-style.js | 15 | ||||
-rwxr-xr-x | bin/minify.js | 15 | ||||
-rwxr-xr-x[-rw-r--r--] | bin/mkdirp.js | 102 | ||||
-rw-r--r-- | bin/package.json | 14 | ||||
-rwxr-xr-x[-rw-r--r--] | bin/style.json (renamed from bin/style.js) | 6 |
11 files changed, 154 insertions, 108 deletions
diff --git a/bin/build-fixtures.js b/bin/build-fixtures.js new file mode 100755 index 0000000000..142147ef88 --- /dev/null +++ b/bin/build-fixtures.js @@ -0,0 +1,22 @@ +#!/usr/bin/env node +'use strict'; + +var load = require('./load-style.js'); +var mkdirp = require('mkdirp'); +var path = require('path'); +var fs = require('fs'); + +var transforms = { + 'fuzz-colors.min.js': require('./fuzz-colors.js'), + 'fuzz-functions.min.js': require('./fuzz-functions.js'), + 'fuzz-layers.min.js': require('./fuzz-layers.js') +}; + +var source = load(process.argv[2]); +var out = process.argv[3]; +mkdirp.sync(out); + +Object.keys(transforms).forEach(function(key) { + source.pipe(transforms[key].call()) + .pipe(fs.createWriteStream(path.join(out, key))); +}); diff --git a/bin/build-shaders.js b/bin/build-shaders.js index be64043d9b..329f8063f7 100755 --- a/bin/build-shaders.js +++ b/bin/build-shaders.js @@ -3,7 +3,7 @@ var fs = require('fs'); var path = require('path'); -var mkdirp = require('./mkdirp'); +var mkdirp = require('mkdirp'); try { var glsl = require('mapbox-glsl-optimizer'); } catch(err) {} diff --git a/bin/build-style.js b/bin/build-style.js index c69fcb8b40..06d4cc0808 100755 --- a/bin/build-style.js +++ b/bin/build-style.js @@ -1,12 +1,12 @@ #!/usr/bin/env node 'use strict'; +var mkdirp = require('mkdirp'); var path = require('path'); var fs = require('fs'); -var mkdirp = require('./mkdirp'); -var name = 'style'; + var data = JSON.stringify(require(path.join(process.cwd(), process.argv[2]))); +var out = path.join(process.argv[3], 'style.min.js'); -var out_path = path.join(process.argv[3], 'bin/style.min.js'); -mkdirp.sync(path.dirname(out_path)); -fs.writeFileSync(out_path, data); +mkdirp.sync(path.dirname(out)); +fs.writeFileSync(out, data); diff --git a/bin/fuzz-colors.js b/bin/fuzz-colors.js new file mode 100755 index 0000000000..c3a64f9acd --- /dev/null +++ b/bin/fuzz-colors.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) process.stdin.pipe(module.exports()).pipe(process.stdout); diff --git a/bin/fuzz-functions.js b/bin/fuzz-functions.js new file mode 100755 index 0000000000..26a079d6d8 --- /dev/null +++ b/bin/fuzz-functions.js @@ -0,0 +1,27 @@ +#!/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 === 'object' && value.hasOwnProperty('fn')) { + var mutator = fuzzer.mutate.object(value); + obj[key] = mutator(); + } + return obj; + }, {}); + + var data = JSON.stringify(json); + this.push(data); + callback(); + }); +}; + +if (!module.parent) process.stdin.pipe(module.exports()).pipe(process.stdout); diff --git a/bin/fuzz-layers.js b/bin/fuzz-layers.js new file mode 100755 index 0000000000..5477757994 --- /dev/null +++ b/bin/fuzz-layers.js @@ -0,0 +1,23 @@ +#!/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.layers.map(function(value) { + var mutator = fuzzer.mutate.object(value); + return mutator(); + }); + + var data = JSON.stringify(json); + this.push(data); + callback(); + }); +}; + +if (!module.parent) process.stdin.pipe(module.exports()).pipe(process.stdout); 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/minify.js b/bin/minify.js new file mode 100755 index 0000000000..253b340019 --- /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/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 67b12b5085..06f3ccbe57 100644 --- a/bin/package.json +++ b/bin/package.json @@ -1,7 +1,11 @@ { - "name": "mbgl-native", - "version": "0.0.1", - "dependencies": { - "mapbox-glsl-optimizer": "~0.1.0" - } + "name": "mbgl-native", + "version": "0.0.1", + "dependencies": { + "brfs": "^1.1.2", + "fuzzer": "^0.2.0", + "mapbox-glsl-optimizer": "~0.1.0", + "mkdirp": "^0.5.0", + "through2": "^0.5.1" + } } diff --git a/bin/style.js b/bin/style.json index dc2e05709a..aea2a1a3ac 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", @@ -2243,4 +2241,4 @@ module.exports = { } } }] -}; +} |