airship-cli 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -0
- package/out/AirshipTypes.d.ts +60 -0
- package/out/AirshipTypes.d.ts.map +1 -0
- package/out/AirshipTypes.js +2 -0
- package/out/AirshipTypes.js.map +1 -0
- package/out/Types.d.ts +2 -0
- package/out/Types.d.ts.map +1 -0
- package/out/Types.js +2 -0
- package/out/Types.js.map +1 -0
- package/out/cli.d.ts +9 -0
- package/out/cli.d.ts.map +1 -0
- package/out/cli.js +44 -0
- package/out/cli.js.map +1 -0
- package/out/commands/CommandTypes.d.ts +8 -0
- package/out/commands/CommandTypes.d.ts.map +1 -0
- package/out/commands/CommandTypes.js +2 -0
- package/out/commands/CommandTypes.js.map +1 -0
- package/out/commands/FetchGame.d.ts +3 -0
- package/out/commands/FetchGame.d.ts.map +1 -0
- package/out/commands/FetchGame.js +55 -0
- package/out/commands/FetchGame.js.map +1 -0
- package/out/commands/FetchUser copy.d.ts +3 -0
- package/out/commands/FetchUser copy.d.ts.map +1 -0
- package/out/commands/FetchUser copy.js +46 -0
- package/out/commands/FetchUser copy.js.map +1 -0
- package/out/commands/FetchUser.d.ts +3 -0
- package/out/commands/FetchUser.d.ts.map +1 -0
- package/out/commands/FetchUser.js +55 -0
- package/out/commands/FetchUser.js.map +1 -0
- package/out/commands/help.d.ts +3 -0
- package/out/commands/help.d.ts.map +1 -0
- package/out/commands/help.js +34 -0
- package/out/commands/help.js.map +1 -0
- package/out/index.d.ts.map +1 -0
- package/out/index.js.map +1 -0
- package/out/util/Styles.d.ts +4 -0
- package/out/util/Styles.d.ts.map +1 -0
- package/out/util/Styles.js +19 -0
- package/out/util/Styles.js.map +1 -0
- package/out/util/TokenManager.d.ts +2 -0
- package/out/util/TokenManager.d.ts.map +1 -0
- package/out/util/TokenManager.js +16 -0
- package/out/util/TokenManager.js.map +1 -0
- package/package.json +24 -0
- package/src/AirshipTypes.ts +63 -0
- package/src/cli.ts +49 -0
- package/src/commands/CommandTypes.ts +7 -0
- package/src/commands/FetchGame.ts +61 -0
- package/src/commands/FetchUser.ts +61 -0
- package/src/commands/Help.ts +36 -0
- package/src/util/Styles.ts +20 -0
- package/src/util/TokenManager.ts +20 -0
- package/tsconfig.json +42 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { CLICommand } from "./CommandTypes.js";
|
|
2
|
+
import { input, select, confirm } from '@inquirer/prompts';
|
|
3
|
+
import { PrintHeader, PrintError, PrintTitle } from '../util/Styles.js';
|
|
4
|
+
import { AirshipToken } from '../util/TokenManager.js';
|
|
5
|
+
import type { AirshipGame } from "../AirshipTypes.js";
|
|
6
|
+
import { StartTool } from "../cli.js";
|
|
7
|
+
|
|
8
|
+
const apiMap = {
|
|
9
|
+
"Slug": "https://api.airship.gg/content/games/slug/",
|
|
10
|
+
"GameId": "https://api.airship.gg/content/games/game-id/"
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const fetchGameCommand: CLICommand = {
|
|
14
|
+
name: "fetch-game",
|
|
15
|
+
description: "Returns data related to the specified game.",
|
|
16
|
+
usage: "fetch-game <method: slug | gameId> <identifier: string>",
|
|
17
|
+
requiresToken: false,
|
|
18
|
+
execute: async () => {
|
|
19
|
+
const fetchMethod = await select({ message: "Which method would you like to use?", choices: [
|
|
20
|
+
"Slug",
|
|
21
|
+
"GameId"
|
|
22
|
+
]});
|
|
23
|
+
|
|
24
|
+
const gameIdentifier = await input({ message: `Please enter the ${fetchMethod}:` });
|
|
25
|
+
|
|
26
|
+
for (let data of Object.entries(apiMap)) {
|
|
27
|
+
const method = data[0];
|
|
28
|
+
const url = data[1];
|
|
29
|
+
|
|
30
|
+
if (method === fetchMethod) {
|
|
31
|
+
fetch(url + gameIdentifier, {
|
|
32
|
+
method: "GET"
|
|
33
|
+
}).then(raw => raw.text().then(data => {
|
|
34
|
+
const gameData = JSON.parse(data) as AirshipGame | {};
|
|
35
|
+
const entries = Object.entries(gameData);
|
|
36
|
+
|
|
37
|
+
if (entries.length === 0) {
|
|
38
|
+
PrintError(`Invalid ${fetchMethod}!`);
|
|
39
|
+
} else if (entries.length === 3) {
|
|
40
|
+
// const styledError = `${entries[0]?.[1]}`.replaceAll("username", "Username").replaceAll(",", ", ");
|
|
41
|
+
// PrintError(styledError);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
console.log(gameData);
|
|
45
|
+
})).catch((err) => {
|
|
46
|
+
PrintError(err);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
setTimeout(async () => {
|
|
50
|
+
const restartTool = await confirm({ message: "Would you like to anything else?" });
|
|
51
|
+
|
|
52
|
+
if (restartTool) {
|
|
53
|
+
StartTool();
|
|
54
|
+
};
|
|
55
|
+
}, 1000);
|
|
56
|
+
|
|
57
|
+
return;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { CLICommand } from "./CommandTypes.js";
|
|
2
|
+
import { input, select, confirm } from '@inquirer/prompts';
|
|
3
|
+
import { PrintHeader, PrintError, PrintTitle } from '../util/Styles.js';
|
|
4
|
+
import { AirshipToken } from '../util/TokenManager.js';
|
|
5
|
+
import type { AirshipUser, AirshipUserError } from "../AirshipTypes.js";
|
|
6
|
+
import { StartTool } from "../cli.js";
|
|
7
|
+
|
|
8
|
+
const apiMap = {
|
|
9
|
+
"Username": "https://api.airship.gg/game-coordinator/users/user?username=",
|
|
10
|
+
"UserId": "https://api.airship.gg/game-coordinator/users/uid/"
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const fetchUserCommand: CLICommand = {
|
|
14
|
+
name: "fetch-user",
|
|
15
|
+
description: "Returns data related to the specified user.",
|
|
16
|
+
usage: "fetch-user <method: username | userId> <identifier: string>",
|
|
17
|
+
requiresToken: false,
|
|
18
|
+
execute: async () => {
|
|
19
|
+
const fetchMethod = await select({ message: "Which method would you like to use?", choices: [
|
|
20
|
+
"Username",
|
|
21
|
+
"UserId"
|
|
22
|
+
]});
|
|
23
|
+
|
|
24
|
+
const userIdentifier = await input({ message: `Please enter the ${fetchMethod}:` });
|
|
25
|
+
|
|
26
|
+
for (let data of Object.entries(apiMap)) {
|
|
27
|
+
const method = data[0];
|
|
28
|
+
const url = data[1];
|
|
29
|
+
|
|
30
|
+
if (method === fetchMethod) {
|
|
31
|
+
fetch(url + userIdentifier, {
|
|
32
|
+
method: "GET"
|
|
33
|
+
}).then(raw => raw.text().then(data => {
|
|
34
|
+
const userData = JSON.parse(data) as AirshipUser | AirshipUserError | {};
|
|
35
|
+
const entries = Object.entries(userData);
|
|
36
|
+
|
|
37
|
+
if (entries.length === 0) {
|
|
38
|
+
PrintError(`Invalid ${fetchMethod}!`);
|
|
39
|
+
} else if (entries.length === 3) {
|
|
40
|
+
const styledError = `${entries[0]?.[1]}`.replaceAll("username", "Username").replaceAll(",", ", ");
|
|
41
|
+
PrintError(styledError);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
console.log(userData);
|
|
45
|
+
})).catch((err) => {
|
|
46
|
+
PrintError(err);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
setTimeout(async () => {
|
|
50
|
+
const restartTool = await confirm({ message: "Would you like to anything else?" });
|
|
51
|
+
|
|
52
|
+
if (restartTool) {
|
|
53
|
+
StartTool();
|
|
54
|
+
};
|
|
55
|
+
}, 1000);
|
|
56
|
+
|
|
57
|
+
return;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { CLICommand } from "./CommandTypes.js";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import { input, select, confirm } from '@inquirer/prompts';
|
|
4
|
+
import { PrintHeader, PrintError, PrintTitle } from '../util/Styles.js';
|
|
5
|
+
import { AirshipToken } from '../util/TokenManager.js';
|
|
6
|
+
import { commandMap, commandList, StartTool } from "../cli.js";
|
|
7
|
+
|
|
8
|
+
export const helpCommand: CLICommand = {
|
|
9
|
+
name: "help",
|
|
10
|
+
description: "Returns the usage of a command.",
|
|
11
|
+
usage: "help <command: string>",
|
|
12
|
+
requiresToken: false,
|
|
13
|
+
execute: async () => {
|
|
14
|
+
const commandSelect = await select({ message: "Which command do you need help with?", choices: commandList.slice(1) });
|
|
15
|
+
|
|
16
|
+
for (let command of Object.entries(commandMap)) {
|
|
17
|
+
if (command[0] === commandSelect) {
|
|
18
|
+
console.log(`\n`);
|
|
19
|
+
console.log(`${chalk.bold(chalk.green(`${commandSelect} Help:`))}`);
|
|
20
|
+
console.log(`- Description: ${chalk.gray(command[1].description)}`);
|
|
21
|
+
console.log(`- Usage: ${chalk.gray(command[1].usage)}`);
|
|
22
|
+
console.log(`\n`);
|
|
23
|
+
|
|
24
|
+
setTimeout(async () => {
|
|
25
|
+
const restartTool = await confirm({ message: "Would you like to anything else?" });
|
|
26
|
+
|
|
27
|
+
if (restartTool) {
|
|
28
|
+
StartTool();
|
|
29
|
+
};
|
|
30
|
+
}, 0);
|
|
31
|
+
|
|
32
|
+
return;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import figlet from "figlet";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
|
|
4
|
+
export async function PrintHeader(message: string) {
|
|
5
|
+
const textArt = await figlet.text(message);
|
|
6
|
+
const coloredText = chalk.blue(textArt);
|
|
7
|
+
|
|
8
|
+
console.log(chalk.bold(coloredText));
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export async function PrintError(message: string) {
|
|
12
|
+
const coloredText = chalk.red(message);
|
|
13
|
+
|
|
14
|
+
console.log(chalk.bold(coloredText));
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export function PrintTitle() {
|
|
18
|
+
console.clear();
|
|
19
|
+
PrintHeader(`Airship CLI\n\n`);
|
|
20
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import type { AccountInfo } from '../AirshipTypes.js';
|
|
3
|
+
import { PrintError } from './Styles.js';
|
|
4
|
+
|
|
5
|
+
const airshipAccountPath = process.env.APPDATA + `../../LocalLow/Easy/Airship/account.json`;
|
|
6
|
+
|
|
7
|
+
function FetchAirshipToken(): string {
|
|
8
|
+
const accountsFile = fs.readFileSync(airshipAccountPath);
|
|
9
|
+
if (!accountsFile) {
|
|
10
|
+
PrintError("No Airship Installation Found!");
|
|
11
|
+
|
|
12
|
+
process.exit(1);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const jsonData: AccountInfo = JSON.parse(accountsFile.toString("utf8"));
|
|
16
|
+
|
|
17
|
+
return jsonData.refreshToken;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const AirshipToken = FetchAirshipToken();
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Visit https://aka.ms/tsconfig to read more about this file
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
// File Layout
|
|
5
|
+
"rootDir": "./src",
|
|
6
|
+
"outDir": "./out",
|
|
7
|
+
|
|
8
|
+
// Environment Settings
|
|
9
|
+
// See also https://aka.ms/tsconfig/module
|
|
10
|
+
"module": "nodenext",
|
|
11
|
+
"target": "esnext",
|
|
12
|
+
// For nodejs:
|
|
13
|
+
// "lib": ["esnext"],
|
|
14
|
+
"types": ["node"],
|
|
15
|
+
|
|
16
|
+
// Other Outputs
|
|
17
|
+
"sourceMap": true,
|
|
18
|
+
"declaration": true,
|
|
19
|
+
"declarationMap": true,
|
|
20
|
+
|
|
21
|
+
// Stricter Typechecking Options
|
|
22
|
+
"noUncheckedIndexedAccess": true,
|
|
23
|
+
"exactOptionalPropertyTypes": true,
|
|
24
|
+
|
|
25
|
+
// Style Options
|
|
26
|
+
// "noImplicitReturns": true,
|
|
27
|
+
// "noImplicitOverride": true,
|
|
28
|
+
// "noUnusedLocals": true,
|
|
29
|
+
// "noUnusedParameters": true,
|
|
30
|
+
// "noFallthroughCasesInSwitch": true,
|
|
31
|
+
// "noPropertyAccessFromIndexSignature": true,
|
|
32
|
+
|
|
33
|
+
// Recommended Options
|
|
34
|
+
"strict": true,
|
|
35
|
+
"jsx": "react-jsx",
|
|
36
|
+
"verbatimModuleSyntax": true,
|
|
37
|
+
"isolatedModules": true,
|
|
38
|
+
"noUncheckedSideEffectImports": true,
|
|
39
|
+
"moduleDetection": "force",
|
|
40
|
+
"skipLibCheck": true,
|
|
41
|
+
}
|
|
42
|
+
}
|