Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: standalone binary distributions for wgc #794

Closed
wants to merge 6 commits into from
Closed
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
7 changes: 3 additions & 4 deletions cli/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"extends": ["eslint-config-unjs", "plugin:require-extensions/recommended"],
"plugins": [
"require-extensions"
],
"plugins": ["require-extensions"],
"rules": {
"space-before-function-paren": 0,
"arrow-parens": 0,
Expand All @@ -23,6 +21,7 @@
"@typescript-eslint/no-non-null-assertion": 0,
"unicorn/expiring-todo-comments": 0,
"no-useless-constructor": 0,
"unicorn/no-process-exit": 0
"unicorn/no-process-exit": 0,
"unicorn/prefer-top-level-await": 0
}
}
181 changes: 94 additions & 87 deletions cli/CHANGELOG.md

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wgc",
"version": "0.53.3",
"version": "0.54.0",
"description": "The official CLI tool to manage the GraphQL Federation Platform Cosmo",
"type": "module",
"main": "dist/index.js",
Expand All @@ -20,6 +20,7 @@
},
"scripts": {
"build": "del dist && tsc",
"build:binaries": "./scripts/build-binaries.sh",
"wgc": "tsx src/index.ts",
"test": "pnpm lint && vitest run",
"coverage": "vitest run --coverage",
Expand Down Expand Up @@ -61,6 +62,10 @@
"picocolors": "^1.0.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.6",
"@types/cli-progress": "^3.11.5",
"@types/cli-table": "^0.3.1",
"@types/decompress": "^4.2.7",
Expand All @@ -71,7 +76,9 @@
"eslint": "^8.52.0",
"eslint-config-unjs": "^0.2.1",
"eslint-plugin-require-extensions": "^0.1.3",
"pkg": "^5.8.1",
"prettier": "^3.0.3",
"rollup": "^4.17.2",
"tsx": "^4.7.1",
"typescript": "^5.2.2",
"vitest": "^1.5.0"
Expand Down
13 changes: 13 additions & 0 deletions cli/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import resolve from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';

export default {
input: 'src/index.ts',
output: {
format: 'cjs',
file: 'dist/bundle.cjs',
},
plugins: [resolve({ exportConditions: ['node'] }), typescript(), commonjs(), json()],
};
21 changes: 21 additions & 0 deletions cli/scripts/build-binaries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
set -euo pipefail

echo " 📦 Building wcg binaries..."
del dist/bundle.cjs
del dist/bin

# vercel/pkg doesnt support es modules so we need to transpile to cjs
# see ../rollup.config.js
rollup -c

pkg dist/bundle.cjs -t node16-macos,node16-linux,node16-win --out-path dist/bin

cd dist/bin

mkdir macos linux win
mv bundle-macos macos/wcg
mv bundle-linux linux/wcg
mv bundle-win.exe win/wcg.exe

echo " 📦 Building wcg binaries... Done"
24 changes: 24 additions & 0 deletions cli/scripts/install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Write-Host "Installing wgc...

__ ____ _ ___
\ \ /\ / / _` |/ __|
\ V V / (_| | (__
\_/\_/ \__, |\___|
|___/
"

$OS = $env:OS
$URL = ""

if ($OS -eq "Windows_NT") {
$URL = "https://github.com/wundegraph/cosmo/releases/latest/download/wgc-windows.exe"
} else {
Write-Host "Unsupported OS: $OS"
exit 1
}

Invoke-WebRequest -Uri $URL -OutFile $env:ProgramFiles\wgc\wgc.exe
chmod +x $env:ProgramFiles\wgc\wgc.exe

Write-Host "wgc installed successfully!"
chmod +x wgc.exe
36 changes: 36 additions & 0 deletions cli/scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
set -e

echo "Installing wgc...

__ ____ _ ___
\ \ /\ / / _\` |/ __|
\ V V / (_| | (__
\_/\_/ \__, |\___|
|___/
"

OS=$(uname -s)
URL=""

case "$OS" in
Linux)
URL="https://github.com/wundegraph/cosmo/releases/latest/download/wgc-linux"
;;
Darwin)
URL="https://github.com/wundegraph/cosmo/releases/latest/download/wgc-mac"
;;
CYGWIN*|MINGW32*|MSYS*|MINGW*)
URL="https://github.com/wundegraph/cosmo/releases/latest/download/wgc-windows.exe"
;;
*)
echo "Unsupported OS: $OS"
exit 1
;;
esac

curl -L -o /usr/local/bin/wgc $URL
chmod +x /usr/local/bin/wgc

echo "wgc installed successfully!"

8 changes: 2 additions & 6 deletions cli/src/core/config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { readFileSync } from 'node:fs';
import { readFile } from 'node:fs/promises';
import path from 'node:path';
import pc from 'picocolors';
import yaml from 'js-yaml';
import envPaths from 'env-paths';

const info = JSON.parse(
await readFile(new URL('../../package.json', import.meta.url), {
encoding: 'utf8',
}),
);
const packageJsonPath = path.join(process.cwd(), 'package.json');
const info = JSON.parse(readFileSync(packageJsonPath, 'utf8'));

const paths = envPaths('cosmo', { suffix: '' });
export const configDir = paths.config;
Expand Down
4 changes: 3 additions & 1 deletion cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import program from './commands/index.js';
dotenv.config();

try {
await program.parseAsync(process.argv);
(async () => {
await program.parseAsync(process.argv);
})();
} catch (e) {
console.log('');

Expand Down
Loading
Loading