tering-serieuze-cli 1.6.0 → 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 CHANGED
@@ -1,2 +1,6 @@
1
- tabWidth: 4
2
- printWidth: 120
1
+ {
2
+ "singleQuote": true,
3
+ "trailingComma": "all",
4
+ "tabWidth": 4,
5
+ "printWidth": 120,
6
+ }
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.4.0";
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.getAll();
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
- let jingles;
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 (matches.length === 0) {
152
+ if (items.length === 0) {
161
153
  console.log("No matches found");
162
154
  return;
163
- } else if (matches.length === 1) {
164
- jingle = { folder: matches[0].folder, file: matches[0].file };
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: sortedMatches.map((jingle2) => jingle2.folder + "/" + jingle2.file)
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
- console.log(users);
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.6.0",
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.5.0",
31
- "tering-serieuze-types": "^1.14.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 "omelette";
2
- import { Commands } from "./index";
3
- import { TssApi } from "tering-serieuze-sdk";
4
- import { JingleFolder } from "tering-serieuze-types";
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[]>("getGrouped")) ?? [];
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]: ["--install", "--uninstall"],
15
- [Commands.clearcache]: ["auth", "jingle", "all"],
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("tss").tree(autocompletionTree);
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 "commander";
4
- import figlet from "figlet";
5
- import inquirer from "inquirer";
6
- import { TssApi, FilesystemCache } from "tering-serieuze-sdk";
7
- import { initCompletion } from "./completion";
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 "../package.json";
9
+ import { version } from '../package.json';
10
10
 
11
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",
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 = "Which jingle do you want to play?";
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 ?? "https://tss.maxserv.dev:8081",
26
+ API_URL: process.env.API_URL ?? 'https://tss.maxserv.dev:8081',
27
27
  },
28
28
  {
29
- jingle: new FilesystemCache("jingle"),
30
- auth: new FilesystemCache("TSS-TOKEN"),
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] === "help") {
38
- console.log(figlet.textSync("TSS CLI"));
37
+ if (process.argv.length <= 2 || process.argv[2] === 'help') {
38
+ console.log(figlet.textSync('TSS CLI'));
39
39
  }
40
40
 
41
- program.name("tss").description("Dé TSS CLI. Dit ding heeft alles.");
41
+ program.name('tss').description('Dé TSS CLI. Dit ding heeft alles.');
42
42
 
43
43
  program
44
44
  .command(Commands.autocomplete)
45
- .description("Install or uninstall TSS CLI autocomplete")
46
- .option("-i, --install", "Install TSS CLI autocomplete")
47
- .option("-u, --uninstall", "Uninstall TSS CLI autocomplete")
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("TSS CLI autocomplete installed!");
50
+ console.log('TSS CLI autocomplete installed!');
51
51
  completion.setupShellInitFile();
52
52
  }
53
53
 
54
54
  if (options.uninstall) {
55
- console.log("TSS autocomplete uninstalled.");
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("Authenticate yourself so you can communicate with the TSS API")
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: "password",
67
- name: "token",
68
- message: "What is your token?",
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("Logged in as " + user.email);
81
+ console.log('Logged in as ' + user.email);
82
82
  } catch (e: any) {
83
83
  if (e.status >= 500) {
84
- console.error("Uit. Dit kan niet gebeuren want TSS geeft een status >= 500 terug");
84
+ console.error('Uit. Dit kan niet gebeuren want TSS geeft een status >= 500 terug');
85
85
  } else {
86
- console.error("Invalid token!");
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("Clear the cache")
96
- .argument("[type]", "The type of cache to clear (jingle, auth, all)")
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 === "jingle") {
98
+ if (type === 'jingle') {
99
99
  await api.jingle.getCache().clear();
100
- console.log("Cleared jingle cache");
101
- } else if (type === "auth") {
100
+ console.log('Cleared jingle cache');
101
+ } else if (type === 'auth') {
102
102
  await api.auth.removeToken();
103
- console.log("Cleared auth cache");
104
- } else if (type === "all" || !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("Cleared all caches");
107
+ console.log('Cleared all caches');
108
108
  } else {
109
- console.error("Invalid cache type");
109
+ console.error('Invalid cache type');
110
110
  }
111
111
  });
112
112
 
113
113
  program
114
114
  .command(Commands.jingles)
115
- .description("Show all jingles")
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 + "/" + jingle.file);
120
+ console.log(jingle.folder + '/' + jingle.file);
121
121
  });
122
122
  } catch (e: any) {
123
- console.error(e.status + ": " + e.message);
123
+ console.error(e.status + ': ' + e.message);
124
124
  }
125
125
  });
126
126
 
127
127
  program
128
128
  .command(Commands.play)
129
- .description("Play a jingle")
130
- .argument("<folder>", "The folder of the jingle")
131
- .argument("<file>", "The jingle to play")
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,52 +139,52 @@ program
139
139
 
140
140
  program
141
141
  .command(Commands.recent)
142
- .description("Show recently added jingles, select a jingle to play")
142
+ .description('Show recently added jingles, select a jingle to play')
143
143
  .action(async () => {
144
144
  try {
145
145
  const jingles = await api.jingle.getRecentlyAdded();
146
146
 
147
147
  const answers = await inquirer.prompt([
148
148
  {
149
- type: "list",
150
- name: "jingle",
149
+ type: 'list',
150
+ name: 'jingle',
151
151
  message: playWhichJingleString,
152
- choices: jingles.slice(0, 30).map((jingle) => jingle.folder + "/" + jingle.file),
152
+ choices: jingles.slice(0, 30).map((jingle) => jingle.folder + '/' + jingle.file),
153
153
  },
154
154
  ]);
155
155
 
156
- const [folder, file]: [folder: string, file: string] = answers.jingle.split("/");
156
+ const [folder, file]: [folder: string, file: string] = answers.jingle.split('/');
157
157
  const jingle = { folder, file };
158
158
  await api.jingle.play(jingle);
159
159
  } catch (e: any) {
160
- console.error(e.status + ": " + e.message);
160
+ console.error(e.status + ': ' + e.message);
161
161
  }
162
162
  });
163
163
 
164
164
  program
165
165
  .command(Commands.playShort)
166
- .description("Play a jingle by typing (some) parts of the name")
167
- .argument("<query...>", "The query to search for")
166
+ .description('Play a jingle by typing (some) parts of the name')
167
+ .argument('<query...>', 'The query to search for')
168
168
  .action(async (query: string[]) => {
169
- const items = await api.jingle.find(query.join(" "));
169
+ const items = await api.jingle.find(query.join(' '));
170
170
 
171
171
  let jingle;
172
172
  if (items.length === 0) {
173
- console.log("No matches found");
173
+ console.log('No matches found');
174
174
  return;
175
175
  } else if (items.length === 1) {
176
176
  jingle = items[0];
177
177
  } else {
178
178
  const answers = await inquirer.prompt([
179
179
  {
180
- type: "list",
181
- name: "jingle",
180
+ type: 'list',
181
+ name: 'jingle',
182
182
  message: playWhichJingleString,
183
- choices: items.map((jingle) => jingle.folder + "/" + jingle.file),
183
+ choices: items.map((jingle) => jingle.folder + '/' + jingle.file),
184
184
  },
185
185
  ]);
186
186
 
187
- const [folder, file]: [folder: string, file: string] = answers.jingle.split("/");
187
+ const [folder, file]: [folder: string, file: string] = answers.jingle.split('/');
188
188
  jingle = { folder, file };
189
189
  }
190
190
 
@@ -197,17 +197,23 @@ program
197
197
 
198
198
  program
199
199
  .command(Commands.version)
200
- .description("Show the TSS-CLI version")
200
+ .description('Show the TSS-CLI version')
201
201
  .action(() => {
202
202
  console.log(version);
203
203
  });
204
204
 
205
- program.command("users").action(async () => {
205
+ program.command('users').action(async () => {
206
206
  try {
207
207
  const users = await api.user.getAll();
208
- console.log(users);
208
+ const items = users.map((user) => {
209
+ return {
210
+ name: user.email,
211
+ value: user.id,
212
+ };
213
+ });
214
+ console.log(items);
209
215
  } catch (e: any) {
210
- console.error(e.status + ": " + e.message);
216
+ console.error(e.status + ': ' + e.message);
211
217
  }
212
218
  });
213
219