diff --git a/bin/gen.js b/bin/gen.js new file mode 100755 index 0000000000000000000000000000000000000000..e1e44f783125b5e08744edbe9402f7520328f772 --- /dev/null +++ b/bin/gen.js @@ -0,0 +1,34 @@ +#!/usr/bin/env node + +const jsf = require('../dist/bundle.umd.min.js'); + +// FIXME: load faker/change on startup? + +const sample = process.argv.slice(2)[0]; + +const { inspect } = require('util'); +const { Transform } = require('stream'); +const { readFileSync } = require('fs'); + +const pretty = process.argv.indexOf('--pretty') !== -1; +const noColor = process.argv.indexOf('--no-color') !== -1; + +function generate(schema, callback) { + jsf.resolve(JSON.parse(schema)).then(result => { + let sample; + + if (pretty) { + sample = inspect(result, { colors: !noColor, depth: Infinity }); + } else { + sample = JSON.stringify(result); + } + + callback(null, `${sample}\n`); + }); +} + +process.stdin.pipe(new Transform({ + transform(entry, enc, callback) { + generate(Buffer.from(entry, enc).toString(), callback); + } +})).pipe(process.stdout); diff --git a/dist/bundle.umd.min.js b/dist/bundle.umd.min.js index 60ce23ccbc162bfe25b0dc5544cc245063ab8d06..5813f7c5bec29aa1a90dde8a4e0769d2d4fcd196 100644 Binary files a/dist/bundle.umd.min.js and b/dist/bundle.umd.min.js differ diff --git a/dist/index.js b/dist/index.js index d5cf473f76728a0935151e7ad6b7ed149211ff4f..c7d052abbc26c44dce60b3dffb40d1abfac05ee7 100644 Binary files a/dist/index.js and b/dist/index.js differ diff --git a/dist/index.mjs b/dist/index.mjs index 19acac0529e583ef00ebf59b9afe7e0d684af72f..15826de5dceb7289578d699f50c6af3d309ccd5c 100644 Binary files a/dist/index.mjs and b/dist/index.mjs differ diff --git a/dist/index.umd.js b/dist/index.umd.js index 8c8957a6c0ad2520437e2f96cda99f86ea4f0ece..bd6a64fd1e98bf2b63993659b9e6a650cbfb62e4 100644 Binary files a/dist/index.umd.js and b/dist/index.umd.js differ diff --git a/dist/index.umd.min.js b/dist/index.umd.min.js index 3e875ae5afb441fb75708c09f7ac30dffdd05fac..5eec9acbd813b6f06b07fcb0d733c6920de99f57 100644 Binary files a/dist/index.umd.min.js and b/dist/index.umd.min.js differ diff --git a/dist/index.umd.min.js.map b/dist/index.umd.min.js.map index e5a265e941855c7e316e43094f06268a8f3d9d1f..0f6932593fec8d3d0ec97b43a27e454ef7e081e5 100644 Binary files a/dist/index.umd.min.js.map and b/dist/index.umd.min.js.map differ diff --git a/package-lock.json b/package-lock.json index a9316730280a5c2e33126babf0202b4b0eb92e85..21893429d20f71eba52cbf4c02642388f50672b2 100644 Binary files a/package-lock.json and b/package-lock.json differ diff --git a/package.json b/package.json index 508008ac84b5cb1f60c43e8a1b8731b1a4e3c98b..89c817d76c189ee9632f0c95b1edce9fe9df4118 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,9 @@ "version": "0.5.0-rc17", "description": "JSON-Schema + fake data generators", "homepage": "http://json-schema-faker.js.org", + "bin": { + "jsf": "./bin/gen.js" + }, "main": "dist/index.js", "module": "dist/index.mjs", "unpkg": "dist/bundle.umd.min.js",