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

New GitHub Action! Now in your local area! #1

Merged
merged 11 commits into from
Aug 24, 2024
123 changes: 123 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: CI

on:
pull_request:
push:

jobs:
eslint:
name: ESLint Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Bun
uses: oven-sh/setup-bun@v2

- name: Install dependencies
run: bun install

- name: Run ESLint
run: bun run eslint .

prettier:
name: Prettier Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Bun
uses: oven-sh/setup-bun@v2

- name: Install dependencies
run: bun install

- name: Run Prettier
run: bun run prettier --check .

tsc:
name: TypeScript Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Bun
uses: oven-sh/setup-bun@v2

- name: Install dependencies
run: bun install

- name: Run TypeScript Compiler
run: bun run tsc --noEmit

build-macos:
name: Build CLI (macOS)
runs-on: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Bun
uses: oven-sh/setup-bun@v2

- name: Install dependencies
run: bun install

- name: Build CLI for x64
run: bun build:cli --target=bun-darwin-x64 --outfile=dist/cli/macos/cli_macos_x64

- name: Build CLI for arm64
run: bun build:cli --target=bun-darwin-arm64 --outfile=dist/cli/macos/cli_macos_arm64

- name: Combine binaries using lipo
run: |
lipo -create -output dist/cli/macos/cli_macos dist/cli/macos/cli_macos_arm64 dist/cli/macos/cli_macos_x64

build-windows:
name: Build CLI (Windows)
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Bun
uses: oven-sh/setup-bun@v2

- name: Install dependencies
run: bun install

- name: Build CLI for x64
run: bun build:cli --target=bun-windows-x64 --outfile=dist/cli/windows/cli_windows_x64.exe

- name: Build CLI for x64 (baseline)
run: bun build:cli --target=bun-windows-x64-baseline --outfile=dist/cli/windows/cli_windows_x64_baseline.exe

- name: Use Resource Hacker
run: |
ResourceHacker.exe -open dist/cli/windows/cli_windows_x64.exe -save dist/cli/windows/cli_windows_x64.exe -action addoverwrite -res resource.res
ResourceHacker.exe -open dist/cli/windows/cli_windows_x64_baseline.exe -save dist/cli/windows/cli_windows_x64_baseline.exe -action addoverwrite -res resource.res

build-linux:
name: Build CLI (Linux)
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Bun
uses: oven-sh/setup-bun@v2

- name: Install dependencies
run: bun install

- name: Build CLI for x64
run: bun build:cli --target=bun-linux-x64 --outfile=dist/cli/linux/cli_linux_x64

- name: Build CLI for x64 (baseline)
run: bun build:cli --target=bun-linux-x64-baseline --outfile=dist/cli/linux/cli_linux_x64_baseline

- name: Build CLI for arm64
run: bun build:cli --target=bun-linux-arm64 --outfile=dist/cli/linux/cli_linux_arm64
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
lbrynet
lbrynet.exe
settings.json
cli.exe
cli
gui.exe
gui
./cli.exe
./cli
./gui.exe
./gui

# Logs

Expand Down
Binary file modified bun.lockb
Binary file not shown.
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
"version": "0.0.1",
"type": "module",
"devDependencies": {
"@eslint/js": "^9.9.0",
"@eslint/js": "^9.9.1",
"@types/bun": "latest",
"@types/cli-progress": "^3.11.5",
"@types/cli-progress": "^3.11.6",
"@types/eslint__js": "^8.42.3",
"@types/readline-sync": "^1.4.8",
"@typescript-eslint/eslint-plugin": "^8.2.0",
"eslint": "^9.9.0",
"eslint": "^9.9.1",
"eslint-config-prettier": "^9.1.0",
"prettier": "^3.3.2",
"prettier": "^3.3.3",
"typescript": "^5.5.4",
"typescript-eslint": "^8.2.0"
},
"scripts": {
"lint": "bun eslint --fix && bun prettier . -w",
"lint": "bun eslint --fix && bun prettier . -w && bun tsc --noEmit",
"start:cli": "NODE_ENV=production bun run src/cli/cli.ts",
"start:gui": "NODE_ENV=production bun run src/gui/gui.ts",
"dev:cli": "NODE_ENV=development bun run src/cli/cli.ts",
Expand All @@ -30,7 +31,7 @@
"app-root-path": "^3.1.0",
"cli-progress": "^3.12.0",
"colors": "^1.4.0",
"hono": "^4.4.10",
"hono": "^4.5.8",
"jszip": "^3.10.1",
"ora": "^8.0.1",
"readline-sync": "^1.4.10"
Expand Down
5 changes: 3 additions & 2 deletions src/cli/cli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { coreEvents, start } from '../core/core.js'
import getOrCreateConfig from './config/config.ts'
import getOrCreateConfig from './settings/settings.ts'
import ora from 'ora'
import 'colors'

Expand All @@ -14,7 +14,8 @@ const config = await getOrCreateConfig()
import * as Sentry from '@sentry/bun'
import commitHash from '../common/commit-hash.ts' with { type: 'macro' }
import sentryDsn from '../common/sentry-dsn.ts' with { type: 'macro' }
if (config.sentry && typeof sentryDsn !== 'undefined' && sentryDsn !== null) Sentry.init({ dsn: sentryDsn, release: commitHash })
if (config.sentry && typeof sentryDsn !== 'undefined' && sentryDsn !== null)
Sentry.init({ dsn: sentryDsn, release: commitHash })

let currentSpinner = ora({
text: 'Checking for the LBRY SDK',
Expand Down
95 changes: 95 additions & 0 deletions src/cli/settings/settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { number, input, confirm } from '@inquirer/prompts'
import colors from 'colors'
import type { Settings } from '../../types/settings'
import type { BunFile } from 'bun'

const theme = {
prefix: '?',
style: {
message: colors.blue,
defaultAnswer: (text: string) => `[${text}]`.gray
}
}

const requestSettings = async (
file: BunFile,
configError: boolean
): Promise<Settings> => {
console.log(
configError
? 'There was an error reading your settings file. Set them up again to start bookbuddies.'
.red.bold
: "Welcome to bookbuddies! Let's get some initial settings sorted.\nYou can always change these while bookbuddies is running.\n"
.yellow
)
const settings: Settings = {
version: 1,
storageSpace: 10,
username: null,
sentry: false,
advanced: {
rpcPort: 5279,
udpPort: 4444,
tcpPort: 4444
}
}
settings.storageSpace =
(await number({
message: 'How much storage space should bookbuddies use in GB?',
default: 10,
theme
})) || 10
settings.username = await input({
message:
"Provide a name if you want to. This is only for the LBRY Foundation, to see who's contributing.",
theme
})
settings.sentry = await confirm({
message:
'Do you want to send error and performance reports to the LBRY Foundation? This will be done via Sentry, and will help us improve bookbuddies.',
default: false,
theme
})
if (
await confirm({
message: 'Do you want to set advanced LBRY SDK settings?',
default: false,
theme
})
) {
settings.advanced.rpcPort =
(await number({
message: 'What port should the LBRY SDK use for JSON-RPC?',
default: 5279,
min: 1024,
max: 65535,
theme
})) || 5279
settings.advanced.udpPort =
(await number({
message:
'What port should the LBRY SDK use for UDP communication for seeding?',
default: 4444,
min: 1024,
theme
})) || 4444
settings.advanced.tcpPort =
(await number({
message:
'What port should the LBRY SDK use for TCP communication for seeding?',
default: 4444,
min: 1024,
max: 65535,
theme
})) || 4444
}

console.log(settings)
await Bun.write(file, JSON.stringify(settings, null, 4))
return settings
}

export default async (): Promise<Settings> => {
const settingsFile = Bun.file('settings.json')
return await requestSettings(settingsFile, true)
}
2 changes: 1 addition & 1 deletion src/common/sentry-dsn.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default process.env.SENTRY_DSN || null
export default process.env.SENTRY_DSN || null
2 changes: 1 addition & 1 deletion src/gui/gui.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import 'colors'

console.log('Not implemented yet.'.red)
console.log('Not implemented yet.'.red)
12 changes: 6 additions & 6 deletions src/types/settings.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type Settings = {
version: number
storageSpace: number
username: string | null
sentry: boolean
advanced: { rpcPort: number; udpPort: number; tcpPort: number }
}
version: number
storageSpace: number
username: string | null
sentry: boolean
advanced: { rpcPort: number; udpPort: number; tcpPort: number }
}
Loading