tering-serieuze-cli 1.5.2 → 1.7.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/.prettierrc +6 -2
- package/dist/index.mjs +14 -21
- package/package.json +3 -3
- package/src/completion.ts +8 -8
- package/src/index.ts +77 -87
package/.prettierrc
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -30,7 +30,7 @@ async function initCompletion(api2) {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
// package.json
|
|
33
|
-
var version = "1.
|
|
33
|
+
var version = "1.6.0";
|
|
34
34
|
|
|
35
35
|
// src/index.ts
|
|
36
36
|
var Commands = /* @__PURE__ */ ((Commands2) => {
|
|
@@ -130,8 +130,7 @@ program.command("play" /* play */).description("Play a jingle").argument("<folde
|
|
|
130
130
|
});
|
|
131
131
|
program.command("recent" /* recent */).description("Show recently added jingles, select a jingle to play").action(async () => {
|
|
132
132
|
try {
|
|
133
|
-
const jingles = await api.jingle.
|
|
134
|
-
jingles.sort((a, b) => b.mtime - a.mtime);
|
|
133
|
+
const jingles = await api.jingle.getRecentlyAdded();
|
|
135
134
|
const answers = await inquirer.prompt([
|
|
136
135
|
{
|
|
137
136
|
type: "list",
|
|
@@ -148,32 +147,20 @@ program.command("recent" /* recent */).description("Show recently added jingles,
|
|
|
148
147
|
}
|
|
149
148
|
});
|
|
150
149
|
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) => {
|
|
151
|
-
|
|
152
|
-
try {
|
|
153
|
-
jingles = await api.jingle.getAll();
|
|
154
|
-
} catch (e) {
|
|
155
|
-
console.error(e.status + ": " + e.message);
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
const matches = jingles.filter((jingle2) => query.every((q) => (jingle2.folder + "/" + jingle2.file).includes(q)));
|
|
150
|
+
const items = await api.jingle.find(query.join(" "));
|
|
159
151
|
let jingle;
|
|
160
|
-
if (
|
|
152
|
+
if (items.length === 0) {
|
|
161
153
|
console.log("No matches found");
|
|
162
154
|
return;
|
|
163
|
-
} else if (
|
|
164
|
-
jingle =
|
|
155
|
+
} else if (items.length === 1) {
|
|
156
|
+
jingle = items[0];
|
|
165
157
|
} else {
|
|
166
|
-
const sortedMatches = matches.sort((a, b) => {
|
|
167
|
-
const aScore = a.keywords.filter((k) => query.includes(k)).length;
|
|
168
|
-
const bScore = b.keywords.filter((k) => query.includes(k)).length;
|
|
169
|
-
return bScore - aScore;
|
|
170
|
-
});
|
|
171
158
|
const answers = await inquirer.prompt([
|
|
172
159
|
{
|
|
173
160
|
type: "list",
|
|
174
161
|
name: "jingle",
|
|
175
162
|
message: playWhichJingleString,
|
|
176
|
-
choices:
|
|
163
|
+
choices: items.map((jingle2) => jingle2.folder + "/" + jingle2.file)
|
|
177
164
|
}
|
|
178
165
|
]);
|
|
179
166
|
const [folder, file] = answers.jingle.split("/");
|
|
@@ -191,7 +178,13 @@ program.command("version" /* version */).description("Show the TSS-CLI version")
|
|
|
191
178
|
program.command("users").action(async () => {
|
|
192
179
|
try {
|
|
193
180
|
const users = await api.user.getAll();
|
|
194
|
-
|
|
181
|
+
const items = users.map((user) => {
|
|
182
|
+
return {
|
|
183
|
+
name: user.email,
|
|
184
|
+
value: user.id
|
|
185
|
+
};
|
|
186
|
+
});
|
|
187
|
+
console.log(items);
|
|
195
188
|
} catch (e) {
|
|
196
189
|
console.error(e.status + ": " + e.message);
|
|
197
190
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tering-serieuze-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "Teringserieuze CLI",
|
|
5
5
|
"author": "Frank",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"figlet": "^1.5.2",
|
|
28
28
|
"inquirer": "^9.1.4",
|
|
29
29
|
"omelette": "^0.4.17",
|
|
30
|
-
"tering-serieuze-sdk": "^3.
|
|
31
|
-
"tering-serieuze-types": "^1.
|
|
30
|
+
"tering-serieuze-sdk": "^3.11.0",
|
|
31
|
+
"tering-serieuze-types": "^1.27.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/figlet": "^1.5.5",
|
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 './index';
|
|
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,71 +1,71 @@
|
|
|
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
|
|
9
|
+
import { version } from '../package.json';
|
|
10
10
|
|
|
11
11
|
export enum Commands {
|
|
12
|
-
autocomplete =
|
|
13
|
-
clearcache =
|
|
14
|
-
login =
|
|
15
|
-
play =
|
|
16
|
-
recent =
|
|
17
|
-
jingles =
|
|
18
|
-
playShort =
|
|
19
|
-
version =
|
|
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
20
|
}
|
|
21
21
|
|
|
22
|
-
const playWhichJingleString =
|
|
22
|
+
const playWhichJingleString = 'Which jingle do you want to play?';
|
|
23
23
|
|
|
24
24
|
const api = new TssApi(
|
|
25
25
|
{
|
|
26
|
-
API_URL: process.env.API_URL ??
|
|
26
|
+
API_URL: process.env.API_URL ?? 'https://tss.maxserv.dev:8081',
|
|
27
27
|
},
|
|
28
28
|
{
|
|
29
|
-
jingle: new FilesystemCache(
|
|
30
|
-
auth: new FilesystemCache(
|
|
31
|
-
}
|
|
29
|
+
jingle: new FilesystemCache('jingle'),
|
|
30
|
+
auth: new FilesystemCache('TSS-TOKEN'),
|
|
31
|
+
},
|
|
32
32
|
);
|
|
33
33
|
|
|
34
34
|
const program = new Command();
|
|
35
35
|
const completion = await initCompletion(api);
|
|
36
36
|
|
|
37
|
-
if (process.argv.length <= 2 || process.argv[2] ===
|
|
38
|
-
console.log(figlet.textSync(
|
|
37
|
+
if (process.argv.length <= 2 || process.argv[2] === 'help') {
|
|
38
|
+
console.log(figlet.textSync('TSS CLI'));
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
program.name(
|
|
41
|
+
program.name('tss').description('Dé TSS CLI. Dit ding heeft alles.');
|
|
42
42
|
|
|
43
43
|
program
|
|
44
44
|
.command(Commands.autocomplete)
|
|
45
|
-
.description(
|
|
46
|
-
.option(
|
|
47
|
-
.option(
|
|
45
|
+
.description('Install or uninstall TSS CLI autocomplete')
|
|
46
|
+
.option('-i, --install', 'Install TSS CLI autocomplete')
|
|
47
|
+
.option('-u, --uninstall', 'Uninstall TSS CLI autocomplete')
|
|
48
48
|
.action(async (options) => {
|
|
49
49
|
if (options.install) {
|
|
50
|
-
console.log(
|
|
50
|
+
console.log('TSS CLI autocomplete installed!');
|
|
51
51
|
completion.setupShellInitFile();
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
if (options.uninstall) {
|
|
55
|
-
console.log(
|
|
55
|
+
console.log('TSS autocomplete uninstalled.');
|
|
56
56
|
completion.cleanupShellInitFile();
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
program
|
|
61
61
|
.command(Commands.login)
|
|
62
|
-
.description(
|
|
62
|
+
.description('Authenticate yourself so you can communicate with the TSS API')
|
|
63
63
|
.action(async () => {
|
|
64
64
|
const { token } = await inquirer.prompt([
|
|
65
65
|
{
|
|
66
|
-
type:
|
|
67
|
-
name:
|
|
68
|
-
message:
|
|
66
|
+
type: 'password',
|
|
67
|
+
name: 'token',
|
|
68
|
+
message: 'What is your token?',
|
|
69
69
|
},
|
|
70
70
|
]);
|
|
71
71
|
|
|
@@ -78,12 +78,12 @@ program
|
|
|
78
78
|
|
|
79
79
|
try {
|
|
80
80
|
const user = await api.user.get();
|
|
81
|
-
console.log(
|
|
81
|
+
console.log('Logged in as ' + user.email);
|
|
82
82
|
} catch (e: any) {
|
|
83
83
|
if (e.status >= 500) {
|
|
84
|
-
console.error(
|
|
84
|
+
console.error('Uit. Dit kan niet gebeuren want TSS geeft een status >= 500 terug');
|
|
85
85
|
} else {
|
|
86
|
-
console.error(
|
|
86
|
+
console.error('Invalid token!');
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
await api.auth.removeToken();
|
|
@@ -92,43 +92,43 @@ program
|
|
|
92
92
|
|
|
93
93
|
program
|
|
94
94
|
.command(Commands.clearcache)
|
|
95
|
-
.description(
|
|
96
|
-
.argument(
|
|
95
|
+
.description('Clear the cache')
|
|
96
|
+
.argument('[type]', 'The type of cache to clear (jingle, auth, all)')
|
|
97
97
|
.action(async (type) => {
|
|
98
|
-
if (type ===
|
|
98
|
+
if (type === 'jingle') {
|
|
99
99
|
await api.jingle.getCache().clear();
|
|
100
|
-
console.log(
|
|
101
|
-
} else if (type ===
|
|
100
|
+
console.log('Cleared jingle cache');
|
|
101
|
+
} else if (type === 'auth') {
|
|
102
102
|
await api.auth.removeToken();
|
|
103
|
-
console.log(
|
|
104
|
-
} else if (type ===
|
|
103
|
+
console.log('Cleared auth cache');
|
|
104
|
+
} else if (type === 'all' || !type) {
|
|
105
105
|
await api.auth.removeToken();
|
|
106
106
|
await api.jingle.getCache().clear();
|
|
107
|
-
console.log(
|
|
107
|
+
console.log('Cleared all caches');
|
|
108
108
|
} else {
|
|
109
|
-
console.error(
|
|
109
|
+
console.error('Invalid cache type');
|
|
110
110
|
}
|
|
111
111
|
});
|
|
112
112
|
|
|
113
113
|
program
|
|
114
114
|
.command(Commands.jingles)
|
|
115
|
-
.description(
|
|
115
|
+
.description('Show all jingles')
|
|
116
116
|
.action(async () => {
|
|
117
117
|
try {
|
|
118
118
|
const jingles = await api.jingle.getAll();
|
|
119
119
|
jingles.forEach((jingle) => {
|
|
120
|
-
console.log(jingle.folder +
|
|
120
|
+
console.log(jingle.folder + '/' + jingle.file);
|
|
121
121
|
});
|
|
122
122
|
} catch (e: any) {
|
|
123
|
-
console.error(e.status +
|
|
123
|
+
console.error(e.status + ': ' + e.message);
|
|
124
124
|
}
|
|
125
125
|
});
|
|
126
126
|
|
|
127
127
|
program
|
|
128
128
|
.command(Commands.play)
|
|
129
|
-
.description(
|
|
130
|
-
.argument(
|
|
131
|
-
.argument(
|
|
129
|
+
.description('Play a jingle')
|
|
130
|
+
.argument('<folder>', 'The folder of the jingle')
|
|
131
|
+
.argument('<file>', 'The jingle to play')
|
|
132
132
|
.action(async (folder, file) => {
|
|
133
133
|
try {
|
|
134
134
|
await api.jingle.play({ folder, file });
|
|
@@ -139,68 +139,52 @@ program
|
|
|
139
139
|
|
|
140
140
|
program
|
|
141
141
|
.command(Commands.recent)
|
|
142
|
-
.description(
|
|
142
|
+
.description('Show recently added jingles, select a jingle to play')
|
|
143
143
|
.action(async () => {
|
|
144
144
|
try {
|
|
145
|
-
const jingles = await api.jingle.
|
|
146
|
-
jingles.sort((a, b) => b.mtime - a.mtime);
|
|
145
|
+
const jingles = await api.jingle.getRecentlyAdded();
|
|
147
146
|
|
|
148
147
|
const answers = await inquirer.prompt([
|
|
149
148
|
{
|
|
150
|
-
type:
|
|
151
|
-
name:
|
|
149
|
+
type: 'list',
|
|
150
|
+
name: 'jingle',
|
|
152
151
|
message: playWhichJingleString,
|
|
153
|
-
choices: jingles.slice(0, 30).map((jingle) => jingle.folder +
|
|
152
|
+
choices: jingles.slice(0, 30).map((jingle) => jingle.folder + '/' + jingle.file),
|
|
154
153
|
},
|
|
155
154
|
]);
|
|
156
155
|
|
|
157
|
-
const [folder, file]: [folder: string, file: string] = answers.jingle.split(
|
|
156
|
+
const [folder, file]: [folder: string, file: string] = answers.jingle.split('/');
|
|
158
157
|
const jingle = { folder, file };
|
|
159
158
|
await api.jingle.play(jingle);
|
|
160
159
|
} catch (e: any) {
|
|
161
|
-
console.error(e.status +
|
|
160
|
+
console.error(e.status + ': ' + e.message);
|
|
162
161
|
}
|
|
163
162
|
});
|
|
164
163
|
|
|
165
164
|
program
|
|
166
165
|
.command(Commands.playShort)
|
|
167
|
-
.description(
|
|
168
|
-
.argument(
|
|
166
|
+
.description('Play a jingle by typing (some) parts of the name')
|
|
167
|
+
.argument('<query...>', 'The query to search for')
|
|
169
168
|
.action(async (query: string[]) => {
|
|
170
|
-
|
|
171
|
-
try {
|
|
172
|
-
jingles = await api.jingle.getAll();
|
|
173
|
-
} catch (e: any) {
|
|
174
|
-
console.error(e.status + ": " + e.message);
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
const matches = jingles.filter((jingle) => query.every((q) => (jingle.folder + "/" + jingle.file).includes(q)));
|
|
169
|
+
const items = await api.jingle.find(query.join(' '));
|
|
179
170
|
|
|
180
171
|
let jingle;
|
|
181
|
-
if (
|
|
182
|
-
console.log(
|
|
172
|
+
if (items.length === 0) {
|
|
173
|
+
console.log('No matches found');
|
|
183
174
|
return;
|
|
184
|
-
} else if (
|
|
185
|
-
jingle =
|
|
175
|
+
} else if (items.length === 1) {
|
|
176
|
+
jingle = items[0];
|
|
186
177
|
} else {
|
|
187
|
-
const sortedMatches = matches.sort((a, b) => {
|
|
188
|
-
const aScore = a.keywords.filter((k) => query.includes(k)).length;
|
|
189
|
-
const bScore = b.keywords.filter((k) => query.includes(k)).length;
|
|
190
|
-
|
|
191
|
-
return bScore - aScore;
|
|
192
|
-
});
|
|
193
|
-
|
|
194
178
|
const answers = await inquirer.prompt([
|
|
195
179
|
{
|
|
196
|
-
type:
|
|
197
|
-
name:
|
|
180
|
+
type: 'list',
|
|
181
|
+
name: 'jingle',
|
|
198
182
|
message: playWhichJingleString,
|
|
199
|
-
choices:
|
|
183
|
+
choices: items.map((jingle) => jingle.folder + '/' + jingle.file),
|
|
200
184
|
},
|
|
201
185
|
]);
|
|
202
186
|
|
|
203
|
-
const [folder, file]: [folder: string, file: string] = answers.jingle.split(
|
|
187
|
+
const [folder, file]: [folder: string, file: string] = answers.jingle.split('/');
|
|
204
188
|
jingle = { folder, file };
|
|
205
189
|
}
|
|
206
190
|
|
|
@@ -213,17 +197,23 @@ program
|
|
|
213
197
|
|
|
214
198
|
program
|
|
215
199
|
.command(Commands.version)
|
|
216
|
-
.description(
|
|
200
|
+
.description('Show the TSS-CLI version')
|
|
217
201
|
.action(() => {
|
|
218
202
|
console.log(version);
|
|
219
203
|
});
|
|
220
204
|
|
|
221
|
-
program.command(
|
|
205
|
+
program.command('users').action(async () => {
|
|
222
206
|
try {
|
|
223
207
|
const users = await api.user.getAll();
|
|
224
|
-
|
|
208
|
+
const items = users.map((user) => {
|
|
209
|
+
return {
|
|
210
|
+
name: user.email,
|
|
211
|
+
value: user.id,
|
|
212
|
+
};
|
|
213
|
+
});
|
|
214
|
+
console.log(items);
|
|
225
215
|
} catch (e: any) {
|
|
226
|
-
console.error(e.status +
|
|
216
|
+
console.error(e.status + ': ' + e.message);
|
|
227
217
|
}
|
|
228
218
|
});
|
|
229
219
|
|