Skip to content
This repository has been archived by the owner on Jul 13, 2022. It is now read-only.

Commit

Permalink
parse FAST files
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelMunoz committed Jun 17, 2021
1 parent 95dc16b commit be43104
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 70 deletions.
23 changes: 20 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,30 @@
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"name": "Run Shoelace",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/Generator/bin/Debug/net5.0/Generator.dll",
"args": [],
"cwd": "${workspaceFolder}",
"args": [
"-cs",
"shoelace"
],
"cwd": "${workspaceFolder}/src/Generator",
"stopAtEntry": false,
"console": "internalConsole"
},
{
"name": "Run Fast",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/Generator/bin/Debug/net5.0/Generator.dll",
"args": [
"-cs",
"fast"
],
"cwd": "${workspaceFolder}/src/Generator",
"stopAtEntry": false,
"console": "internalConsole"
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Shoelace.Generator
# Sutil.Generator

This is a [Shoelace](https://github.com/shoelace-style/shoelace) wrapper generator for [Sutil](https://github.com/davedawkins/Sutil) heavily inspider in [react-generator](https://github.com/shoelace-style/react-generator)

Expand Down
102 changes: 73 additions & 29 deletions src/Generator/IO.fs → src/Generator/Generation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ open Types
open System.Threading.Tasks


module IO =
module Generation =
let private isWindows =
RuntimeInformation.IsOSPlatform(OSPlatform.Windows)

Expand Down Expand Up @@ -92,35 +92,79 @@ module IO =

fsproj.Write bytes

let private generateShoelaceLib () =
task {
printfn "Generating Shoelace Library..."
printfn "Downloading package @shoelace-style/shoelace"

let generateLibrary (componentSystem: ComponentSystem) =
match componentSystem with
| ComponentSystem.Shoelace ->
let! result = downloadPackage "@shoelace-style/shoelace"

if result.ExitCode <> 0 then
raise (Exception("Failed to Download the package"))

let! metadata = parseShoelaceMetadata ()
let path = Path.Combine("../", "Sutil.Shoelace")

let dir = Directory.CreateDirectory(path)

match metadata with
| Some metadata ->
printfn $"Using Shoelace - {metadata.version} from {metadata.author}, {metadata.license}"

metadata.components
|> Array.Parallel.iter (writeShelaceComponentFile dir.FullName)

writeShoelaceLibraryFsProj dir.FullName metadata.version metadata.components
printfn $"Generated {metadata.components.Length} Components"
| None ->
printfn "Failed to parse the metadata.json file, will not continue."
()
}

let private getFastComponents () =
let tryDeserializeFile (path: string) =
task {
printfn "Generating Shoelace Library..."
printfn "Downloading package @shoelace-style/shoelace"
let! result = downloadPackage ("@shoelace-style/shoelace")

if result.ExitCode <> 0 then
raise (Exception("Failed to Download the package"))

let! metadata = parseShoelaceMetadata ()
let path = Path.Combine("../", "Sutil.Shoelace")

let dir = Directory.CreateDirectory(path)

match metadata with
| Some metadata ->
printfn $"Using Shoelace - {metadata.version} from {metadata.author}, {metadata.license}"
metadata.components
|> Array.Parallel.iter (writeShelaceComponentFile dir.FullName)

writeShoelaceLibraryFsProj dir.FullName metadata.version metadata.components
printfn $"Generated {metadata.components.Length} Components"
| None ->
printfn "Failed to parse the metadata.json file, will not continue."
()
use content = File.OpenRead path

try
let! definition =
JsonSerializer.DeserializeAsync<Types.HtmlCustomDataVSC>(content, getJsonOptions ())

return definition.tags |> Seq.tryHead
with ex ->
eprintfn "Failed to parse File %s %s" path ex.Message
return None
}
| ComponentSystem.Fast -> Task.FromResult(())


task {
let path =
let combined =
Path.Combine("./", "node_modules", "@microsoft", "fast-components", "dist", "esm")

Path.GetFullPath combined

return!
Directory.GetFiles(path, "*.vscode.definition.json", SearchOption.AllDirectories)
|> Array.Parallel.map tryDeserializeFile
|> Task.WhenAll
}

let generateFastLib () =
task {
printfn "Generate FAST library..."
printfn "Downloading package @microsoft/fast-components"

let! result = downloadPackage "@microsoft/fast-components"

if result.ExitCode <> 0 then
raise (Exception("Failed to Download the package"))

let! components = getFastComponents ()
let result = components |> Array.Parallel.choose id
printfn "%A" result
}

let generateLibrary (componentSystem: ComponentSystem) =
match componentSystem with
| ComponentSystem.Shoelace -> generateShoelaceLib ()
| ComponentSystem.Fast -> generateFastLib ()
2 changes: 1 addition & 1 deletion src/Generator/Generator.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Compile Include="Types.fs" />
<Compile Include="Fast.fs" />
<Compile Include="Shoelace.fs" />
<Compile Include="IO.fs" />
<Compile Include="Generation.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
Expand Down
16 changes: 9 additions & 7 deletions src/Generator/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

open System.Threading.Tasks
open FSharp.Control.Tasks
open Sutil.Generator.IO
open Sutil.Generator.Generation
open Argu
open Sutil.Generator.Types

Expand All @@ -17,18 +17,20 @@ let main argv =
let result =
parser.Parse(argv, ignoreUnrecognized = true)

let activeTask() =
let activeTask () =
match result.GetAllResults() with
| [ Component_System ComponentSystem.Fast ] ->
printfn "Start FAST pipeline"
Task.FromResult(0)
task {
do! generateLibrary ComponentSystem.Fast
return 0
}
| [ Component_System ComponentSystem.Shoelace ]
| _ ->
| _ ->
task {
do! generateLibrary ComponentSystem.Shoelace
return 0
}
activeTask()

activeTask ()
|> Async.AwaitTask
|> Async.RunSynchronously
27 changes: 27 additions & 0 deletions src/Generator/Types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,30 @@ module Types =
homepage: string
license: string
components: SlComponent array }

type AttributeVscodeDefinition =
{ name: string
title: string
``type``: string
description: string
``default``: obj
required: bool option
values: seq<{| name: string |}> option
value: obj option }

type SlotVsCodeDefinition =
{ name: string
title: string
description: string }

type TagVsCodeDefinition =
{ name: string
title: string
description: string
attributes: seq<AttributeVscodeDefinition>
slots: seq<SlotVsCodeDefinition> }


type HtmlCustomDataVSC =
{ version: float
tags: seq<TagVsCodeDefinition> }
5 changes: 2 additions & 3 deletions src/Generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
"private": true,
"dependencies": {
"@microsoft/fast-components": "^1.21.6",
"@shoelace-style/shoelace": "^2.0.0-beta.43",
"package": "^1.0.1"
"@shoelace-style/shoelace": "^2.0.0-beta.43"
},
"devDependencies": {
"peerDependencies": {
"@microsoft/fast-foundation": "1.24.6",
"lodash-es": "4.17.21"
}
Expand Down
Loading

0 comments on commit be43104

Please sign in to comment.