forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextensionBuildInstaller.ts
More file actions
77 lines (69 loc) · 3.71 KB
/
extensionBuildInstaller.ts
File metadata and controls
77 lines (69 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { inject, injectable, named } from 'inversify';
import { Uri } from 'vscode';
import { IApplicationShell, ICommandManager } from '../application/types';
import { Octicons, PVSC_EXTENSION_ID, STANDARD_OUTPUT_CHANNEL } from '../constants';
import { traceDecorators } from '../logger';
import { IFileSystem } from '../platform/types';
import { IFileDownloader, IOutputChannel } from '../types';
import { ExtensionChannels } from '../utils/localize';
import { IExtensionBuildInstaller } from './types';
export const developmentBuildUri = 'https://pvsc.blob.core.windows.net/extension-builds/ms-python-insiders.vsix';
export const vsixFileExtension = '.vsix';
@injectable()
export class StableBuildInstaller implements IExtensionBuildInstaller {
constructor(
@inject(IOutputChannel) @named(STANDARD_OUTPUT_CHANNEL) private readonly output: IOutputChannel,
@inject(ICommandManager) private readonly cmdManager: ICommandManager,
@inject(IApplicationShell) private readonly appShell: IApplicationShell,
) {}
@traceDecorators.error('Installing stable build of extension failed')
public async install(): Promise<void> {
this.output.append(ExtensionChannels.installingStableMessage());
await this.appShell.withProgressCustomIcon(Octicons.Installing, async (progress) => {
progress.report({ message: ExtensionChannels.installingStableMessage() });
return this.cmdManager.executeCommand('workbench.extensions.installExtension', PVSC_EXTENSION_ID, {
installOnlyNewlyAddedFromExtensionPackVSIX: true,
});
});
this.output.appendLine(ExtensionChannels.installationCompleteMessage());
}
}
@injectable()
export class InsidersBuildInstaller implements IExtensionBuildInstaller {
constructor(
@inject(IOutputChannel) @named(STANDARD_OUTPUT_CHANNEL) private readonly output: IOutputChannel,
@inject(IFileDownloader) private readonly fileDownloader: IFileDownloader,
@inject(IFileSystem) private readonly fs: IFileSystem,
@inject(ICommandManager) private readonly cmdManager: ICommandManager,
@inject(IApplicationShell) private readonly appShell: IApplicationShell,
) {}
@traceDecorators.error('Installing insiders build of extension failed')
public async install(): Promise<void> {
const vsixFilePath = await this.downloadInsiders();
this.output.append(ExtensionChannels.installingInsidersMessage());
await this.appShell.withProgressCustomIcon(Octicons.Installing, async (progress) => {
progress.report({ message: ExtensionChannels.installingInsidersMessage() });
return this.cmdManager.executeCommand('workbench.extensions.installExtension', Uri.file(vsixFilePath), {
installOnlyNewlyAddedFromExtensionPackVSIX: true,
});
});
this.output.appendLine(ExtensionChannels.installationCompleteMessage());
await this.fs.deleteFile(vsixFilePath);
}
@traceDecorators.error('Downloading insiders build of extension failed')
public async downloadInsiders(): Promise<string> {
this.output.appendLine(ExtensionChannels.startingDownloadOutputMessage());
const downloadOptions = {
extension: vsixFileExtension,
outputChannel: this.output,
progressMessagePrefix: ExtensionChannels.downloadingInsidersMessage(),
};
return this.fileDownloader.downloadFile(developmentBuildUri, downloadOptions).then((file) => {
this.output.appendLine(ExtensionChannels.downloadCompletedOutputMessage());
return file;
});
}
}