Skip to content

TiLied/CSTOJS_CLI

Repository files navigation

CSTOJS_CLI

Dotnet tool | Core library | Website | Try it online!

This dotnet tool/CLI is a "front-end" that implements a "core" library CSharpToJavaScript translator, converter, transpiler, transcompiler, compiler, source-to-source compiler, you name it. CLI inspired (a little) by Meson, but it should behave like the dotnet cli and tsc cli.

Quick start

To install:

dotnet tool install --global TiLied.CSTOJS_CLI

To use:

cstojs-cli setup "Output"
cstojs-cli translate

To update:

dotnet tool update --global TiLied.CSTOJS_CLI

To delete:

dotnet tool uninstall --global TiLied.CSTOJS_CLI

In-depth start

  • Dotnet 10 required.
  • To install dotnet tool globally run:
dotnet tool install --global TiLied.CSTOJS_CLI
  • Make a new directory "Test". Inside that directory, run:
cstojs-cli setup "Output"
    • The command executes:
      • dotnet new console -f net10.0
      • dotnet add package CSharpToJavaScript
      • Creating "Output" folder
      • Creating "cstojs_options.xml"
    • Structure will be:
- obj
- Output
- cstojs_options.xml
- Program.cs
- Test.csproj
    • "Output" folder is where the translated JS files will be.
    • "cstojs_options.xml" is project options, see below for an example.
  • To translate "Program.cs", run:
cstojs-cli translate
    • The "Output" folder will contain a translated "Program.js" file.
  • To add a new CS file, add <File Source="./Test.cs" /> to "cstojs_options.xml" and run "cstojs-cli translate" again.
  • To update, run:
dotnet tool update --global TiLied.CSTOJS_CLI
  • To delete, run:
dotnet tool uninstall --global TiLied.CSTOJS_CLI

cstojs_options.xml

<ProjectOptions>
  <!-- This is specifying an output folder for a js files. This example is "Output". -->
  <Output Folder="Output" />

  <!-- This is a default options which will be applied for every file that follows. -->
  <DefaultOptions>
    <!-- This is a "NormalizeWhitespace" option. See all available options at https://github.com/TiLied/CSharpToJavaScript/blob/master/CSharpToJavaScript/CSTOJSOptions.cs -->
    <Option NormalizeWhitespace="true" />
  </DefaultOptions>

  <!-- This is a file that will be translated to js. -->
  <File Source="./Program.cs" />

  <!-- This is a file that will be translated to js with overridden options. -->
  <File Source="./Test.cs">
     <!-- This is a "Debug" option applying to only this file. -->
    <Option Debug="true" />
  </File>

</ProjectOptions>

Tutorials/Examples

More on the website

Commands

Run subcommands with -h to get more information.

init <folder>   Create a barebone 'cstojs_options.xml', without running the dotnet commands.
setup <folder>  Setup cstojs project.
translate       Translate specified files in the 'cstojs_options.xml'.
watch           Watches specified files in the 'cstojs_options.xml' with an interval and translates them. Note: The
                  'cstojs_options.xml' file is not being monitored, so any changes require the command to be restarted.

Related Repository