diff --git a/cli/bun.lockb b/cli/bun.lockb index fbf857b..41a174c 100755 Binary files a/cli/bun.lockb and b/cli/bun.lockb differ diff --git a/cli/index.ts b/cli/index.ts old mode 100644 new mode 100755 diff --git a/cli/package.json b/cli/package.json index 8775505..9f16da3 100644 --- a/cli/package.json +++ b/cli/package.json @@ -2,13 +2,26 @@ "name": "roadsign-cli", "module": "index.ts", "type": "module", + "scripts": { + "build": "rimraf dist && rollup -c rollup.config.js" + }, + "bin": { + "rdcli": "./dist/index.cjs" + }, "devDependencies": { + "@rollup/plugin-commonjs": "^28.0.0", + "@rollup/plugin-json": "^6.1.0", + "@rollup/plugin-node-resolve": "^15.3.0", + "@rollup/plugin-typescript": "^12.1.0", "@types/bun": "latest", "@types/cli-progress": "^3.11.6", - "@types/figlet": "^1.5.8" + "@types/figlet": "^1.5.8", + "rimraf": "^6.0.1", + "rollup": "^4.24.0", + "rollup-plugin-typescript2": "^0.36.0" }, "peerDependencies": { - "typescript": "^5.0.0" + "typescript": "^5.6.2" }, "dependencies": { "chalk": "^5.3.0", diff --git a/cli/rollup.config.js b/cli/rollup.config.js new file mode 100644 index 0000000..6898456 --- /dev/null +++ b/cli/rollup.config.js @@ -0,0 +1,22 @@ +import resolve from "@rollup/plugin-node-resolve" +import commonjs from "@rollup/plugin-commonjs" +import typescript from "@rollup/plugin-typescript" +import json from "@rollup/plugin-json" + +export default { + input: "index.ts", + output: { + banner: "#!/usr/bin/env node", + file: "dist/index.cjs", + format: "cjs", + inlineDynamicImports: true, + }, + plugins: [ + resolve(), + commonjs(), + json(), + typescript({ + tsconfig: "./tsconfig.json" + }) + ], +} \ No newline at end of file diff --git a/cli/src/cmd/info.ts b/cli/src/cmd/info.ts index 8b48637..a3e9640 100644 --- a/cli/src/cmd/info.ts +++ b/cli/src/cmd/info.ts @@ -48,7 +48,7 @@ export class InfoCommand extends Command { throw new Error(await res.text()) } - const data = await res.json() + const data: any = await res.json() this.context.stdout.write('\n') this.context.stdout.write(`\nServer stats of ${chalk.bold(this.label)}\n`) this.context.stdout.write(` • Uptime: ${chalk.bold(InfoCommand.formatUptime(data["uptime"]))}\n`) @@ -75,7 +75,7 @@ export class InfoCommand extends Command { throw new Error(await res.text()) } - const data = await res.json() + const data: any = await res.json() for (const trace of data) { const ts = new Date(trace["timestamp"]).toLocaleString() const path = [trace["region"], trace["location"], trace["destination"]].join(" ➜ ") @@ -94,7 +94,7 @@ export class InfoCommand extends Command { throw new Error(await res.text()) } - const data = await res.json() + const data: any = await res.json() this.context.stdout.write("\n\n") for (const region of data) { this.context.stdout.write(` • ${chalk.bgGrey('region#')}${chalk.bold(region.id)} ${chalk.gray(`(${region.locations.length} locations)`)}\n`) diff --git a/cli/src/cmd/login.ts b/cli/src/cmd/login.ts index 564d994..182a7e4 100644 --- a/cli/src/cmd/login.ts +++ b/cli/src/cmd/login.ts @@ -36,7 +36,7 @@ export class LoginCommand extends Command { if (pingRes.status !== 200) { throw new Error(await pingRes.text()) } else { - const info = await pingRes.json() + const info: any = await pingRes.json() spinner.succeed(`Connected to ${this.host}, remote version ${info["version"]}`) config.config.servers.push({ diff --git a/cli/src/cmd/process-info.ts b/cli/src/cmd/process-info.ts index 48cfa06..569e378 100644 --- a/cli/src/cmd/process-info.ts +++ b/cli/src/cmd/process-info.ts @@ -57,7 +57,7 @@ export class ProcessCommand extends Command { const statusMapping = ["Created", "Starting", "Started", "Exited", "Failed"] - const data = await res.json() + const data: any = await res.json() for (const app of data) { table.push([app["id"], statusMapping[app["status"]], app["command"].join(" ")]) } diff --git a/cli/src/utils/config-local.ts b/cli/src/utils/config-local.ts index 32274e2..ed3c10b 100644 --- a/cli/src/utils/config-local.ts +++ b/cli/src/utils/config-local.ts @@ -1,5 +1,5 @@ import * as path from "node:path" -import * as fs from "node:fs/promises" +import * as fs from "node:fs" interface RsLocalConfigData { sync?: RsLocalConfigSyncData @@ -42,18 +42,18 @@ class RsLocalConfig { public async readConfig() { const basepath = process.cwd() const filepath = path.join(basepath, ".roadsignrc") - if (!await fs.exists(filepath)) { + if (!fs.existsSync(filepath)) { throw new Error(`.roadsignrc file was not found at ${filepath}`) } - const data = await fs.readFile(filepath, "utf8") + const data = fs.readFileSync(filepath, "utf8") this.config = JSON.parse(data) } public async writeConfig() { const basepath = process.cwd() const filepath = path.join(basepath, ".roadsignrc") - await fs.writeFile(filepath, JSON.stringify(this.config)) + fs.writeFileSync(filepath, JSON.stringify(this.config)) } } diff --git a/cli/src/utils/config.ts b/cli/src/utils/config.ts index cee8034..abf3862 100644 --- a/cli/src/utils/config.ts +++ b/cli/src/utils/config.ts @@ -1,6 +1,6 @@ import * as os from "node:os" import * as path from "node:path" -import * as fs from "node:fs/promises" +import * as fs from "node:fs" interface RsConfigData { servers: RsConfigServerData[] @@ -33,18 +33,18 @@ class RsConfig { public async readConfig() { const basepath = os.homedir() const filepath = path.join(basepath, ".roadsignrc") - if (!await fs.exists(filepath)) { - await fs.writeFile(filepath, JSON.stringify(this.config)) + if (!fs.existsSync(filepath)) { + fs.writeFileSync(filepath, JSON.stringify(this.config)) } - const data = await fs.readFile(filepath, "utf8") + const data = fs.readFileSync(filepath, "utf8") this.config = JSON.parse(data) } public async writeConfig() { const basepath = os.homedir() const filepath = path.join(basepath, ".roadsignrc") - await fs.writeFile(filepath, JSON.stringify(this.config)) + fs.writeFileSync(filepath, JSON.stringify(this.config)) } } diff --git a/cli/tsconfig.json b/cli/tsconfig.json index 238655f..28f4a28 100644 --- a/cli/tsconfig.json +++ b/cli/tsconfig.json @@ -1,18 +1,17 @@ { "compilerOptions": { - // Enable latest features - "lib": ["ESNext", "DOM"], + "lib": ["ESNext"], "target": "ESNext", - "module": "ESNext", - "moduleDetection": "force", - "jsx": "react-jsx", + "module": "NodeNext", "allowJs": true, // Bundler mode - "moduleResolution": "bundler", + "esModuleInterop": true, + "moduleResolution": "NodeNext", "allowImportingTsExtensions": true, "verbatimModuleSyntax": true, "noEmit": true, + "resolveJsonModule": true, // Best practices "strict": true, @@ -22,6 +21,7 @@ // Some stricter flags (disabled by default) "noUnusedLocals": false, "noUnusedParameters": false, - "noPropertyAccessFromIndexSignature": false + "noPropertyAccessFromIndexSignature": false, + "useUnknownInCatchVariables": false, } }