Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@
},
"enablement": "!virtualWorkspace"
},
{
"command": "azureFunctions.createNewProjectWithDockerfile",
"title": "%azureFunctions.createNewProjectWithDockerfile%",
"category": "Azure Functions",
"enablement": "!virtualWorkspace"
},
{
"command": "azureFunctions.createSlot",
"title": "%azureFunctions.createSlot%",
Expand Down Expand Up @@ -381,6 +387,10 @@
"command": "azureFunctions.createNewProject",
"group": "1_projects@2"
},
{
"command": "azureFunctions.createNewProjectWithDockerfile",
"group": "1_projects@3"
},
{
"command": "azureFunctions.deploy",
"group": "2_deploy@1"
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"azureFunctions.createFunctionAppAdvanced": "Create Function App in Azure... (Advanced)",
"azureFunctions.createFunctionAppDetail": "For serverless, event driven apps and automation.",
"azureFunctions.createNewProject": "Create New Project...",
"azureFunctions.createNewProjectWithDockerfile": "Create New Project With Dockerfile...",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should call it Create New Containerized Project...?

I don't have a strong preference, but the learn document does refer to it as a containerized function app.

https://learn.microsoft.com/en-us/azure/azure-functions/functions-deploy-container?tabs=acr%2Cbash%2Cazure-cli&pivots=programming-language-javascript

"azureFunctions.createPythonVenv": "Create a virtual environment when creating a new Python project.",
"azureFunctions.createSlot": "Create Slot...",
"azureFunctions.createServiceConnector": "Create connection...",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { ext } from "@microsoft/vscode-azext-serviceconnector";
import { AzureWizardExecuteStep, UserCancelledError, nonNullValueAndProp } from "@microsoft/vscode-azext-utils";
import { validateFuncCoreToolsInstalled } from "../../../funcCoreTools/validateFuncCoreToolsInstalled";
import { localize } from "../../../localize";
import { cpUtils } from "../../../utils/cpUtils";
import { type IDockerfileProjectContext } from "./IDockerfileProjectContext";

export class CreateDockerfileProjectStep extends AzureWizardExecuteStep<IDockerfileProjectContext>{
public priority: number = 100;

public async execute(context: IDockerfileProjectContext): Promise<void> {
const message: string = localize('installFuncTools', 'You must have the Azure Functions Core Tools installed to run this command.');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mentioned this in another PR, but you should front-load this error. Nothing more annoying than going through a project wizard and then having it fail right at the end.

if (!await validateFuncCoreToolsInstalled(context, message, context.workspacePath)) {
throw new UserCancelledError('validateFuncCoreToolsInstalled');
}

await cpUtils.executeCommand(ext.outputChannel, nonNullValueAndProp(context, 'projectPath'), "func", "init", "--worker-runtime", nonNullValueAndProp(context, 'projectLanguage'), "--docker");
}

public shouldExecute(): boolean {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*---------------------------------------------------------------------------------------------
* 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 { ProjectLanguage } from "../../../constants";
import { type IDockerfileProjectContext } from "./IDockerfileProjectContext";

export class DockerfileProjectLanguageStep extends AzureWizardPromptStep<IDockerfileProjectContext> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could probably just use the NewProjectLanguageStep and add some filtering in the case for DockerfileProjectLanguageStep instead of creating a new file that does largely the same thing.

Copy link
Copy Markdown
Contributor Author

@motm32 motm32 Dec 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did think about that but the data property in the NewProjectLanguageStep does not match up with the data property I need. I can utilize language: ProjectLanguage property that you commented about above but will probably still need the new step since the data is different.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually update since I am not using the NewProjectLanguageStep I don't think I can use the language: ProjectLanguage since the data types don't match up.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah but you should be able to just change the type instead of using a string.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this more, I think we should just speak offline about this.

public async prompt(context: IDockerfileProjectContext): Promise<void> {
const language: IAzureQuickPickItem<string>[] = [
{ label: ProjectLanguage.JavaScript, data: 'node' },
Comment thread
MicroFish91 marked this conversation as resolved.
Outdated
{ label: ProjectLanguage.TypeScript, data: 'typescript' },
{ label: ProjectLanguage.Python, data: 'python' },
{ label: ProjectLanguage.CSharp, data: 'csharp' },
{ label: ProjectLanguage.PowerShell, data: 'powershell' },
];

context.projectLanguage = (await context.ui.showQuickPick(language, { placeHolder: 'Select a language' })).data;
}

public shouldPrompt(context: IDockerfileProjectContext): boolean {
return !context.projectLanguage;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { type ExecuteActivityContext, type IActionContext } from "@microsoft/vscode-azext-utils";
import { type IProjectWizardContext } from "../IProjectWizardContext";

export interface IDockerfileProjectContext extends IActionContext, ExecuteActivityContext, IProjectWizardContext {
projectLanguage?: string;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IProjectWizardContext already should have a language: ProjectLanguage property that you should be able to leverage.

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { AzureWizard, type IActionContext } from "@microsoft/vscode-azext-utils";
import { localize } from "../../../localize";
import { createActivityContext } from "../../../utils/activityUtils";
import { FolderListStep } from "../FolderListStep";
import { type IProjectWizardContext } from "../IProjectWizardContext";
import { OpenBehaviorStep } from "../OpenBehaviorStep";
import { OpenFolderStep } from "../OpenFolderStep";
import { CreateDockerfileProjectStep } from "./CreateDockerfileProjectStep";
import { DockerfileProjectLanguageStep } from "./DockefileProjectLanguageStep";
import { type IDockerfileProjectContext } from "./IDockerfileProjectContext";

export async function createNewProjectWithDockerfile(context: IActionContext): Promise<void> {
const wizardContext: Partial<IDockerfileProjectContext> & Partial<IProjectWizardContext> & IActionContext = {
...context,
...(await createActivityContext())
}

const wizard: AzureWizard<IDockerfileProjectContext> = new AzureWizard(wizardContext, {
title: localize('createNewProject', 'Create new project with dockerfile'),
promptSteps: [new FolderListStep(), new DockerfileProjectLanguageStep(), new OpenBehaviorStep()],
executeSteps: [new CreateDockerfileProjectStep(), new OpenFolderStep()]
});

wizardContext.activityTitle = localize('createNewDockerfileProject', 'Create new project with dockerfile');

await wizard.prompt();
await wizard.execute();
}
2 changes: 2 additions & 0 deletions src/commands/registerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { createChildNode } from './createChildNode';
import { createFunctionFromCommand } from './createFunction/createFunction';
import { createFunctionApp, createFunctionAppAdvanced } from './createFunctionApp/createFunctionApp';
import { createNewProjectFromCommand } from './createNewProject/createNewProject';
import { createNewProjectWithDockerfile } from './createNewProject/dockerfileSteps/createNewProjectWithDockerfile';
import { createSlot } from './createSlot';
import { deleteFunction } from './deleteFunction';
import { deleteFunctionApp } from './deleteFunctionApp';
Expand Down Expand Up @@ -75,6 +76,7 @@ export function registerCommands(): void {
registerCommandWithTreeNodeUnwrapping('azureFunctions.createFunctionApp', createFunctionApp);
registerCommandWithTreeNodeUnwrapping('azureFunctions.createFunctionAppAdvanced', createFunctionAppAdvanced);
registerCommand('azureFunctions.createNewProject', createNewProjectFromCommand);
registerCommandWithTreeNodeUnwrapping('azureFunctions.createNewProjectWithDockerfile', createNewProjectWithDockerfile);
registerCommandWithTreeNodeUnwrapping('azureFunctions.createSlot', createSlot);
registerCommandWithTreeNodeUnwrapping('azureFunctions.deleteFunction', deleteFunction);
registerCommandWithTreeNodeUnwrapping('azureFunctions.deleteFunctionApp', deleteFunctionApp);
Expand Down