-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathSourcePathStep.ts
More file actions
50 lines (41 loc) · 2.32 KB
/
SourcePathStep.ts
File metadata and controls
50 lines (41 loc) · 2.32 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { AzureWizardPromptStep } 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> {
await context.ui.showQuickPick([browseItem], {
placeHolder: localize('sourceDirectoryPick', 'Choose your source code directory')
});
context.srcPath = (await context.ui.showOpenDialog({
defaultUri: context.rootFolder?.uri,
canSelectFiles: false,
canSelectFolders: true
}))[0].fsPath;
context.telemetry.properties.sourceDepth = String(this.getRelativePathDepthFromRoot(context.srcPath));
}
public async configureBeforePrompt(context: BuildImageInAzureImageSourceContext): Promise<void> {
if (context.srcPath) {
context.telemetry.properties.sourceDepth = String(this.getRelativePathDepthFromRoot(context.srcPath));
}
}
public shouldPrompt(context: BuildImageInAzureImageSourceContext): boolean {
return !context.srcPath && !this.hasRootDockerfile(context);
}
// If a provided dockerfile is not at the project root, we need to acquire the project's source context
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);
}
private getRelativePathDepthFromRoot(relativePath: string): number {
return relativePath === '.' ? 0 : relativePath.split(path.sep).length;
}
}