Skip to content

Commit

Permalink
Merge pull request #300 from betwixt-labs/playground
Browse files Browse the repository at this point in the history
feat: playground
  • Loading branch information
andrewmd5 committed Feb 6, 2024
2 parents dd214d6 + 515b5b5 commit c9a568c
Show file tree
Hide file tree
Showing 58 changed files with 6,919 additions and 781 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
name: Bebop WebAssembly REPL
name: Bebop Playground
on:
workflow_dispatch:
push:
paths:
- "Repl/**"
- "playground/**"
pull_request:
paths:
- "Repl/**"
- "playground/**"
jobs:
build-repl:
env:
REPL_ROOT: ${{github.workspace}}/Repl
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
Expand All @@ -24,15 +22,15 @@ jobs:
with:
dotnet-version: "8.0.x"
dotnet-quality: 'preview'
- name: Restore Project
run: dotnet restore
working-directory: ${{env.REPL_ROOT}}
- name: Build REPL
run: dotnet publish -c Release -p:ReleaseVersion=${{ steps.dotenv.outputs.version }}
working-directory: ${{env.REPL_ROOT}}
- name: Build Playground
run: |
../scripts/install-wasi.sh
yarn install
yarn build:site
working-directory: ./playground/

- name: Upload Package
uses: actions/upload-artifact@v4
with:
name: bebop-repl-latest
path: ${{github.workspace}}/bin/repl/Release/publish/wwwroot/
name: bebop-playground-latest
path: ${{github.workspace}}/playground/dist/
12 changes: 0 additions & 12 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,18 +249,6 @@ jobs:
name: bebop-runtime-ts-${{ steps.dotenv.outputs.version }}
path: ${{env.TS_RUNTIME_ROOT}}/bebop-v${{ steps.dotenv.outputs.version }}.tgz

- name: Build REPL
run: |
dotnet restore
dotnet publish -c Release -p:ReleaseVersion=${{ steps.dotenv.outputs.version }}
working-directory: ./Repl/

- name: Upload REPL Artifacts
uses: actions/upload-artifact@v4
with:
name: bebop-repl-${{ steps.dotenv.outputs.version }}
path: ./bin/repl/Release/publish/wwwroot/

build-tools:
env:
TOOLS_ROOT: ${{github.workspace}}/Tools
Expand Down
24 changes: 17 additions & 7 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Simple workflow for deploying static content to GitHub Pages
name: Deploy Website
name: Deploy Websites

on:
# Runs on pushes targeting the default branch
Expand Down Expand Up @@ -45,15 +45,25 @@ jobs:
dotnet-version: "8.0.x" # SDK Version to use; x will use the latest version of the 7.0 channel
dotnet-quality: 'preview'

- name: Build REPL
- name: Build Playground
run: |
dotnet restore
dotnet publish -c Release -p:ReleaseVersion=${{ steps.dotenv.outputs.version }}
working-directory: ./Repl/
../scripts/install-wasi.sh
yarn install
yarn build:site
working-directory: ./playground/

- name: Stage Repl
- name: Deploy Playground
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: bebopc-playground
directory: ${{github.workspace}}/playground/dist
# Optional: Enable this if you want to have GitHub Deployments triggered
gitHubToken: ${{ secrets.GITHUB_TOKEN }}

- name: Stage Homepage
run: |
mkdir -p homepage/repl && cp -a ./bin/repl/Release/publish/wwwroot/. homepage/repl
sed 's/0.0.0/${{ steps.dotenv.outputs.version }}/' ${{env.TOOLS_ROOT}}/bash/install.sh > homepage/install.sh
sed 's/0.0.0/${{ steps.dotenv.outputs.version }}/' ${{env.TOOLS_ROOT}}/ps/install.ps1 > homepage/install.ps1
Expand Down
9 changes: 5 additions & 4 deletions Compiler/Commands/BuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ private async Task<int> HandleCommandAsync(ParseResult result, CancellationToken
}
schema = compiler.ParseSchema(resolvedSchemas);
}

if (config is { Generators.Length: <= 0 } && !config.NoEmit)
{
return DiagnosticLogger.Instance.WriteDiagonstic(new CompilerException("No code generators specified."));
}
var isStandardOut = result.GetValue<bool>(CliStrings.StandardOutputFlag);
var (Warnings, Errors) = BebopCompiler.GetSchemaDiagnostics(schema, config.SupressedWarningCodes);
if (config.NoEmit || Errors.Count != 0)
Expand All @@ -79,10 +84,6 @@ private async Task<int> HandleCommandAsync(ParseResult result, CancellationToken
{
DiagnosticLogger.Instance.WriteSpanDiagonstics(Warnings);
}
if (config is { Generators.Length: <= 0 })
{
return DiagnosticLogger.Instance.WriteDiagonstic(new CompilerException("No code generators specified."));
}
var generatedFiles = new List<GeneratedFile>();
foreach (var generatorConfig in config.Generators)
{
Expand Down
7 changes: 2 additions & 5 deletions Compiler/Commands/RootCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@ public static int HandleCommand(ParseResult result)
private static int ShowConfig(BebopConfig config)
{
var json = new JsonText(config.ToJson());

DiagnosticLogger.Instance.Out.Write(new Panel(json)
.Collapse()
.RoundedBorder()
.BorderColor(Color.Yellow));
DiagnosticLogger.Instance.Out.Write(json);
DiagnosticLogger.Instance.Out.WriteLine();
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions Compiler/Compiler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<PublishDir>../bin/compiler/$(Configuration)/publish/$(RuntimeIdentifier)</PublishDir>
<Platforms>AnyCPU</Platforms>
<Configurations>Debug;Release</Configurations>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
</PropertyGroup>

Expand Down
12 changes: 6 additions & 6 deletions Compiler/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,20 @@ public static void WriteHostInfo(CompilerHost host)
{
if (host.Extensions.Any())
{
DiagnosticLogger.Instance.Error.MarkupLine("[yellow]Using extensions defined in bebop.json[/]");
DiagnosticLogger.Instance.Error.MarkupLine("[blue]- Extensions:[/]");
DiagnosticLogger.Instance.Out.MarkupLine("[yellow]Using extensions defined in bebop.json[/]");
DiagnosticLogger.Instance.Out.MarkupLine("[blue]- Extensions:[/]");
foreach (var extension in host.Extensions)
{
DiagnosticLogger.Instance.Error.MarkupLine($" - [white]{extension.Name}[/]: [green]{extension.Version}[/]");
DiagnosticLogger.Instance.Out.MarkupLine($" - [white]{extension.Name}[/]: [green]{extension.Version}[/]");
}
}
if (host.EnvironmentVariableStore.DevVarsCount > 0)
{
DiagnosticLogger.Instance.Error.MarkupLine("[yellow]Using vars defined in .dev.vars[/]");
DiagnosticLogger.Instance.Error.MarkupLine("[blue]- Vars:[/]");
DiagnosticLogger.Instance.Out.MarkupLine("[yellow]Using vars defined in .dev.vars[/]");
DiagnosticLogger.Instance.Out.MarkupLine("[blue]- Vars:[/]");
foreach (var name in host.EnvironmentVariableStore.DevVarNames)
{
DiagnosticLogger.Instance.Error.MarkupLine($" - [white]{name}[/]: [green](hidden)[/]");
DiagnosticLogger.Instance.Out.MarkupLine($" - [white]{name}[/]: [green](hidden)[/]");
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions Compiler/Options/DiagnosticFormatOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,19 @@ public DiagnosticFormatOption() : base(name: CliStrings.DiagnosticFormatFlag, al
};
}

private static bool IsLogFormatter(string? token)
public static bool IsLogFormatter(string? token)
{
if (string.IsNullOrWhiteSpace(token)) return false;
return token.ToLowerInvariant() switch
{
"enhanced" => true,
"json" => true,
"structured" => true,
"msbuild" => true,
_ => false,
};
}

private static LogFormatter Parse(string? token)
public static LogFormatter Parse(string? token)
{
if (string.IsNullOrWhiteSpace(token)) return LogFormatter.Enhanced;
return token.ToLowerInvariant() switch
Expand Down
11 changes: 10 additions & 1 deletion Compiler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@
Environment.SetEnvironmentVariable("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1");
}
Console.OutputEncoding = System.Text.Encoding.UTF8;
DiagnosticLogger.Initialize(LogFormatter.Enhanced);
var forcedFormatter = Environment.GetEnvironmentVariable("BEBOPC_LOG_FORMAT");
if (DiagnosticFormatOption.IsLogFormatter(forcedFormatter) is true)
{

DiagnosticLogger.Initialize(DiagnosticFormatOption.Parse(forcedFormatter));
}
else
{
DiagnosticLogger.Initialize(LogFormatter.Enhanced);
}

try
{
Expand Down
43 changes: 38 additions & 5 deletions Core/EnvironmentVariableStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,53 @@
namespace Core;
public sealed partial class EnvironmentVariableStore
{

private readonly FrozenDictionary<string, string> _devVariables;

public EnvironmentVariableStore(string workingDirectory)
{
var devEnvFilePath = Path.Combine(workingDirectory, ".dev.vars");
if (File.Exists(devEnvFilePath))
{
_devVariables = File.ReadAllLines(devEnvFilePath)
.Select(line => line.Split('=', 2))
.Where(parts => parts.Length == 2)
.ToDictionary(parts => parts[0], parts => parts[1])
.ToFrozenDictionary();
_devVariables = ParseDevVars(File.ReadAllText(devEnvFilePath));
}
else
{
_devVariables = FrozenDictionary<string, string>.Empty;
}
}
private static FrozenDictionary<string, string> ParseDevVars(string fileContent)
{
fileContent = fileContent.Replace("\r\n", "\n");
var result = new Dictionary<string, string>();

foreach (Match match in LineRegex().Matches(fileContent))
{
if (match.Success)
{
var key = match.Groups[1].Value;
var value = match.Groups[2].Value.Trim();

if (value.StartsWith("'") || value.StartsWith("\"") || value.StartsWith("`"))
{
value = UnquoteRegex().Replace(value, "$2");
}

if (value.StartsWith("\""))
{
value = value.Replace("\\n", "\n").Replace("\\r", "\r");
}

if (!string.IsNullOrEmpty(key) && !result.ContainsKey(key))
{
result[key] = value;
}
}
}
return result.ToFrozenDictionary();
}


public int DevVarsCount => _devVariables.Count;
public IEnumerable<string> DevVarNames => _devVariables.Keys;

Expand Down Expand Up @@ -66,4 +95,8 @@ public string Replace(string input, List<SpanException> errors, Span span)

[GeneratedRegex(@"\$\{([^\}]+)\}")]
private static partial Regex TemplateRegex();
[GeneratedRegex(@"\s*([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*""(?:\\""|[^""])*""|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?", RegexOptions.Multiline | RegexOptions.Compiled)]
private static partial Regex LineRegex();
[GeneratedRegex(@"^(['""`])([\s\S]*)\1$")]
private static partial Regex UnquoteRegex();
}
4 changes: 1 addition & 3 deletions Core/Generators/CPlusPlus/CPlusPlusGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,7 @@ private string TypeName(in TypeBase type)

private static string EscapeStringLiteral(string value)
{
// C++ accepts \u0000 style escape sequences, so we can escape the string JSON-style.
var options = new JsonSerializerOptions { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping };
return JsonSerializer.Serialize(value, options);
return $@"""{value.EscapeString()}""";
}

private string EmitLiteral(Literal literal)
Expand Down
4 changes: 1 addition & 3 deletions Core/Generators/CSharp/CSharpGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,7 @@ public override ValueTask<string> Compile(BebopSchema schema, GeneratorConfig co
#region Const
private static string EscapeStringLiteral(string value)
{
// C# accepts \u0000 style escape sequences, so we can escape the string JSON-style.
var options = new JsonSerializerOptions { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping };
return JsonSerializer.Serialize(value, options);
return $@"""{value.EscapeString()}""";
}

private string EmitLiteral(Literal literal)
Expand Down
4 changes: 1 addition & 3 deletions Core/Generators/Dart/DartGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,7 @@ private string TypeName(in TypeBase type)

private static string EscapeStringLiteral(string value)
{
// Dart accepts \u0000 style escape sequences, so we can escape the string JSON-style.
var options = new JsonSerializerOptions { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping };
return JsonSerializer.Serialize(value, options);
return $@"""{value.EscapeString()}""";
}

private string EmitLiteral(Literal literal)
Expand Down
2 changes: 1 addition & 1 deletion Core/Generators/GeneratorUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static string GetMarkdownAutoGeneratedNotice()
}
private static string GetAutoGeneratedNotice()
{
const string repo = "https://github.com/RainwayApp/bebop";
const string repo = "https://github.com/betwixt-labs/bebop";
var builder = new IndentedStringBuilder();
builder.AppendLine("This code was generated by a tool.").Indent(2);
builder.AppendLine().AppendLine();
Expand Down
4 changes: 1 addition & 3 deletions Core/Generators/Python/PythonGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,7 @@ private string TypeName(in TypeBase type)

private static string EscapeStringLiteral(string value)
{
// Dart accepts \u0000 style escape sequences, so we can escape the string JSON-style.
var options = new JsonSerializerOptions { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping };
return JsonSerializer.Serialize(value, options);
return $@"""{value.EscapeString()}""";
}

private string EmitLiteral(Literal literal)
Expand Down
4 changes: 1 addition & 3 deletions Core/Generators/TypeScript/TypeScriptGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,7 @@ private string TypeName(in TypeBase type)

private static string EscapeStringLiteral(string value)
{
// TypeScript accepts \u0000 style escape sequences, so we can escape the string JSON-style.
var options = new JsonSerializerOptions { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping };
return JsonSerializer.Serialize(value, options);
return $@"""{value.EscapeString()}""";
}

private string EmitLiteral(Literal literal)
Expand Down
4 changes: 2 additions & 2 deletions Core/Logging/DiagnosticLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ public int WriteDiagonstic(Exception exception)
{
case SpanException span:
WriteSpanDiagonstics(new List<SpanException>() { span });
return 74;
return 1;
case FileNotFoundException file:
WriteFileNotFoundDiagonstic(file);
return 66;
return 1;
case CompilerException compiler:
WriteCompilerDiagonstic(compiler);
return 1;
Expand Down

0 comments on commit c9a568c

Please sign in to comment.