UNPKG

vasku

Version:

TVM-Solidity contract development framework

62 lines (61 loc) 1.98 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.writeCache = exports.readCache = void 0; const path_1 = __importDefault(require("path")); const fs_extra_1 = __importDefault(require("fs-extra")); const FILE = 'contracts.json'; /** * Read metadata from cache * @param config * @return Example: * { * 'TokenRoot.tsol': { * modificationTime: 1685314482, * imports: ['ITokenRoot.tsol'] * }, * 'TokenWallet.tsol': { * modificationTime: 1685314482, * imports: ['ITokenWallet.tsol'] * } * } */ function readCache(config) { const file = path_1.default.resolve(process.cwd(), config.paths.cache, FILE); if (!fs_extra_1.default.existsSync(file)) return {}; const cache = JSON.parse(fs_extra_1.default.readFileSync(file, { encoding: 'utf8' })); if (cache.compiler !== config.compile.compiler && cache.linker !== config.compile.linker) return {}; return cache.contracts ?? {}; } exports.readCache = readCache; /** * Write metadata to cache * @param config * @param metadata Example: * { * 'TokenRoot.tsol': { * modificationTime: 1685314482, * imports: ['ITokenRoot.tsol'] * }, * 'TokenWallet.tsol': { * modificationTime: 1685314482, * imports: ['ITokenWallet.tsol'] * } * } */ function writeCache(config, metadata) { const file = path_1.default.resolve(process.cwd(), config.paths.cache, FILE); const directory = path_1.default.dirname(file); const cache = { compiler: config.compile.compiler, linker: config.compile.linker, contracts: metadata }; fs_extra_1.default.mkdirSync(directory, { recursive: true }); fs_extra_1.default.writeFileSync(file, JSON.stringify(cache, null, 2)); } exports.writeCache = writeCache;