Compare commits

...

5 Commits

Author SHA1 Message Date
Sambo Chea d5f4abeeb0
Add list profiles 2023-07-27 09:13:44 +07:00
Sambo Chea 7d17ee38a4
Merge pull request #146 from CUBETIQ/dependabot/npm_and_yarn/types/node-20.4.5
Bump @types/node from 20.4.4 to 20.4.5
2023-07-26 08:33:01 +07:00
dependabot[bot] d500dac31c
Bump @types/node from 20.4.4 to 20.4.5
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 20.4.4 to 20.4.5.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-25 20:53:00 +00:00
Sambo Chea fbda263da2
Merge pull request #145 from CUBETIQ/dependabot/npm_and_yarn/types/node-20.4.4
Bump @types/node from 20.4.1 to 20.4.4
2023-07-25 21:25:46 +07:00
dependabot[bot] 3d94eae00b
Bump @types/node from 20.4.1 to 20.4.4
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 20.4.1 to 20.4.4.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-24 20:49:54 +00:00
5 changed files with 61 additions and 15 deletions

View File

@ -1,4 +1,8 @@
### 14/07/2023 (1.0.8)
### 27/07/2023 (1.0.10)
- Add list profiles
### 14/07/2023 (1.0.9)
- Fixed the start with port unable to start

6
package-lock.json generated
View File

@ -178,9 +178,9 @@
"devOptional": true
},
"node_modules/@types/node": {
"version": "20.4.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.4.1.tgz",
"integrity": "sha512-JIzsAvJeA/5iY6Y/OxZbv1lUcc8dNSE77lb2gnBH+/PJ3lFR1Ccvgwl5JWnHAkNHcRsT0TbpVOsiMKZ1F/yyJg=="
"version": "20.4.5",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.4.5.tgz",
"integrity": "sha512-rt40Nk13II9JwQBdeYqmbn2Q6IVTA5uPhvSO+JVqdXw/6/4glI6oR9ezty/A9Hg5u7JH4OmYmuQ+XvjKm0Datg=="
},
"node_modules/@types/qs": {
"version": "6.9.7",

View File

@ -1,6 +1,6 @@
{
"name": "@cubetiq/hlt",
"version": "0.1.9",
"version": "0.1.10",
"description": "A lightweight http tunnel client using nodejs and socket.io client",
"main": "dist/cli.js",
"bin": {

View File

@ -4,6 +4,7 @@ import * as os from "os";
import * as path from "path";
import { initConfigFileClient, startClient } from "./api";
import { PROFILE_DEFAULT, PROFILE_PATH, SERVER_DEFAULT_URL, TOKEN_FREE } from "./constant";
import { listProfile } from "./manage";
import { createProxyServer } from "./proxy";
import { createProxyServer as createProxyTCPServer } from "./proxy_tcp";
import { getTokenFree } from './sdk';
@ -22,20 +23,20 @@ program
program
.command("init")
.description("generate a new client and token with free access")
.option("-s --server <string>", "setting server url", SERVER_DEFAULT_URL)
.option("-s, --server <string>", "setting server url", SERVER_DEFAULT_URL)
.option(
"-t --token <string>",
"-t, --token <string>",
"setting token (default generate FREE access token)",
""
)
.option("-a --access <string>", "setting token access type", TOKEN_FREE)
.option("-c --client <string>", "setting client (auto generate uuid)")
.option("-a, --access <string>", "setting token access type", TOKEN_FREE)
.option("-c, --client <string>", "setting client (auto generate uuid)")
.option(
"-k --key <string>",
"-k, --key <string>",
"setting client api key for authentication access"
)
.option("-p --profile <string>", "setting profile name", PROFILE_DEFAULT)
.option("-f --force", "force to generate new client and token", false)
.option("-p, --profile <string>", "setting profile name", PROFILE_DEFAULT)
.option("-f, --force", "force to generate new client and token", false)
.action(async (options) => {
initConfigFileClient(options);
});
@ -91,7 +92,7 @@ program
])
)
.argument("<value>", "config value")
.option("-p --profile <string>", "setting profile name", PROFILE_DEFAULT)
.option("-p, --profile <string>", "setting profile name", PROFILE_DEFAULT)
.action(async (type, value, options) => {
if (!type) {
console.error("type config is required!");
@ -179,7 +180,7 @@ program
"key",
])
)
.option("-p --profile <string>", "setting profile name", PROFILE_DEFAULT)
.option("-p, --profile <string>", "setting profile name", PROFILE_DEFAULT)
.action(async (type, options) => {
if (!type) {
console.error("type config is required!");
@ -271,7 +272,7 @@ program
throw new InvalidArgumentError("Target is not a url or host with port.");
})
.option("-p --profile <string>", "setting profile name for connect with hlt server (proxy with current local port)")
.option("-p, --profile <string>", "setting profile name for connect with hlt server (proxy with current local port)")
.action((port, target, options) => {
const isTcp = target.indexOf("tcp") === 0;
if (isTcp) {
@ -322,4 +323,17 @@ const onConnectProxy = (port: number, options: any) => {
}
}
// profile
program
.command("profile")
.description("manage profile")
.option("-l, --list", "list all profiles", false)
.action((options) => {
if (options.list) {
listProfile();
} else {
console.log("profile command is required");
}
});
program.parse();

28
src/manage.ts Normal file
View File

@ -0,0 +1,28 @@
import * as fs from "fs";
import * as os from "os";
import * as path from "path";
import { PROFILE_DEFAULT, PROFILE_PATH } from "./constant";
export const listProfile = () => {
const configDir = path.resolve(os.homedir(), PROFILE_PATH);
if (!fs.existsSync(configDir)) {
console.log(`config file ${configDir} not found`);
return;
}
const configFiles = fs.readdirSync(configDir);
if (configFiles.length === 0) {
console.log(`config file ${configDir} not found`);
return;
}
console.log("List of profile:");
configFiles.forEach((file) => {
const configFilePath = path.resolve(configDir, file);
const config = JSON.parse(fs.readFileSync(configFilePath, "utf8"));
const name = file.replace(".json", "");
console.log(`- ${name} (${config.clientId})`);
});
console.log(`\nCurrent profile: ${PROFILE_DEFAULT}`);
}