From 5dc234c024c76838e9575415103b6aeaddc4bd19 Mon Sep 17 00:00:00 2001 From: xhyrom Date: Sat, 8 Jan 2022 14:48:08 +0100 Subject: [PATCH] feat(test): workflow, fix(removeCommand): message --- .eslintrc.json | 3 +- .github/workflows/test.yml | 38 ++++++++++ .../discord-api-manager/removeCommand.ts | 12 +-- .../discord-api-manager/removePrompt.ts | 74 +++++++++---------- 4 files changed, 83 insertions(+), 44 deletions(-) create mode 100644 .github/workflows/test.yml diff --git a/.eslintrc.json b/.eslintrc.json index 29aa368..32e1661 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -28,6 +28,7 @@ "always" ], "prefer-const": "error", - "@typescript-eslint/no-explicit-any": "off" + "@typescript-eslint/no-explicit-any": "off", + "no-async-promise-executor": "off" } } diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..b9265c6 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,38 @@ +name: Testing +on: [push, pull_request] +jobs: + lint: + name: ESLint + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Install Node v16 + uses: actions/setup-node@v2 + with: + node-version: 16 + + - name: Install dependencies + run: npm ci + + - name: Run ESLint + run: npm run lint + + build: + name: Package + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Install Node v16 + uses: actions/setup-node@v2 + with: + node-version: 16 + + - name: Install dependencies + run: npm ci + + - name: Run package build + run: npm run build:babel \ No newline at end of file diff --git a/src/commands/discord-api-manager/removeCommand.ts b/src/commands/discord-api-manager/removeCommand.ts index 048db6c..b425331 100644 --- a/src/commands/discord-api-manager/removeCommand.ts +++ b/src/commands/discord-api-manager/removeCommand.ts @@ -12,12 +12,12 @@ export default async() => { const commands = await runJob(() => getCommands(clientId, response), 'Getting commands').catch(() => process.exit(1)); - if (!Array.isArray(commands) || commands.length === 0) return console.log(chalk.red(`There are probably no commands, or you have entered some property wrong.`)); + if (!Array.isArray(commands) || commands.length === 0) return console.log(chalk.red('There are probably no commands, or you have entered some property wrong.')); const commandsToDelete = (await prompts(selectCommand(commands))).commands; const jobs: [() => any, string][] = [ - [() => deleteCommands(clientId, response, commandsToDelete, commands), 'Generating config'] + [() => deleteCommands(clientId, response, commandsToDelete, commands), 'Removing commands'] ]; for (const [job, message] of jobs) { @@ -45,9 +45,9 @@ export const deleteCommands = (clientId, response, commandsToDelete, allCommands }).catch(e => e); if (res.ok) resolve(true); - else reject(res.data) - }) -} + else reject(res.data); + }); +}; export const getCommands = (clientId, response) => { return new Promise(async(resolve, reject) => { @@ -67,4 +67,4 @@ export const getCommands = (clientId, response) => { if (res.ok) resolve(res.data); else reject(res.data); }); -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/prompts/discord-api-manager/removePrompt.ts b/src/prompts/discord-api-manager/removePrompt.ts index 6daed8b..812ffb4 100644 --- a/src/prompts/discord-api-manager/removePrompt.ts +++ b/src/prompts/discord-api-manager/removePrompt.ts @@ -3,44 +3,44 @@ import type { PromptObject } from 'prompts'; export const removePrompt = (): Array => { return [ { - type: 'password', - name: 'token', - message: 'You must provide a token to fetch commands.' - }, - { - type: 'select', - name: 'select', - message: 'Select whether the command you want to delete is a global or a guild command.', - choices: [ - { - title: 'Global Command', - value: 'global' - }, - { - title: 'Guild Command', - value: 'guild' - } - ] - }, - { - type: (prev) => prev === 'guild' ? 'text' : null, - name: 'guildId', - message: 'What\'s the id of your guild?' - } + type: 'password', + name: 'token', + message: 'You must provide a token to fetch commands.' + }, + { + type: 'select', + name: 'select', + message: 'Select whether the command you want to delete is a global or a guild command.', + choices: [ + { + title: 'Global Command', + value: 'global' + }, + { + title: 'Guild Command', + value: 'guild' + } + ] + }, + { + type: (prev) => prev === 'guild' ? 'text' : null, + name: 'guildId', + message: 'What\'s the id of your guild?' + } ]; }; export const selectCommand = (commands): Array => { - return [ - { - type: 'multiselect', - name: 'commands', - message: 'Select the command you want to delete.', - choices: commands.map(c => new Object({ - title: c.name, - value: c.id, - description: c.description - })) - } - ] -} \ No newline at end of file + return [ + { + type: 'multiselect', + name: 'commands', + message: 'Select the command you want to delete.', + choices: commands.map(c => new Object({ + title: c.name, + value: c.id, + description: c.description + })) + } + ]; +}; \ No newline at end of file