UNPKG

@iexec/iapp

Version:

A CLI to guide you through the process of building an iExec iApp

44 lines 1.88 kB
import { join } from 'node:path'; import { mkdir, readFile, writeFile } from 'node:fs/promises'; import { CACHE_DIR } from '../config/config.js'; import { fileExists } from './fs.utils.js'; // Utility function to ensure the cache directory and file exist async function ensureCacheFileExists(fileName, chainName) { const chainCacheDir = join(CACHE_DIR, chainName); const cacheFile = join(chainCacheDir, fileName); // Create cache directory if it doesn't exist await mkdir(chainCacheDir, { recursive: true }); // Create the specified cache file if it doesn't exist if (!(await fileExists(cacheFile))) { await writeFile(cacheFile, JSON.stringify([])); } return cacheFile; } // Utility function to add data to the specified cache file async function addDataToCache(fileName, chainName, data) { const cacheFile = await ensureCacheFileExists(fileName, chainName); const cacheFileContent = await readFile(cacheFile, 'utf8'); const existingData = JSON.parse(cacheFileContent); existingData.unshift({ ...data, date: new Date().toISOString() }); // Add the new data to the beginning of the array await writeFile(cacheFile, JSON.stringify(existingData, null, 2)); } // Function to add run data to runs.json export async function addRunData({ iAppAddress, dealid, taskid, txHash, chainName, }) { const runData = { iAppAddress, dealid, taskid, txHash, }; await addDataToCache('runs.json', chainName, runData); } // Function to add deployment data to deployments.json export async function addDeploymentData({ sconifiedImage, appContractAddress, owner, chainName, }) { const deploymentData = { sconifiedImage, appContractAddress, owner, }; await addDataToCache('deployments.json', chainName, deploymentData); } //# sourceMappingURL=cacheExecutions.js.map