mirror of https://github.com/Chocobozzz/PeerTube
CLI: plugins install command accept a --plugin-version parameter. (#4599)
* CLI: plugins install command accept a --plugin-version parameter. * Unit tests for plugins install --plugin-version. * Fix linting. * Styling Co-authored-by: Chocobozzz <me@florianbigard.com>pull/4606/head
parent
37cb07eae2
commit
3a1157a68a
|
@ -144,8 +144,13 @@ async function installPlugin (req: express.Request, res: express.Response) {
|
||||||
|
|
||||||
const fromDisk = !!body.path
|
const fromDisk = !!body.path
|
||||||
const toInstall = body.npmName || body.path
|
const toInstall = body.npmName || body.path
|
||||||
|
|
||||||
|
const pluginVersion = body.pluginVersion && body.npmName
|
||||||
|
? body.pluginVersion
|
||||||
|
: undefined
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const plugin = await PluginManager.Instance.install(toInstall, undefined, fromDisk)
|
const plugin = await PluginManager.Instance.install(toInstall, pluginVersion, fromDisk)
|
||||||
|
|
||||||
return res.json(plugin.toFormattedJSON())
|
return res.json(plugin.toFormattedJSON())
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
@ -116,6 +116,9 @@ const installOrUpdatePluginValidator = [
|
||||||
body('npmName')
|
body('npmName')
|
||||||
.optional()
|
.optional()
|
||||||
.custom(isNpmPluginNameValid).withMessage('Should have a valid npm name'),
|
.custom(isNpmPluginNameValid).withMessage('Should have a valid npm name'),
|
||||||
|
body('pluginVersion')
|
||||||
|
.optional()
|
||||||
|
.custom(isPluginVersionValid).withMessage('Should have a valid plugin version'),
|
||||||
body('path')
|
body('path')
|
||||||
.optional()
|
.optional()
|
||||||
.custom(isSafePath).withMessage('Should have a valid safe path'),
|
.custom(isSafePath).withMessage('Should have a valid safe path'),
|
||||||
|
@ -129,6 +132,9 @@ const installOrUpdatePluginValidator = [
|
||||||
if (!body.path && !body.npmName) {
|
if (!body.path && !body.npmName) {
|
||||||
return res.fail({ message: 'Should have either a npmName or a path' })
|
return res.fail({ message: 'Should have either a npmName or a path' })
|
||||||
}
|
}
|
||||||
|
if (body.pluginVersion && !body.npmName) {
|
||||||
|
return res.fail({ message: 'Should have a npmName when specifying a pluginVersion' })
|
||||||
|
}
|
||||||
|
|
||||||
return next()
|
return next()
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,6 +207,25 @@ describe('Test CLI wrapper', function () {
|
||||||
|
|
||||||
expect(res).to.not.contain('peertube-plugin-hello-world')
|
expect(res).to.not.contain('peertube-plugin-hello-world')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Should install a plugin in requested version', async function () {
|
||||||
|
this.timeout(60000)
|
||||||
|
|
||||||
|
await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world --plugin-version 0.0.17`)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should list installed plugins, in correct version', async function () {
|
||||||
|
const res = await cliCommand.execWithEnv(`${cmd} plugins list`)
|
||||||
|
|
||||||
|
expect(res).to.contain('peertube-plugin-hello-world')
|
||||||
|
expect(res).to.contain('0.0.17')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should uninstall the plugin again', async function () {
|
||||||
|
const res = await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
|
||||||
|
|
||||||
|
expect(res).to.not.contain('peertube-plugin-hello-world')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Manage video redundancies', function () {
|
describe('Manage video redundancies', function () {
|
||||||
|
|
|
@ -31,6 +31,7 @@ program
|
||||||
.option('-p, --password <token>', 'Password')
|
.option('-p, --password <token>', 'Password')
|
||||||
.option('-P --path <path>', 'Install from a path')
|
.option('-P --path <path>', 'Install from a path')
|
||||||
.option('-n, --npm-name <npmName>', 'Install from npm')
|
.option('-n, --npm-name <npmName>', 'Install from npm')
|
||||||
|
.option('--plugin-version <pluginVersion>', 'Specify the plugin version to install (only available when installing from npm)')
|
||||||
.action((options, command) => installPluginCLI(command, options))
|
.action((options, command) => installPluginCLI(command, options))
|
||||||
|
|
||||||
program
|
program
|
||||||
|
@ -109,7 +110,7 @@ async function installPluginCLI (command: Command, options: OptionValues) {
|
||||||
await assignToken(server, username, password)
|
await assignToken(server, username, password)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await server.plugins.install({ npmName: options.npmName, path: options.path })
|
await server.plugins.install({ npmName: options.npmName, path: options.path, pluginVersion: options.pluginVersion })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Cannot install plugin.', err)
|
console.error('Cannot install plugin.', err)
|
||||||
process.exit(-1)
|
process.exit(-1)
|
||||||
|
|
|
@ -158,15 +158,16 @@ export class PluginsCommand extends AbstractCommand {
|
||||||
install (options: OverrideCommandOptions & {
|
install (options: OverrideCommandOptions & {
|
||||||
path?: string
|
path?: string
|
||||||
npmName?: string
|
npmName?: string
|
||||||
|
pluginVersion?: string
|
||||||
}) {
|
}) {
|
||||||
const { npmName, path } = options
|
const { npmName, path, pluginVersion } = options
|
||||||
const apiPath = '/api/v1/plugins/install'
|
const apiPath = '/api/v1/plugins/install'
|
||||||
|
|
||||||
return this.postBodyRequest({
|
return this.postBodyRequest({
|
||||||
...options,
|
...options,
|
||||||
|
|
||||||
path: apiPath,
|
path: apiPath,
|
||||||
fields: { npmName, path },
|
fields: { npmName, path, pluginVersion },
|
||||||
implicitToken: true,
|
implicitToken: true,
|
||||||
defaultExpectedStatus: HttpStatusCode.OK_200
|
defaultExpectedStatus: HttpStatusCode.OK_200
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
export interface InstallOrUpdatePlugin {
|
export interface InstallOrUpdatePlugin {
|
||||||
npmName?: string
|
npmName?: string
|
||||||
|
pluginVersion?: string
|
||||||
path?: string
|
path?: string
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue