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 0000000..58a91c9 Binary files /dev/null and b/cli/bun.lockb differ diff --git a/cli/index.ts b/cli/index.ts new file mode 100644 index 0000000..7bf29a8 --- /dev/null +++ b/cli/index.ts @@ -0,0 +1,24 @@ +import { Cli } from "clipanion" +import figlet from "figlet" +import chalk from "chalk" + +import { LoginCommand } from "./src/cmd/login.ts" +import { LogoutCommand } from "./src/cmd/logout.ts" +import { ListServerCommand } from "./src/cmd/list.ts" + +const [node, app, ...args] = process.argv + +console.log( + chalk.yellow(figlet.textSync("RoadSign CLI", { horizontalLayout: "default", verticalLayout: "default" })) +) + +const cli = new Cli({ + binaryLabel: `RoadSign CLI`, + binaryName: `${node} ${app}`, + binaryVersion: `1.0.0` +}) + +cli.register(LoginCommand) +cli.register(LogoutCommand) +cli.register(ListServerCommand) +cli.runExit(args) \ No newline at end of file diff --git a/cli/package.json b/cli/package.json new file mode 100644 index 0000000..4b95169 --- /dev/null +++ b/cli/package.json @@ -0,0 +1,18 @@ +{ + "name": "roadsign-cli", + "module": "index.ts", + "type": "module", + "devDependencies": { + "@types/bun": "latest", + "@types/figlet": "^1.5.8" + }, + "peerDependencies": { + "typescript": "^5.0.0" + }, + "dependencies": { + "chalk": "^5.3.0", + "clipanion": "^4.0.0-rc.4", + "figlet": "^1.7.0", + "ora": "^8.1.0" + } +} \ No newline at end of file diff --git a/cli/src/cmd/list.ts b/cli/src/cmd/list.ts new file mode 100644 index 0000000..6271686 --- /dev/null +++ b/cli/src/cmd/list.ts @@ -0,0 +1,26 @@ +import { Command, type Usage } from "clipanion" +import { RsConfig } from "../utils/config.ts" +import chalk from "chalk" + +export class ListServerCommand extends Command { + static paths = [[`list`], [`ls`]] + static usage: Usage = { + category: `Networking`, + description: `List all connected RoadSign Sideload Services`, + details: `Listing all servers that already saved in RoadSign CLI configuration file`, + examples: [["List all", `list`]] + } + + async execute() { + const config = await RsConfig.getInstance() + + for (let idx = 0; idx < config.config.servers.length; idx++) { + const server = config.config.servers[idx] + this.context.stdout.write(`${idx + 1}. ${chalk.bold(server.label)} ${chalk.gray(`(${server.url})`)}\n`) + } + + this.context.stdout.write("\n" + chalk.cyan(`Connected ${config.config.servers.length} server(s) in total.`) + "\n") + + process.exit(0) + } +} \ No newline at end of file diff --git a/cli/src/cmd/login.ts b/cli/src/cmd/login.ts new file mode 100644 index 0000000..5bca4fb --- /dev/null +++ b/cli/src/cmd/login.ts @@ -0,0 +1,55 @@ +import { Command, Option, type Usage } from "clipanion" +import { createAuthHeader } from "../utils/auth.ts" +import { RsConfig } from "../utils/config.ts" +import ora, { oraPromise } from "ora" + +export class LoginCommand extends Command { + static paths = [[`login`]] + static usage: Usage = { + category: `Networking`, + description: `Login to RoadSign Sideload Service`, + details: `Login to RoadSign Server`, + examples: [["Login with credentials", `login