Fixes #34 Add scripts to auto-generate type definitions via TypedocConverter tool
Requires node.js and PowerShell
This commit is contained in:
Родитель
91c4e25169
Коммит
941cc8ea3a
|
@ -13,6 +13,7 @@
|
|||
# TypeScript ignores
|
||||
*.js
|
||||
*.js.map
|
||||
package-lock.json
|
||||
|
||||
# Monaco Dependency (Download from https://microsoft.github.io/monaco-editor/)
|
||||
MonacoEditorComponent/monaco-editor
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
Generate Monaco Typings
|
||||
=======================
|
||||
|
||||
This [Node.js](https://nodejs.org/) project is provided as a simple way to download the required dependencies needed to take the Monaco TypeScript definition file and generate C# classes for the API.
|
||||
|
||||
This document assumes you have a Node.js environment setup running on Windows (as PowerShell is also required), but all other dependencies should be installed/setup as part of the script.
|
||||
|
||||
To get started, in this directory just run:
|
||||
|
||||
```
|
||||
npm install
|
||||
```
|
||||
|
||||
Voila! C# Typings should be generated! Run `npm install` or `npm run postinstall` to re-generate typings again.
|
||||
|
||||
**Note:** The script is configured to overwrite the existing definitions within the main repo, you can configure an alternate output directory (`outdir`) via the `npm config set` command. It defaults to the `MonacoEditorComponent` directory and the namespace will automatically create a `Monaco` sub-directory.
|
||||
|
||||
**Note:** This script is currently meant as a guide-post, the typings generated are not all meant to be consumed directly by the project, and certain interfaces have been sculpted to provide a better experience to C# developers. This tool is mostly meant to boot-strap enabling features from the Monaco API and adapting to new versions of the Monaco API. If you have any questions or need a specific feature, please first file an issue on [our repo](https://github.com/hawkerm/monaco-editor-uwp). Thanks!
|
|
@ -0,0 +1,58 @@
|
|||
# This script run after downloading the npm package dependencies inorder to generate the C# typings.
|
||||
# https://github.com/hez2010/TypedocConverter
|
||||
|
||||
# Requires .NET Core Runtime 3.1.x to be installed
|
||||
|
||||
# ------------------------
|
||||
$monaco_file = ".\node_modules\monaco-editor\monaco.d.ts"
|
||||
$typedoc_bin_url = $env:npm_package_config_typedocConverter #"https://github.com/hez2010/TypedocConverter/releases/download/v1.5/Windows_x64.zip"
|
||||
$temp_dir_name = ".temp"
|
||||
|
||||
function Get-ScriptDirectory {
|
||||
Split-Path -parent $PSCommandPath
|
||||
}
|
||||
|
||||
$script_dir = Get-ScriptDirectory
|
||||
|
||||
Push-Location $script_dir
|
||||
|
||||
# Create Temp Directory and Output
|
||||
New-Item -Name $temp_dir_name -ItemType Directory | Out-Null
|
||||
|
||||
# Make sure we can see our 'monaco.d.ts' file
|
||||
|
||||
if (!(Test-Path $monaco_file -PathType Leaf)) {
|
||||
Write-Error "Monaco Definitions Not Found, run npm install first."
|
||||
|
||||
Pop-Location
|
||||
exit
|
||||
}
|
||||
|
||||
# Copy monaco.d.ts to monaco.ts in temp folder (need to change extension)
|
||||
|
||||
Copy-Item $monaco_file -Destination (Join-Path $temp_dir_name "monaco.ts")
|
||||
|
||||
Push-Location $temp_dir_name
|
||||
|
||||
# Run typedoc to generate json representation
|
||||
Invoke-Expression "npx typedoc monaco.ts --json monaco.json"
|
||||
|
||||
# Need TypedocConverter next
|
||||
Write-Host "Downloading TypedocConverter"
|
||||
|
||||
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
|
||||
Invoke-WebRequest -Uri $typedoc_bin_url -OutFile "TypedocConverter.zip"
|
||||
|
||||
Write-Host "Extracting..."
|
||||
Expand-Archive "TypedocConverter.zip" -DestinationPath .
|
||||
|
||||
# Now run TypedocConverter on our monaco.json
|
||||
|
||||
Invoke-Expression ".\TypedocConverter.exe --inputfile monaco.json --splitfiles true --outputdir ../$env:npm_package_config_outdir --promise-type WinRT"
|
||||
|
||||
Pop-Location
|
||||
|
||||
# Clean-up Temp Dir
|
||||
Remove-Item $temp_dir_name -Force -Recurse -ErrorAction SilentlyContinue
|
||||
|
||||
Pop-Location
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"name": "generatemonacotypings",
|
||||
"version": "1.0.0",
|
||||
"description": "Used to Generate C# Typing info for the Monaco editor from its TypeScript definitions (also requires PowerShell)",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"postinstall": "@powershell -NoProfile -ExecutionPolicy Unrestricted -Command ./generate-typings.ps1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"config": {
|
||||
"outdir": "../MonacoEditorComponent",
|
||||
"typedocConverter": "https://github.com/hez2010/TypedocConverter/releases/download/v1.5/Windows_x64.zip"
|
||||
},
|
||||
"dependencies": {
|
||||
"monaco-editor": "0.20.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typedoc": "^0.17.3",
|
||||
"typescript": "^3.8.3"
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
|||
ProjectSection(SolutionItems) = preProject
|
||||
.editorconfig = .editorconfig
|
||||
changelog.md = changelog.md
|
||||
install-dependencies.ps1 = install-dependencies.ps1
|
||||
MonacoEditorComponent\MonacoEditorComponent.nuspec = MonacoEditorComponent\MonacoEditorComponent.nuspec
|
||||
README.md = README.md
|
||||
EndProjectSection
|
||||
|
|
|
@ -77,6 +77,7 @@ Built using Visual Studio 2019 for Windows 10 16299 and above.
|
|||
|
||||
The **released** complete Monaco v0.20.0 build is used as a reference, this is not included in this repository and can be downloaded from the [Monaco site](https://microsoft.github.io/monaco-editor/). The contents of its uncompressed 'package' directory should be placed in the *MonacoEditorComponent/monaco-editor* directory. The `install-dependencies.ps1` PowerShell script can install this for you automatically.
|
||||
|
||||
In order to re-generate C# typings from a version of Monaco, see the GenerateMonacoTypings Node.js project [readme here](GenerateMonacoTypings\README.md).
|
||||
|
||||
License
|
||||
-------
|
||||
|
|
Загрузка…
Ссылка в новой задаче