Skip to content
Snippets Groups Projects
Commit 14d8add7 authored by Tomasz Ducin's avatar Tomasz Ducin
Browse files

typescript migration coninued

parent 9bcff00e
No related branches found
No related tags found
No related merge requests found
# Architecture
![JSON Schema Faker module graph](structure.png)
JSON Schema Faker is a JavaScript tool that can be executed both in the browser and the server.
JSF has been migrated to [TypeScript](typescriptlang.org). The structure is still being refactored.
Currently JSF consists of:
* `types` - each module represents one basic JSON Schema structure
* there is also the `external` module which executes `chance` and `faker` generators
* `generators` - very small modules which generate some low-level stuff
* `core` - the engine, various files
* `api` - here are additional methods you can call on jsf object:
* `format()` - to register/get/call your own formats
* `extend()` - extending jsf dependencies with user custom logic
* `class` - encapsulated containers; you might consider them as part of core
* `format` - for custom regular expressions
* `container` - for dependencies (`faker`, `chance`, `randexp`); this is needed for two reasons:
* end user might want to extend `faker` or `chance` with his/her custom generator functions and we need to remember that
* we don't want to include both faker and chance by default - we wanna make them optional
# Sources
Currently we've got both:
* new TypeScript source files (`ts` directory)
* old JavaScript output (`lib` directory).
This is a temporary state, of course, it will be refactored :).
Once we find a suitable solution for bundling TypeScript directly into final js build files - we might remove `lib` directory then.
TypeScript is fired with ``--module commonjs` option - javascript output uses standard CommonJS `require` calls and then
it's processed via browserify to create bundles (as it used to before introducing TypeScript).
The codebase is quite complex and so the whole process had to be cplit into parts. THe migration/refactoring is still a work-in-progress.
# Building
Compile typescript to javascript:
npm run tsc
Build package files:
./build/dist.js
![JSON Schema Faker logo](logo/JSF_logo.png) ![JSON Schema Faker logo](logo/typescript-logo.png)
[![Build Status](https://travis-ci.org/json-schema-faker/json-schema-faker.svg?branch=master)](https://travis-ci.org/json-schema-faker/json-schema-faker) [![Build Status](https://travis-ci.org/json-schema-faker/json-schema-faker.svg?branch=master)](https://travis-ci.org/json-schema-faker/json-schema-faker)
[![NPM version](https://badge.fury.io/js/json-schema-faker.svg)](http://badge.fury.io/js/json-schema-faker) [![NPM version](https://badge.fury.io/js/json-schema-faker.svg)](http://badge.fury.io/js/json-schema-faker)
...@@ -13,12 +13,6 @@ Use [JSON Schema](http://json-schema.org/) along with fake generators to provide ...@@ -13,12 +13,6 @@ Use [JSON Schema](http://json-schema.org/) along with fake generators to provide
***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). ***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).
### migrating to TypeScript
![JSON Schema Faker migration to TypeScript](migration.jpg)
JSON-Schema-Faker is being migrated into TypeScript.
# Table of contents # Table of contents
- Basics - Basics
...@@ -413,6 +407,19 @@ In that case you may bundle the distribution yourself manually. It's easily achi ...@@ -413,6 +407,19 @@ In that case you may bundle the distribution yourself manually. It's easily achi
Use [grunt-jsonschema-faker](https://github.com/json-schema-faker/grunt-jsonschema-faker) Use [grunt-jsonschema-faker](https://github.com/json-schema-faker/grunt-jsonschema-faker)
to automate running `json-schema-faker` against your JSON schemas. to automate running `json-schema-faker` against your JSON schemas.
## Contribution
* [Alvaro Cabrera](https://twitter.com/pateketrueke)
* [Tomasz Ducin](https://twitter.com/tomasz_ducin)
* artwork by [Ajay Karat](http://www.devilsgarage.com/)
We are more than happy to welcome new contributors, our project is heavily developed, but we need more power :)
Please see [contribution guide](CONTRIBUTING.md), you can always contact us to ask how you can help.
### Architecture
If you want to contribute, take a look at [the architecture page](ARCHITECTURE.md). You may find some important information there making it easier to start.
## Resources ## Resources
* [JSON, JSON Schema & JSON-schema-faker](https://www.youtube.com/watch?v=TkqiUG3j_Xw) - WarsawJS meetup presentation recording, a step-by-step guide to JSON-related tools, including `jsf` * [JSON, JSON Schema & JSON-schema-faker](https://www.youtube.com/watch?v=TkqiUG3j_Xw) - WarsawJS meetup presentation recording, a step-by-step guide to JSON-related tools, including `jsf`
...@@ -432,14 +439,4 @@ There were some existing projects or services trying to achieve similar goals as ...@@ -432,14 +439,4 @@ There were some existing projects or services trying to achieve similar goals as
but they were either incomplete, outdated, broken or non-standard. That's why `jsf` was created. but they were either incomplete, outdated, broken or non-standard. That's why `jsf` was created.
## Contribution
* [Alvaro Cabrera](https://twitter.com/pateketrueke)
* [Tomasz Ducin](https://twitter.com/tomasz_ducin)
* artwork by [Ajay Karat](http://www.devilsgarage.com/)
Any contribution is well received, please see [contribution guide](CONTRIBUTING.md).
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/json-schema-faker/json-schema-faker/trend.png)](https://bitdeli.com/free "Bitdeli Badge") [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/json-schema-faker/json-schema-faker/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
#!/bin/sh #!/bin/sh
# --out will not work with CommonJS, see https://github.com/Microsoft/TypeScript/issues/1544 # --out will not work with CommonJS, see https://github.com/Microsoft/TypeScript/issues/1544
tsc --module commonjs ts/index.ts ts/index.ts tsc --module commonjs ts/index.ts ts/index.ts # add `--noImplicitAny` at some point
mkdir -p lib/api lib/class lib/core lib/generators lib/types mkdir -p lib/api lib/class lib/core lib/generators lib/types
mv ts/api/*.js lib/api/ mv ts/api/*.js lib/api/
......
var browserify = require('browserify');
var tsify = require('tsify');
browserify()
.add('ts/index.ts')
.plugin(tsify, { noImplicitAny: true })
.bundle()
.on('error', function (error) { console.error(error.toString()); })
.pipe(process.stdout);
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
logo/typescript-logo.png

83.4 KiB

migration.jpg

20.9 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment