Skip to content

Commit

Permalink
Merge pull request #3 from LBRYFoundation/read-settings
Browse files Browse the repository at this point in the history
More precise messaging again, checks settings.json
  • Loading branch information
ezShroom authored Aug 26, 2024
2 parents f55f463 + 7d66541 commit d434aac
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 19 deletions.
18 changes: 10 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: CI
on:
pull_request:
push:
branches:
- main

jobs:
eslint:
Expand Down Expand Up @@ -91,14 +93,14 @@ jobs:

- 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
#
# - 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)
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ Download the correct binary for your system from here, and run it.
| -------- | ------------ | --- | ----------------------------------------------------------------------------------------------- |
| Windows | x64 | GUI | [Download](https://github.com/lbryfoundation/bookbuddies/releases/download/windows-x64-gui.exe) |
| Windows | x64 | CLI | [Download](https://github.com/lbryfoundation/bookbuddies/releases/download/windows-x64-cli.exe) |
| macOS | x64 | GUI | [Download](https://github.com/lbryfoundation/bookbuddies/releases/download/macos-x64-gui) |
| macOS | x64 | CLI | [Download](https://github.com/lbryfoundation/bookbuddies/releases/download/macos-x64-cli) |
| macOS | arm64 | GUI | [Download](https://github.com/lbryfoundation/bookbuddies/releases/download/macos-arm64-gui) |
| macOS | arm64 | CLI | [Download](https://github.com/lbryfoundation/bookbuddies/releases/download/macos-arm64-cli) |
| macOS | Universal | GUI | [Download](https://github.com/lbryfoundation/bookbuddies/releases/download/macos-x64-gui) |
| macOS | Universal | CLI | [Download](https://github.com/lbryfoundation/bookbuddies/releases/download/macos-x64-cli) |
| Linux | x64 | GUI | [Download](https://github.com/lbryfoundation/bookbuddies/releases/download/linux-x64-gui) |
| Linux | x64 | CLI | [Download](https://github.com/lbryfoundation/bookbuddies/releases/download/linux-x64-cli) |
| Linux | arm64 | GUI | [Download](https://github.com/lbryfoundation/bookbuddies/releases/download/linux-arm64-gui) |
Expand Down
Binary file modified bun.lockb
Binary file not shown.
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"@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",
"@typescript-eslint/eslint-plugin": "^8.3.0",
"eslint": "^9.9.1",
"eslint-config-prettier": "^9.1.0",
"prettier": "^3.3.3",
"typescript": "^5.5.4",
"typescript-eslint": "^8.2.0"
"typescript-eslint": "^8.3.0"
},
"scripts": {
"lint": "bun update && bun eslint --fix && bun prettier . -w && bun tsc --noEmit",
Expand All @@ -28,12 +28,13 @@
"@inquirer/prompts": "^5.3.8",
"@sentry/bun": "^8.26.0",
"adm-zip": "^0.5.15",
"ajv": "^8.17.1",
"app-root-path": "^3.1.0",
"cli-progress": "^3.12.0",
"colors": "^1.4.0",
"hono": "^4.5.8",
"hono": "^4.5.9",
"jszip": "^3.10.1",
"ora": "^8.0.1",
"ora": "^8.1.0",
"readline-sync": "^1.4.10"
}
}
2 changes: 1 addition & 1 deletion src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ coreEvents.on('lbrynet downloaded', () => {
})
coreEvents.on('lbrynet starting', () => {
currentSpinner = ora({
text: `Starting the LBRY SDK${process.platform === 'win32' ? ', this may trigger a Windows Firewall prompt or take a long time!' : ''}`,
text: `Starting the LBRY SDK, this may ${process.platform === 'win32' ? 'trigger a Windows Firewall prompt or ' : ''}take a long time!`,
spinner: 'bouncingBar'
}).start()
})
Expand Down
20 changes: 20 additions & 0 deletions src/cli/settings/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"version": { "type": "number", "minimum": 1, "maximum": 1 },
"storageSpace": { "type": "number", "minimum": 1 },
"username": { "type": "string" },
"sentry": { "type": "boolean" },
"advanced": {
"type": "object",
"properties": {
"rpcPort": { "type": "number", "minimum": 1024, "maximum": 65535 },
"udpPort": { "type": "number", "minimum": 1024, "maximum": 65535 },
"tcpPort": { "type": "number", "minimum": 1024, "maximum": 65535 }
},
"required": ["rpcPort", "udpPort", "tcpPort"]
}
},
"required": ["version", "storageSpace", "sentry", "advanced"]
}
21 changes: 19 additions & 2 deletions src/cli/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { number, input, confirm } from '@inquirer/prompts'
import colors from 'colors'
import type { Settings } from '../../types/settings'
import type { BunFile } from 'bun'
import Ajv from 'ajv'
import schema from './schema.json' with { type: 'file' }

const ajv = new Ajv()

const theme = {
prefix: '?',
Expand Down Expand Up @@ -90,6 +94,19 @@ const requestSettings = async (
}

export default async (): Promise<Settings> => {
const settingsFile = Bun.file('settings.json')
return await requestSettings(settingsFile, true)
const settingsFile = await Bun.file('settings.json')
let requiresRequest = false
const settingsJson = await settingsFile
.json()
.catch(() => (requiresRequest = true))
if (
!ajv.validate(
await Bun.file(schema as unknown as string).json(),
settingsJson
)
)
requiresRequest = true
if (requiresRequest)
return await requestSettings(settingsFile, await settingsFile.exists())
return settingsJson
}

0 comments on commit d434aac

Please sign in to comment.