csproj-to-tsconfig
v0.3.0
Published
Converts .csproj files with TypeScript includes to their tsconfig.json equivalents.
Downloads
29
Maintainers
Readme
csproj-to-tsconfig
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 readTypeScriptCompile
directives from--target
: a file path to where to output the generatedtsconfig.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 valuesGeneralKey=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