diff options
author | Chocobozzz <me@florianbigard.com> | 2019-07-12 11:39:58 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-07-24 10:58:16 +0200 |
commit | b5f919ac8eb2a1c20e26582fdfd377d687710d8f (patch) | |
tree | 5ec28be6f750f54bba560803ddba681103c2d82e /server/tools/peertube-plugins.ts | |
parent | 8d2be0ed7bb87283a1ec98609df6b82d83db706a (diff) | |
download | PeerTube-b5f919ac8eb2a1c20e26582fdfd377d687710d8f.tar.gz PeerTube-b5f919ac8eb2a1c20e26582fdfd377d687710d8f.tar.zst PeerTube-b5f919ac8eb2a1c20e26582fdfd377d687710d8f.zip |
WIP plugins: update plugin
Diffstat (limited to 'server/tools/peertube-plugins.ts')
-rw-r--r-- | server/tools/peertube-plugins.ts | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/server/tools/peertube-plugins.ts b/server/tools/peertube-plugins.ts index d5e024383..10cff7dd7 100644 --- a/server/tools/peertube-plugins.ts +++ b/server/tools/peertube-plugins.ts | |||
@@ -2,7 +2,7 @@ import * as program from 'commander' | |||
2 | import { PluginType } from '../../shared/models/plugins/plugin.type' | 2 | import { PluginType } from '../../shared/models/plugins/plugin.type' |
3 | import { getAccessToken } from '../../shared/extra-utils/users/login' | 3 | import { getAccessToken } from '../../shared/extra-utils/users/login' |
4 | import { getMyUserInformation } from '../../shared/extra-utils/users/users' | 4 | import { getMyUserInformation } from '../../shared/extra-utils/users/users' |
5 | import { installPlugin, listPlugins, uninstallPlugin } from '../../shared/extra-utils/server/plugins' | 5 | import { installPlugin, listPlugins, uninstallPlugin, updatePlugin } from '../../shared/extra-utils/server/plugins' |
6 | import { getServerCredentials } from './cli' | 6 | import { getServerCredentials } from './cli' |
7 | import { User, UserRole } from '../../shared/models/users' | 7 | import { User, UserRole } from '../../shared/models/users' |
8 | import { PeerTubePlugin } from '../../shared/models/plugins/peertube-plugin.model' | 8 | import { PeerTubePlugin } from '../../shared/models/plugins/peertube-plugin.model' |
@@ -35,6 +35,16 @@ program | |||
35 | .action((options) => installPluginCLI(options)) | 35 | .action((options) => installPluginCLI(options)) |
36 | 36 | ||
37 | program | 37 | program |
38 | .command('update') | ||
39 | .description('Update a plugin or a theme') | ||
40 | .option('-u, --url <url>', 'Server url') | ||
41 | .option('-U, --username <username>', 'Username') | ||
42 | .option('-p, --password <token>', 'Password') | ||
43 | .option('-P --path <path>', 'Update from a path') | ||
44 | .option('-n, --npm-name <npmName>', 'Update from npm') | ||
45 | .action((options) => updatePluginCLI(options)) | ||
46 | |||
47 | program | ||
38 | .command('uninstall') | 48 | .command('uninstall') |
39 | .description('Uninstall a plugin or a theme') | 49 | .description('Uninstall a plugin or a theme') |
40 | .option('-u, --url <url>', 'Server url') | 50 | .option('-u, --url <url>', 'Server url') |
@@ -122,6 +132,38 @@ async function installPluginCLI (options: any) { | |||
122 | process.exit(0) | 132 | process.exit(0) |
123 | } | 133 | } |
124 | 134 | ||
135 | async function updatePluginCLI (options: any) { | ||
136 | if (!options['path'] && !options['npmName']) { | ||
137 | console.error('You need to specify the npm name or the path of the plugin you want to update.\n') | ||
138 | program.outputHelp() | ||
139 | process.exit(-1) | ||
140 | } | ||
141 | |||
142 | if (options['path'] && !isAbsolute(options['path'])) { | ||
143 | console.error('Path should be absolute.') | ||
144 | process.exit(-1) | ||
145 | } | ||
146 | |||
147 | const { url, username, password } = await getServerCredentials(options) | ||
148 | const accessToken = await getAdminTokenOrDie(url, username, password) | ||
149 | |||
150 | try { | ||
151 | await updatePlugin({ | ||
152 | url, | ||
153 | accessToken, | ||
154 | npmName: options['npmName'], | ||
155 | path: options['path'] | ||
156 | }) | ||
157 | } catch (err) { | ||
158 | console.error('Cannot update plugin.', err) | ||
159 | process.exit(-1) | ||
160 | return | ||
161 | } | ||
162 | |||
163 | console.log('Plugin updated.') | ||
164 | process.exit(0) | ||
165 | } | ||
166 | |||
125 | async function uninstallPluginCLI (options: any) { | 167 | async function uninstallPluginCLI (options: any) { |
126 | if (!options['npmName']) { | 168 | if (!options['npmName']) { |
127 | console.error('You need to specify the npm name of the plugin/theme you want to uninstall.\n') | 169 | console.error('You need to specify the npm name of the plugin/theme you want to uninstall.\n') |