grunt-ts-knockout-generation

1.1.1 • Public • Published

ts-knockout-generation

Generate Knockout ViewModels in Typescript from C# ViewModels

Getting Started

This plugin requires Grunt ~0.4.5

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install ts-knockout-generation --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('ts-knockout-generation');

The "ts_knockout_generation" task

Overview

In your project's Gruntfile, add a section named ts_knockout_generation to the data object passed into grunt.initConfig().

grunt.initConfig({
  ts_knockout_generation: {
    your_target: {
      options: {
            basePath: 'path/to/source/files',
            destPath: 'path/to/dest/files'
        }
    },
  },
});

You only have to specify the root file of all your C# ViewModels files and folder. The pluging will search recursively inside your directories.

Options

options.basePath

Type: String Required

A string value that is used to indicate your C# source files.

options.destPath

Type: String Required

A string value that is used to indicate the directory that files will be generated.

Usage Examples

C# ViewModels

Assume we have this C# ViewModel

public class EntityItemViewModel
{
    public int Id { get; set; }
    public string Valeur { get; set; }
}

And the plugin will generate

/// <reference path="knockout.d.ts"/>
class EntityItemViewModel
{
    public Id: KnockoutObservable<number>;
    public Valeur: KnockoutObservable<string>;
 
    constructor(){
        this.Id = ko.observable(0);
        this.Valeur = ko.observable("");
    }
}

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

(Nothing yet)

Package Sidebar

Install

npm i grunt-ts-knockout-generation

Weekly Downloads

1

Version

1.1.1

License

none

Last publish

Collaborators

  • christophegigax