-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 43c94d6
Showing
3 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
name: Release | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
env: | ||
DENO_DIR: .deno-cache # Arbitrary?? | ||
|
||
jobs: | ||
release: | ||
strategy: | ||
matrix: | ||
include: | ||
- artifact-name: luau-to-rojo-win64 | ||
deno-target: x86_64-pc-windows-msvc | ||
- artifact-name: luau-to-rojo-linux | ||
deno-target: x86_64-unknown-linux-gnu | ||
- artifact-name: luau-to-rojo-macos | ||
deno-target: x86_64-apple-darwin | ||
- artifact-name: luau-to-rojo-macos-aarch64 | ||
deno-target: aarch64-apple-darwin | ||
|
||
name: Build (${{ matrix.artifact-name }}) | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: denoland/[email protected] | ||
with: | ||
deno-version: v1.x # Run with latest stable Deno. | ||
- uses: actions/cache@v3 | ||
with: | ||
path: ${{ env.DENO_DIR }} | ||
key: deno-cache | ||
|
||
- name: Compile executable | ||
run: deno compile --allow-read --allow-write --target ${{ matrix.deno-target }} luau-to-rojo.ts | ||
|
||
- name: Zip executable | ||
shell: bash | ||
run: | | ||
mkdir -p staging | ||
if [ "${{ matrix.deno-target }}" = "x86_64-pc-windows-msvc" ]; then | ||
cp "luau-to-rojo.exe" staging | ||
else | ||
cp "luau-to-rojo" staging | ||
fi | ||
zip release.zip staging/* | ||
- name: Get release | ||
id: get_release | ||
uses: bruceadams/[email protected] | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
|
||
- name: Upload Binary Artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: ${{ matrix.artifact-name }} | ||
path: release.zip | ||
|
||
- name: Upload Binary to Release | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
with: | ||
upload_url: ${{ steps.get_release.outputs.upload_url }} | ||
asset_path: release.zip | ||
asset_name: ${{ matrix.artifact-name }}.zip | ||
asset_content_type: application/octet-stream |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"deno.enable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Command } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { | ||
emptyDirSync, | ||
walkSync, | ||
} from "https://deno.land/[email protected]/fs/mod.ts"; | ||
import { dirname } from "https://deno.land/[email protected]/path/mod.ts"; | ||
|
||
await new Command() | ||
.name("luau-to-rojo") | ||
.version("0.1.0") | ||
.description("Converts a Luau project to a Rojo project.") | ||
.arguments("<projectPath:string> <outputPath:string>") | ||
.action((_options, projectPath, outputPath) => { | ||
// Expand output path to absolute path | ||
projectPath = Deno.realPathSync(projectPath); | ||
emptyDirSync(outputPath); | ||
Deno.mkdirSync(outputPath + "/src", { recursive: true }); | ||
// Convert outputPath to a RegExp that can be skipped | ||
// This code is magic spit out by copilot. | ||
const skipPath = new RegExp( | ||
outputPath.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&"), | ||
); | ||
for ( | ||
const entry of walkSync(projectPath, { | ||
exts: [".lua", ".luau"], | ||
skip: [skipPath], | ||
}) | ||
) { | ||
if (!entry.isFile) continue; | ||
const relativePath = entry.path.substring(projectPath.length); | ||
// Find the depth of the path | ||
const depth = relativePath.split("/").length - 1; | ||
// if it's a directory, create it in the output directory | ||
Deno.mkdirSync(dirname(outputPath + "/src" + relativePath), { | ||
recursive: true, | ||
}); | ||
let text = Deno.readTextFileSync(entry.path); | ||
// Replace string-based require() calls with module-based require() calls. | ||
// We need to replace `/` with `.` to make it a valid module path. | ||
text = text.replace( | ||
/require\((.+)\)/g, | ||
(_match, p1) => `require(${p1.replace(/\//g, ".")})`, | ||
); | ||
// We need to repeat `.Parent` based on the depth of the path. | ||
text = text.replace( | ||
/require\("(.+)"\)/g, | ||
`require(script${"\.Parent".repeat(depth)}.$1)`, | ||
); | ||
Deno.writeTextFileSync( | ||
outputPath + "/src" + relativePath, | ||
text, | ||
); | ||
} | ||
const name = projectPath.split("/").pop(); | ||
const rojoProject = { name, tree: { $path: "src" } }; | ||
Deno.writeTextFileSync( | ||
outputPath + "/default.project.json", | ||
JSON.stringify(rojoProject, undefined, 2), | ||
); | ||
}) | ||
.parse(Deno.args); |