Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>Magic Code GeneratorNew to Visual Studio Code? Get it now.

Magic Code Generator

netfolder

|
4,956 installs
| (2) | Free
generate code from data models
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Magic Code Generator

The Magic code generator produces code from models and templates. Models are defined with decorators similar to Angular.

To be informed of new releases and additional packages, go to: magiccodegenerator.com

Features

Models are defined as javascript objects.The model definition is transformed into code with templates defined with handlebar.

This extension is actually a Beta version.

Demo

To create a new model.

  • Create a new file with an ".mdl" extension, this indicates it is a model from which code is generated
  • on the newly created editor, type CTRL + Space" (windows) or type command + Space (Mac)
  • fill properties content indicated by "< >" or modify existing one.

See how short video below

model

Models comprises three parts:

  • A server definition
  • One or several service definition¸
  • One or several collection definition. We are working hard to produce some documentation providing guidance to specify the models.

code generator

actually only two code generator are provided, Prior to code code generation, you will have to create a directory to receive the generated content. The directory path will have to be included into the "Start" function invocation.

  • mongoose: this will create a mongoose+mongoDB micro service based on the collection definition provided.

demo

Model

code is generated from a model decribing the data structure to be stored in a database having a microservide interface. From the very same model, client code can also be generated.

import {Model, Start} from 'magicCode.js';

 
@Model([
   {
       // Server specifications
       server: {
           path: '/',              // Main server entry point
           type: 'NodeJS',         // server type: nodeJS, Apache
           host: 'localhost',      // host name
           port: 5000,             // server port
           url: 'http://localhost',// main server endpoint
           description: '<Include here your description>',
           cryptoKey: '<Include here your application encryption key',
       }
   },
   {
       // service specifications
       service: {
           path: '/',        // Service endpoint
           name: 'myClass',  // WARNING this property name should be identical to the class name and in 'Start' statement.
           type: 'mongoose', // Template used to generate code. Could be: mongoose(server), nativescript(client)
           connector: '<Include here your dataBase connector>'
       }
   },
   {
       // Collection specifications
       // you can define more than one collection per model
       // each collection is defined as an object in the Array of objects
       collection: {
           path: '/endpoint',          // change the endpoint to yours
           name: 'collectionName',     // collection name
           model: { // for model syntax refer to 
                   // _id: { type: String, label:'id', required: true} -> this an example
                   name: {type:String, label: 'Name', required: true}
           },
       view: 'form',                   // used to generate client code
       // Indicate with true or false if a method is included in the generated code
       methods: {
           get: true,
           put: true,
           post: true,
           delete: true
       }
   }
}
])
class myClass {} // Change for your class name 
Start(myClass,'d:/testMagicCode'); // parameters: class name, folder to contain the generated files

Model types

The model section is used to define the structure of each record in a collection. These types are valid

  • String
  • Number
  • Date
  • Boolean

String

Property Description
type String type, example: {name: {type: String}
index Indicates if this property is used as an index, takes a value a boolean, example: { index: true }
unique indicates if this property has a unique value in an index, takes a boolean as value, example: {unique: true }

Number

property Description
type Number type, example: {type: Number }
index Indicates if this property is used as an index, takes a value a boolean, example: { index: true }
unique indicates if this property has a unique value in an index, takes a boolean as value, example: {unique: true }

Date

property description
type Number type, example: {type: Date }
index Indicates if this property is used as an index, takes a value a boolean, example: { index: true }
unique indicates if this property has a unique value in an index, takes a boolean as value, example: {unique: true }

Boolean

property description
type Boolean type, example: {type: Boolean }
index Indicates if this property is used as an index, takes a value a boolean, example: { index: true }
unique indicates if this property has a unique value in an index, takes a boolean as value, example: {unique: true }

Copyright

Didier PH Martin 2017

  • Contact us
  • Jobs
  • Privacy
  • Terms of use
  • Trademarks
© 2019 Microsoft