Renamed to QR Script

- Split into three projects: Library, Console, and Tests
- Library compiles as QRScript.Interpreter to avoid conflicts
This commit is contained in:
Tony Bark 2025-05-07 15:22:16 -04:00
parent e681e6144c
commit 6501b72973
16 changed files with 82 additions and 20 deletions

View file

@ -0,0 +1,75 @@
namespace QRScript.Console;
[Command("build", Description = "Build Glyph program.")]
public class BuildCommand : ICommand
{
[CommandParameter(0, Name = "file", Description = "Path to the Glyph source file.")]
public string FilePath { get; set; }
[CommandOption("dry", 'd', Description = "Dry run.")]
public bool DryRun { get; set; }
[CommandOption("sample", 's', Description = "Generate ASCII sample.")]
public bool Sample { get; set; }
[CommandOption("byte", 'b', Description = "Convert source to byte code.")]
public bool ByteCode { get; set; }
[CommandOption("verbose", 'v', Description = "Enable verbose output.")]
public bool Verbose { get; set; }
public async ValueTask ExecuteAsync(IConsole console)
{
var fileInfo = new FileInfo(FilePath);
var file = fileInfo.FullName;
var dir = Path.GetDirectoryName(FilePath);
var path = Path.Combine(dir, file);
if (!File.Exists(FilePath))
{
await console.Error.WriteLineAsync($"Error: File not found: {file}");
return;
}
;
var lines = await File.ReadAllLinesAsync(path);
var source = lines.JoinLines();
if (ByteCode)
source = source.ToBase64();
if (Verbose)
{
await console.Output.WriteLineAsync($"Compiling: {path}");
}
if (source.ExceedsLengthLimit(1259))
await console.Output.WriteAsync($"Warning: source code exceeds {1259:n} characters.");
var qrGenerator = new QRCodeGenerator();
var qrCodeData = qrGenerator.CreateQrCode(source, QRCodeGenerator.ECCLevel.M);
var qrCode = new SvgQRCode(qrCodeData);
var asciiCode = new AsciiQRCode(qrCodeData);
var qrCodeAsASCII = asciiCode.GetGraphicSmall();
var qrCodeAsSvg = qrCode.GetGraphic(57);
if (string.IsNullOrEmpty(qrCodeAsSvg)
|| string.IsNullOrEmpty(qrCodeAsASCII))
{
await console.Output.WriteLineAsync("There was an issue in the rendering process.");
return;
}
if (Sample)
await console.Output.WriteLineAsync(qrCodeAsASCII);
if (DryRun)
return;
await console.Output.WriteLineAsync("Rendered successfully.");
var srcName = Path.GetFileNameWithoutExtension(fileInfo.Name);
File.WriteAllText(Path.Combine(dir, $"{srcName}.svg"), qrCodeAsSvg);
}
}

View file

@ -0,0 +1,7 @@
global using QRScript.Console;
global using QRScript.Extensions;
global using QRCoder;
global using CliFx;
global using CliFx.Attributes;
global using CliFx.Infrastructure;
global using System.IO;

37
QRScript.Console/Makefile Normal file
View file

@ -0,0 +1,37 @@
# Makefile for building and packaging the Sims 2 .s2pk CLI tool
APP_NAME = qrscript
CONFIGURATION = Release
RUNTIME_LINUX = linux-x64
RUNTIME_MAC = osx-x64
OUTPUT_DIR = ./dist
APPIMAGE_DIR = ./AppDir
.PHONY: all clean build-linux build-mac build-appimage package-linux package-mac package-appimage
all: build-linux build-mac package-linux package-mac
linux: build-linux package-linux
mac: build-mac package-mac
clean:
rm -rf bin obj $(OUTPUT_DIR)
build-linux:
dotnet publish -c $(CONFIGURATION) -r $(RUNTIME_LINUX) --self-contained true /p:PublishSingleFile=true -o $(OUTPUT_DIR)/$(APP_NAME)-linux
build-appimage:
dotnet publish -c $(CONFIGURATION) -r $(RUNTIME_LINUX) --self-contained true /p:PublishSingleFile=true -o $(APPIMAGE_DIR)/usr/bin
build-mac:
dotnet publish -c $(CONFIGURATION) -r $(RUNTIME_MAC) --self-contained true /p:PublishSingleFile=true -o $(OUTPUT_DIR)/$(APP_NAME)-mac
package-linux:
tar -czvf $(OUTPUT_DIR)/$(APP_NAME)-linux.tar.gz -C $(OUTPUT_DIR)/$(APP_NAME)-linux .
package-mac:
tar -czvf $(OUTPUT_DIR)/$(APP_NAME)-mac.tar.gz -C $(OUTPUT_DIR)/$(APP_NAME)-mac .
package-appimage:
appimage-builder

View file

@ -0,0 +1,6 @@
await new CliApplicationBuilder()
.AddCommand<RunCommand>()
.AddCommand<BuildCommand>()
.SetExecutableName("QR Script")
.Build()
.RunAsync();

View file

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<AssemblyName>qrscript</AssemblyName>
<Nullable>enable</Nullable>
<Version>0.2.104</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CliFx" Version="2.3.5" />
<PackageReference Include="QRCoder" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\QRScript\QRScript.csproj" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,59 @@
namespace QRScript.Console;
[Command("run", Description = "Run a Glyph program.")]
public class RunCommand : ICommand
{
[CommandParameter(0, Name = "file", Description = "Path to the Glyph source file.")]
public string FilePath { get; set; }
[CommandOption("input", 'i', Description = "Path to optional input file.")]
public string InputPath { get; set; }
[CommandOption("binary", 'b', Description = "Run binary file")]
public bool Binary { get; set; }
[CommandOption("verbose", 'v', Description = "Enable verbose output.")]
public bool Verbose { get; set; }
public async ValueTask ExecuteAsync(IConsole console)
{
var lines = new string[] { };
var fileInfo = new FileInfo(FilePath);
var file = fileInfo.FullName;
var dir = Path.GetDirectoryName(FilePath);
var path = Path.Combine(dir, file);
if (!System.IO.File.Exists(path))
{
await console.Error.WriteLineAsync($"Error: File not found: {file}");
return;
}
if (Binary)
{
// TODO: Implement binary file execution
await console.Error.WriteLineAsync($"Error: Binary file execution not implemented");
return;
}
lines = await System.IO.File.ReadAllLinesAsync(path);
var source = lines.JoinLines();
if (!string.IsNullOrEmpty(InputPath))
{
// You could inject input to the interpreter here
string input = await File.ReadAllTextAsync(InputPath);
// TODO: Attach to interpreter input stream
}
if (Verbose)
{
await console.Output.WriteLineAsync($"Executing: {path}");
if (source.ExceedsLengthLimit(1259))
await console.Output.WriteAsync($"Warning: source code exceeds {1259:n} characters.");
}
Runner.Interpret(lines);
}
}

28
QRScript.Console/install.sh Executable file
View file

@ -0,0 +1,28 @@
#!/bin/bash
# Install qrscript locally for current user (no sudo)
# Usage: ./install.sh ./dist/qrscript-linux/qrscript
set -e
PLATFORM="$1"
SOURCE_BIN="./dist/qrscript-$PLATFORM/qrscript"
INSTALL_DIR="$HOME/.local/bin"
TARGET="$INSTALL_DIR/qrscript"
if [[ ! -x "$SOURCE_BIN" ]]; then
echo "❌ Error: Provide a valid built qrscript binary as the first argument."
exit 1
fi
mkdir -p "$INSTALL_DIR"
cp "$SOURCE_BIN" "$TARGET"
chmod +x "$TARGET"
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
echo "⚠️ $INSTALL_DIR is not in your PATH. Consider adding this to your shell profile:"
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
else
echo "✅ Installed qrscript to $TARGET"
echo "Run 'qrscript --help' to get started."
fi