Skip to content

Commit 6484d97

Browse files
author
Dan Clayton
committed
docs(changeset): publish bins
1 parent f8d037b commit 6484d97

3 files changed

Lines changed: 63 additions & 16 deletions

File tree

.changeset/stupid-kiwis-trade.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@azwebmaster/dependency-optimizer": patch
3+
---
4+
5+
publish bins

.github/workflows/main.yml

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414

1515
publish:
1616
name: Publish
17-
runs-on: ubuntu-latest
17+
runs-on: macos-latest
1818
needs: ci
1919
steps:
2020
- name: Checkout Repo
@@ -39,12 +39,6 @@ jobs:
3939
- name: Build
4040
run: bun run build
4141

42-
- name: Setup Node.js for NPM
43-
uses: actions/setup-node@v4
44-
with:
45-
node-version: '18'
46-
registry-url: 'https://registry.npmjs.org'
47-
4842
- name: Create Release Pull Request or Publish to NPM
4943
id: changesets
5044
uses: changesets/action@v1
@@ -53,6 +47,58 @@ jobs:
5347
version: bun run version
5448
commit: "chore: release package"
5549
title: "chore: release package"
50+
createGithubReleases: true
5651
env:
5752
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58-
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
53+
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
54+
55+
- name: Get version
56+
if: steps.changesets.outputs.published == 'true'
57+
run: echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV
58+
59+
- name: Build executables
60+
if: steps.changesets.outputs.published == 'true'
61+
run: |
62+
# macOS (Intel)
63+
bun build src/cli.ts --compile --outfile dependency-optimizer-macos-x64
64+
# macOS (Apple Silicon)
65+
bun build src/cli.ts --compile --outfile dependency-optimizer-macos-arm64 --target=bun-darwin-arm64
66+
# Linux
67+
bun build src/cli.ts --compile --outfile dependency-optimizer-linux-x64 --target=bun-linux-x64
68+
# Windows
69+
bun build src/cli.ts --compile --outfile dependency-optimizer-windows-x64.exe --target=bun-windows-x64
70+
71+
- name: Upload executables to release
72+
if: steps.changesets.outputs.published == 'true'
73+
uses: actions/github-script@v7
74+
with:
75+
script: |
76+
const fs = require('fs');
77+
const { Octokit } = require('@octokit/rest');
78+
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
79+
const tag = `v${process.env.VERSION}`;
80+
const release = await octokit.repos.getReleaseByTag({
81+
owner: context.repo.owner,
82+
repo: context.repo.repo,
83+
tag: tag
84+
});
85+
86+
const executables = [
87+
{ name: 'dependency-optimizer-macos-x64', path: 'dependency-optimizer-macos-x64' },
88+
{ name: 'dependency-optimizer-macos-arm64', path: 'dependency-optimizer-macos-arm64' },
89+
{ name: 'dependency-optimizer-linux-x64', path: 'dependency-optimizer-linux-x64' },
90+
{ name: 'dependency-optimizer-windows-x64.exe', path: 'dependency-optimizer-windows-x64.exe' }
91+
];
92+
93+
for (const exe of executables) {
94+
if (fs.existsSync(exe.path)) {
95+
const file = fs.readFileSync(exe.path);
96+
await octokit.repos.uploadReleaseAsset({
97+
owner: context.repo.owner,
98+
repo: context.repo.repo,
99+
release_id: release.data.id,
100+
name: exe.name,
101+
data: file
102+
});
103+
}
104+
}

src/cli.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,19 @@ import { Command } from 'commander';
44
import { DependencyScanner } from './scanner.js';
55
import { NodeModulesAnalyzer } from './analyzer.js';
66
import type { ScanOptions, AnalyzeOptions } from './types.js';
7-
import * as fs from 'fs';
87
import * as path from 'path';
9-
import { fileURLToPath } from 'url';
108

11-
const __filename = fileURLToPath(import.meta.url);
12-
const __dirname = path.dirname(__filename);
9+
import pkg from "../package.json" with { type: "json" };
1310

14-
// Read package.json for version info
15-
const packageJsonPath = path.join(__dirname, '..', 'package.json');
16-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
11+
// Read version from package.json dynamically
12+
const VERSION: string = pkg.version;
1713

1814
const program = new Command();
1915

2016
program
2117
.name('dependency-optimizer')
2218
.description('Scan for unused dependencies and node_modules waste')
23-
.version(packageJson.version);
19+
.version(VERSION);
2420

2521
program
2622
.command('scan')

0 commit comments

Comments
 (0)