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

csproj-to-tsconfig

v0.3.0

Published

Converts .csproj files with TypeScript includes to their tsconfig.json equivalents.

Downloads

29

Readme

csproj-to-tsconfig

Build Status NPM version

Converts .csproj files with TypeScript includes to their tsconfig.json equivalents.

It will read the TypeScriptCompile include strings from the source .csproj and put them into a destination tsconfig.json as files.

Usage

csproj-to-tsconfig provides a CLI and an importable Converter clas.

Both require Node >=7.6!

CLI

npm install -g csproj-to-tsconfig

At a minimum, the CLI requires:

  • --csproj: a file path to a .csproj file path to read TypeScriptCompile directives from
  • --target: a file path to where to output the generated tsconfig.json-like file

Converting ./framework.csproj to ./tsconfig.json (merging onto any existing ./tsconfig.json):

csproj-to-tsconfig --csproj ./framework.csproj --target ./tsconfig.json

You can also specify a --template file path to a separate tsconfig.json-like file to serve as a template for the generated output file.

Converting ./framework.csproj to ./tsconfig.json with ./tsconfig.base.json as a template for settings:

csproj-to-tsconfig --csproj ./framework.csproj --target ./tsconfig.json --template ./tsconfig.base.json

Add --timestamp to include a timestamp comment at the top of generated files.

csproj-to-tsconfig --csproj ./framework.csproj --target ./tsconfig.json --timestamp

Since many MSBuild files use @(Items) and $(Properties) to dynamically generate paths, you can provide any number of key-value --replacement pairs to replace them.

  • @(ItemKey)=value works on ItemGroup values
  • $(PropertyKey)=value works on PropertyGroup values
  • GeneralKey=value will be applied to all files after MSBuild pre-processing

Converting ./framework.csproj to ./tsconfig.json and replacing $(OutputDirectory) with ../lib:

csproj-to-tsconfig --csproj ./framework.csproj --target ./tsconfig.json --replacement $(OutputDirectory)=../lib

Lastly, to support projects that use a large file consisting of /// references to enable direct-to-source Intellisense across projects (instead of .d.ts files), you may provide a --references file path to a file that will contain a plain list of /// references to the source files. It will respect the same replacements as tsconfig generation logic.

csproj-to-tsconfig --csproj ./framework.csproj --references ./_AllReferences.ts

You may provide one or both of --references and --target. At least one is required.

All Options

Converter

npm install --save csproj-to-tsconfig

The importable Converter class behaves a little differently from the CLI. It has a single async method convert that takes in a csproj path for an input project with targetReferences and/or targetTsconfig output descriptors.

import { Converter } from "csproj-to-tsconfig";

// Use with the following code samples
const converter = new Converter();

targetTsconfig

Equivalent to the --target CLI flag.

await converter.convert({
    csproj: "path/to/project.csproj",
    targetTsconfig: {
        fileName: "path/to/tsconfig.json",
        overrides: {
            noResolve: true
        },
        templateTsconfig: "path/to/tsconfig.template.json",
    }
});

targetReferences

Equivalent to the --references CLI flag.

await converter.convert({
    csproj: "path/to/project.csproj",
    targetReferences: {
        fileName: "path/to/_AllReferences.ts",
        includeTimestamp: true,
        locale: "en-GB"
    }
});

.references

Unlike the CLI, targetTsconfig and targetReferences each take in their own replacements objects. The replacements objects are taken in as mapping functions to transform file, ItemGroup, and PropertyGroup names, instead of direct key/value pairs.

await converter.convert({
    csproj: "path/to/project.csproj",
    targetTsconfig: {
        fileName: "path/to/tsconfig.json",
        replacements: {
            properties: (propertyName) => {
                if (propertyName === "MyProperty") {
                    return "Replaced";
                }

                return propertyName;
            },
        },
        templateTsconfig: "path/to/tsconfig.template.json",
    }
});

A generateKeyValueReplacements function is provided that can create a set of replacers for CLI-like inputs.

import { generateKeyValueReplacements } from "csproj-to-tsconfig";

const replacements = generateKeyValueReplacements([
    "foo=bar",
    "@(baz)=qux",
    "$(quux)=corge"
])

See lib/converter.d.ts in the package for a full description of the API options.

Development

Set the project up locally to be run via Gulp:

npm install -g gulp
npm install
gulp