diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7aa1479..30bca04 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -396,18 +396,51 @@ jobs: env: NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} run: | - # prepare binaries for distribution - mv ./mobilecli-darwin/mobilecli-darwin-arm64 publish/npm/bin - mv ./mobilecli-darwin/mobilecli-darwin-amd64 publish/npm/bin - mv ./mobilecli-linux/mobilecli-linux-amd64 publish/npm/bin - mv ./mobilecli-linux/mobilecli-linux-arm64 publish/npm/bin - mv ./mobilecli-windows/mobilecli-windows-amd64.exe publish/npm/bin - chmod +x publish/npm/bin/* # setup npmrc echo "//registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN" >> ~/.npmrc - # copy README.md + + # publish platform-specific packages + # darwin-arm64 + cp ./mobilecli-darwin/mobilecli-darwin-arm64 publish/npm-darwin-arm64/ + chmod +x publish/npm-darwin-arm64/mobilecli-darwin-arm64 + cd publish/npm-darwin-arm64 + npm version "${{ github.ref_name }}" --no-git-tag-version + npm publish --access public + cd ../.. + + # darwin-amd64 + cp ./mobilecli-darwin/mobilecli-darwin-amd64 publish/npm-darwin-amd64/ + chmod +x publish/npm-darwin-amd64/mobilecli-darwin-amd64 + cd publish/npm-darwin-amd64 + npm version "${{ github.ref_name }}" --no-git-tag-version + npm publish --access public + cd ../.. + + # linux-arm64 + cp ./mobilecli-linux/mobilecli-linux-arm64 publish/npm-linux-arm64/ + chmod +x publish/npm-linux-arm64/mobilecli-linux-arm64 + cd publish/npm-linux-arm64 + npm version "${{ github.ref_name }}" --no-git-tag-version + npm publish --access public + cd ../.. + + # linux-amd64 + cp ./mobilecli-linux/mobilecli-linux-amd64 publish/npm-linux-amd64/ + chmod +x publish/npm-linux-amd64/mobilecli-linux-amd64 + cd publish/npm-linux-amd64 + npm version "${{ github.ref_name }}" --no-git-tag-version + npm publish --access public + cd ../.. + + # windows-amd64 + cp ./mobilecli-windows/mobilecli-windows-amd64.exe publish/npm-windows-amd64/ + cd publish/npm-windows-amd64 + npm version "${{ github.ref_name }}" --no-git-tag-version + npm publish --access public + cd ../.. + + # publish main package (wrapper) cp README.md publish/npm - # publish to npm cd publish/npm npm version "${{ github.ref_name }}" --no-git-tag-version npm install --ignore-scripts diff --git a/publish/npm-darwin-amd64/package.json b/publish/npm-darwin-amd64/package.json new file mode 100644 index 0000000..9ab5b90 --- /dev/null +++ b/publish/npm-darwin-amd64/package.json @@ -0,0 +1,13 @@ +{ + "name": "@mobilenext/mobilecli-darwin-amd64", + "version": "0.0.4", + "author": "Mobile Next", + "description": "mobilecli binary for macOS x64", + "repository": { + "type": "git", + "url": "git+https://github.com/mobile-next/mobilecli.git" + }, + "license": "MIT", + "os": ["darwin"], + "cpu": ["x64"] +} diff --git a/publish/npm-darwin-arm64/package.json b/publish/npm-darwin-arm64/package.json new file mode 100644 index 0000000..f038a2a --- /dev/null +++ b/publish/npm-darwin-arm64/package.json @@ -0,0 +1,13 @@ +{ + "name": "@mobilenext/mobilecli-darwin-arm64", + "version": "0.0.4", + "author": "Mobile Next", + "description": "mobilecli binary for macOS ARM64", + "repository": { + "type": "git", + "url": "git+https://github.com/mobile-next/mobilecli.git" + }, + "license": "MIT", + "os": ["darwin"], + "cpu": ["arm64"] +} diff --git a/publish/npm-linux-amd64/package.json b/publish/npm-linux-amd64/package.json new file mode 100644 index 0000000..d3fad8c --- /dev/null +++ b/publish/npm-linux-amd64/package.json @@ -0,0 +1,13 @@ +{ + "name": "@mobilenext/mobilecli-linux-amd64", + "version": "0.0.4", + "author": "Mobile Next", + "description": "mobilecli binary for Linux x64", + "repository": { + "type": "git", + "url": "git+https://github.com/mobile-next/mobilecli.git" + }, + "license": "MIT", + "os": ["linux"], + "cpu": ["x64"] +} diff --git a/publish/npm-linux-arm64/package.json b/publish/npm-linux-arm64/package.json new file mode 100644 index 0000000..59c48fb --- /dev/null +++ b/publish/npm-linux-arm64/package.json @@ -0,0 +1,13 @@ +{ + "name": "@mobilenext/mobilecli-linux-arm64", + "version": "0.0.4", + "author": "Mobile Next", + "description": "mobilecli binary for Linux ARM64", + "repository": { + "type": "git", + "url": "git+https://github.com/mobile-next/mobilecli.git" + }, + "license": "MIT", + "os": ["linux"], + "cpu": ["arm64"] +} diff --git a/publish/npm-windows-amd64/package.json b/publish/npm-windows-amd64/package.json new file mode 100644 index 0000000..5733abe --- /dev/null +++ b/publish/npm-windows-amd64/package.json @@ -0,0 +1,13 @@ +{ + "name": "@mobilenext/mobilecli-windows-amd64", + "version": "0.0.4", + "author": "Mobile Next", + "description": "mobilecli binary for Windows x64", + "repository": { + "type": "git", + "url": "git+https://github.com/mobile-next/mobilecli.git" + }, + "license": "MIT", + "os": ["win32"], + "cpu": ["x64"] +} diff --git a/publish/npm/index.js b/publish/npm/index.js index 3421dd1..18c6ff2 100644 --- a/publish/npm/index.js +++ b/publish/npm/index.js @@ -3,16 +3,19 @@ const { join } = require("node:path"); const { spawn } = require("node:child_process"); -let binary; +let packageName; +let binaryName; switch (process.platform) { case "darwin": switch (process.arch) { case "arm64": - binary = "mobilecli-darwin-arm64"; + packageName = "@mobilenext/mobilecli-darwin-arm64"; + binaryName = "mobilecli-darwin-arm64"; break; case "x64": - binary = "mobilecli-darwin-amd64"; + packageName = "@mobilenext/mobilecli-darwin-amd64"; + binaryName = "mobilecli-darwin-amd64"; break; } break; @@ -20,10 +23,21 @@ switch (process.platform) { case "linux": switch (process.arch) { case "arm64": - binary = "mobilecli-linux-arm64"; + packageName = "@mobilenext/mobilecli-linux-arm64"; + binaryName = "mobilecli-linux-arm64"; break; case "x64": - binary = "mobilecli-linux-amd64"; + packageName = "@mobilenext/mobilecli-linux-amd64"; + binaryName = "mobilecli-linux-amd64"; + break; + } + break; + + case "win32": + switch (process.arch) { + case "x64": + packageName = "@mobilenext/mobilecli-windows-amd64"; + binaryName = "mobilecli-windows-amd64.exe"; break; } break; @@ -33,7 +47,19 @@ switch (process.platform) { process.exit(1); } -const binaryPath = join(__dirname, "bin", binary); +if (!packageName) { + console.error(`Unsupported platform: ${process.platform}-${process.arch}`); + process.exit(1); +} + +let binaryPath; +try { + const packagePath = require.resolve(packageName); + binaryPath = join(packagePath, "..", binaryName); +} catch (error) { + console.error(`Failed to find ${packageName}. Please reinstall @mobilenext/mobilecli.`); + process.exit(1); +} const args = process.argv.slice(2); const child = spawn(binaryPath, args, { diff --git a/publish/npm/package.json b/publish/npm/package.json index f7479f0..6fbd328 100644 --- a/publish/npm/package.json +++ b/publish/npm/package.json @@ -10,6 +10,13 @@ "license": "MIT", "bin": { "mobilecli": "index.js" + }, + "optionalDependencies": { + "@mobilenext/mobilecli-darwin-arm64": "0.0.4", + "@mobilenext/mobilecli-darwin-amd64": "0.0.4", + "@mobilenext/mobilecli-linux-arm64": "0.0.4", + "@mobilenext/mobilecli-linux-amd64": "0.0.4", + "@mobilenext/mobilecli-windows-amd64": "0.0.4" } }