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
83 changes: 83 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,86 @@ jobs:
run: |
sleep 3
gh release edit "${{ needs.check.outputs.tag }}" --draft=false

npm:
needs: [check, build]
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 1

- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version: "22"
registry-url: "https://registry.npmjs.org"

- name: Download all artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
path: artifacts
merge-multiple: true

- name: Generate and publish platform packages
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
VERSION="${{ needs.check.outputs.version }}"

declare -A PLATFORM_MAP=(
["linux-amd64"]="linux-x64 linux x64"
["linux-arm64"]="linux-arm64 linux arm64"
["darwin-arm64"]="darwin-arm64 darwin arm64"
["darwin-amd64"]="darwin-x64 darwin x64"
["windows-amd64"]="win32-x64 win32 x64"
)

for key in "${!PLATFORM_MAP[@]}"; do
read -r suffix os cpu <<< "${PLATFORM_MAP[$key]}"
PKG_DIR="npm-staging/@tslua/cli-${suffix}"
mkdir -p "${PKG_DIR}/bin"

# Copy binary
SRC="artifacts/tslua-${key}"
if [ "$os" = "win32" ]; then
SRC="${SRC}.exe"
cp "$SRC" "${PKG_DIR}/bin/tslua.exe"
else
cp "$SRC" "${PKG_DIR}/bin/tslua"
chmod +x "${PKG_DIR}/bin/tslua"
fi

# Generate package.json
node -e "
const pkg = { name: '@tslua/cli-${suffix}', version: '${VERSION}',
description: 'tslua platform binary (${os}-${cpu})', license: 'MIT',
os: ['${os}'], cpu: ['${cpu}'], files: ['bin/'] };
require('fs').writeFileSync('${PKG_DIR}/package.json', JSON.stringify(pkg, null, 2) + '\n');
"

echo "Publishing @tslua/cli-${suffix}@${VERSION}"
npm publish "${PKG_DIR}" --tag dev --access public --provenance
done

- name: Publish main package
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
VERSION="${{ needs.check.outputs.version }}"
PKG_DIR="npm/tslua"

# Inject version into main package and its optionalDependencies
node -e "
const pkg = require('./${PKG_DIR}/package.json');
pkg.version = '${VERSION}';
for (const dep of Object.keys(pkg.optionalDependencies || {})) {
pkg.optionalDependencies[dep] = '${VERSION}';
}
require('fs').writeFileSync('./${PKG_DIR}/package.json', JSON.stringify(pkg, null, 2) + '\n');
"

echo "Publishing @tslua/cli@${VERSION}"
npm publish "${PKG_DIR}" --tag dev --access public
7 changes: 0 additions & 7 deletions npm/package.json

This file was deleted.

36 changes: 36 additions & 0 deletions npm/tslua/bin/tslua.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env node

const process = require("node:process");
const child_process = require("node:child_process");

const PLATFORMS = {
darwin: { x64: "@tslua/cli-darwin-x64", arm64: "@tslua/cli-darwin-arm64" },
linux: { x64: "@tslua/cli-linux-x64", arm64: "@tslua/cli-linux-arm64" },
win32: { x64: "@tslua/cli-win32-x64" },
};

const platformPkgs = PLATFORMS[process.platform];
if (!platformPkgs) {
console.error(`Unsupported platform: ${process.platform}`);
process.exit(1);
}
const pkg = platformPkgs[process.arch];
if (!pkg) {
console.error(`Unsupported architecture: ${process.platform}-${process.arch}`);
process.exit(1);
}

const bin = process.platform === "win32" ? "tslua.exe" : "tslua";
const exePath = require.resolve(`${pkg}/bin/${bin}`);

try {
child_process.execFileSync(exePath, process.argv.slice(2), {
stdio: "inherit",
});
} catch (e) {
if (e.status != null) {
process.exitCode = e.status;
} else {
throw e;
}
}
24 changes: 24 additions & 0 deletions npm/tslua/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@tslua/cli",
"version": "0.0.0",
"description": "TypeScript-to-Lua transpiler",
"author": "Cold Fry",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/RealColdFry/tslua"
},
"bin": {
"tslua": "bin/tslua.js"
},
"files": [
"bin/tslua.js"
],
"optionalDependencies": {
"@tslua/cli-darwin-arm64": "0.0.0",
"@tslua/cli-darwin-x64": "0.0.0",
"@tslua/cli-linux-arm64": "0.0.0",
"@tslua/cli-linux-x64": "0.0.0",
"@tslua/cli-win32-x64": "0.0.0"
}
}