Skip to content

Commit

Permalink
fix: fixed windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
Bajdzis committed Sep 16, 2019
1 parent 8d6bf32 commit 0fc7ec2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
6 changes: 3 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 6 additions & 5 deletions src/fileInfo/createVariableTemplate.ts
Original file line number Diff line number Diff line change
@@ -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(`(?<=^([^\\$\\{]|\\$\\{[^"]*\\})*)(?<varName>${variableName})`,'i');
let regExpResult: RegExpExecArray|null = null;

Expand Down
2 changes: 2 additions & 0 deletions src/fileInfo/getInfoAboutPath.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { WordsInfo, getInfoWords } from "./getInfoWords";
import { addSlashes } from "../helpers/addSlashes";

export interface PathInfo {
path: string;
Expand All @@ -8,6 +9,7 @@ export interface PathInfo {
}

export function getInfoAboutPath(path: string): PathInfo{
path = addSlashes(path);
const searchExtension = /(?<pathWithoutExtension>.*)\.(?<extension>[a-z0-9]*)$/;
const result = searchExtension.exec(path);
const pathWithoutExtension = result && result.groups && result.groups.pathWithoutExtension || path;
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/addSlashes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

export function addSlashes(s: string) {
return s.replace(/\\/g, '/');
}

0 comments on commit 0fc7ec2

Please sign in to comment.