Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vscode): Introduce support for Static Web Apps #5099

Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7a62e67
added log when project started
alain-zhiyanov May 29, 2024
00b4539
add wizard option to init swa and add log to reg each decision
alain-zhiyanov Jun 4, 2024
a0a7c77
add all LA folders in to their own LA dir and then call SWA
alain-zhiyanov Jun 14, 2024
b69cb09
added start swa from new LA workspace menu. note current SWA start co…
alain-zhiyanov Jun 21, 2024
b87bd94
changed task json so it sets swa start dynamically
alain-zhiyanov Jun 21, 2024
6053a4a
added basic workflow and can now view SWA with SAS when designer opened
alain-zhiyanov Jul 9, 2024
2122ec6
changed default stateful workflow and altered tasks.json
alain-zhiyanov Jul 10, 2024
71f0017
added comments and fixed workflows
alain-zhiyanov Jul 10, 2024
79b814e
fixed deployment
alain-zhiyanov Jul 11, 2024
697eaf8
added new command to call swa generate, removed SWA URL popup in over…
alain-zhiyanov Jul 16, 2024
8f820e3
Update CodelessWorkflowCreateStep.ts comments
alain-zhiyanov Jul 16, 2024
c6c2e2b
removed inspect flag from launch.json
alain-zhiyanov Jul 16, 2024
830669f
fixed create workflow command and altered default workflow
alain-zhiyanov Jul 17, 2024
2723503
Merge branch 'using-swa-extension' of https://github.com/alain-zhiyan…
alain-zhiyanov Jul 17, 2024
a1ca497
comments and style
alain-zhiyanov Jul 23, 2024
2a3af12
Update launch.json
alain-zhiyanov Jul 23, 2024
7176a58
Update generateStaticWebApp.ts
alain-zhiyanov Aug 1, 2024
9801764
fixed style
alain-zhiyanov Aug 9, 2024
4a8fef5
fixed style part 2
alain-zhiyanov Aug 9, 2024
bce9b28
resolved merge conflicts
alain-zhiyanov Aug 9, 2024
6ebf023
Update InitVSCodeStepBase.ts
alain-zhiyanov Aug 9, 2024
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
1 change: 1 addition & 0 deletions .vscode/launch.json
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: I think there is no need for an extra breakline here

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",

"args": [
"--extensionDevelopmentPath=${workspaceFolder}/apps/vs-code-designer/dist"
],
Expand Down
4 changes: 0 additions & 4 deletions Localize/lang/strings.json
Copy link
Author

Choose a reason for hiding this comment

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

automatically changed. let me know if I should revert

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, please revert it

Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@
"7ZR1xr": "Add an action",
"7aJqIH": "Optional. The locale to be used when formatting (defaults to 'en-us').",
"7gUE8h": "This will revert your workflow to the state it was in before Copilot's edit. If you made additional edits to the workflow after Copilot's, you will lose them. This action cannot be undone. Do you want to continue?",
"7jAQar": "Enter value for parameter.",
Copy link

Choose a reason for hiding this comment

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

revert?

"7jcTNd": "Enter a valid email.",
"7k9jXx": "Status code",
"7lnElz": "Returns the number of ticks (100 nanoseconds interval) since 1 January 0001 00:00:00 UT of a string timestamp",
Expand Down Expand Up @@ -1158,7 +1157,6 @@
"_7ZR1xr.comment": "Text on example action node",
"_7aJqIH.comment": "Optional locale parameter to apply formatNumber function with",
"_7gUE8h.comment": "Warning description of what undoing operation will do to the workflow",
"_7jAQar.comment": "Parameter Field Default Value Placeholder Text",
"_7jcTNd.comment": "Error validation message for emails",
"_7k9jXx.comment": "Label text for response status code",
"_7lnElz.comment": "Label for description of custom ticks Function",
Expand Down Expand Up @@ -2136,7 +2134,6 @@
"_mGUdCO.comment": "Label for description of custom getPastTime Function",
"_mGpKsl.comment": "Label for description of custom dataUriToString Function",
"_mNaBPE.comment": "Error message for invalid JSON in authentication editor",
"_mOxbN1.comment": "Parameter Field Default Value Title",
"_mPakaD.comment": "Label for description of custom encodeUriComponent Function",
"_mPuXlv.comment": "Error message for when split on array is invalid. Do not remove the double single quotes around the placeholder text, as it is needed to wrap the placeholder text in single quotes.",
"_mUURJW.comment": "Tooltip for the button to reassign actions",
Expand Down Expand Up @@ -2784,7 +2781,6 @@
"mGUdCO": "Returns a timestamp that is the current time minus the specified time interval.",
"mGpKsl": "Returns a string representation of a data URI",
"mNaBPE": "Enter a valid JSON.",
"mOxbN1": "Value",
"mPakaD": "Url encodes the input string",
"mPuXlv": "Invalid type on split on value ''{splitOn}'', split on not in array.",
"mUURJW": "Connection is invalid",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { IAzureConnectorsContext } from '../workflows/azureConnectorWizard';
import type * as vscode from 'vscode';
import { executeCommand } from '../../utils/funcCoreTools/cpUtils';
import { ext } from '../../../extensionVariables';

export async function generateStaticWebApp(context: IAzureConnectorsContext, node: vscode.Uri): Promise<void> {
console.log('generate SWA');
Copy link

Choose a reason for hiding this comment

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

Since this is user facing can we make this more descriptive?

Copy link
Contributor

Choose a reason for hiding this comment

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

@alain-zhiyanov Overall I would say to remove all console logs. If you want actually display something for the user to be aware of it, please the output channel and please localize the text. For example:
ext.outputChannel.appendLog(localize('excludedSettings', 'Excluded the following settings:'));

//removing "/c: because that doesn't fit SWA cli format"
Copy link

Choose a reason for hiding this comment

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

Is this comment still needed?

const command: string = `node C:\\Users\\t-azhiyanov\\static-web-apps-cli-sifat\\dist\\cli\\bin.js generate ${node.path.substring(3)}`;
Copy link

Choose a reason for hiding this comment

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

how can this be a static path? Won't it fail to find the bits on another machine?

Copy link
Contributor

Choose a reason for hiding this comment

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

@alain-zhiyanov I am not fully aware of the implementation or how we get this script, however if this is a static script, please upload the script in the repo or even better just make a function to call it. If its not static (generated), please make sure to have it a kind of static place for all users to work and also use path.join() since the pat diff for windows (\) is different than the one for linux (/)

executeCommand(ext.outputChannel, undefined, command);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import type { IFunctionWizardContext, IWorkflowTemplate, IHostJsonV2, StandardAp
import * as fse from 'fs-extra';
import * as path from 'path';
import type { MessageItem } from 'vscode';
import * as vscodeExtension from 'vscode';

export class CodelessWorkflowCreateStep extends WorkflowCreateStepBase<IFunctionWizardContext> {
private constructor() {
Expand All @@ -45,19 +46,71 @@ export class CodelessWorkflowCreateStep extends WorkflowCreateStepBase<IFunction
}

public async executeCore(context: IFunctionWizardContext): Promise<string> {
// Check if the user chose to initialize a static web app
if (context.initializeStaticWebApp) {
Copy link

Choose a reason for hiding this comment

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

Is the comment needed here?

Copy link

Choose a reason for hiding this comment

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

shouldInitializeStaticWebApp

context.telemetry.properties.initializeStaticWebApp = 'true';
//call deploy command

vscodeExtension.commands.executeCommand('azureLogicAppsStandard.deploy');
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: Here is just better to call the function if possible, rather than calling the command

} else {
context.telemetry.properties.initializeStaticWebApp = 'false';
}

const template: IWorkflowTemplate = nonNullProp(context, 'functionTemplate');
const functionPath: string = path.join(context.projectPath, nonNullProp(context, 'functionName'));

const emptyStatefulDefinition: StandardApp = {
definition: {
$schema: 'https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#',
actions: {},
contentVersion: '1.0.0.0',
outputs: {},
triggers: {},
},
kind: 'Stateful',
};
let emptyStatefulDefinition: StandardApp;
if (context.initializeStaticWebApp) {
//initiate basic logic app which can be called from SWA
emptyStatefulDefinition = {
Copy link

Choose a reason for hiding this comment

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

should we read this from a file instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

we have a file to store the templates apps/vs-code-designer/src/app/utils/codeless/templates.ts

definition: {
$schema: 'https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#',
actions: {
Compose: {
type: 'Compose',
inputs: {
status: 'Hello from Logic App',
},
runAfter: {},
},
Response: {
type: 'Response',
kind: 'Http',
inputs: {
statusCode: 200,
body: "@outputs('Compose')",
},
runAfter: {
Compose: ['SUCCEEDED'],
},
},
},
contentVersion: '1.0.0.0',
outputs: {},
triggers: {
When_a_HTTP_request_is_received: {
type: 'Request',
kind: 'Http',
inputs: {
method: 'GET',
relativePath: '/api/message',
},
},
},
},
kind: 'Stateful',
};
} else {
emptyStatefulDefinition = {
definition: {
$schema: 'https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#',
actions: {},
contentVersion: '1.0.0.0',
outputs: {},
triggers: {},
},
kind: 'Stateful',
};
}

const emptyStatelessDefinition: StandardApp = {
definition: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,33 @@ import { AzureWizardPromptStep } from '@microsoft/vscode-azext-utils';
import type { IAzureQuickPickItem } from '@microsoft/vscode-azext-utils';
import type { IProjectWizardContext } from '@microsoft/vscode-extension-logic-apps';

interface ILogicAppPickData {
isCustomCodeLogicApp: boolean;
initializeStaticWebApp: boolean;
}

export class SetLogicAppType extends AzureWizardPromptStep<IProjectWizardContext> {
public async prompt(context: IProjectWizardContext): Promise<void> {
const picks: IAzureQuickPickItem<boolean>[] = [
{ label: localize('logicApp', 'Logic app'), data: false },
{ label: localize('logicAppCustomCode', 'Logic app with custom code project'), data: true },
const picks: IAzureQuickPickItem<ILogicAppPickData>[] = [
{ label: localize('logicApp', 'Logic app'), data: { isCustomCodeLogicApp: false, initializeStaticWebApp: false } },
{
label: localize('logicAppCustomCode', 'Logic app with custom code project'),
data: { isCustomCodeLogicApp: true, initializeStaticWebApp: false },
},
{
label: localize('logicAppStaticWebApp', 'Logic app with Static Web App'),
data: { isCustomCodeLogicApp: false, initializeStaticWebApp: true },
},
];

const placeHolder = localize('logicAppProjectTemplatePlaceHolder', 'Select a project template for your logic app workspace');
context.isCustomCodeLogicApp = (await context.ui.showQuickPick(picks, { placeHolder })).data;
const selectedPick = await context.ui.showQuickPick(picks, { placeHolder });

Copy link

Choose a reason for hiding this comment

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

nit: remove extra line

context.isCustomCodeLogicApp = selectedPick.data.isCustomCodeLogicApp;
context.initializeStaticWebApp = selectedPick.data.initializeStaticWebApp;
}

public shouldPrompt(context: IProjectWizardContext): boolean {
return context.isCustomCodeLogicApp === undefined;
return context.isCustomCodeLogicApp === undefined && context.initializeStaticWebApp === undefined;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ export async function createNewCodeProjectInternal(context: IActionContext, opti
title: localize('createNewCodeProject', 'Create new logic app workspace'),
promptSteps: [
new FolderListStep(),

new setWorkspaceName(),
new SetLogicAppType(),
new SetLogicAppName(),
new NewCodeProjectTypeStep(options.templateId, options.functionSettings),

new OpenBehaviorStep(),
],
executeSteps: [new OpenFolderStepCodeProject()],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export async function createNewProjectFromCommand(
functionName?: string,
functionSettings?: { [key: string]: string | undefined }
): Promise<void> {
console.log('CREATE NEW PROJECT LOG');
await createNewProjectInternal(context, {
folderPath: isString(folderPath) ? folderPath : undefined,
templateId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ export class ScriptProjectCreateStep extends ProjectCreateStepBase {
}

const localSettingsJsonPath: string = path.join(context.projectPath, localSettingsFileName);
//added new setting here to allow local start without SAS
Copy link

Choose a reason for hiding this comment

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

Are we always adding this setting now or only if is starting through swa cli?

if (await confirmOverwriteFile(context, localSettingsJsonPath)) {
const localSettingsJson: ILocalSettingsJson = {
IsEncrypted: false,
Values: {
AzureWebJobsStorage: '',
APP_KIND: logicAppKind,
'AzureFunctionsJobHost__extensions__workflow__Settings__Runtime.Triggers.AnonymousAuthEnabledForDevEnvironment': 'true',
Copy link

Choose a reason for hiding this comment

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

nit: the formatting here is off

Copy link
Contributor

Choose a reason for hiding this comment

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

Also make sure to just add it when is needed for static web apps and not for all of the scenarios

ProjectDirectoryPath: path.join(context.projectPath),
},
};
Expand Down
11 changes: 10 additions & 1 deletion apps/vs-code-designer/src/app/commands/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import type { ConnectionsData, FuncVersion, IIdentityWizardContext, ProjectLangu
import * as fse from 'fs-extra';
import * as path from 'path';
import type { Uri, MessageItem, WorkspaceFolder } from 'vscode';
import * as vscodeExtension from 'vscode';

export async function deployProductionSlot(
context: IActionContext,
Expand Down Expand Up @@ -188,8 +189,16 @@ async function deploy(
}
}
});

await node.loadAllChildren(context);

//need to add flag for this call and remove region hardcode TODO
const suffix = '/config/web';
const logicAppBackendResourceId = siteConfig.id.substring(0, siteConfig.id.length - suffix.length);
vscodeExtension.commands.executeCommand('staticWebApps.createStaticWebApp', undefined, undefined, {
backendResourceId: logicAppBackendResourceId,
region: 'eastus',
Copy link

Choose a reason for hiding this comment

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

How can this region be static?

name: siteConfig.name,
});
await notifyDeployComplete(node, context.workspaceFolder, settingsToExclude);
}

Expand Down
Loading
Loading