-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathSourcePathStep.ts
More file actions
59 lines (49 loc) · 2.64 KB
/
SourcePathStep.ts
File metadata and controls
59 lines (49 loc) · 2.64 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { AzureWizardPromptStep, type IAzureQuickPickItem } from '@microsoft/vscode-azext-utils';
import * as path from 'path';
import { browseItem } from '../../../../constants';
import { localize } from '../../../../utils/localize';
import { type BuildImageInAzureImageSourceContext } from './BuildImageInAzureImageSourceContext';
export class SourcePathStep extends AzureWizardPromptStep<BuildImageInAzureImageSourceContext> {
public async prompt(context: BuildImageInAzureImageSourceContext): Promise<void> {
const srcPath: string | undefined = (await context.ui.showQuickPick(this.getPicks(context), {
placeHolder: localize('sourceDirectoryPick', 'Choose your source code directory'),
suppressPersistence: true
})).data;
context.srcPath = srcPath ?? (await context.ui.showOpenDialog({
defaultUri: context.rootFolder?.uri,
canSelectFiles: false,
canSelectFolders: true
}))[0].fsPath;
}
public async configureBeforePrompt(context: BuildImageInAzureImageSourceContext): Promise<void> {
if (this.hasRootDockerfile(context)) {
context.srcPath = context.rootFolder.uri.fsPath;
}
}
public shouldPrompt(context: BuildImageInAzureImageSourceContext): boolean {
return !context.srcPath;
}
private getPicks(context: BuildImageInAzureImageSourceContext): IAzureQuickPickItem<string | undefined>[] {
const rootPath: string = context.rootFolder.uri.fsPath;
const directories: string[] = path.relative(rootPath, path.dirname(context.dockerfilePath)).split(path.sep);
const picks: IAzureQuickPickItem<string | undefined>[] = [{ label: '.' + path.sep, data: rootPath }];
let p: string = '';
for (const directory of directories) {
p += path.sep + directory;
picks.push({ label: '.' + p, data: rootPath + p });
}
picks.push(browseItem);
return picks;
}
private hasRootDockerfile(context: BuildImageInAzureImageSourceContext): boolean {
if (!context.rootFolder || !context.dockerfilePath) {
return false;
}
const rootPath: string = context.rootFolder.uri.fsPath;
return path.relative(rootPath, context.dockerfilePath) === path.basename(context.dockerfilePath);
}
}