ts-from-csmodels

0.1.2 • Public • Published

Generate Typescript form C# models

This is a tool that consumes your C# domain models and types and creates TypeScript declaration files from them. There's other tools that does this but what makes this one different is that it internally uses Roslyn (the .NET compiler platform) to parse the source files, which removes the need to create and maintain our own parser.

NPM version

Dependencies

Install

$ npm install --save ts-from-csmodels

How to use

  1. Add a config file to your project that contains for example...
{
    "include": {
  
      "./src/output-directory": [ 
        "../../another-csharp-models/first/**/*.cs",
        "../../another-csharp-models/second/models.ts"
       ],
      "./src/another-output-directory": [ 
        "../../another-csharp-models/another/**/*.cs",
      ]  
  
    },
    "camelCase": false,
    "camelCaseEnums": false,
    "numericEnums": false,
    "stringLiteralTypesInsteadOfEnums": false,
    "customTypeTranslations": {
      "ProductName": "string",
      "ProductNumber": "string"
    }
  }
  1. Add a npm script to your package.json that references your config file...
"scripts": {
    "generate-types": "ts-from-csmodels --config=your-config-file.json"
},
  1. Run the npm script generate-types and the output file specified in your config should be created and populated with your models.

License

MIT © Saeed Rahimi

Readme

Keywords

none

Package Sidebar

Install

npm i ts-from-csmodels

Weekly Downloads

0

Version

0.1.2

License

MIT

Unpacked Size

5.73 MB

Total Files

35

Last publish

Collaborators

  • saeedr