From 329619b3453479f76c049816b7403b86e9d45cb5 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 5 Jul 2021 16:37:50 +0200 Subject: Introduce CLI command --- shared/extra-utils/bulk/index.ts | 1 + shared/extra-utils/cli/cli.ts | 33 ++++++++++++++++++--------------- shared/extra-utils/cli/index.ts | 1 + shared/extra-utils/index.ts | 4 ++-- shared/extra-utils/server/servers.ts | 8 ++++++++ 5 files changed, 30 insertions(+), 17 deletions(-) create mode 100644 shared/extra-utils/bulk/index.ts create mode 100644 shared/extra-utils/cli/index.ts (limited to 'shared') diff --git a/shared/extra-utils/bulk/index.ts b/shared/extra-utils/bulk/index.ts new file mode 100644 index 000000000..5d2f9d3ad --- /dev/null +++ b/shared/extra-utils/bulk/index.ts @@ -0,0 +1 @@ +export * from './bulk' diff --git a/shared/extra-utils/cli/cli.ts b/shared/extra-utils/cli/cli.ts index c62e170bb..1bf100869 100644 --- a/shared/extra-utils/cli/cli.ts +++ b/shared/extra-utils/cli/cli.ts @@ -1,24 +1,27 @@ import { exec } from 'child_process' +import { AbstractCommand } from '../shared' -import { ServerInfo } from '../server/servers' +class CLICommand extends AbstractCommand { -function getEnvCli (server?: ServerInfo) { - return `NODE_ENV=test NODE_APP_INSTANCE=${server.internalServerNumber}` -} - -async function execCLI (command: string) { - return new Promise((res, rej) => { - exec(command, (err, stdout, stderr) => { - if (err) return rej(err) + static exec (command: string) { + return new Promise((res, rej) => { + exec(command, (err, stdout, _stderr) => { + if (err) return rej(err) - return res(stdout) + return res(stdout) + }) }) - }) -} + } -// --------------------------------------------------------------------------- + getEnv () { + return `NODE_ENV=test NODE_APP_INSTANCE=${this.server.internalServerNumber}` + } + + async execWithEnv (command: string) { + return CLICommand.exec(`${this.getEnv()} ${command}`) + } +} export { - execCLI, - getEnvCli + CLICommand } diff --git a/shared/extra-utils/cli/index.ts b/shared/extra-utils/cli/index.ts new file mode 100644 index 000000000..8a3f31e2f --- /dev/null +++ b/shared/extra-utils/cli/index.ts @@ -0,0 +1 @@ +export * from './cli' diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts index 87ee8abba..4bf057492 100644 --- a/shared/extra-utils/index.ts +++ b/shared/extra-utils/index.ts @@ -1,6 +1,6 @@ -export * from './bulk/bulk' +export * from './bulk' -export * from './cli/cli' +export * from './cli' export * from './custom-pages/custom-pages' diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 28e431e94..1b0775421 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -6,6 +6,8 @@ import { copy, ensureDir, pathExists, readdir, readFile, remove } from 'fs-extra import { join } from 'path' import { randomInt } from '../../core-utils/miscs/miscs' import { VideoChannel } from '../../models/videos' +import { BulkCommand } from '../bulk' +import { CLICommand } from '../cli' import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../miscs/miscs' import { makeGetRequest } from '../requests/requests' @@ -60,6 +62,9 @@ interface ServerInfo { } videos?: { id: number, uuid: string }[] + + bulkCommand?: BulkCommand + cliCommand?: CLICommand } function parallelTests () { @@ -265,6 +270,9 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] } catch { /* empty */ } }) + server.bulkCommand = new BulkCommand(server) + server.cliCommand = new CLICommand(server) + res(server) }) }) -- cgit v1.2.3