npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

csharp-webpack-plugin

v1.0.3

Published

This is a webpack plugin that converts csharp classes into typescript interfaces and javascript functions with jsdoc annotation for type checking for both javascript or typescript based projects.

Downloads

3

Readme

csharp-webpack-plugin

This is a plugin for Webpack that generates TypeScript interfaces and JavaScript wrapper functions from C# source code. It is based on the csharp-models-to-typescript library.

Prerequisites

This plugin depends on .NET Core SDK.

Installation

To install this plugin, run the following command:

npm i -D csharp-webpack-plugin

Usage

To use this plugin, you must have .NET Core SDK installed on your system. You also need to create a csconfig.json file in the root of your project, with the following configuration:

{
    "include": [
        "src/csharp/**/*.cs"
    ]
}

OR

{
    "include": [
        "src/csharp/**/*.cs"
    ],
    "ignoreTypes": [
        "PeriodStudentCompare"
    ],
    "baseTypeTs": "src/csharp/BaseType.ts"    
}

The "include" property specifies the C# source files to parse. The optional "ignoreTypes" property can be used to exclude certain types from being generated. The optional "baseTypeTs" property is the path to the TypeScript file that contains the base types for your application.

To use the plugin, add it to your Webpack configuration:

const CSharpWebpackPlugin = require('csharp-webpack-plugin');

module.exports = {
    // ...
    plugins: [
        new CSharpWebpackPlugin()
    ]
};

For vue project, add plugin to vue.config.js configuration file:

const { defineConfig } = require('@vue/cli-service')
const CsharpWebpackPlugin = require('csharp-webpack-plugin')

module.exports = defineConfig({
  transpileDependencies: true,
  configureWebpack: config => {
    config.plugins.push(new CsharpWebpackPlugin())
  }
})

When you run Webpack, the plugin will generate TypeScript interfaces and JavaScript wrapper functions for each of the types defined in your C# source code. For each "Xxx.cs" file, it generates "Xxx.ts" and "XxxWrappers.js" files.

Output

The plugin generates two files for each C# class or struct:

  • Xxx.ts: TypeScript interface for the type
  • XxxWrappers.js: JavaScript wrapper function with JSDoc annotations

The TypeScript interface is generated based on the public properties and methods of the C# type. The JavaScript wrapper function is a thin wrapper around the .NET Core CLR hosting API, and provides an easy-to-use JavaScript API for interacting with the C# code.

Example Api.cs file:

using System;
using System.Collections.Generic;
using ActRegisterBase.Models;

namespace ActRegister.Controllers.Types {
    class PostLeavesStatistics {
        public int Added { get; set; }
        public int Modified { get; set; }
        public int Deleted { get; set; }
    }
    public class GaMergedRegistration {
        public  bool IsTeam { get; set; }
        public GaRegistration Registration { get; set; }
        public GameActivity Ga { get; set; }
        public GaTeam Team { get; set; }
    }
}

Example output Api.ts:

import { GaRegistration } from "./Ref";
import { GameActivity } from "./BaseType";
import { GaTeam } from "./BaseType";

export interface PostLeavesStatistics {
    Added: number;
    Modified: number;
    Deleted: number;
}
export interface GaMergedRegistration {
    IsTeam: boolean;
    Registration: GaRegistration;
    Ga: GameActivity;
    Team: GaTeam;
}

Example output ApiWrappers.js

/** @returns {PostLeavesStatistics} */
export const toPostLeavesStatistics = (o) => (o)

/** @returns {GaMergedRegistration} */
export const toGaMergedRegistration = (o) => (o)

License

This project is licensed under the MIT License. See the LICENSE file for more information.