( nodeId: string, textContent: string, packName: string, packedFileName: string, )
| 2640 | } |
| 2641 | |
| 2642 | async function executeSaveTextNode( |
| 2643 | nodeId: string, |
| 2644 | textContent: string, |
| 2645 | packName: string, |
| 2646 | packedFileName: string, |
| 2647 | ): Promise<NodeExecutionResult> { |
| 2648 | console.log( |
| 2649 | `SaveText Node ${nodeId}: Saving text file with packName="${packName}", packedFileName="${packedFileName}"`, |
| 2650 | ); |
| 2651 | |
| 2652 | try { |
| 2653 | const nodePath = await import("path"); |
| 2654 | const { format } = await import("date-fns"); |
| 2655 | |
| 2656 | // Generate default names if not provided |
| 2657 | const timestamp = format(new Date(), "ddMMyy_HHmmss"); |
| 2658 | const packFileBaseName = packName || `textflow_${timestamp}`; |
| 2659 | const textFileName = packedFileName || `output_${timestamp}.txt`; |
| 2660 | |
| 2661 | // Create buffer from text content |
| 2662 | const buffer = Buffer.from(textContent, "utf8"); |
| 2663 | |
| 2664 | // Create NewPackedFile object |
| 2665 | const newFile: NewPackedFile = { |
| 2666 | name: textFileName, |
| 2667 | buffer: buffer, |
| 2668 | file_size: buffer.length, |
| 2669 | }; |
| 2670 | |
| 2671 | // Determine pack path - save to /whmm_flows/ folder |
| 2672 | const gamePath = appData.gamesToGameFolderPaths[appData.currentGame].gamePath as string; |
| 2673 | const whmmFlowsFolder = nodePath.join(gamePath, "whmm_flows"); |
| 2674 | |
| 2675 | // Create whmm_flows directory if it doesn't exist |
| 2676 | const fs = await import("fs"); |
| 2677 | if (!fs.existsSync(whmmFlowsFolder)) { |
| 2678 | fs.mkdirSync(whmmFlowsFolder, { recursive: true }); |
| 2679 | } |
| 2680 | |
| 2681 | const newPackPath = nodePath.join(whmmFlowsFolder, `${packFileBaseName}.pack`); |
| 2682 | |
| 2683 | // Write the pack file |
| 2684 | await writePack([newFile], newPackPath); |
| 2685 | |
| 2686 | console.log(`SaveText Node ${nodeId}: Successfully saved text file to ${newPackPath}`); |
| 2687 | |
| 2688 | return { |
| 2689 | success: true, |
| 2690 | data: { |
| 2691 | type: "SaveResult", |
| 2692 | savedTo: newPackPath, |
| 2693 | format: "text", |
| 2694 | fileName: textFileName, |
| 2695 | message: `Successfully saved text file to ${packFileBaseName}.pack`, |
| 2696 | }, |
| 2697 | }; |
| 2698 | } catch (error) { |
| 2699 | console.error(`SaveText Node ${nodeId}: Error saving text file:`, error); |
no test coverage detected