export async function editAction()

in src/commands/editAction.ts [25:65]


export async function editAction(action: WskAction): Promise<void> {
    let dir = path.join(os.tmpdir(), 'openwhisk-vscode', 'action');
    if (action.packageDesc && action.packageDesc.name) {
        dir = path.join(dir, action.packageDesc.name);
    }
    if (!fs.existsSync(dir)) {
        fs.mkdirSync(dir, { recursive: true });
    }

    const localFilePath = dir + '/' + action.label + action.fileExtension;
    if (fs.existsSync(localFilePath)) {
        fs.unlinkSync(localFilePath);
    }

    const content = await action.client.actions.get(
        WskAction.removeExtension(action.getFullName())
    );
    if (content.exec.kind === 'sequence') {
        vscode.window.showErrorMessage("Can't edit sequence action type");
        return;
    }
    if (content.exec.binary) {
        vscode.window.showErrorMessage("Can't edit binary action code");
        return;
    }
    if ((content.exec.kind as string) === 'blackbox' && !content.exec.code) {
        vscode.window.showErrorMessage("Can't edit blackbox action without action code");
        return;
    }
    if (content.exec.code) {
        fs.writeFileSync(localFilePath, content.exec.code);
    }

    vscode.workspace.openTextDocument(localFilePath).then((textDocument: vscode.TextDocument) => {
        vscode.window
            .showTextDocument(textDocument, { preview: false })
            .then((textEditor: vscode.TextEditor) => {
                actionEditMap[textEditor.document.uri.toString()] = action;
            });
    });
}