From 329619b3453479f76c049816b7403b86e9d45cb5 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 5 Jul 2021 16:37:50 +0200 Subject: [PATCH] Introduce CLI command --- scripts/generate-code-contributors.ts | 4 +- .../tests/cli/create-import-video-file-job.ts | 14 ++-- server/tests/cli/create-transcoding-job.ts | 23 ++---- server/tests/cli/optimize-old-videos.ts | 6 +- server/tests/cli/peertube.ts | 82 ++++++------------- server/tests/cli/plugins.ts | 13 +-- server/tests/cli/print-transcode-command.ts | 7 +- server/tests/cli/prune-storage.ts | 7 +- server/tests/cli/regenerate-thumbnails.ts | 5 +- server/tests/cli/reset-password.ts | 10 +-- server/tests/cli/update-host.ts | 14 ++-- 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 ++ 16 files changed, 94 insertions(+), 138 deletions(-) create mode 100644 shared/extra-utils/bulk/index.ts create mode 100644 shared/extra-utils/cli/index.ts diff --git a/scripts/generate-code-contributors.ts b/scripts/generate-code-contributors.ts index db5af3f91..935ed3c5a 100755 --- a/scripts/generate-code-contributors.ts +++ b/scripts/generate-code-contributors.ts @@ -1,7 +1,7 @@ import { registerTSPaths } from '../server/helpers/register-ts-paths' registerTSPaths() -import { execCLI } from '@shared/extra-utils' +import { CLICommand } from '@shared/extra-utils' run() .then(() => process.exit(0)) @@ -59,7 +59,7 @@ async function run () { } async function getGitContributors () { - const output = await execCLI(`git --no-pager shortlog -sn < /dev/tty | sed 's/^\\s\\+[0-9]\\+\\s\\+//g'`) + const output = await CLICommand.exec(`git --no-pager shortlog -sn < /dev/tty | sed 's/^\\s\\+[0-9]\\+\\s\\+//g'`) return output.split('\n') .filter(l => !!l) diff --git a/server/tests/cli/create-import-video-file-job.ts b/server/tests/cli/create-import-video-file-job.ts index 49758ff56..8a23a94de 100644 --- a/server/tests/cli/create-import-video-file-job.ts +++ b/server/tests/cli/create-import-video-file-job.ts @@ -6,9 +6,7 @@ import { VideoFile } from '@shared/models/videos/video-file.model' import { cleanupTests, doubleFollow, - execCLI, flushAndRunMultipleServers, - getEnvCli, getVideo, getVideosList, ServerInfo, @@ -57,8 +55,8 @@ describe('Test create import video jobs', function () { }) it('Should run a import job on video 1 with a lower resolution', async function () { - const env = getEnvCli(servers[0]) - await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short-480.webm`) + const command = `npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short-480.webm` + await servers[0].cliCommand.execWithEnv(command) await waitJobs(servers) @@ -77,8 +75,8 @@ describe('Test create import video jobs', function () { }) it('Should run a import job on video 2 with the same resolution and a different extension', async function () { - const env = getEnvCli(servers[1]) - await execCLI(`${env} npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv`) + const command = `npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv` + await servers[1].cliCommand.execWithEnv(command) await waitJobs(servers) @@ -99,8 +97,8 @@ describe('Test create import video jobs', function () { }) it('Should run a import job on video 2 with the same resolution and the same extension', async function () { - const env = getEnvCli(servers[0]) - await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short2.webm`) + const command = `npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short2.webm` + await servers[0].cliCommand.execWithEnv(command) await waitJobs(servers) diff --git a/server/tests/cli/create-transcoding-job.ts b/server/tests/cli/create-transcoding-job.ts index 5bc1687cd..be46dec25 100644 --- a/server/tests/cli/create-transcoding-job.ts +++ b/server/tests/cli/create-transcoding-job.ts @@ -2,13 +2,10 @@ import 'mocha' import * as chai from 'chai' -import { VideoDetails } from '../../../shared/models/videos' import { cleanupTests, doubleFollow, - execCLI, flushAndRunMultipleServers, - getEnvCli, getVideo, getVideosList, ServerInfo, @@ -17,6 +14,7 @@ import { uploadVideo } from '../../../shared/extra-utils' import { waitJobs } from '../../../shared/extra-utils/server/jobs' +import { VideoDetails } from '../../../shared/models/videos' const expect = chai.expect @@ -81,9 +79,7 @@ describe('Test create transcoding jobs', function () { it('Should run a transcoding job on video 2', async function () { this.timeout(60000) - const env = getEnvCli(servers[0]) - await execCLI(`${env} npm run create-transcoding-job -- -v ${videosUUID[1]}`) - + await servers[0].cliCommand.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[1]}`) await waitJobs(servers) for (const server of servers) { @@ -123,8 +119,7 @@ describe('Test create transcoding jobs', function () { it('Should run a transcoding job on video 1 with resolution', async function () { this.timeout(60000) - const env = getEnvCli(servers[0]) - await execCLI(`${env} npm run create-transcoding-job -- -v ${videosUUID[0]} -r 480`) + await servers[0].cliCommand.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[0]} -r 480`) await waitJobs(servers) @@ -147,8 +142,7 @@ describe('Test create transcoding jobs', function () { it('Should generate an HLS resolution', async function () { this.timeout(120000) - const env = getEnvCli(servers[0]) - await execCLI(`${env} npm run create-transcoding-job -- -v ${videosUUID[2]} --generate-hls -r 480`) + await servers[0].cliCommand.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[2]} --generate-hls -r 480`) await waitJobs(servers) @@ -168,8 +162,7 @@ describe('Test create transcoding jobs', function () { it('Should not duplicate an HLS resolution', async function () { this.timeout(120000) - const env = getEnvCli(servers[0]) - await execCLI(`${env} npm run create-transcoding-job -- -v ${videosUUID[2]} --generate-hls -r 480`) + await servers[0].cliCommand.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[2]} --generate-hls -r 480`) await waitJobs(servers) @@ -186,8 +179,7 @@ describe('Test create transcoding jobs', function () { it('Should generate all HLS resolutions', async function () { this.timeout(120000) - const env = getEnvCli(servers[0]) - await execCLI(`${env} npm run create-transcoding-job -- -v ${videosUUID[3]} --generate-hls`) + await servers[0].cliCommand.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[3]} --generate-hls`) await waitJobs(servers) @@ -209,8 +201,7 @@ describe('Test create transcoding jobs', function () { config.transcoding.hls.enabled = true await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) - const env = getEnvCli(servers[0]) - await execCLI(`${env} npm run create-transcoding-job -- -v ${videosUUID[4]}`) + await servers[0].cliCommand.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[4]}`) await waitJobs(servers) diff --git a/server/tests/cli/optimize-old-videos.ts b/server/tests/cli/optimize-old-videos.ts index 91a1c9cc4..bd15012fe 100644 --- a/server/tests/cli/optimize-old-videos.ts +++ b/server/tests/cli/optimize-old-videos.ts @@ -7,10 +7,8 @@ import { buildServerDirectory, cleanupTests, doubleFollow, - execCLI, flushAndRunMultipleServers, generateHighBitrateVideo, - getEnvCli, getVideo, getVideosList, ServerInfo, @@ -73,9 +71,7 @@ describe('Test optimize old videos', function () { it('Should run optimize script', async function () { this.timeout(200000) - const env = getEnvCli(servers[0]) - await execCLI(`${env} npm run optimize-old-videos`) - + await servers[0].cliCommand.execWithEnv('npm run optimize-old-videos') await waitJobs(servers) for (const server of servers) { diff --git a/server/tests/cli/peertube.ts b/server/tests/cli/peertube.ts index fcf7e2e2e..0a4f54ffa 100644 --- a/server/tests/cli/peertube.ts +++ b/server/tests/cli/peertube.ts @@ -8,11 +8,10 @@ import { areHttpImportTestsDisabled, buildAbsoluteFixturePath, cleanupTests, + CLICommand, createUser, doubleFollow, - execCLI, flushAndRunServer, - getEnvCli, getLocalIdByUUID, getVideo, getVideosList, @@ -30,6 +29,8 @@ describe('Test CLI wrapper', function () { let server: ServerInfo let userAccessToken: string + let cliCommand: CLICommand + const cmd = 'node ./dist/server/tools/peertube.js' before(async function () { @@ -46,6 +47,8 @@ describe('Test CLI wrapper', function () { const args = { name: 'user_channel', displayName: 'User channel', support: 'super support text' } await addVideoChannel(server.url, userAccessToken, args) } + + cliCommand = server.cliCommand }) describe('Authentication and instance selection', function () { @@ -53,46 +56,38 @@ describe('Test CLI wrapper', function () { it('Should display no selected instance', async function () { this.timeout(60000) - const env = getEnvCli(server) - const stdout = await execCLI(`${env} ${cmd} --help`) - + const stdout = await cliCommand.execWithEnv(`${cmd} --help`) expect(stdout).to.contain('no instance selected') }) it('Should add a user', async function () { this.timeout(60000) - const env = getEnvCli(server) - await execCLI(`${env} ${cmd} auth add -u ${server.url} -U user_1 -p super_password`) + await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U user_1 -p super_password`) }) it('Should not fail to add a user if there is a slash at the end of the instance URL', async function () { this.timeout(60000) - const env = getEnvCli(server) - let fullServerURL - fullServerURL = server.url + '/' - await execCLI(`${env} ${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`) + let fullServerURL = server.url + '/' + + await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`) fullServerURL = server.url + '/asdfasdf' - await execCLI(`${env} ${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`) + await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`) }) it('Should default to this user', async function () { this.timeout(60000) - const env = getEnvCli(server) - const stdout = await execCLI(`${env} ${cmd} --help`) - + const stdout = await cliCommand.execWithEnv(`${cmd} --help`) expect(stdout).to.contain(`instance ${server.url} selected`) }) it('Should remember the user', async function () { this.timeout(60000) - const env = getEnvCli(server) - const stdout = await execCLI(`${env} ${cmd} auth list`) - + const stdout = await cliCommand.execWithEnv(`${cmd} auth list`) expect(stdout).to.contain(server.url) }) }) @@ -102,13 +97,10 @@ describe('Test CLI wrapper', function () { it('Should upload a video', async function () { this.timeout(60000) - const env = getEnvCli(server) - const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4') - const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'` - await execCLI(`${env} ${cmd} upload ${params}`) + await cliCommand.execWithEnv(`${cmd} upload ${params}`) }) it('Should have the video uploaded', async function () { @@ -130,11 +122,8 @@ describe('Test CLI wrapper', function () { this.timeout(60000) - const env = getEnvCli(server) - const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel` - - await execCLI(`${env} ${cmd} import ${params}`) + await cliCommand.execWithEnv(`${cmd} import ${params}`) }) it('Should have imported the video', async function () { @@ -166,11 +155,8 @@ describe('Test CLI wrapper', function () { this.timeout(60000) - const env = getEnvCli(server) - const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel --video-name toto --nsfw --support support` - - await execCLI(`${env} ${cmd} import ${params}`) + await cliCommand.execWithEnv(`${cmd} import ${params}`) await waitJobs([ server ]) @@ -194,18 +180,14 @@ describe('Test CLI wrapper', function () { describe('Admin auth', function () { it('Should remove the auth user', async function () { - const env = getEnvCli(server) - - await execCLI(`${env} ${cmd} auth del ${server.url}`) - - const stdout = await execCLI(`${env} ${cmd} --help`) + await cliCommand.execWithEnv(`${cmd} auth del ${server.url}`) + const stdout = await cliCommand.execWithEnv(`${cmd} --help`) expect(stdout).to.contain('no instance selected') }) it('Should add the admin user', async function () { - const env = getEnvCli(server) - await execCLI(`${env} ${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`) + await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`) }) }) @@ -214,8 +196,7 @@ describe('Test CLI wrapper', function () { it('Should install a plugin', async function () { this.timeout(60000) - const env = getEnvCli(server) - await execCLI(`${env} ${cmd} plugins install --npm-name peertube-plugin-hello-world`) + await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world`) }) it('Should have registered settings', async function () { @@ -223,15 +204,13 @@ describe('Test CLI wrapper', function () { }) it('Should list installed plugins', async function () { - const env = getEnvCli(server) - const res = await execCLI(`${env} ${cmd} plugins list`) + const res = await cliCommand.execWithEnv(`${cmd} plugins list`) expect(res).to.contain('peertube-plugin-hello-world') }) it('Should uninstall the plugin', async function () { - const env = getEnvCli(server) - const res = await execCLI(`${env} ${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`) + const res = await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`) expect(res).to.not.contain('peertube-plugin-hello-world') }) @@ -262,11 +241,8 @@ describe('Test CLI wrapper', function () { it('Should add a redundancy', async function () { this.timeout(60000) - const env = getEnvCli(server) - const params = `add --video ${video1Server2}` - - await execCLI(`${env} ${cmd} redundancy ${params}`) + await cliCommand.execWithEnv(`${cmd} redundancy ${params}`) await waitJobs(servers) }) @@ -275,10 +251,8 @@ describe('Test CLI wrapper', function () { this.timeout(60000) { - const env = getEnvCli(server) - const params = 'list-my-redundancies' - const stdout = await execCLI(`${env} ${cmd} redundancy ${params}`) + const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`) expect(stdout).to.contain('super video') expect(stdout).to.contain(`localhost:${server.port}`) @@ -288,18 +262,14 @@ describe('Test CLI wrapper', function () { it('Should remove a redundancy', async function () { this.timeout(60000) - const env = getEnvCli(server) - const params = `remove --video ${video1Server2}` - - await execCLI(`${env} ${cmd} redundancy ${params}`) + await cliCommand.execWithEnv(`${cmd} redundancy ${params}`) await waitJobs(servers) { - const env = getEnvCli(server) const params = 'list-my-redundancies' - const stdout = await execCLI(`${env} ${cmd} redundancy ${params}`) + const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`) expect(stdout).to.not.contain('super video') } diff --git a/server/tests/cli/plugins.ts b/server/tests/cli/plugins.ts index 7f19f14b7..efdc20748 100644 --- a/server/tests/cli/plugins.ts +++ b/server/tests/cli/plugins.ts @@ -1,12 +1,11 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' +import { expect } from 'chai' import { cleanupTests, - execCLI, flushAndRunServer, getConfig, - getEnvCli, getPluginTestPath, killallServers, reRunServer, @@ -14,7 +13,6 @@ import { setAccessTokensToServers } from '../../../shared/extra-utils' import { ServerConfig } from '../../../shared/models/server' -import { expect } from 'chai' describe('Test plugin scripts', function () { let server: ServerInfo @@ -31,15 +29,13 @@ describe('Test plugin scripts', function () { const packagePath = getPluginTestPath() - const env = getEnvCli(server) - await execCLI(`${env} npm run plugin:install -- --plugin-path ${packagePath}`) + await server.cliCommand.execWithEnv(`npm run plugin:install -- --plugin-path ${packagePath}`) }) it('Should install a theme from stateless CLI', async function () { this.timeout(60000) - const env = getEnvCli(server) - await execCLI(`${env} npm run plugin:install -- --npm-name peertube-theme-background-red`) + await server.cliCommand.execWithEnv(`npm run plugin:install -- --npm-name peertube-theme-background-red`) }) it('Should have the theme and the plugin registered when we restart peertube', async function () { @@ -63,8 +59,7 @@ describe('Test plugin scripts', function () { it('Should uninstall a plugin from stateless CLI', async function () { this.timeout(60000) - const env = getEnvCli(server) - await execCLI(`${env} npm run plugin:uninstall -- --npm-name peertube-plugin-test`) + await server.cliCommand.execWithEnv(`npm run plugin:uninstall -- --npm-name peertube-plugin-test`) }) it('Should have removed the plugin on another peertube restart', async function () { diff --git a/server/tests/cli/print-transcode-command.ts b/server/tests/cli/print-transcode-command.ts index 2d7255db7..3a7969e68 100644 --- a/server/tests/cli/print-transcode-command.ts +++ b/server/tests/cli/print-transcode-command.ts @@ -2,14 +2,15 @@ import 'mocha' import * as chai from 'chai' -import { execCLI } from '../../../shared/extra-utils' +import { getVideoFileBitrate, getVideoFileFPS } from '@server/helpers/ffprobe-utils' +import { CLICommand } from '@shared/extra-utils' import { getTargetBitrate, VideoResolution } from '../../../shared/models/videos' import { VIDEO_TRANSCODING_FPS } from '../../initializers/constants' -import { getVideoFileBitrate, getVideoFileFPS } from '@server/helpers/ffprobe-utils' const expect = chai.expect describe('Test create transcoding jobs', function () { + it('Should print the correct command for each resolution', async function () { const fixturePath = 'server/tests/fixtures/video_short.webm' const fps = await getVideoFileFPS(fixturePath) @@ -19,7 +20,7 @@ describe('Test create transcoding jobs', function () { VideoResolution.H_720P, VideoResolution.H_1080P ]) { - const command = await execCLI(`npm run print-transcode-command -- ${fixturePath} -r ${resolution}`) + const command = await CLICommand.exec(`npm run print-transcode-command -- ${fixturePath} -r ${resolution}`) const targetBitrate = Math.min(getTargetBitrate(resolution, fps, VIDEO_TRANSCODING_FPS), bitrate) expect(command).to.includes(`-vf scale=w=-2:h=${resolution}`) diff --git a/server/tests/cli/prune-storage.ts b/server/tests/cli/prune-storage.ts index a0af09de8..81f91105c 100644 --- a/server/tests/cli/prune-storage.ts +++ b/server/tests/cli/prune-storage.ts @@ -9,12 +9,11 @@ import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-code import { buildServerDirectory, cleanupTests, + CLICommand, createVideoPlaylist, doubleFollow, - execCLI, flushAndRunMultipleServers, getAccount, - getEnvCli, killallServers, makeGetRequest, ServerInfo, @@ -193,8 +192,8 @@ describe('Test prune storage scripts', function () { it('Should run prune storage', async function () { this.timeout(30000) - const env = getEnvCli(servers[0]) - await execCLI(`echo y | ${env} npm run prune-storage`) + const env = servers[0].cliCommand.getEnv() + await CLICommand.exec(`echo y | ${env} npm run prune-storage`) }) it('Should have removed files', async function () { diff --git a/server/tests/cli/regenerate-thumbnails.ts b/server/tests/cli/regenerate-thumbnails.ts index 8acb9f263..1b460e9c0 100644 --- a/server/tests/cli/regenerate-thumbnails.ts +++ b/server/tests/cli/regenerate-thumbnails.ts @@ -7,9 +7,7 @@ import { buildServerDirectory, cleanupTests, doubleFollow, - execCLI, flushAndRunMultipleServers, - getEnvCli, getVideo, makeRawRequest, ServerInfo, @@ -91,8 +89,7 @@ describe('Test regenerate thumbnails script', function () { it('Should regenerate local thumbnails from the CLI', async function () { this.timeout(15000) - const env = getEnvCli(servers[0]) - await execCLI(`${env} npm run regenerate-thumbnails`) + await servers[0].cliCommand.execWithEnv(`npm run regenerate-thumbnails`) }) it('Should have generated new thumbnail files', async function () { diff --git a/server/tests/cli/reset-password.ts b/server/tests/cli/reset-password.ts index a84463b33..97a6eae15 100644 --- a/server/tests/cli/reset-password.ts +++ b/server/tests/cli/reset-password.ts @@ -1,16 +1,14 @@ import 'mocha' - +import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' import { cleanupTests, + CLICommand, createUser, - execCLI, flushAndRunServer, - getEnvCli, login, ServerInfo, setAccessTokensToServers } from '../../../shared/extra-utils' -import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' describe('Test reset password scripts', function () { let server: ServerInfo @@ -26,8 +24,8 @@ describe('Test reset password scripts', function () { it('Should change the user password from CLI', async function () { this.timeout(60000) - const env = getEnvCli(server) - await execCLI(`echo coucou | ${env} npm run reset-password -- -u user_1`) + const env = server.cliCommand.getEnv() + await CLICommand.exec(`echo coucou | ${env} npm run reset-password -- -u user_1`) await login(server.url, server.client, { username: 'user_1', password: 'coucou' }, HttpStatusCode.OK_200) }) diff --git a/server/tests/cli/update-host.ts b/server/tests/cli/update-host.ts index 2070f16f5..1b1a76aef 100644 --- a/server/tests/cli/update-host.ts +++ b/server/tests/cli/update-host.ts @@ -2,27 +2,26 @@ import 'mocha' import * as chai from 'chai' -import { VideoDetails } from '../../../shared/models/videos' -import { waitJobs } from '../../../shared/extra-utils/server/jobs' -import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments' import { addVideoChannel, cleanupTests, createUser, - execCLI, flushAndRunServer, - getEnvCli, getVideo, getVideoChannelsList, getVideosList, killallServers, makeActivityPubGetRequest, - parseTorrentVideo, reRunServer, + parseTorrentVideo, + reRunServer, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../../shared/extra-utils' +import { waitJobs } from '../../../shared/extra-utils/server/jobs' import { getAccountsList } from '../../../shared/extra-utils/users/accounts' +import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments' +import { VideoDetails } from '../../../shared/models/videos' const expect = chai.expect @@ -72,8 +71,7 @@ describe('Test update host scripts', function () { // Run server with standard configuration await reRunServer(server) - const env = getEnvCli(server) - await execCLI(`${env} npm run update-host`) + await server.cliCommand.execWithEnv(`npm run update-host`) }) it('Should have updated videos url', async function () { 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) }) }) -- 2.41.0