diff --git a/.banner.txt b/.banner.txt new file mode 100644 index 0000000000000000000000000000000000000000..03ea51d304303ad2e187441398ef20601733e798 --- /dev/null +++ b/.banner.txt @@ -0,0 +1,9 @@ +/*! + * <%= pkg.name %> library v<%= pkg.version %> + * <%= pkg.homepage %> + * + * Copyright (c) 2014-2016 Alvaro Cabrera & Tomasz Ducin + * Released under the <%= pkg.license %> license + * + * Date: <%= now %> + */ diff --git a/CHANGELOG.md b/CHANGELOG.md index 49c8c2a50e605ce1192c00b0f4171de72c2fe7db..12cba157cafb5f4632f00f2ee56e15da5c31ba99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,52 @@ +v0.2.6: + date: 2015-12-30 + changes: + - dependency update +v0.2.5: + date: 2015-11-26 + changes: + - mixins should be arrays +v0.2.4: + date: 2015-11-25 + changes: + - Call reduce() on each resolved reference +v0.2.3: + date: 2015-11-25 + changes: + - references fixes + - minor fixes +v0.2.2: + date: 2015-10-09 + changes: + - linting + - dereferencing update +v0.2.1: + date: 2015-09-12 + changes: + - docs update + - logo added + - underscores allowed + - straight approach to sub-schema containers + - inferred types update +v0.2.0: + date: 2015-07-15 + changes: + - docs update +v0.1.13: + date: 2015-06-25 + changes: + - extending chance.js +v0.1.12: + date: 2015-06-11 + changes: + - max issues solved +v0.1.11: + date: 2015-06-08 + changes: + - docs update + - test specs + - contributing guidelines + - inferred types v0.1.10: date: 2015-05-21 changes: diff --git a/Gruntfile.js b/Gruntfile.js index 09ee717d3d8e8da5a099793a47ae8760c2bf3f79..eb14198af56ade914134877c945ad8c9e385a878 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,3 +1,45 @@ -module.exports = function(grunt) { - grunt.loadNpmTasks('grunt-parts'); +module.exports = function (grunt) { + require('load-grunt-tasks')(grunt); + + grunt.initConfig({ + pkg: grunt.file.readJSON('package.json'), + + banner: grunt.file.read('.banner.txt'), + + now: (new Date()).toISOString().replace('T', ' '), + + browserify: { + options: { + watch: "on", + banner: "<%= banner %>", + browserifyOptions: { + detectGlobals: "off", + noBuiltins: "on" + } + }, + dist: { + files: { + 'dist/jsf.js': ['lib/index.js'] + } + }, + min: { + options: { + transform: ['uglifyify'] + }, + files: { + 'dist/jsf-min.js': ['lib/index.js'] + } + } + } + }); + + grunt.registerTask('build', [ + 'browserify' + ]); + + grunt.registerTask('default', [ + 'spec', + 'build' + ]); + }; diff --git a/README.md b/README.md index 80b1ad8b69e1535fed60663182cf4f5a60409ac9..c284509b8c7b79e93bbaf675933f0ddddf86e65d 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [](https://david-dm.org/json-schema-faker/json-schema-faker) [](https://david-dm.org/json-schema-faker/json-schema-faker#info=devDependencies) -Use [JSON Schema](http://json-schema.org/) along with fake generators to provide consistent fake data for your system. Note that `json-schema-faker` supports (currently) the JSON-Schema specification **draft-04** only. +Use [JSON Schema](http://json-schema.org/) along with fake generators to provide consistent fake data for your system. ***Want to support `jsf`?*** We are looking for a free database hosting, please see the [call for providers](https://github.com/json-schema-faker/json-schema-faker/issues/89). @@ -27,6 +27,7 @@ Use [JSON Schema](http://json-schema.org/) along with fake generators to provide - [Custom formats](#custom-formats) - [Extending dependencies](#extending-dependencies) - [Inferred Types](#inferred-types) + - [Bundling](#bundling) - [Automation](#automation) - [Grunt plugin](#grunt-plugin) - Misc @@ -46,7 +47,7 @@ Install `json-schema-faker` with npm: ## Overview -JSON-schema-faker (or `jsf` for short) combines two things: +JSON-Schema-faker (or `jsf` for short) combines two things: * The [JSON-schema specification](http://json-schema.org/), that defines what is the allowed content of a JSON document * Fake data generators, that are used to generate basic or complex data, conforming to the schema. Following libraries come bundled with jsf: @@ -106,6 +107,8 @@ Clone these gists and execute them locally (each gist has its own readme with in ## Supported keywords +Note that `jsf` supports (currently) the JSON-Schema specification **draft-04** only. Below is the list of supported keywords: + - **$ref** — Resolve internal references only, and/or external if provided. - **required** — All required properties are guaranteed, if not can be omitted. - **pattern** — Generate samples based on RegExp values. @@ -129,7 +132,7 @@ Clone these gists and execute them locally (each gist has its own readme with in ## Using references -Inline references are fully supported (json-pointers) but external can't be resolved by `json-schema-faker`. +Inline references are fully supported (json-pointers) but external can't be resolved by `jsf`. In order to achieve that you can use [refaker](https://github.com/json-schema-faker/refaker) and then use the resolved schemas: @@ -158,7 +161,7 @@ console.log(sample.someValue); ## Faking values -`json-schema-faker` has built-in generators for core-formats, [Faker.js](http://marak.com/faker.js/) and [Chance.js](http://chancejs.com/) are also supported. +`jsf` has built-in generators for core-formats, [Faker.js](http://marak.com/faker.js/) and [Chance.js](http://chancejs.com/) are also supported. You can use **faker** or **chance** properties but they are optional: @@ -319,7 +322,7 @@ JSON Schema does not require you to provide the `type` property for your JSON Sc But since `jsf` uses the `type` property to create the proper fake data, we attempt to infer the type whenever it is not provided. We do this based on the JSON Schema validation properties you use. -> Now this means that if you do not use any of the JSON Schema validation properties, json-schema-faker will not be able to infer the type for you and you will need to **explicitly** set your `type` manually.) +> Now this means that if you do not use any of the JSON Schema validation properties, jsf will not be able to infer the type for you and you will need to **explicitly** set your `type` manually.) Below is the list of JSON Schema validation properties and the inferred type based on the property: @@ -355,6 +358,17 @@ Below is the list of JSON Schema validation properties and the inferred type bas * `minLength` * `pattern` +## Bundling + +JSON-Schema-faker might be used in Node.js as well as in the browser. In order to execute `jsf` in a browser, you should include the distribution file from [`dist`](dist) directory. Each new version of `jsf` is bundled using []browserify](http://browserify.org/) and stored by the library maintainers. The bundle includes full versions of all dependencies. + +However, you may want to bundle a smaller package of `jsf`, because: +* you want to reduce the bundle file size +* you don't need all languages from faker.js +* you wish to use chance.js only and get rid of other dependencies +* or for any other reason... +In that case you may bundle the distribution yourself manually. It's easily achievable: just modify the [`lib/util/container.js`](lib/util/container.js) file and either remove o rmodify the `require` calls (they're directly used by browserify to include dependencies). Automation of this feature is expected in near future. + ## Automation ### Grunt plugin diff --git a/dist/jsf-min.js b/dist/jsf-min.js new file mode 100644 index 0000000000000000000000000000000000000000..9b285d4b105a04f9e553adedaa55b39949d65a7a Binary files /dev/null and b/dist/jsf-min.js differ diff --git a/dist/jsf.js b/dist/jsf.js new file mode 100644 index 0000000000000000000000000000000000000000..1005867affe74e3252215c313fdd06a65f9936c8 Binary files /dev/null and b/dist/jsf.js differ diff --git a/package.json b/package.json index 69f4063bcbdef82fb1351685f9e11df87b12f714..51c609599806240545a31bdbc1cd2a8994722905 100644 --- a/package.json +++ b/package.json @@ -2,15 +2,16 @@ "name": "json-schema-faker", "version": "0.2.6", "description": "JSON-Schema + Faker", + "homepage": "http://json-schema-faker.js.org", "main": "lib/index.js", - "author": { - "name": "Alvaro Cabrera", - "email": "pateketrueke@gmail.com" - }, "contributors": [ + { + "name": "Alvaro Cabrera", + "email": "pateketrueke@gmail.com" + }, { "name": "Tomasz Ducin", - "email": "tomasz.ducin@gmail.com", + "email": "tomasz@ducin.it", "url": "http://ducin.it" } ], @@ -18,6 +19,7 @@ "type": "git", "url": "https://github.com/json-schema-faker/json-schema-faker" }, + "bugs": "https://github.com/json-schema-faker/json-schema-faker/issues", "license": "MIT", "dependencies": { "chance": "^0.8.0", @@ -26,13 +28,17 @@ "randexp": "^0.4.2" }, "devDependencies": { + "browserify": "^13.0.0", "clone": "^1.0.2", "glob": "^6.0.3", "grunt": "^0.4.5", + "grunt-browserify": "^4.0.1", "grunt-parts": "^0.5.7", "jayschema": "^0.3.1", + "load-grunt-tasks": "^3.4.0", "semver": "^5.1.0", "tv4": "^1.2.7", + "uglifyify": "^3.0.1", "z-schema": "^3.16.1" }, "keywords": [