From 0fc7ec2e2910e50102721b8a0207b35fa259d602 Mon Sep 17 00:00:00 2001 From: Bajdzis Date: Mon, 16 Sep 2019 21:03:32 +0200 Subject: [PATCH] fix: fixed windows support --- package.json | 2 +- src/extension.ts | 6 +++--- src/fileInfo/createVariableTemplate.ts | 11 ++++++----- src/fileInfo/getInfoAboutPath.ts | 2 ++ src/helpers/addSlashes.ts | 4 ++++ 5 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 src/helpers/addSlashes.ts diff --git a/package.json b/package.json index 4c1c4ef..e6cf124 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "displayName": "Awesome tree", "description": "Stop creating folders, start creating structures! (Automated file creation)", "publisher": "bajdzis", - "version": "0.0.2", + "version": "0.0.3", "engines": { "vscode": "^1.37.0" }, diff --git a/src/extension.ts b/src/extension.ts index 8d63c1f..fa3124f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -20,7 +20,7 @@ export function activate(context: vscode.ExtensionContext) { const fileSystemWatcher = vscode.workspace.createFileSystemWatcher("**/*",false, true, true); fileSystemWatcher.onDidCreate(async(uri: vscode.Uri) => { try { - const relative = getRelative(uri.path); + const relative = getRelative(uri.fsPath); // when directory or file is not empty probably change name parent directory if (isEmptyDirectory(uri)) { @@ -67,7 +67,7 @@ export function activate(context: vscode.ExtensionContext) { preparePathFiles.map(filePathTemplate => { const filePath: string = renderVariableTemplate(filePathTemplate, [infoAboutNewDirectory]); - const newFilePath = path.join(uri.path, filePath); + const newFilePath = path.join(uri.fsPath, filePath); const content = createFileContent(filePathTemplate, directories, [infoAboutNewDirectory]); ensureDirectoryExistence(newFilePath); @@ -165,7 +165,7 @@ export function activate(context: vscode.ExtensionContext) { return path; } for (let i = 0; i < workspaceFolders.length; i++) { - const dirPath = workspaceFolders[i].uri.path; + const dirPath = workspaceFolders[i].uri.fsPath; path = path.replace(dirPath, ''); } return path; diff --git a/src/fileInfo/createVariableTemplate.ts b/src/fileInfo/createVariableTemplate.ts index 5f43159..294c6cb 100644 --- a/src/fileInfo/createVariableTemplate.ts +++ b/src/fileInfo/createVariableTemplate.ts @@ -1,26 +1,27 @@ import { PathInfo } from "./getInfoAboutPath"; -import { TextCase, getTextCase } from "./getInfoWords"; +import { getTextCase } from "./getInfoWords"; +import { addSlashes } from "../helpers/addSlashes"; export function createVariableTemplate(search:string, information: PathInfo[]) { const variables: { - [key: string] : [TextCase, number,number,number]; + [key: string] : [number,number,number]; } = {}; information.forEach((info, infoIndex) => { info.pathParts.forEach((words, wordsIndex) => { words.parts.forEach((word, wordIndex) => { if(!variables[word]){ - variables[word] = [words.textCase, infoIndex, wordsIndex, wordIndex]; + variables[word] = [infoIndex, wordsIndex, wordIndex]; } }); }); }); - let result = encodeURIComponent(search); + let result = encodeURIComponent(addSlashes(search)); Object.keys(variables).sort((a: string,b: string) => a.length - b.length).forEach((variableName) => { - const [_, index0, index1, index2] = variables[variableName]; + const [index0, index1, index2] = variables[variableName]; const regExp = new RegExp(`(?<=^([^\\$\\{]|\\$\\{[^"]*\\})*)(?${variableName})`,'i'); let regExpResult: RegExpExecArray|null = null; diff --git a/src/fileInfo/getInfoAboutPath.ts b/src/fileInfo/getInfoAboutPath.ts index 892c088..35440cd 100644 --- a/src/fileInfo/getInfoAboutPath.ts +++ b/src/fileInfo/getInfoAboutPath.ts @@ -1,4 +1,5 @@ import { WordsInfo, getInfoWords } from "./getInfoWords"; +import { addSlashes } from "../helpers/addSlashes"; export interface PathInfo { path: string; @@ -8,6 +9,7 @@ export interface PathInfo { } export function getInfoAboutPath(path: string): PathInfo{ + path = addSlashes(path); const searchExtension = /(?.*)\.(?[a-z0-9]*)$/; const result = searchExtension.exec(path); const pathWithoutExtension = result && result.groups && result.groups.pathWithoutExtension || path; diff --git a/src/helpers/addSlashes.ts b/src/helpers/addSlashes.ts new file mode 100644 index 0000000..9489ec4 --- /dev/null +++ b/src/helpers/addSlashes.ts @@ -0,0 +1,4 @@ + +export function addSlashes(s: string) { + return s.replace(/\\/g, '/'); +}