tering-serieuze-cli 1.8.0 → 1.9.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/.oxfmtrc.json +6 -0
- package/.oxlintrc.json +178 -0
- package/build.mjs +5 -5
- package/dist/index.mjs +11 -24
- package/package.json +9 -3
- package/src/commands.ts +10 -0
- package/src/completion.ts +8 -8
- package/src/index.ts +68 -76
- package/tsconfig.json +1 -1
- package/.prettierrc +0 -6
package/.oxfmtrc.json
ADDED
package/.oxlintrc.json
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "./node_modules/oxlint/configuration_schema.json",
|
|
3
|
+
|
|
4
|
+
"plugins": ["typescript", "unicorn", "oxc", "import", "vitest", "node", "promise"],
|
|
5
|
+
|
|
6
|
+
"categories": {
|
|
7
|
+
"correctness": "error",
|
|
8
|
+
"suspicious": "warn",
|
|
9
|
+
"perf": "warn"
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
"options": {
|
|
13
|
+
"typeAware": true
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
"env": {
|
|
17
|
+
"node": true,
|
|
18
|
+
"es2024": true
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
"rules": {
|
|
22
|
+
"oxc/approx-constant": "error",
|
|
23
|
+
"oxc/bad-array-method-on-arguments": "error",
|
|
24
|
+
"oxc/bad-bitwise-operator": "error",
|
|
25
|
+
"oxc/bad-char-at-comparison": "error",
|
|
26
|
+
"oxc/bad-comparison-sequence": "error",
|
|
27
|
+
"oxc/bad-min-max-func": "error",
|
|
28
|
+
"oxc/bad-object-literal-comparison": "error",
|
|
29
|
+
"oxc/bad-replace-all-arg": "error",
|
|
30
|
+
"oxc/branches-sharing-code": "warn",
|
|
31
|
+
"oxc/const-comparisons": "error",
|
|
32
|
+
"oxc/double-comparisons": "error",
|
|
33
|
+
"oxc/erasing-op": "error",
|
|
34
|
+
"oxc/misrefactored-assign-op": "error",
|
|
35
|
+
"oxc/missing-throw": "error",
|
|
36
|
+
"oxc/no-accumulating-spread": "error",
|
|
37
|
+
"oxc/no-barrel-file": "error",
|
|
38
|
+
"oxc/no-const-enum": "error",
|
|
39
|
+
"oxc/no-map-spread": "error",
|
|
40
|
+
"oxc/number-arg-out-of-range": "error",
|
|
41
|
+
"oxc/only-used-in-recursion": "warn",
|
|
42
|
+
"oxc/uninvoked-array-callback": "error",
|
|
43
|
+
|
|
44
|
+
"typescript/await-thenable": "off",
|
|
45
|
+
"typescript/consistent-type-imports": "off",
|
|
46
|
+
"typescript/no-extraneous-class": "off",
|
|
47
|
+
"typescript/no-floating-promises": ["error", { "ignoreVoid": true }],
|
|
48
|
+
"typescript/no-misused-promises": "warn",
|
|
49
|
+
"typescript/no-unnecessary-condition": "warn",
|
|
50
|
+
"typescript/switch-exhaustiveness-check": "error",
|
|
51
|
+
"typescript/prefer-optional-chain": "error",
|
|
52
|
+
"typescript/prefer-nullish-coalescing": "warn",
|
|
53
|
+
"typescript/no-deprecated": "warn",
|
|
54
|
+
"typescript/no-unsafe-enum-comparison": "error",
|
|
55
|
+
"typescript/prefer-includes": "error",
|
|
56
|
+
"typescript/prefer-string-starts-ends-with": "error",
|
|
57
|
+
"typescript/prefer-find": "error",
|
|
58
|
+
"typescript/no-base-to-string": "warn",
|
|
59
|
+
"typescript/return-await": "error",
|
|
60
|
+
"typescript/no-confusing-void-expression": "warn",
|
|
61
|
+
"typescript/no-misused-spread": "error",
|
|
62
|
+
"typescript/restrict-plus-operands": "warn",
|
|
63
|
+
"typescript/restrict-template-expressions": "warn",
|
|
64
|
+
"typescript/no-unnecessary-type-assertion": "error",
|
|
65
|
+
"typescript/no-unnecessary-type-arguments": "off",
|
|
66
|
+
"typescript/no-unnecessary-template-expression": "error",
|
|
67
|
+
"typescript/no-non-null-assertion": "error",
|
|
68
|
+
"typescript/no-inferrable-types": "error",
|
|
69
|
+
"typescript/no-namespace": "error",
|
|
70
|
+
"typescript/no-dynamic-delete": "error",
|
|
71
|
+
"typescript/array-type": ["error", { "default": "array" }],
|
|
72
|
+
"typescript/prefer-for-of": "error",
|
|
73
|
+
"typescript/prefer-literal-enum-member": "off",
|
|
74
|
+
"typescript/prefer-readonly": "error",
|
|
75
|
+
"typescript/prefer-function-type": "error",
|
|
76
|
+
"typescript/prefer-promise-reject-errors": "warn",
|
|
77
|
+
"typescript/only-throw-error": "error",
|
|
78
|
+
"typescript/require-await": "error",
|
|
79
|
+
"typescript/strict-boolean-expressions": "off",
|
|
80
|
+
"typescript/consistent-return": "warn",
|
|
81
|
+
|
|
82
|
+
"eslint/complexity": ["error", { "max": 15 }],
|
|
83
|
+
"eslint/no-await-in-loop": "error",
|
|
84
|
+
"eslint/no-param-reassign": "error",
|
|
85
|
+
"eslint/no-nested-ternary": "error",
|
|
86
|
+
"eslint/no-else-return": "error",
|
|
87
|
+
"eslint/yoda": "error",
|
|
88
|
+
"eslint/curly": "error",
|
|
89
|
+
"eslint/prefer-const": "error",
|
|
90
|
+
"eslint/default-param-last": "error",
|
|
91
|
+
"eslint/default-case": "error",
|
|
92
|
+
"eslint/prefer-object-spread": "error",
|
|
93
|
+
"eslint/prefer-destructuring": "warn",
|
|
94
|
+
"eslint/operator-assignment": "error",
|
|
95
|
+
"eslint/object-shorthand": "warn",
|
|
96
|
+
"eslint/no-var": "error",
|
|
97
|
+
"eslint/no-empty": "error",
|
|
98
|
+
"eslint/no-empty-function": "error",
|
|
99
|
+
"eslint/no-warning-comments": "warn",
|
|
100
|
+
"eslint/radix": "error",
|
|
101
|
+
"eslint/no-array-constructor": "error",
|
|
102
|
+
"eslint/no-self-compare": "error",
|
|
103
|
+
"eslint/no-new-func": "error",
|
|
104
|
+
"eslint/no-script-url": "error",
|
|
105
|
+
"eslint/no-useless-concat": "error",
|
|
106
|
+
|
|
107
|
+
"import/no-cycle": "warn",
|
|
108
|
+
"import/no-self-import": "error",
|
|
109
|
+
"import/no-duplicates": "error",
|
|
110
|
+
"import/first": "error",
|
|
111
|
+
"import/no-namespace": "error",
|
|
112
|
+
"import/no-commonjs": "error",
|
|
113
|
+
"import/no-mutable-exports": "error",
|
|
114
|
+
|
|
115
|
+
"unicorn/prefer-node-protocol": "error",
|
|
116
|
+
"unicorn/prefer-number-properties": "error",
|
|
117
|
+
"unicorn/numeric-separators-style": "error",
|
|
118
|
+
"unicorn/prefer-string-slice": "error",
|
|
119
|
+
"unicorn/throw-new-error": "error",
|
|
120
|
+
"unicorn/error-message": "error",
|
|
121
|
+
"unicorn/new-for-builtins": "error",
|
|
122
|
+
"unicorn/no-lonely-if": "error",
|
|
123
|
+
"unicorn/explicit-length-check": "error",
|
|
124
|
+
"unicorn/prefer-string-trim-start-end": "error",
|
|
125
|
+
"unicorn/require-number-to-fixed-digits-argument": "error",
|
|
126
|
+
"unicorn/no-await-in-promise-methods": "error",
|
|
127
|
+
"unicorn/no-single-promise-in-promise-methods": "error",
|
|
128
|
+
"unicorn/no-useless-spread": "error",
|
|
129
|
+
"unicorn/prefer-structured-clone": "warn",
|
|
130
|
+
"unicorn/consistent-function-scoping": "warn",
|
|
131
|
+
"unicorn/no-thenable": "error",
|
|
132
|
+
"unicorn/prefer-at": "warn",
|
|
133
|
+
"unicorn/no-negation-in-equality-check": "error",
|
|
134
|
+
"unicorn/no-useless-fallback-in-spread": "error",
|
|
135
|
+
|
|
136
|
+
"promise/catch-or-return": "warn",
|
|
137
|
+
"promise/no-return-in-finally": "error",
|
|
138
|
+
"promise/no-multiple-resolved": "warn",
|
|
139
|
+
"promise/valid-params": "error",
|
|
140
|
+
"promise/no-nesting": "warn",
|
|
141
|
+
"promise/prefer-await-to-callbacks": "warn",
|
|
142
|
+
|
|
143
|
+
"node/no-path-concat": "error",
|
|
144
|
+
"node/no-new-require": "error",
|
|
145
|
+
|
|
146
|
+
"vitest/max-nested-describe": ["error", { "max": 5 }],
|
|
147
|
+
"vitest/no-focused-tests": "error",
|
|
148
|
+
"vitest/no-disabled-tests": "error",
|
|
149
|
+
"vitest/no-duplicate-hooks": "error",
|
|
150
|
+
"jest/no-export": "error",
|
|
151
|
+
"vitest/no-standalone-expect": "error",
|
|
152
|
+
"vitest/no-conditional-expect": "error",
|
|
153
|
+
"vitest/require-to-throw-message": "error",
|
|
154
|
+
"vitest/valid-expect": "error",
|
|
155
|
+
"vitest/valid-title": ["error", { "ignoreTypeOfDescribeName": true }],
|
|
156
|
+
"vitest/expect-expect": ["error", { "assertFunctionNames": ["expect", "vitest.waitUntil", "vi.waitUntil"] }],
|
|
157
|
+
"vitest/prefer-hooks-on-top": "error",
|
|
158
|
+
"vitest/no-conditional-tests": "error",
|
|
159
|
+
"vitest/prefer-to-be-falsy": "warn",
|
|
160
|
+
"vitest/prefer-to-be-truthy": "warn",
|
|
161
|
+
"vitest/prefer-to-be-object": "warn",
|
|
162
|
+
"vitest/prefer-expect-type-of": "warn"
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
"overrides": [
|
|
166
|
+
{
|
|
167
|
+
"files": ["**/*.spec.ts", "test/**/*.ts"],
|
|
168
|
+
"rules": {
|
|
169
|
+
"typescript/no-non-null-assertion": "off",
|
|
170
|
+
"eslint/no-empty-function": "off",
|
|
171
|
+
"typescript/no-floating-promises": "off",
|
|
172
|
+
"vitest/require-mock-type-parameters": "off"
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
],
|
|
176
|
+
|
|
177
|
+
"ignorePatterns": ["dist", "node_modules", "coverage", "output"]
|
|
178
|
+
}
|
package/build.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import esbuild from "esbuild";
|
|
2
|
+
|
|
3
|
+
const makeAllPackagesExternalPlugin = {
|
|
2
4
|
name: "make-all-packages-external",
|
|
3
5
|
setup(build) {
|
|
4
|
-
|
|
6
|
+
const filter = /^[^./]|^\.[^./]|^\.\.[^/]/; // Must not start with "/" or "./" or "../"
|
|
5
7
|
build.onResolve({ filter }, (args) => ({ path: args.path, external: true }));
|
|
6
8
|
},
|
|
7
9
|
};
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
esbuild.build({
|
|
11
|
+
void esbuild.build({
|
|
12
12
|
entryPoints: ["./src/index.ts"],
|
|
13
13
|
bundle: true,
|
|
14
14
|
sourcemap: true,
|
package/dist/index.mjs
CHANGED
|
@@ -30,24 +30,13 @@ async function initCompletion(api2) {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
// package.json
|
|
33
|
-
var version = "1.
|
|
33
|
+
var version = "1.8.1";
|
|
34
34
|
|
|
35
35
|
// src/index.ts
|
|
36
|
-
var Commands = /* @__PURE__ */ ((Commands2) => {
|
|
37
|
-
Commands2["autocomplete"] = "autocomplete";
|
|
38
|
-
Commands2["clearcache"] = "clearcache";
|
|
39
|
-
Commands2["login"] = "login";
|
|
40
|
-
Commands2["play"] = "play";
|
|
41
|
-
Commands2["recent"] = "recent";
|
|
42
|
-
Commands2["jingles"] = "jingles";
|
|
43
|
-
Commands2["playShort"] = "p";
|
|
44
|
-
Commands2["version"] = "version";
|
|
45
|
-
return Commands2;
|
|
46
|
-
})(Commands || {});
|
|
47
36
|
var playWhichJingleString = "Which jingle do you want to play?";
|
|
48
37
|
var api = new TssApi(
|
|
49
38
|
{
|
|
50
|
-
API_URL: process.env.API_URL ?? "https://tss.maxserv.dev
|
|
39
|
+
API_URL: process.env.API_URL ?? "https://tss.maxserv.dev"
|
|
51
40
|
},
|
|
52
41
|
{
|
|
53
42
|
jingle: new FilesystemCache("jingle"),
|
|
@@ -60,7 +49,7 @@ if (process.argv.length <= 2 || process.argv[2] === "help") {
|
|
|
60
49
|
console.log(figlet.textSync("TSS CLI"));
|
|
61
50
|
}
|
|
62
51
|
program.name("tss").description("D\xE9 TSS CLI. Dit ding heeft alles.");
|
|
63
|
-
program.command("autocomplete" /* autocomplete */).description("Install or uninstall TSS CLI autocomplete").option("-i, --install", "Install TSS CLI autocomplete").option("-u, --uninstall", "Uninstall TSS CLI autocomplete").action(
|
|
52
|
+
program.command("autocomplete" /* autocomplete */).description("Install or uninstall TSS CLI autocomplete").option("-i, --install", "Install TSS CLI autocomplete").option("-u, --uninstall", "Uninstall TSS CLI autocomplete").action((options) => {
|
|
64
53
|
if (options.install) {
|
|
65
54
|
console.log("TSS CLI autocomplete installed!");
|
|
66
55
|
completion.setupShellInitFile();
|
|
@@ -80,7 +69,7 @@ program.command("login" /* login */).description("Authenticate yourself so you c
|
|
|
80
69
|
]);
|
|
81
70
|
try {
|
|
82
71
|
await api.auth.setToken(token);
|
|
83
|
-
} catch
|
|
72
|
+
} catch {
|
|
84
73
|
console.error("Can't set the token");
|
|
85
74
|
return;
|
|
86
75
|
}
|
|
@@ -98,14 +87,14 @@ program.command("login" /* login */).description("Authenticate yourself so you c
|
|
|
98
87
|
});
|
|
99
88
|
program.command("clearcache" /* clearcache */).description("Clear the cache").argument("[type]", "The type of cache to clear (jingle, auth, all)").action(async (type) => {
|
|
100
89
|
if (type === "jingle") {
|
|
101
|
-
|
|
90
|
+
api.jingle.getCache().clear();
|
|
102
91
|
console.log("Cleared jingle cache");
|
|
103
92
|
} else if (type === "auth") {
|
|
104
93
|
await api.auth.removeToken();
|
|
105
94
|
console.log("Cleared auth cache");
|
|
106
95
|
} else if (type === "all" || !type) {
|
|
107
96
|
await api.auth.removeToken();
|
|
108
|
-
|
|
97
|
+
api.jingle.getCache().clear();
|
|
109
98
|
console.log("Cleared all caches");
|
|
110
99
|
} else {
|
|
111
100
|
console.error("Invalid cache type");
|
|
@@ -148,19 +137,20 @@ program.command("recent" /* recent */).description("Show recently added jingles,
|
|
|
148
137
|
});
|
|
149
138
|
program.command("p" /* playShort */).description("Play a jingle by typing (some) parts of the name").argument("<query...>", "The query to search for").action(async (query) => {
|
|
150
139
|
const items = await api.jingle.find(query.join(" "));
|
|
151
|
-
let jingle;
|
|
152
140
|
if (items.length === 0) {
|
|
153
141
|
console.log("No matches found");
|
|
154
142
|
return;
|
|
155
|
-
}
|
|
156
|
-
|
|
143
|
+
}
|
|
144
|
+
let jingle;
|
|
145
|
+
if (items.length === 1) {
|
|
146
|
+
[jingle] = items;
|
|
157
147
|
} else {
|
|
158
148
|
const answers = await inquirer.prompt([
|
|
159
149
|
{
|
|
160
150
|
type: "list",
|
|
161
151
|
name: "jingle",
|
|
162
152
|
message: playWhichJingleString,
|
|
163
|
-
choices: items.map((
|
|
153
|
+
choices: items.map((item) => item.folder + "/" + item.file)
|
|
164
154
|
}
|
|
165
155
|
]);
|
|
166
156
|
const [folder, file] = answers.jingle.split("/");
|
|
@@ -190,6 +180,3 @@ program.command("users").action(async () => {
|
|
|
190
180
|
}
|
|
191
181
|
});
|
|
192
182
|
program.parse();
|
|
193
|
-
export {
|
|
194
|
-
Commands
|
|
195
|
-
};
|
package/package.json
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tering-serieuze-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "Teringserieuze CLI",
|
|
5
5
|
"author": "Frank",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"dev": "esbuild src/index.ts --bundle --platform=node --outfile=dist/index.mjs --packages=external --format=esm --watch",
|
|
10
|
-
"build": "esbuild src/index.ts --bundle --platform=node --outfile=dist/index.mjs --packages=external --format=esm"
|
|
10
|
+
"build": "esbuild src/index.ts --bundle --platform=node --outfile=dist/index.mjs --packages=external --format=esm",
|
|
11
|
+
"format": "oxfmt src",
|
|
12
|
+
"format:check": "oxfmt --check src",
|
|
13
|
+
"lint": "oxlint",
|
|
14
|
+
"lint:fix": "oxlint --fix"
|
|
11
15
|
},
|
|
12
16
|
"bin": {
|
|
13
17
|
"tss": "dist/index.mjs"
|
|
@@ -36,6 +40,8 @@
|
|
|
36
40
|
"@types/node": "^18.15.3",
|
|
37
41
|
"@types/omelette": "^0.4.2",
|
|
38
42
|
"esbuild": "^0.17.12",
|
|
39
|
-
"
|
|
43
|
+
"oxfmt": "^0.44.0",
|
|
44
|
+
"oxlint": "^1.60.0",
|
|
45
|
+
"oxlint-tsgolint": "^0.20.0"
|
|
40
46
|
}
|
|
41
47
|
}
|
package/src/commands.ts
ADDED
package/src/completion.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import omelette from
|
|
2
|
-
import { Commands } from
|
|
3
|
-
import { TssApi } from
|
|
4
|
-
import { JingleFolder } from
|
|
1
|
+
import omelette from "omelette";
|
|
2
|
+
import { Commands } from "./commands";
|
|
3
|
+
import { TssApi } from "tering-serieuze-sdk";
|
|
4
|
+
import { JingleFolder } from "tering-serieuze-types";
|
|
5
5
|
|
|
6
6
|
export async function initCompletion(api: TssApi) {
|
|
7
7
|
const playCompletion: { [key: string]: string[] } = {};
|
|
8
|
-
const jingleFolders = (await api.jingle.getCache().get<JingleFolder[]>(
|
|
8
|
+
const jingleFolders = (await api.jingle.getCache().get<JingleFolder[]>("getGrouped")) ?? [];
|
|
9
9
|
jingleFolders.forEach((jingleFolder) => {
|
|
10
10
|
playCompletion[jingleFolder.folder] = jingleFolder.jingles.map((jingle) => jingle.file);
|
|
11
11
|
});
|
|
12
12
|
|
|
13
13
|
const autocompletionTree: { [key in Commands]: any } = {
|
|
14
|
-
[Commands.autocomplete]: [
|
|
15
|
-
[Commands.clearcache]: [
|
|
14
|
+
[Commands.autocomplete]: ["--install", "--uninstall"],
|
|
15
|
+
[Commands.clearcache]: ["auth", "jingle", "all"],
|
|
16
16
|
[Commands.login]: [],
|
|
17
17
|
[Commands.play]: playCompletion,
|
|
18
18
|
[Commands.recent]: [],
|
|
@@ -21,7 +21,7 @@ export async function initCompletion(api: TssApi) {
|
|
|
21
21
|
[Commands.version]: [],
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
const completion = omelette(
|
|
24
|
+
const completion = omelette("tss").tree(autocompletionTree);
|
|
25
25
|
completion.init();
|
|
26
26
|
|
|
27
27
|
return completion;
|
package/src/index.ts
CHANGED
|
@@ -1,89 +1,79 @@
|
|
|
1
1
|
#! /usr/bin/env node --no-warnings
|
|
2
2
|
|
|
3
|
-
import { Command } from
|
|
4
|
-
import figlet from
|
|
5
|
-
import inquirer from
|
|
6
|
-
import { TssApi, FilesystemCache } from
|
|
7
|
-
import { initCompletion } from
|
|
3
|
+
import { Command } from "commander";
|
|
4
|
+
import figlet from "figlet";
|
|
5
|
+
import inquirer from "inquirer";
|
|
6
|
+
import { TssApi, FilesystemCache } from "tering-serieuze-sdk";
|
|
7
|
+
import { initCompletion } from "./completion";
|
|
8
8
|
// @ts-ignore
|
|
9
|
-
import { version } from
|
|
10
|
-
|
|
11
|
-
export enum Commands {
|
|
12
|
-
autocomplete = 'autocomplete',
|
|
13
|
-
clearcache = 'clearcache',
|
|
14
|
-
login = 'login',
|
|
15
|
-
play = 'play',
|
|
16
|
-
recent = 'recent',
|
|
17
|
-
jingles = 'jingles',
|
|
18
|
-
playShort = 'p',
|
|
19
|
-
version = 'version',
|
|
20
|
-
}
|
|
9
|
+
import { version as packageVersion } from "../package.json";
|
|
10
|
+
import { Commands } from "./commands";
|
|
21
11
|
|
|
22
|
-
const playWhichJingleString =
|
|
12
|
+
const playWhichJingleString = "Which jingle do you want to play?";
|
|
23
13
|
|
|
24
14
|
const api = new TssApi(
|
|
25
15
|
{
|
|
26
|
-
API_URL: process.env.API_URL ??
|
|
16
|
+
API_URL: process.env.API_URL ?? "https://tss.maxserv.dev",
|
|
27
17
|
},
|
|
28
18
|
{
|
|
29
|
-
jingle: new FilesystemCache(
|
|
30
|
-
auth: new FilesystemCache(
|
|
19
|
+
jingle: new FilesystemCache("jingle"),
|
|
20
|
+
auth: new FilesystemCache("TSS-TOKEN"),
|
|
31
21
|
},
|
|
32
22
|
);
|
|
33
23
|
|
|
34
24
|
const program = new Command();
|
|
35
25
|
const completion = await initCompletion(api);
|
|
36
26
|
|
|
37
|
-
if (process.argv.length <= 2 || process.argv[2] ===
|
|
38
|
-
console.log(figlet.textSync(
|
|
27
|
+
if (process.argv.length <= 2 || process.argv[2] === "help") {
|
|
28
|
+
console.log(figlet.textSync("TSS CLI"));
|
|
39
29
|
}
|
|
40
30
|
|
|
41
|
-
program.name(
|
|
31
|
+
program.name("tss").description("Dé TSS CLI. Dit ding heeft alles.");
|
|
42
32
|
|
|
43
33
|
program
|
|
44
34
|
.command(Commands.autocomplete)
|
|
45
|
-
.description(
|
|
46
|
-
.option(
|
|
47
|
-
.option(
|
|
48
|
-
.action(
|
|
35
|
+
.description("Install or uninstall TSS CLI autocomplete")
|
|
36
|
+
.option("-i, --install", "Install TSS CLI autocomplete")
|
|
37
|
+
.option("-u, --uninstall", "Uninstall TSS CLI autocomplete")
|
|
38
|
+
.action((options) => {
|
|
49
39
|
if (options.install) {
|
|
50
|
-
console.log(
|
|
40
|
+
console.log("TSS CLI autocomplete installed!");
|
|
51
41
|
completion.setupShellInitFile();
|
|
52
42
|
}
|
|
53
43
|
|
|
54
44
|
if (options.uninstall) {
|
|
55
|
-
console.log(
|
|
45
|
+
console.log("TSS autocomplete uninstalled.");
|
|
56
46
|
completion.cleanupShellInitFile();
|
|
57
47
|
}
|
|
58
48
|
});
|
|
59
49
|
|
|
60
50
|
program
|
|
61
51
|
.command(Commands.login)
|
|
62
|
-
.description(
|
|
52
|
+
.description("Authenticate yourself so you can communicate with the TSS API")
|
|
63
53
|
.action(async () => {
|
|
64
54
|
const { token } = await inquirer.prompt([
|
|
65
55
|
{
|
|
66
|
-
type:
|
|
67
|
-
name:
|
|
68
|
-
message:
|
|
56
|
+
type: "password",
|
|
57
|
+
name: "token",
|
|
58
|
+
message: "What is your token?",
|
|
69
59
|
},
|
|
70
60
|
]);
|
|
71
61
|
|
|
72
62
|
try {
|
|
73
63
|
await api.auth.setToken(token);
|
|
74
|
-
} catch
|
|
64
|
+
} catch {
|
|
75
65
|
console.error("Can't set the token");
|
|
76
66
|
return;
|
|
77
67
|
}
|
|
78
68
|
|
|
79
69
|
try {
|
|
80
70
|
const user = await api.user.get();
|
|
81
|
-
console.log(
|
|
71
|
+
console.log("Logged in as " + user.email);
|
|
82
72
|
} catch (e: any) {
|
|
83
73
|
if (e.status >= 500) {
|
|
84
|
-
console.error(
|
|
74
|
+
console.error("Uit. Dit kan niet gebeuren want TSS geeft een status >= 500 terug");
|
|
85
75
|
} else {
|
|
86
|
-
console.error(
|
|
76
|
+
console.error("Invalid token!");
|
|
87
77
|
}
|
|
88
78
|
|
|
89
79
|
await api.auth.removeToken();
|
|
@@ -92,43 +82,43 @@ program
|
|
|
92
82
|
|
|
93
83
|
program
|
|
94
84
|
.command(Commands.clearcache)
|
|
95
|
-
.description(
|
|
96
|
-
.argument(
|
|
85
|
+
.description("Clear the cache")
|
|
86
|
+
.argument("[type]", "The type of cache to clear (jingle, auth, all)")
|
|
97
87
|
.action(async (type) => {
|
|
98
|
-
if (type ===
|
|
99
|
-
|
|
100
|
-
console.log(
|
|
101
|
-
} else if (type ===
|
|
88
|
+
if (type === "jingle") {
|
|
89
|
+
api.jingle.getCache().clear();
|
|
90
|
+
console.log("Cleared jingle cache");
|
|
91
|
+
} else if (type === "auth") {
|
|
102
92
|
await api.auth.removeToken();
|
|
103
|
-
console.log(
|
|
104
|
-
} else if (type ===
|
|
93
|
+
console.log("Cleared auth cache");
|
|
94
|
+
} else if (type === "all" || !type) {
|
|
105
95
|
await api.auth.removeToken();
|
|
106
|
-
|
|
107
|
-
console.log(
|
|
96
|
+
api.jingle.getCache().clear();
|
|
97
|
+
console.log("Cleared all caches");
|
|
108
98
|
} else {
|
|
109
|
-
console.error(
|
|
99
|
+
console.error("Invalid cache type");
|
|
110
100
|
}
|
|
111
101
|
});
|
|
112
102
|
|
|
113
103
|
program
|
|
114
104
|
.command(Commands.jingles)
|
|
115
|
-
.description(
|
|
105
|
+
.description("Show all jingles")
|
|
116
106
|
.action(async () => {
|
|
117
107
|
try {
|
|
118
108
|
const jingles = await api.jingle.getAll();
|
|
119
109
|
jingles.forEach((jingle) => {
|
|
120
|
-
console.log(jingle.folder +
|
|
110
|
+
console.log(jingle.folder + "/" + jingle.file);
|
|
121
111
|
});
|
|
122
112
|
} catch (e: any) {
|
|
123
|
-
console.error(e.status +
|
|
113
|
+
console.error(e.status + ": " + e.message);
|
|
124
114
|
}
|
|
125
115
|
});
|
|
126
116
|
|
|
127
117
|
program
|
|
128
118
|
.command(Commands.play)
|
|
129
|
-
.description(
|
|
130
|
-
.argument(
|
|
131
|
-
.argument(
|
|
119
|
+
.description("Play a jingle")
|
|
120
|
+
.argument("<folder>", "The folder of the jingle")
|
|
121
|
+
.argument("<file>", "The jingle to play")
|
|
132
122
|
.action(async (folder, file) => {
|
|
133
123
|
try {
|
|
134
124
|
await api.jingle.play({ folder, file });
|
|
@@ -139,52 +129,54 @@ program
|
|
|
139
129
|
|
|
140
130
|
program
|
|
141
131
|
.command(Commands.recent)
|
|
142
|
-
.description(
|
|
132
|
+
.description("Show recently added jingles, select a jingle to play")
|
|
143
133
|
.action(async () => {
|
|
144
134
|
try {
|
|
145
135
|
const jingles = await api.jingle.getRecentlyAdded();
|
|
146
136
|
|
|
147
137
|
const answers = await inquirer.prompt([
|
|
148
138
|
{
|
|
149
|
-
type:
|
|
150
|
-
name:
|
|
139
|
+
type: "list",
|
|
140
|
+
name: "jingle",
|
|
151
141
|
message: playWhichJingleString,
|
|
152
|
-
choices: jingles.slice(0, 30).map((jingle) => jingle.folder +
|
|
142
|
+
choices: jingles.slice(0, 30).map((jingle) => jingle.folder + "/" + jingle.file),
|
|
153
143
|
},
|
|
154
144
|
]);
|
|
155
145
|
|
|
156
|
-
const [folder, file]: [folder: string, file: string] = answers.jingle.split(
|
|
146
|
+
const [folder, file]: [folder: string, file: string] = answers.jingle.split("/");
|
|
157
147
|
const jingle = { folder, file };
|
|
158
148
|
await api.jingle.play(jingle);
|
|
159
149
|
} catch (e: any) {
|
|
160
|
-
console.error(e.status +
|
|
150
|
+
console.error(e.status + ": " + e.message);
|
|
161
151
|
}
|
|
162
152
|
});
|
|
163
153
|
|
|
164
154
|
program
|
|
165
155
|
.command(Commands.playShort)
|
|
166
|
-
.description(
|
|
167
|
-
.argument(
|
|
156
|
+
.description("Play a jingle by typing (some) parts of the name")
|
|
157
|
+
.argument("<query...>", "The query to search for")
|
|
168
158
|
.action(async (query: string[]) => {
|
|
169
|
-
const items = await api.jingle.find(query.join(
|
|
159
|
+
const items = await api.jingle.find(query.join(" "));
|
|
170
160
|
|
|
171
|
-
let jingle;
|
|
172
161
|
if (items.length === 0) {
|
|
173
|
-
console.log(
|
|
162
|
+
console.log("No matches found");
|
|
174
163
|
return;
|
|
175
|
-
}
|
|
176
|
-
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
let jingle;
|
|
167
|
+
if (items.length === 1) {
|
|
168
|
+
[jingle] = items;
|
|
177
169
|
} else {
|
|
178
170
|
const answers = await inquirer.prompt([
|
|
179
171
|
{
|
|
180
|
-
type:
|
|
181
|
-
name:
|
|
172
|
+
type: "list",
|
|
173
|
+
name: "jingle",
|
|
182
174
|
message: playWhichJingleString,
|
|
183
|
-
choices: items.map((
|
|
175
|
+
choices: items.map((item) => item.folder + "/" + item.file),
|
|
184
176
|
},
|
|
185
177
|
]);
|
|
186
178
|
|
|
187
|
-
const [folder, file]: [folder: string, file: string] = answers.jingle.split(
|
|
179
|
+
const [folder, file]: [folder: string, file: string] = answers.jingle.split("/");
|
|
188
180
|
jingle = { folder, file };
|
|
189
181
|
}
|
|
190
182
|
|
|
@@ -197,12 +189,12 @@ program
|
|
|
197
189
|
|
|
198
190
|
program
|
|
199
191
|
.command(Commands.version)
|
|
200
|
-
.description(
|
|
192
|
+
.description("Show the TSS-CLI version")
|
|
201
193
|
.action(() => {
|
|
202
|
-
console.log(
|
|
194
|
+
console.log(packageVersion);
|
|
203
195
|
});
|
|
204
196
|
|
|
205
|
-
program.command(
|
|
197
|
+
program.command("users").action(async () => {
|
|
206
198
|
try {
|
|
207
199
|
const users = await api.user.getAll();
|
|
208
200
|
const items = users.map((user) => {
|
|
@@ -213,7 +205,7 @@ program.command('users').action(async () => {
|
|
|
213
205
|
});
|
|
214
206
|
console.log(items);
|
|
215
207
|
} catch (e: any) {
|
|
216
|
-
console.error(e.status +
|
|
208
|
+
console.error(e.status + ": " + e.message);
|
|
217
209
|
}
|
|
218
210
|
});
|
|
219
211
|
|
package/tsconfig.json
CHANGED