@aeternity/aepp-sdk
Version:
SDK for the æternity blockchain
33 lines (32 loc) • 1.63 kB
JavaScript
import _flagsInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/flags";
import { readFile } from 'fs/promises';
import { dirname, resolve, basename } from 'path';
import { InternalError } from '../../utils/errors.js';
const defaultIncludes = ['List.aes', 'Option.aes', 'String.aes', 'Func.aes', 'Pair.aes', 'Triple.aes', 'BLS12_381.aes', 'Frac.aes', 'Set.aes', 'Bitwise.aes'];
const includeRegExp = /^include\s*"([\w/.-]+)"/im;
const includesRegExp = new RegExp(includeRegExp.source, `${_flagsInstanceProperty(includeRegExp)}g`);
async function getFileSystemRec(root, relative) {
var _sourceCode$match;
const sourceCode = await readFile(resolve(root, relative), 'utf8');
const filesystem = {};
await Promise.all(((_sourceCode$match = sourceCode.match(includesRegExp)) !== null && _sourceCode$match !== void 0 ? _sourceCode$match : []).map(include => {
const m = include.match(includeRegExp);
if (m?.length !== 2) throw new InternalError('Unexpected match length');
return m[1];
}).filter(include => !defaultIncludes.includes(include)).map(async include => {
const includePath = resolve(root, include);
filesystem[include] = await readFile(includePath, 'utf8');
Object.assign(filesystem, await getFileSystemRec(root, include));
}));
return filesystem;
}
/**
* Reads all files included in the provided contract
* Available only in Node.js
* @param path - a path to the main contract source code
* @category contract
*/
export default async function getFileSystem(path) {
return getFileSystemRec(dirname(path), basename(path));
}
//# sourceMappingURL=getFileSystem.js.map