From 632d37caf5f3d0bebe5c98fa9f86c98bbb7c8553 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Tue, 1 Oct 2024 22:19:27 +0800 Subject: [PATCH] :tada: Initial Commit of next version RoadSign CLI --- cli/.gitignore | 175 ++++++++++++++++++++++++++++++++++++++++ cli/README.md | 3 + cli/bun.lockb | Bin 0 -> 11188 bytes cli/index.ts | 24 ++++++ cli/package.json | 18 +++++ cli/src/cmd/list.ts | 26 ++++++ cli/src/cmd/login.ts | 55 +++++++++++++ cli/src/cmd/logout.ts | 31 +++++++ cli/src/utils/auth.ts | 4 + cli/src/utils/config.ts | 51 ++++++++++++ cli/tsconfig.json | 27 +++++++ pkg/sideload/publish.go | 2 +- 12 files changed, 415 insertions(+), 1 deletion(-) create mode 100644 cli/.gitignore create mode 100644 cli/README.md create mode 100755 cli/bun.lockb create mode 100644 cli/index.ts create mode 100644 cli/package.json create mode 100644 cli/src/cmd/list.ts create mode 100644 cli/src/cmd/login.ts create mode 100644 cli/src/cmd/logout.ts create mode 100644 cli/src/utils/auth.ts create mode 100644 cli/src/utils/config.ts create mode 100644 cli/tsconfig.json diff --git a/cli/.gitignore b/cli/.gitignore new file mode 100644 index 0000000..9b1ee42 --- /dev/null +++ b/cli/.gitignore @@ -0,0 +1,175 @@ +# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore + +# Logs + +logs +_.log +npm-debug.log_ +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Caches + +.cache + +# Diagnostic reports (https://nodejs.org/api/report.html) + +report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json + +# Runtime data + +pids +_.pid +_.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover + +lib-cov + +# Coverage directory used by tools like istanbul + +coverage +*.lcov + +# nyc test coverage + +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) + +.grunt + +# Bower dependency directory (https://bower.io/) + +bower_components + +# node-waf configuration + +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) + +build/Release + +# Dependency directories + +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) + +web_modules/ + +# TypeScript cache + +*.tsbuildinfo + +# Optional npm cache directory + +.npm + +# Optional eslint cache + +.eslintcache + +# Optional stylelint cache + +.stylelintcache + +# Microbundle cache + +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history + +.node_repl_history + +# Output of 'npm pack' + +*.tgz + +# Yarn Integrity file + +.yarn-integrity + +# dotenv environment variable files + +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) + +.parcel-cache + +# Next.js build output + +.next +out + +# Nuxt.js build / generate output + +.nuxt +dist + +# Gatsby files + +# Comment in the public line in if your project uses Gatsby and not Next.js + +# https://nextjs.org/blog/next-9-1#public-directory-support + +# public + +# vuepress build output + +.vuepress/dist + +# vuepress v2.x temp and cache directory + +.temp + +# Docusaurus cache and generated files + +.docusaurus + +# Serverless directories + +.serverless/ + +# FuseBox cache + +.fusebox/ + +# DynamoDB Local files + +.dynamodb/ + +# TernJS port file + +.tern-port + +# Stores VSCode versions used for testing VSCode extensions + +.vscode-test + +# yarn v2 + +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +# IntelliJ based IDEs +.idea + +# Finder (MacOS) folder config +.DS_Store diff --git a/cli/README.md b/cli/README.md new file mode 100644 index 0000000..1ebeeab --- /dev/null +++ b/cli/README.md @@ -0,0 +1,3 @@ +# RoadSign CLI + +RoadSign CLI is a command-line interface (CLI) tool that allows you to manage your RoadSign servers and applications. \ No newline at end of file diff --git a/cli/bun.lockb b/cli/bun.lockb new file mode 100755 index 0000000000000000000000000000000000000000..58a91c9870d4017206d7a410021780462b8df85a GIT binary patch literal 11188 zcmeHN2UL^UwoWiM6a{Rcq7;QIm;ezWLPQYs4%iXPAT1^Vf+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NWc*QxJ`z zMF9_6VihM$O#BrAi=Wi>FJJ4bag_ z0T(UCR_!&7n5Egg0I7L{NvSa?OcEv$vV$UIuu#cm4QNomAW+p$P&JV)>VfOKL?#kX z=Y&!X@Tu2d;8DN8AVr-To_Nqb>LnUrweQdZV2f%AZv;+uT|kppc0Z17;}gE#mO)n; zj);xaS-0;14!_UD?HpDaY$%AScBKYdskV#;ttzkL;0{0z4gEAq^CE*irU5!yDImnc zZ1qV28UffMWFm=B(x_7OVn9QW!Z3j2MgOKX$}|el( `]] + } + + label = Option.String({ required: true }) + host = Option.String({ required: true }) + credentials = Option.String({ required: true }) + + async execute() { + const config = await RsConfig.getInstance() + const spinner = ora(`Connecting to ${this.host}...`).start() + + if (!this.host.includes(":")) { + this.host += ":81" + } + if (!this.host.startsWith("http")) { + this.host = "http://" + this.host + } + + try { + const pingRes = await fetch(`${this.host}/cgi/metadata`, { + headers: { + Authorization: createAuthHeader("RoadSign CLI", this.credentials) + } + }) + if (pingRes.status !== 200) { + throw new Error(await pingRes.text()) + } else { + const info = await pingRes.json() + spinner.succeed(`Connected to ${this.host}, remote version ${info["version"]}`) + + config.config.servers.push({ + label: this.label, + url: this.host, + credential: this.credentials + }) + await oraPromise(config.writeConfig(), { text: "Saving changes..." }) + } + } catch (e) { + spinner.fail(`Unable connect to remote: ${e}`) + } + + process.exit(0) + } +} \ No newline at end of file diff --git a/cli/src/cmd/logout.ts b/cli/src/cmd/logout.ts new file mode 100644 index 0000000..5c59a04 --- /dev/null +++ b/cli/src/cmd/logout.ts @@ -0,0 +1,31 @@ +import { Command, Option, type Usage } from "clipanion" +import { RsConfig } from "../utils/config.ts" +import { oraPromise } from "ora" +import chalk from "chalk" + +export class LogoutCommand extends Command { + static paths = [[`logout`]] + static usage: Usage = { + category: `Networking`, + description: `Logout from RoadSign Sideload Service`, + details: `Logout from RoadSign Server`, + examples: [["Logout with server label", `logout