mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-27 05:37:45 +00:00
@@ -9,7 +9,6 @@ import pkg from 'vs/platform/node/package';
|
||||
import * as path from 'path';
|
||||
import * as semver from 'semver';
|
||||
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { sequence } from 'vs/base/common/async';
|
||||
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
|
||||
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
|
||||
@@ -63,7 +62,7 @@ export function getIdAndVersion(id: string): [string, string] {
|
||||
}
|
||||
|
||||
|
||||
type Task = { (): TPromise<void> };
|
||||
type Task = { (): Thenable<void> };
|
||||
|
||||
class Main {
|
||||
|
||||
@@ -73,41 +72,40 @@ class Main {
|
||||
@IExtensionGalleryService private extensionGalleryService: IExtensionGalleryService
|
||||
) { }
|
||||
|
||||
run(argv: ParsedArgs): TPromise<any> {
|
||||
// TODO@joao - make this contributable
|
||||
|
||||
let returnPromise: TPromise<any>;
|
||||
async run(argv: ParsedArgs): Promise<any> {
|
||||
if (argv['install-source']) {
|
||||
returnPromise = this.setInstallSource(argv['install-source']);
|
||||
await this.setInstallSource(argv['install-source']);
|
||||
|
||||
} else if (argv['list-extensions']) {
|
||||
returnPromise = this.listExtensions(argv['show-versions']);
|
||||
await this.listExtensions(argv['show-versions']);
|
||||
|
||||
} else if (argv['install-extension']) {
|
||||
const arg = argv['install-extension'];
|
||||
const args: string[] = typeof arg === 'string' ? [arg] : arg;
|
||||
returnPromise = this.installExtension(args, argv['force']);
|
||||
await this.installExtension(args, argv['force']);
|
||||
|
||||
} else if (argv['uninstall-extension']) {
|
||||
const arg = argv['uninstall-extension'];
|
||||
const ids: string[] = typeof arg === 'string' ? [arg] : arg;
|
||||
returnPromise = this.uninstallExtension(ids);
|
||||
await this.uninstallExtension(ids);
|
||||
}
|
||||
return returnPromise || TPromise.as(null);
|
||||
}
|
||||
|
||||
private setInstallSource(installSource: string): TPromise<any> {
|
||||
private setInstallSource(installSource: string): Promise<any> {
|
||||
return writeFile(this.environmentService.installSourcePath, installSource.slice(0, 30));
|
||||
}
|
||||
|
||||
private listExtensions(showVersions: boolean): TPromise<any> {
|
||||
return this.extensionManagementService.getInstalled(LocalExtensionType.User).then(extensions => {
|
||||
extensions.forEach(e => console.log(getId(e.manifest, showVersions)));
|
||||
});
|
||||
private async listExtensions(showVersions: boolean): Promise<any> {
|
||||
const extensions = await this.extensionManagementService.getInstalled(LocalExtensionType.User);
|
||||
extensions.forEach(e => console.log(getId(e.manifest, showVersions)));
|
||||
}
|
||||
|
||||
private installExtension(extensions: string[], force: boolean): TPromise<any> {
|
||||
private installExtension(extensions: string[], force: boolean): Promise<any> {
|
||||
const vsixTasks: Task[] = extensions
|
||||
.filter(e => /\.vsix$/i.test(e))
|
||||
.map(id => () => {
|
||||
const extension = path.isAbsolute(id) ? id : path.join(process.cwd(), id);
|
||||
|
||||
return this.validate(extension, force)
|
||||
.then(valid => {
|
||||
if (valid) {
|
||||
@@ -118,7 +116,7 @@ class Main {
|
||||
console.log(localize('cancelVsixInstall', "Cancelled installing Extension '{0}'.", getBaseLabel(extension)));
|
||||
return null;
|
||||
} else {
|
||||
return TPromise.wrapError(error);
|
||||
return Promise.reject(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -136,16 +134,16 @@ class Main {
|
||||
if (err.responseText) {
|
||||
try {
|
||||
const response = JSON.parse(err.responseText);
|
||||
return TPromise.wrapError(response.message);
|
||||
return Promise.reject(response.message);
|
||||
} catch (e) {
|
||||
// noop
|
||||
}
|
||||
}
|
||||
return TPromise.wrapError(err);
|
||||
return Promise.reject(err);
|
||||
})
|
||||
.then(extension => {
|
||||
if (!extension) {
|
||||
return TPromise.wrapError(new Error(`${notFound(version ? `${id}@${version}` : id)}\n${useId}`));
|
||||
return Promise.reject(new Error(`${notFound(version ? `${id}@${version}` : id)}\n${useId}`));
|
||||
}
|
||||
|
||||
const [installedExtension] = installed.filter(e => areSameExtensions({ id: getGalleryExtensionIdFromLocal(e) }, { id }));
|
||||
@@ -160,7 +158,7 @@ class Main {
|
||||
}
|
||||
} else {
|
||||
console.log(localize('alreadyInstalled', "Extension '{0}' is already installed.", version ? `${id}@${version}` : id));
|
||||
return TPromise.as(null);
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
} else {
|
||||
console.log(localize('foundExtension', "Found '{0}' in the marketplace.", id));
|
||||
@@ -173,42 +171,41 @@ class Main {
|
||||
return sequence([...vsixTasks, ...galleryTasks]);
|
||||
}
|
||||
|
||||
private validate(vsix: string, force: boolean): Thenable<boolean> {
|
||||
return getManifest(vsix)
|
||||
.then(manifest => {
|
||||
if (manifest) {
|
||||
const extensionIdentifier = { id: getGalleryExtensionId(manifest.publisher, manifest.name) };
|
||||
return this.extensionManagementService.getInstalled(LocalExtensionType.User)
|
||||
.then(installedExtensions => {
|
||||
const newer = installedExtensions.filter(local => areSameExtensions(extensionIdentifier, { id: getGalleryExtensionIdFromLocal(local) }) && semver.gt(local.manifest.version, manifest.version))[0];
|
||||
if (newer && !force) {
|
||||
console.log(localize('forceDowngrade', "A newer version of this extension '{0}' v{1} is already installed. Use '--force' option to downgrade to older version.", newer.galleryIdentifier.id, newer.manifest.version, manifest.version));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
} else {
|
||||
return Promise.reject(new Error('Invalid vsix'));
|
||||
}
|
||||
});
|
||||
private async validate(vsix: string, force: boolean): Promise<boolean> {
|
||||
const manifest = await getManifest(vsix);
|
||||
|
||||
if (!manifest) {
|
||||
throw new Error('Invalid vsix');
|
||||
}
|
||||
|
||||
const extensionIdentifier = { id: getGalleryExtensionId(manifest.publisher, manifest.name) };
|
||||
const installedExtensions = await this.extensionManagementService.getInstalled(LocalExtensionType.User);
|
||||
const newer = installedExtensions.filter(local => areSameExtensions(extensionIdentifier, { id: getGalleryExtensionIdFromLocal(local) }) && semver.gt(local.manifest.version, manifest.version))[0];
|
||||
|
||||
if (newer && !force) {
|
||||
console.log(localize('forceDowngrade', "A newer version of this extension '{0}' v{1} is already installed. Use '--force' option to downgrade to older version.", newer.galleryIdentifier.id, newer.manifest.version, manifest.version));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private installFromGallery(id: string, extension: IGalleryExtension): TPromise<void> {
|
||||
private async installFromGallery(id: string, extension: IGalleryExtension): Promise<void> {
|
||||
console.log(localize('installing', "Installing..."));
|
||||
return this.extensionManagementService.installFromGallery(extension)
|
||||
.then(
|
||||
() => console.log(localize('successInstall', "Extension '{0}' v{1} was successfully installed!", id, extension.version)),
|
||||
error => {
|
||||
if (isPromiseCanceledError(error)) {
|
||||
console.log(localize('cancelVsixInstall', "Cancelled installing Extension '{0}'.", id));
|
||||
return null;
|
||||
} else {
|
||||
return TPromise.wrapError(error);
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
await this.extensionManagementService.installFromGallery(extension);
|
||||
console.log(localize('successInstall', "Extension '{0}' v{1} was successfully installed!", id, extension.version));
|
||||
} catch (error) {
|
||||
if (isPromiseCanceledError(error)) {
|
||||
console.log(localize('cancelVsixInstall', "Cancelled installing Extension '{0}'.", id));
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private uninstallExtension(extensions: string[]): TPromise<any> {
|
||||
private uninstallExtension(extensions: string[]): Thenable<any> {
|
||||
async function getExtensionId(extensionDescription: string): Promise<string> {
|
||||
if (!/\.vsix$/i.test(extensionDescription)) {
|
||||
return extensionDescription;
|
||||
@@ -225,7 +222,7 @@ class Main {
|
||||
const [extension] = installed.filter(e => areSameExtensions({ id: getGalleryExtensionIdFromLocal(e) }, { id }));
|
||||
|
||||
if (!extension) {
|
||||
return TPromise.wrapError(new Error(`${notInstalled(id)}\n${useId}`));
|
||||
return Promise.reject(new Error(`${notInstalled(id)}\n${useId}`));
|
||||
}
|
||||
|
||||
console.log(localize('uninstalling', "Uninstalling {0}...", id));
|
||||
@@ -240,7 +237,7 @@ class Main {
|
||||
|
||||
const eventPrefix = 'monacoworkbench';
|
||||
|
||||
export function main(argv: ParsedArgs): TPromise<void> {
|
||||
export function main(argv: ParsedArgs): Promise<void> {
|
||||
const services = new ServiceCollection();
|
||||
|
||||
const environmentService = new EnvironmentService(argv, process.execPath);
|
||||
@@ -259,7 +256,7 @@ export function main(argv: ParsedArgs): TPromise<void> {
|
||||
const envService = accessor.get(IEnvironmentService);
|
||||
const stateService = accessor.get(IStateService);
|
||||
|
||||
return TPromise.join([envService.appSettingsHome, envService.extensionsPath].map(p => mkdirp(p))).then(() => {
|
||||
return Promise.all([envService.appSettingsHome, envService.extensionsPath].map(p => mkdirp(p))).then(() => {
|
||||
const { appRoot, extensionsPath, extensionDevelopmentLocationURI, isBuilt, installSourcePath } = envService;
|
||||
|
||||
const services = new ServiceCollection();
|
||||
|
||||
Reference in New Issue
Block a user