Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions dependencies/jszip.min.js

Large diffs are not rendered by default.

52 changes: 41 additions & 11 deletions project-downloader.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ $WEBSITE_CONFIG = @{
}
AssetBaseUrl = { param($id) return "https://html-classic.itch.zone/html/$id/assets" }
Method = "embedded_or_json"
Unpackager = "https://turbowarp.github.io/unpackager/"
Unpackager = ""
}
"scratch" = @{
Aliases = @("scratch.mit.edu", "turbowarp.org")
Expand Down Expand Up @@ -280,11 +280,26 @@ if ($null -eq $websiteInfo) {
$PAGE_HTML | Out-File -FilePath $SAVE_PATH -Encoding UTF8

Write-Green "✓ Saved to: $SAVE_PATH"
Write-Yellow "`n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
Write-Yellow " This HTML file was downloaded from an unrecognized source."
Write-Yellow " To unpack this project, upload the saved HTML file to:"
Write-Green " https://turbowarp.github.io/unpackager/"
Write-Yellow "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`n"

$OUTPUT_SB3 = $SAVE_PATH -replace '\.html$', '.sb3'

Write-Blue "`n→ Unpacking project locally..."

try {
$process = Start-Process -FilePath "node" `
-ArgumentList "unpackager-cli.js `"$SAVE_PATH`" `"$OUTPUT_SB3`"" `
-NoNewWindow -Wait -PassThru

if ($process.ExitCode -eq 0 -and (Test-Path $OUTPUT_SB3)) {
Write-Green "✓ Unpacked successfully: $OUTPUT_SB3"
} else {
Write-Red "✗ Unpackager failed (exit code $($process.ExitCode))"
Write-Yellow "You can still manually upload: https://turbowarp.github.io/unpackager/"
}
} catch {
Write-Red "✗ Failed to run Node.js: $_"
Write-Yellow "Make sure Node.js is installed."
}

} elseif ($PAGE_HTML -match 'assets/project\.json') {
# Type B: project.json + assets relative to the page URL
Expand Down Expand Up @@ -431,11 +446,26 @@ if ($PAGE_HTML -match '<script data=') {

Write-Green "✓ Saved to: $SAVE_PATH"

if ($siteConfig.Unpackager) {
Write-Yellow "`n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
Write-Yellow " To unpack this project, upload the saved HTML file to:"
Write-Green " $($siteConfig.Unpackager)"
Write-Yellow "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`n"
$OUTPUT_SB3 = $SAVE_PATH -replace '\.html$', '.sb3'

Write-Blue "`n→ Unpacking project locally..."

try {
$process = Start-Process -FilePath "node" `
-ArgumentList "unpackager-cli.js `"$SAVE_PATH`" `"$OUTPUT_SB3`"" `
-NoNewWindow -Wait -PassThru

if ($process.ExitCode -eq 0 -and (Test-Path $OUTPUT_SB3)) {
Write-Green "✓ Unpacked successfully: $OUTPUT_SB3"
} else {
Write-Red "✗ Unpackager failed"
if ($siteConfig.Unpackager) {
Write-Yellow "Fallback:"
Write-Green " $($siteConfig.Unpackager)"
}
}
} catch {
Write-Red "✗ Failed to run Node.js: $_"
}

} elseif ($PAGE_HTML -match 'assets/project\.json') {
Expand Down
57 changes: 47 additions & 10 deletions project-downloader.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,29 @@ if [[ -z "$SITE_ID" ]]; then
echo "$PAGE_HTML" > "$SAVE_PATH"

write_green "✓ Saved to: $SAVE_PATH"
write_yellow "\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
write_yellow " This HTML file was downloaded from an unrecognized source."
write_yellow " To unpack this project, upload the saved HTML file to:"
write_green " https://turbowarp.github.io/unpackager/"
write_yellow "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n"

OUTPUT_SB3="${SAVE_PATH%.html}.sb3"

write_blue "\n→ Unpacking project locally..."

if command -v node >/dev/null 2>&1; then
if node unpackager-cli.js "$SAVE_PATH" "$OUTPUT_SB3"; then
if [[ -f "$OUTPUT_SB3" ]]; then
write_green "✓ Unpacked successfully: $OUTPUT_SB3"
else
write_red "✗ Unpack failed (no output file)"
fi
else
write_red "✗ Unpackager failed"
write_yellow "Fallback:"
write_green " https://turbowarp.github.io/unpackager/"
fi
else
write_red "✗ Node.js not found"
write_yellow "Fallback:"
write_green " https://turbowarp.github.io/unpackager/"
fi


elif echo "$PAGE_HTML" | grep -q 'assets/project\.json'; then
# Type B: project.json + assets relative to the page URL
Expand Down Expand Up @@ -431,11 +449,30 @@ if echo "$PAGE_HTML" | grep -q '<script data='; then

write_green "✓ Saved to: $SAVE_PATH"

if [[ -n "${!unpackager_var}" ]]; then
write_yellow "\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
write_yellow " To unpack this project, upload the saved HTML file to:"
write_green " ${!unpackager_var}"
write_yellow "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n"
OUTPUT_SB3="${SAVE_PATH%.html}.sb3"

write_blue "\n→ Unpacking project locally..."

if command -v node >/dev/null 2>&1; then
if node unpackager-cli.js "$SAVE_PATH" "$OUTPUT_SB3"; then
if [[ -f "$OUTPUT_SB3" ]]; then
write_green "✓ Unpacked successfully: $OUTPUT_SB3"
else
write_red "✗ Unpack failed (no output file)"
fi
else
write_red "✗ Unpackager failed"
if [[ -n "${!unpackager_var}" ]]; then
write_yellow "Fallback:"
write_green " ${!unpackager_var}"
fi
fi
else
write_red "✗ Node.js not found"
if [[ -n "${!unpackager_var}" ]]; then
write_yellow "Fallback:"
write_green " ${!unpackager_var}"
fi
fi

elif [[ "${!method_var}" == "scratch_api" ]]; then
Expand Down
32 changes: 32 additions & 0 deletions unpackager-cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env node

const fs = require('fs');
const path = require('path');
const JSZip = require('./dependencies/jszip.min.js');
global.JSZip = JSZip;
const unpackage = require('./unpackager');

async function main() {
const input = process.argv[2];
const output = process.argv[3] || 'output.sb3';

if (!input) {
console.error('Usage: node unpackager-cli.js <input.html> [output.sb3]');
process.exit(1);
}

const data = fs.readFileSync(input);

try {
const result = await unpackage(data);

fs.writeFileSync(output, Buffer.from(result.data));

console.log(`✓ Unpacked as ${output} (${result.type})`);
} catch (e) {
console.error('✗ Failed:', e.message);
process.exit(1);
}
}

main();
Loading
Loading