Skip to content

smprime/sm-json-transform

Repository files navigation

sm-json-transform

Gulp JSON Transformations

Compiles json schema to Mongoose, TS-Interface, MySQL,

Example

Schema/${yourSchema}:

{
  "companyId": "54495ad94c934721ede76d90",
  "appId": "54495ad94c934721ede76d90",
  "questionId": "54495ad94c934721ede76d90",
  "adminId": "54495ad94c934721ede76d90",
  "userId": "54495ad94c934721ede76d90",
  "clientId": "54495ad94c934721ede76d90",
  "answer": "Test",
  "key": "test",
  "dateCreated": 1559534398414,
  "dateUpdated": 1559534398414,
  "lastCreatedBy": "Jason",
  "lastUpdatedBy": "Jason"
}

Output:

const mongoose = require('mongoose');
const { Schema } = mongoose;
const { ObjectId } = Schema.Types;

const userschemaSchema = Schema({
	companyId: {
		type: 'ObjectId'
	},
	appId: {
		type: 'ObjectId'
	},
	questionId: {
		type: 'ObjectId'
	},
	adminId: {
		type: 'ObjectId'
	},
	userId: {
		type: 'ObjectId'
	},
	clientId: {
		type: 'ObjectId'
	},
	answer: {
		type: 'String'
	},
	key: {
		type: 'String'
	},
	dateCreated: {
		type: 'Number'
	},
	dateUpdated: {
		type: 'Number'
	},
	lastCreatedBy: {
		type: 'String'
	},
	lastUpdatedBy: {
		type: 'String'
	}
}) 

module.exports = mongoose.model('userschema', userschemaSchema, 'userschema');

... and much, much more!!

Installation

# Using Yarn:
yarn add sm-json-transform

# Or, using NPM:
npm install sm-json-transform --save

Usage

import { gulpAutoSchema } from 'sm-json-transform'
const paths = {
    files: ['src/schemas/*.js*'],
    dest: ['dist/'],
    tssrc: ['src/interfaces']
};

// compile from file
gulp.task('json2ts', () =>
    gulp.src(paths.files)
        .pipe(gulpAutoSchema('JsonTs'))
        .pipe(rename(paths => paths.extname = '.ts'))
        .pipe(gulp.dest(paths.tssrc))
);

Develop

npm run watch

npm run dev

Build

npm run build

Production

npm run prod

Tests

npm run test

About

Gulp JSON Transformations

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published