From 161f6e94a07d1dd51dad5122b9073f67e42ca71b Mon Sep 17 00:00:00 2001 From: David Feldhoff Date: Tue, 9 Feb 2021 21:31:51 +0100 Subject: [PATCH] #94 create parent directories if they're not there yet --- .../src/App logic/Utils/elementInsertionUtils.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vscode-extension/src/App logic/Utils/elementInsertionUtils.ts b/vscode-extension/src/App logic/Utils/elementInsertionUtils.ts index 4d8d593..ad22cd8 100644 --- a/vscode-extension/src/App logic/Utils/elementInsertionUtils.ts +++ b/vscode-extension/src/App logic/Utils/elementInsertionUtils.ts @@ -1,5 +1,7 @@ import * as CRSApi from 'crs-al-language-extension-api'; +import { mkdirSync } from 'fs'; import { readFileSync, renameSync, writeFileSync } from "fs-extra"; +import { parse } from 'path'; import { Extension, extensions, Position, Range, TextDocument, Uri, workspace, WorkspaceEdit } from "vscode"; import { MessageUpdate, TypeChanged } from "../../typings/types"; import { ALFullSyntaxTreeNodeExt } from "../AL Code Outline Ext/alFullSyntaxTreeNodeExt"; @@ -29,10 +31,11 @@ export class ElementInsertionUtils { private static async addNewFeatureToCode(msg: MessageUpdate): Promise { let srcFolder: string = Config.getTestSrcFolder()!; - + let objectName: string = new StringUtils(msg.NewValue).titleCase().removeSpecialChars().value(); let fileName: string = objectName + '.al'; msg.FsPath = WorkspaceUtils.getFullFsPathOfRelativePath(srcFolder, fileName); + mkdirSync(parse(msg.FsPath).dir, { recursive: true }) writeFileSync(msg.FsPath, (await TestCodeunitUtils.getDefaultTestCodeunit(msg.NewValue, Uri.file(msg.FsPath))).join('\r\n'), { encoding: 'utf8' }); let id: string | undefined = await TestCodeunitUtils.getNextCodeunitId(msg.FsPath); if (id) {