diff --git a/docs/cli/test.md b/docs/cli/test.md index c90576d4..2eb3cc2a 100644 --- a/docs/cli/test.md +++ b/docs/cli/test.md @@ -24,6 +24,7 @@ Helper and utilities for AEproject use, e.g. prefunded wallets, network definiti ```js const { networks, utils, wallets } = require('@aeternity/aeproject'); +const { getFileSystem } = require("@aeternity/aepp-sdk"); ``` Read [AEproject Library](../lib.md) for a more detailed explanation about the usage of these imports. @@ -42,7 +43,7 @@ aeSdk = await utils.getSdk(); Get the filesystem definition for (custom) `includes` of the given contract: ```js -const filesystem = utils.getFilesystem(EXAMPLE_CONTRACT_SOURCE); +const fileSystem = getFileSystem(EXAMPLE_CONTRACT_SOURCE); ``` Read the contract source from the filesystem: @@ -52,7 +53,7 @@ const sourceCode = utils.getContractContent(EXAMPLE_CONTRACT_SOURCE); Initialize the contract instance: ```js -contract = await aeSdk.initializeContract({ sourceCode, filesystem }); +contract = await aeSdk.initializeContract({ sourceCode, fileSystem }); ``` Deploy the contract: diff --git a/docs/lib.md b/docs/lib.md index bddb6920..ced3705a 100644 --- a/docs/lib.md +++ b/docs/lib.md @@ -13,11 +13,6 @@ utils.getContractContent(contractPath); ``` Read the contract source from given path, just a wrapper for `fs.readFileSync` using `utf-8` encoding. -```javascript -utils.getFilesystem(contractPath); -``` -Add the required filesystem imports for contract from given path, excluding the Sophia provided library imports. - ```javascript utils.get(url); ``` diff --git a/src/init/update-artifacts/test/exampleTest.js b/src/init/update-artifacts/test/exampleTest.js index f38363a6..e535a765 100644 --- a/src/init/update-artifacts/test/exampleTest.js +++ b/src/init/update-artifacts/test/exampleTest.js @@ -1,5 +1,6 @@ const { assert } = require('chai'); const { utils } = require('@aeternity/aeproject'); +const { getFileSystem } = require("@aeternity/aepp-sdk"); const EXAMPLE_CONTRACT_SOURCE = './contracts/ExampleContract.aes'; @@ -11,7 +12,7 @@ describe('ExampleContract', () => { aeSdk = await utils.getSdk(); // a filesystem object must be passed to the compiler if the contract uses custom includes - const fileSystem = utils.getFilesystem(EXAMPLE_CONTRACT_SOURCE); + const fileSystem = await getFileSystem(EXAMPLE_CONTRACT_SOURCE); // get content of contract const sourceCode = utils.getContractContent(EXAMPLE_CONTRACT_SOURCE); diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 2f94f694..28cc4207 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -1,8 +1,7 @@ import fs from 'fs'; -import path from 'path'; import { - AeSdk, MemoryAccount, Node, CompilerHttp, + AeSdk, MemoryAccount, Node, CompilerHttp, getFileSystem, } from '@aeternity/aepp-sdk'; import * as networks from './networks.json'; import wallets from './wallets.json'; @@ -10,48 +9,6 @@ import { get } from '../utils/utils'; export const getContractContent = (contractPath) => fs.readFileSync(contractPath, 'utf8'); -export const getFilesystem = (contractPath) => { - const defaultIncludes = [ - 'List.aes', 'Option.aes', 'String.aes', - 'Func.aes', 'Pair.aes', 'Triple.aes', - 'BLS12_381.aes', 'Frac.aes', 'Set.aes', - 'Bitwise.aes', - ]; - - const rgx = /^include\s+"([\w/.-]+)"/gim; - const rgxIncludePath = /"([\w/.-]+)"/i; - const rgxMainPath = /.*\//g; - - const contractContent = getContractContent(contractPath); - const filesystem = {}; - - const rootIncludes = contractContent.match(rgx); - if (!rootIncludes) return filesystem; - const contractPathMatch = rgxMainPath.exec(contractPath); - - // eslint-disable-next-line no-restricted-syntax - for (const rootInclude of rootIncludes) { - const includeRelativePath = rgxIncludePath.exec(rootInclude); - - // eslint-disable-next-line no-continue - if (defaultIncludes.includes(includeRelativePath[1])) continue; - - // eslint-disable-next-line no-console - console.log(`==> Adding include to filesystem: ${includeRelativePath[1]}`); - const includePath = path.resolve(`${contractPathMatch[0]}/${includeRelativePath[1]}`); - - try { - filesystem[includeRelativePath[1]] = fs.readFileSync(includePath, 'utf-8'); - } catch (error) { - throw Error(`File to include '${includeRelativePath[1]}' not found.`); - } - - Object.assign(filesystem, getFilesystem(includePath)); - } - - return filesystem; -}; - export const getDefaultAccounts = () => wallets.map((keypair) => new MemoryAccount(keypair.secretKey)); export const getSdk = () => {