From c72eb899c4c492e00670946b0c22e7ba9ce19319 Mon Sep 17 00:00:00 2001 From: msivasubramaniaan Date: Fri, 8 Sep 2023 21:13:05 +0530 Subject: [PATCH 1/2] initial commit Signed-off-by: msivasubramaniaan --- src/serverlessFunction/commands.ts | 4 ++-- .../serverless-function/serverlessFunctionLoader.ts | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/serverlessFunction/commands.ts b/src/serverlessFunction/commands.ts index f1fae944a..5517d0967 100644 --- a/src/serverlessFunction/commands.ts +++ b/src/serverlessFunction/commands.ts @@ -60,8 +60,8 @@ export class ServerlessCommand { return commandText } - static createFunction(language: string, template: string, location: string): CommandText { - return new CommandText(`func create ${location}`, undefined, [ + static createFunction(name: string, language: string, template: string, location: string): CommandText { + return new CommandText(`func create ${name} ${location}`, undefined, [ new CommandOption('-l', language), new CommandOption('-t', template) ]); diff --git a/src/webview/serverless-function/serverlessFunctionLoader.ts b/src/webview/serverless-function/serverlessFunctionLoader.ts index 8eb4a3b65..3d49c8b74 100644 --- a/src/webview/serverless-function/serverlessFunctionLoader.ts +++ b/src/webview/serverless-function/serverlessFunctionLoader.ts @@ -28,7 +28,7 @@ async function messageListener(panel: vscode.WebviewPanel, event: any): Promise< let response: CliExitData; const eventName = event.action; const functionName = event.name; - const functionPath: vscode.Uri = event.folderPath ? vscode.Uri.from(event.folderPath) : undefined; + const functionPath: vscode.Uri = event.folderPath; switch (eventName) { case 'validateName': const flag = validateName(functionName); @@ -64,11 +64,14 @@ async function messageListener(panel: vscode.WebviewPanel, event: any): Promise< }); break; case 'createFunction': - const selctedFolder: vscode.Uri = vscode.Uri.file(path.join(functionPath.fsPath, functionName)); + let selctedFolder: vscode.Uri = vscode.Uri.file(functionPath.fsPath); + if ((await fs.readdir(selctedFolder.fsPath)).length !== 0) { + selctedFolder = vscode.Uri.file(path.join(selctedFolder.fsPath, functionName)); + } await Progress.execFunctionWithProgress( `Creating function '${functionName}'`, async () => { - response = await ServerlessFunctionViewLoader.createFunction(event.language, event.template, selctedFolder.fsPath, event.selectedImage); + response = await ServerlessFunctionViewLoader.createFunction(functionName, event.language, event.template, selctedFolder.fsPath, event.selectedImage); }); if (response && response.error) { void vscode.window.showErrorMessage(`Error while creating the function ${functionName}`); @@ -198,6 +201,7 @@ export default class ServerlessFunctionViewLoader { } static async createFunction( + name: string, language: string, template: string, location: string, @@ -206,7 +210,7 @@ export default class ServerlessFunctionViewLoader { let functionResponse: CliExitData; try { const response = await OdoImpl.Instance.execute( - ServerlessCommand.createFunction(language, template, location), + ServerlessCommand.createFunction(name, language, template, location), ); if (response && !response.error) { const yamlContent = await Utils.getFuncYamlContent(location); From 76071332d59fd50bd8b8b404f4910130b690725a Mon Sep 17 00:00:00 2001 From: msivasubramaniaan Date: Tue, 12 Sep 2023 18:44:49 +0530 Subject: [PATCH 2/2] check func.yaml recursively under workspace sub folder Signed-off-by: msivasubramaniaan --- src/serverlessFunction/commands.ts | 4 ++-- src/serverlessFunction/functionModel.ts | 6 ++++++ .../serverless-function/serverlessFunctionLoader.ts | 10 +++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/serverlessFunction/commands.ts b/src/serverlessFunction/commands.ts index 5517d0967..f1fae944a 100644 --- a/src/serverlessFunction/commands.ts +++ b/src/serverlessFunction/commands.ts @@ -60,8 +60,8 @@ export class ServerlessCommand { return commandText } - static createFunction(name: string, language: string, template: string, location: string): CommandText { - return new CommandText(`func create ${name} ${location}`, undefined, [ + static createFunction(language: string, template: string, location: string): CommandText { + return new CommandText(`func create ${location}`, undefined, [ new CommandOption('-l', language), new CommandOption('-t', template) ]); diff --git a/src/serverlessFunction/functionModel.ts b/src/serverlessFunction/functionModel.ts index 49db9b529..d51cb5cbe 100644 --- a/src/serverlessFunction/functionModel.ts +++ b/src/serverlessFunction/functionModel.ts @@ -36,6 +36,12 @@ export class ServerlessFunctionModel implements Disposable { const folders: Uri[] = []; if (workspace.workspaceFolders) { for (const wf of workspace.workspaceFolders) { + const entries = await fs.readdir(wf.uri.fsPath, { withFileTypes: true }); + for (const file of entries) { + if (file.isDirectory() && fs.existsSync(path.join(wf.uri.fsPath, file.name, 'func.yaml'))) { + folders.push(Uri.file(path.join(wf.uri.fsPath, file.name))); + } + } if (fs.existsSync(path.join(wf.uri.fsPath, 'func.yaml'))) { folders.push(wf.uri); } diff --git a/src/webview/serverless-function/serverlessFunctionLoader.ts b/src/webview/serverless-function/serverlessFunctionLoader.ts index 3d49c8b74..1b64ecce8 100644 --- a/src/webview/serverless-function/serverlessFunctionLoader.ts +++ b/src/webview/serverless-function/serverlessFunctionLoader.ts @@ -64,14 +64,11 @@ async function messageListener(panel: vscode.WebviewPanel, event: any): Promise< }); break; case 'createFunction': - let selctedFolder: vscode.Uri = vscode.Uri.file(functionPath.fsPath); - if ((await fs.readdir(selctedFolder.fsPath)).length !== 0) { - selctedFolder = vscode.Uri.file(path.join(selctedFolder.fsPath, functionName)); - } + const selctedFolder: vscode.Uri = vscode.Uri.file(path.join(functionPath.fsPath, functionName)); await Progress.execFunctionWithProgress( `Creating function '${functionName}'`, async () => { - response = await ServerlessFunctionViewLoader.createFunction(functionName, event.language, event.template, selctedFolder.fsPath, event.selectedImage); + response = await ServerlessFunctionViewLoader.createFunction(event.language, event.template, selctedFolder.fsPath, event.selectedImage); }); if (response && response.error) { void vscode.window.showErrorMessage(`Error while creating the function ${functionName}`); @@ -201,7 +198,6 @@ export default class ServerlessFunctionViewLoader { } static async createFunction( - name: string, language: string, template: string, location: string, @@ -210,7 +206,7 @@ export default class ServerlessFunctionViewLoader { let functionResponse: CliExitData; try { const response = await OdoImpl.Instance.execute( - ServerlessCommand.createFunction(name, language, template, location), + ServerlessCommand.createFunction(language, template, location), ); if (response && !response.error) { const yamlContent = await Utils.getFuncYamlContent(location);