🔨 Make cli package distributable

This commit is contained in:
2024-10-03 15:04:23 +08:00
parent 8a5cc34bb4
commit 498eb05514
10 changed files with 58 additions and 23 deletions

View File

@@ -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`)

View File

@@ -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({

View File

@@ -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(" ")])
}

View File

@@ -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))
}
}

View File

@@ -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))
}
}