diff options
Diffstat (limited to 'server/tools/peertube-plugins.ts')
-rw-r--r-- | server/tools/peertube-plugins.ts | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/server/tools/peertube-plugins.ts b/server/tools/peertube-plugins.ts index 05b75fab2..08e8cd713 100644 --- a/server/tools/peertube-plugins.ts +++ b/server/tools/peertube-plugins.ts | |||
@@ -10,6 +10,7 @@ import { getAdminTokenOrDie, getServerCredentials } from './cli' | |||
10 | import { PeerTubePlugin } from '../../shared/models/plugins/peertube-plugin.model' | 10 | import { PeerTubePlugin } from '../../shared/models/plugins/peertube-plugin.model' |
11 | import { isAbsolute } from 'path' | 11 | import { isAbsolute } from 'path' |
12 | import * as CliTable3 from 'cli-table3' | 12 | import * as CliTable3 from 'cli-table3' |
13 | import commander = require('commander') | ||
13 | 14 | ||
14 | program | 15 | program |
15 | .name('plugins') | 16 | .name('plugins') |
@@ -33,7 +34,7 @@ program | |||
33 | .option('-p, --password <token>', 'Password') | 34 | .option('-p, --password <token>', 'Password') |
34 | .option('-P --path <path>', 'Install from a path') | 35 | .option('-P --path <path>', 'Install from a path') |
35 | .option('-n, --npm-name <npmName>', 'Install from npm') | 36 | .option('-n, --npm-name <npmName>', 'Install from npm') |
36 | .action((options) => installPluginCLI(options)) | 37 | .action((options, command) => installPluginCLI(command, options)) |
37 | 38 | ||
38 | program | 39 | program |
39 | .command('update') | 40 | .command('update') |
@@ -43,7 +44,7 @@ program | |||
43 | .option('-p, --password <token>', 'Password') | 44 | .option('-p, --password <token>', 'Password') |
44 | .option('-P --path <path>', 'Update from a path') | 45 | .option('-P --path <path>', 'Update from a path') |
45 | .option('-n, --npm-name <npmName>', 'Update from npm') | 46 | .option('-n, --npm-name <npmName>', 'Update from npm') |
46 | .action((options) => updatePluginCLI(options)) | 47 | .action((options, command) => updatePluginCLI(command, options)) |
47 | 48 | ||
48 | program | 49 | program |
49 | .command('uninstall') | 50 | .command('uninstall') |
@@ -52,7 +53,7 @@ program | |||
52 | .option('-U, --username <username>', 'Username') | 53 | .option('-U, --username <username>', 'Username') |
53 | .option('-p, --password <token>', 'Password') | 54 | .option('-p, --password <token>', 'Password') |
54 | .option('-n, --npm-name <npmName>', 'NPM plugin/theme name') | 55 | .option('-n, --npm-name <npmName>', 'NPM plugin/theme name') |
55 | .action(options => uninstallPluginCLI(options)) | 56 | .action((options, command) => uninstallPluginCLI(command, options)) |
56 | 57 | ||
57 | if (!process.argv.slice(2).length) { | 58 | if (!process.argv.slice(2).length) { |
58 | program.outputHelp() | 59 | program.outputHelp() |
@@ -60,6 +61,8 @@ if (!process.argv.slice(2).length) { | |||
60 | 61 | ||
61 | program.parse(process.argv) | 62 | program.parse(process.argv) |
62 | 63 | ||
64 | const options = program.opts() | ||
65 | |||
63 | // ---------------------------------------------------------------------------- | 66 | // ---------------------------------------------------------------------------- |
64 | 67 | ||
65 | async function pluginsListCLI () { | 68 | async function pluginsListCLI () { |
@@ -67,8 +70,8 @@ async function pluginsListCLI () { | |||
67 | const accessToken = await getAdminTokenOrDie(url, username, password) | 70 | const accessToken = await getAdminTokenOrDie(url, username, password) |
68 | 71 | ||
69 | let pluginType: PluginType | 72 | let pluginType: PluginType |
70 | if (program['onlyThemes']) pluginType = PluginType.THEME | 73 | if (options.onlyThemes) pluginType = PluginType.THEME |
71 | if (program['onlyPlugins']) pluginType = PluginType.PLUGIN | 74 | if (options.onlyPlugins) pluginType = PluginType.PLUGIN |
72 | 75 | ||
73 | const res = await listPlugins({ | 76 | const res = await listPlugins({ |
74 | url, | 77 | url, |
@@ -101,27 +104,27 @@ async function pluginsListCLI () { | |||
101 | process.exit(0) | 104 | process.exit(0) |
102 | } | 105 | } |
103 | 106 | ||
104 | async function installPluginCLI (options: any) { | 107 | async function installPluginCLI (command: commander.CommanderStatic, options: commander.OptionValues) { |
105 | if (!options['path'] && !options['npmName']) { | 108 | if (!options.path && !options.npmName) { |
106 | console.error('You need to specify the npm name or the path of the plugin you want to install.\n') | 109 | console.error('You need to specify the npm name or the path of the plugin you want to install.\n') |
107 | program.outputHelp() | 110 | program.outputHelp() |
108 | process.exit(-1) | 111 | process.exit(-1) |
109 | } | 112 | } |
110 | 113 | ||
111 | if (options['path'] && !isAbsolute(options['path'])) { | 114 | if (options.path && !isAbsolute(options.path)) { |
112 | console.error('Path should be absolute.') | 115 | console.error('Path should be absolute.') |
113 | process.exit(-1) | 116 | process.exit(-1) |
114 | } | 117 | } |
115 | 118 | ||
116 | const { url, username, password } = await getServerCredentials(options) | 119 | const { url, username, password } = await getServerCredentials(command) |
117 | const accessToken = await getAdminTokenOrDie(url, username, password) | 120 | const accessToken = await getAdminTokenOrDie(url, username, password) |
118 | 121 | ||
119 | try { | 122 | try { |
120 | await installPlugin({ | 123 | await installPlugin({ |
121 | url, | 124 | url, |
122 | accessToken, | 125 | accessToken, |
123 | npmName: options['npmName'], | 126 | npmName: options.npmName, |
124 | path: options['path'] | 127 | path: options.path |
125 | }) | 128 | }) |
126 | } catch (err) { | 129 | } catch (err) { |
127 | console.error('Cannot install plugin.', err) | 130 | console.error('Cannot install plugin.', err) |
@@ -132,27 +135,27 @@ async function installPluginCLI (options: any) { | |||
132 | process.exit(0) | 135 | process.exit(0) |
133 | } | 136 | } |
134 | 137 | ||
135 | async function updatePluginCLI (options: any) { | 138 | async function updatePluginCLI (command: commander.CommanderStatic, options: commander.OptionValues) { |
136 | if (!options['path'] && !options['npmName']) { | 139 | 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') | 140 | console.error('You need to specify the npm name or the path of the plugin you want to update.\n') |
138 | program.outputHelp() | 141 | program.outputHelp() |
139 | process.exit(-1) | 142 | process.exit(-1) |
140 | } | 143 | } |
141 | 144 | ||
142 | if (options['path'] && !isAbsolute(options['path'])) { | 145 | if (options.path && !isAbsolute(options.path)) { |
143 | console.error('Path should be absolute.') | 146 | console.error('Path should be absolute.') |
144 | process.exit(-1) | 147 | process.exit(-1) |
145 | } | 148 | } |
146 | 149 | ||
147 | const { url, username, password } = await getServerCredentials(options) | 150 | const { url, username, password } = await getServerCredentials(command) |
148 | const accessToken = await getAdminTokenOrDie(url, username, password) | 151 | const accessToken = await getAdminTokenOrDie(url, username, password) |
149 | 152 | ||
150 | try { | 153 | try { |
151 | await updatePlugin({ | 154 | await updatePlugin({ |
152 | url, | 155 | url, |
153 | accessToken, | 156 | accessToken, |
154 | npmName: options['npmName'], | 157 | npmName: options.npmName, |
155 | path: options['path'] | 158 | path: options.path |
156 | }) | 159 | }) |
157 | } catch (err) { | 160 | } catch (err) { |
158 | console.error('Cannot update plugin.', err) | 161 | console.error('Cannot update plugin.', err) |
@@ -163,21 +166,21 @@ async function updatePluginCLI (options: any) { | |||
163 | process.exit(0) | 166 | process.exit(0) |
164 | } | 167 | } |
165 | 168 | ||
166 | async function uninstallPluginCLI (options: any) { | 169 | async function uninstallPluginCLI (command: commander.CommanderStatic, options: commander.OptionValues) { |
167 | if (!options['npmName']) { | 170 | if (!options.npmName) { |
168 | console.error('You need to specify the npm name of the plugin/theme you want to uninstall.\n') | 171 | console.error('You need to specify the npm name of the plugin/theme you want to uninstall.\n') |
169 | program.outputHelp() | 172 | program.outputHelp() |
170 | process.exit(-1) | 173 | process.exit(-1) |
171 | } | 174 | } |
172 | 175 | ||
173 | const { url, username, password } = await getServerCredentials(options) | 176 | const { url, username, password } = await getServerCredentials(command) |
174 | const accessToken = await getAdminTokenOrDie(url, username, password) | 177 | const accessToken = await getAdminTokenOrDie(url, username, password) |
175 | 178 | ||
176 | try { | 179 | try { |
177 | await uninstallPlugin({ | 180 | await uninstallPlugin({ |
178 | url, | 181 | url, |
179 | accessToken, | 182 | accessToken, |
180 | npmName: options['npmName'] | 183 | npmName: options.npmName |
181 | }) | 184 | }) |
182 | } catch (err) { | 185 | } catch (err) { |
183 | console.error('Cannot uninstall plugin.', err) | 186 | console.error('Cannot uninstall plugin.', err) |