SushiScript.JavaScript
1.0.6
See the version list below for details.
dotnet add package SushiScript.JavaScript --version 1.0.6
NuGet\Install-Package SushiScript.JavaScript -Version 1.0.6
<PackageReference Include="SushiScript.JavaScript" Version="1.0.6" />
paket add SushiScript.JavaScript --version 1.0.6
#r "nuget: SushiScript.JavaScript, 1.0.6"
// Install SushiScript.JavaScript as a Cake Addin #addin nuget:?package=SushiScript.JavaScript&version=1.0.6 // Install SushiScript.JavaScript as a Cake Tool #tool nuget:?package=SushiScript.JavaScript&version=1.0.6
Sushi
Library for converting .NET models to different script languages.
Use server-side classes / models in whatever script language you prefer! Also generates javascript reference files:<br>
Developed by: Jeroen Vorsselman @ 2018<br> GitHub LinkedIn
Main features
Main framework for generating script files.
- Write inline code documentation to script
- Customize templates and formatting
- Extend by implementing your own script-language
- Write to file (asynchronous)
- Detect models to convert in assembly
- By Interface or Attribute <br> <br>
Sushi.JavaScript
Implementation for generating JavaScript (EcmaScript) models.
- EcmaScript V5 and V6
- Isolated function-block
- Complete JsDoc support
object
parsing & validation- Class inheritance <br> <br>
Sushi.JavaScript
Implementation for generating TypeScript models.
- Able to generate the latest TypeScript specification
- Able to generate DefinitelyTyped declaration files
- Use to improve autocomplete for Visual Studio Intellisense
- Class inheritance <br> <br>
How to use
- Create an instance of the
ConversionKernel
and pass the assembly with the models to convert.- Invoke the
LoadXmlDocumentation
method to try and load the "PROJECT_NAMESPACE".xml file generated by the VS project.
- Invoke the
- Create the
ModelConverter
instance for the requested script-language.- Default script-languages have a static method for doing this that are named as follows
CreateConverterFor
+ script-language depending on what Sushi implementation is referenced.
- Default script-languages have a static method for doing this that are named as follows
- Invoke the
Convert()
method on the createdModelConverter
instance.- Iterates through each found
DataModel
and compiles them. - The generated script string will be set on the
DataModel.Script
property.
- Iterates through each found
Reading the generated script as a string:<br>
Simply invoke the ModelConverter.MergeModelsToString
method and pass the converted IEnumerable<DataModel>
.
This will iterate through the populated DataModel
(s) and join its Script
contents to one string.
<br>
<br>
Writing the generated script to a file:<br>
The ModelConverter.WriteToFile'Async'
can be used to write the script contents to a file with a given name and path.
This method uses the ModelConverter.MergeModelsToString
method internally to join the generated script(s) to one string.
<br>
PLEASE NOTE: The
fileName
argument does not include its extension. This is defined in the language-specification.
Minifying the generated script:<br>
Basic script minification is supported. This only removes return-newline(s), tabs, comments and leading-whitespaces.
This can be done in the ModelConverter.MergeModelsToString
and ModelConverter.WriteToFile'Async'
methods. Both have a minify:boolean
argument.
<br>
<br>
Creating or modifing a script-language
Sushi
contains two base-classes for defining a language, the LanguageSpecification
and StatementPipeline
.<br>
Directly linked to how certain placeholders in the template are generated so it can best be explained with including the placeholders.
Note: The keys are ALWAYS paired with the '$$' prefix and suffix.
KEY | USAGE | SUMMARY |
---|---|---|
$$SUMMARY$$ | LanguageSpecification.FormatProperty |
The summary doc for the specific PropertyInfo . |
$$TYPENAME$$ | ModelConverter.Compile>Replace |
The name for the specific Type to compile. |
$$TYPE_NAMESPACE$$ | ModelConverter.Compile>Replace |
The namespace for the specific Type to compile. |
$$VALIDATE_OBJECT$$ | LanguageSpecification.FormatStatements |
Placeholder for the Type properties validation. |
$$DEFINE_PROPERTIES$$ | LanguageSpecification.FormatPropertyDefinition |
Placeholder for the properties that should be defined. |
$$SET_PROPERTY_VALUES$$ | LanguageSpecification.FormatProperty |
Placeholder for the values that should be set. |
$$INHERIT_TYPE$$ | LanguageSpecification.FormatInheritanceStatement |
Statement for the name of the inherited Type . |
$$DEFINED_CHECK$$ | StatementPipeline.ArgumentDefinedStatement |
Statement if the Property is defined / has a value. |
$$UNDEFINED_CHECK$$ | StatementPipeline.ArgumentUndefinedStatement |
Statement if the Property is not defined / has no value. |
$$ARGUMENT_NAME$$ | ModelConverter.Compile>Replace |
Placeholder for the argument of the object that should be used. |
$$SCRIPT_MODELS$$ | ModelConverter.MergeModelsToString |
Placeholder for the generated SCRIPT_MODELS . Mainly used for the LanguageSpecification.WrapTemplate . |
Using another Template
It is really easy to use another template for generating script models. These templates can also be tested for missing template-keys. <br> <br> How to use another template:
- Create an instance of the
LanguageSpecification
you want to use. - Load the contents of the template into a string.
- Invoke
LanguageSpecification.UseTemplate(fileContents)
.
Thats it! You're done. <br>
Testing the integrity of the template:<br>
The template can be checked for the amount of placeholders it uses. A template requires atleast one placeholder.<br>
The template won't be allowed to use if it has no contents or no placeholders.<br><br>
You can test the template if you invoke TemplateConsistency.TestTemplate(fileContents)
.
This will return the placeholder-keys that arent used by the template.
Wrapping the script models > V1.0.3
The generated script models can now be wrapped in custom code-blocks. <br>
A wrapper for AMD
/ Dependency Injection
/ Node
and Self Invoking Anonymous Functions
are available by default.<br>
You can always choose to use your own wrapper template. This can be done when you invoke LanguageSpecification.UseWrapTemplate
.<br>
The method CreateConverterForJavaScript
has a new Wrap
enum argument that specifies what wrap to use. <br>
Note: A wrap template should always use the
$$SCRIPT_MODELS$$
placeholder. Also: It can use the$$TYPENAME$$
and$$TYPE_NAMESPACE$$
placeholders.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
- Newtonsoft.Json (>= 11.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
- Support for EcmaScript (JavaScript) and TypeScript
- Write inline code documentation to script
- Customize templates and formatting
- Extend by implementing your own script-language
- Write to file (asynchronous)
- Detect models to convert in assembly