diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..7387615 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -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 diff --git a/.gitignore b/.gitignore index 3cb219a..7dce21e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,10 +4,10 @@ lbrynet lbrynet.exe settings.json -cli.exe -cli -gui.exe -gui +./cli.exe +./cli +./gui.exe +./gui # Logs diff --git a/bun.lockb b/bun.lockb index 71337f0..9d573c6 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index e840eb3..7780649 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" diff --git a/src/cli/cli.ts b/src/cli/cli.ts index 2b8017b..bebe457 100644 --- a/src/cli/cli.ts +++ b/src/cli/cli.ts @@ -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' @@ -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', diff --git a/src/cli/settings/settings.ts b/src/cli/settings/settings.ts new file mode 100644 index 0000000..88cd393 --- /dev/null +++ b/src/cli/settings/settings.ts @@ -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 => { + 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 => { + const settingsFile = Bun.file('settings.json') + return await requestSettings(settingsFile, true) +} diff --git a/src/common/sentry-dsn.ts b/src/common/sentry-dsn.ts index 4985e8f..7dbffe3 100644 --- a/src/common/sentry-dsn.ts +++ b/src/common/sentry-dsn.ts @@ -1 +1 @@ -export default process.env.SENTRY_DSN || null \ No newline at end of file +export default process.env.SENTRY_DSN || null diff --git a/src/gui/gui.ts b/src/gui/gui.ts index f83e07c..22d1c3e 100644 --- a/src/gui/gui.ts +++ b/src/gui/gui.ts @@ -1,3 +1,3 @@ import 'colors' -console.log('Not implemented yet.'.red) \ No newline at end of file +console.log('Not implemented yet.'.red) diff --git a/src/types/settings.d.ts b/src/types/settings.d.ts index cf52a66..854c2da 100644 --- a/src/types/settings.d.ts +++ b/src/types/settings.d.ts @@ -1,7 +1,7 @@ export type Settings = { - version: number - storageSpace: number - username: string | null - sentry: boolean - advanced: { rpcPort: number; udpPort: number; tcpPort: number } -} \ No newline at end of file + version: number + storageSpace: number + username: string | null + sentry: boolean + advanced: { rpcPort: number; udpPort: number; tcpPort: number } +}