(un)install multiple extensions at once

fixes #691
This commit is contained in:
Joao Moreno 2016-05-04 17:36:17 +02:00
parent ac7a5c5d9e
commit 93eb848846
2 changed files with 41 additions and 32 deletions

View file

@ -29,8 +29,8 @@ export interface ParsedArgs extends minimist.ParsedArgs {
debugBrkPluginHost: string; debugBrkPluginHost: string;
debugPluginHost: string; debugPluginHost: string;
'list-extensions': boolean; 'list-extensions': boolean;
'install-extension': string; 'install-extension': string | string[];
'uninstall-extension': string; 'uninstall-extension': string | string[];
} }
const options: minimist.Opts = { const options: minimist.Opts = {

View file

@ -6,6 +6,7 @@
import { localize } from 'vs/nls'; import { localize } from 'vs/nls';
import { ParsedArgs } from 'vs/code/node/argv'; import { ParsedArgs } from 'vs/code/node/argv';
import { TPromise } from 'vs/base/common/winjs.base'; import { TPromise } from 'vs/base/common/winjs.base';
import { sequence } from 'vs/base/common/async';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
@ -41,57 +42,65 @@ class Main {
if (argv['list-extensions']) { if (argv['list-extensions']) {
return this.listExtensions(); return this.listExtensions();
} else if (argv['install-extension']) { } else if (argv['install-extension']) {
return this.installExtension(argv['install-extension']); const arg = argv['install-extension'];
const ids: string[] = typeof arg === 'string' ? [arg] : arg;
return this.installExtension(ids);
} else if (argv['uninstall-extension']) { } else if (argv['uninstall-extension']) {
return this.uninstallExtension(argv['uninstall-extension']); const arg = argv['uninstall-extension'];
const ids: string[] = typeof arg === 'string' ? [arg] : arg;
return this.uninstallExtension(ids);
} }
} }
private listExtensions(): TPromise<any> { private listExtensions(): TPromise<any> {
return this.extensionManagementService.getInstalled().then(extensions => { return this.extensionManagementService.getInstalled().then(extensions => {
extensions.forEach(e => console.log(`${ e.displayName } (${ getExtensionId(e) })`)); extensions.forEach(e => console.log(getExtensionId(e)));
}); });
} }
private installExtension(id: string): TPromise<any> { private installExtension(ids: string[]): TPromise<any> {
return this.extensionGalleryService.query({ ids: [id] }).then(result => { return sequence(ids.map(id => () => {
const [extension] = result.firstPage; return this.extensionGalleryService.query({ ids: [id] }).then(result => {
const [extension] = result.firstPage;
if (!extension) { if (!extension) {
return TPromise.wrapError(`${ notFound(id) }\n${ useId }`); return TPromise.wrapError(`${ notFound(id) }\n${ useId }`);
}
return this.extensionManagementService.getInstalled().then(installed => {
const isInstalled = installed.some(e => getExtensionId(e) === id);
if (isInstalled) {
return TPromise.wrapError(localize('alreadyInstalled', "Extension '{0}' is already installed.", id));
} }
console.log(localize('foundExtension', "Found '{0}' in the marketplace.", id)); return this.extensionManagementService.getInstalled().then(installed => {
console.log(localize('installing', "Installing...")); const isInstalled = installed.some(e => getExtensionId(e) === id);
return this.extensionManagementService.install(extension).then(extension => { if (isInstalled) {
console.log(localize('successInstall', "Extension '{0}' v{1} was successfully installed!", id, extension.version)); return TPromise.wrapError(localize('alreadyInstalled', "Extension '{0}' is already installed.", id));
}
console.log(localize('foundExtension', "Found '{0}' in the marketplace.", id));
console.log(localize('installing', "Installing..."));
return this.extensionManagementService.install(extension).then(extension => {
console.log(localize('successInstall', "Extension '{0}' v{1} was successfully installed!", id, extension.version));
});
}); });
}); });
}); }));
} }
private uninstallExtension(id: string): TPromise<any> { private uninstallExtension(ids: string[]): TPromise<any> {
return this.extensionManagementService.getInstalled().then(installed => { return sequence(ids.map(id => () => {
const [extension] = installed.filter(e => getExtensionId(e) === id); return this.extensionManagementService.getInstalled().then(installed => {
const [extension] = installed.filter(e => getExtensionId(e) === id);
if (!extension) { if (!extension) {
return TPromise.wrapError(`${ notInstalled(id) }\n${ useId }`); return TPromise.wrapError(`${ notInstalled(id) }\n${ useId }`);
} }
console.log(localize('uninstalling', "Uninstalling {0}...", id)); console.log(localize('uninstalling', "Uninstalling {0}...", id));
return this.extensionManagementService.uninstall(extension).then(() => { return this.extensionManagementService.uninstall(extension).then(() => {
console.log(localize('successUninstall', "Extension '{0}' was successfully uninstalled!", id)); console.log(localize('successUninstall', "Extension '{0}' was successfully uninstalled!", id));
});
}); });
}); }));
} }
} }