+23
-6
@@ -28,4 +28,11 @@ // src/index.ts | ||
| } | ||
| function isFolder(content, name) { | ||
| if (name && name.includes("$")) | ||
| return false; | ||
| return typeof content === "object" && content !== null && !Array.isArray(content); | ||
| } | ||
| // src/ProjectBuilder.ts | ||
| var FOLDER_MARKER = Symbol("FOLDER"); | ||
| class ProjectBuilder { | ||
@@ -54,3 +61,6 @@ static instance; | ||
| } | ||
| isFolder(content) { | ||
| isFolder(content, name) { | ||
| if (name.includes("$")) { | ||
| return false; | ||
| } | ||
| return typeof content === "object" && content !== null && !Array.isArray(content); | ||
@@ -61,11 +71,17 @@ } | ||
| const processedName = normalizeFileName(this.processVariables(name, variables)); | ||
| if (this.isFolder(content)) { | ||
| if (this.isFolder(content, name)) { | ||
| const folderPath = posix.join(currentPath, processedName); | ||
| this.pathContentMap.set(folderPath, null); | ||
| this.pathContentMap.set(folderPath, FOLDER_MARKER); | ||
| await this.analyzeStructure(content, folderPath, variables); | ||
| } else { | ||
| if (content === null || content === undefined) { | ||
| continue; | ||
| } | ||
| const filePath = posix.join(currentPath, processedName); | ||
| const fileContent = this.processVariables(content, variables); | ||
| this.pathContentMap.set(filePath, fileContent); | ||
| this.pathContentMap.set(posix.dirname(filePath), null); | ||
| const parentDir = posix.dirname(filePath); | ||
| if (!this.pathContentMap.has(parentDir)) { | ||
| this.pathContentMap.set(parentDir, FOLDER_MARKER); | ||
| } | ||
| } | ||
@@ -75,3 +91,3 @@ } | ||
| async createFolders() { | ||
| const folders = Array.from(this.pathContentMap.entries()).filter(([_, content]) => content === null).map(([path]) => path).sort((a, b) => a.split("/").length - b.split("/").length); | ||
| const folders = Array.from(this.pathContentMap.entries()).filter(([_, content]) => content === FOLDER_MARKER).map(([path]) => path).sort((a, b) => a.split("/").length - b.split("/").length); | ||
| for (const dir of folders) { | ||
@@ -87,3 +103,3 @@ await mkdir(dir, { recursive: true }); | ||
| async createFiles() { | ||
| const files = Array.from(this.pathContentMap.entries()).filter(([_, content]) => content !== null); | ||
| const files = Array.from(this.pathContentMap.entries()).filter(([_, content]) => content !== FOLDER_MARKER); | ||
| await Promise.all(files.map(async ([path, content]) => { | ||
@@ -202,2 +218,3 @@ try { | ||
| normalizeFileName, | ||
| isFolder, | ||
| getPath, | ||
@@ -204,0 +221,0 @@ getFolder, |
+1
-0
| export declare function normalizeFileName(name: string): string; | ||
| export declare function fileExists(directory: string, fileName: string): Promise<boolean>; | ||
| export declare function isFolder(content: any, name: string): boolean; |
+1
-1
| { | ||
| "name": "forji", | ||
| "version": "1.0.4", | ||
| "version": "1.0.5", | ||
| "description": "Library for building project structures with dynamic folder/file names", | ||
@@ -5,0 +5,0 @@ "type": "module", |
19963
3.03%257
7.08%