Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: use sdk getfilesystem #5

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/pre-check-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on: [push]

jobs:
pre-check-publish:

runs-on: ubuntu-latest

steps:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ npm install -g @aeternity/aeproject
- [Unit Testing](docs/cli/test.md)
- [AEproject Library](docs/lib.md)
- [Migration from 3.x.x to 4.x.x](docs/migration-from-3.x.x-to-4.x.x.md)
- [Migration from 4.x.x to 5.x.x](docs/migration-from-4.x.x-to-5.x.x.md)
- [Upcoming Version Support](docs/next-support.md)

## Release Process
Expand Down
4 changes: 2 additions & 2 deletions docs/cli/init.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Creates a new project structure with a few folders in which the developer can cr

## Update existing project

For upgrade from old AEproject versions check out [Migration from 3.x.x to 4.x.x](../migration-from-3.x.x-to-4.x.x.md).
For upgrade from old AEproject versions check out [Migration from 3.x.x to 4.x.x](../migration-from-3.x.x-to-4.x.x.md) and [Migration from 4.x.x to 5.x.x](../migration-from-4.x.x-to-5.x.x.md).

```text
aeproject init --update
Expand All @@ -20,4 +20,4 @@ Updates the project structure and needed artifacts to the latest version, as wel

## Upcoming Hard-fork initialization

The additional parameter `--next` can be used to either initialize or update a project with changes for an upcoming hard-fork if available.
The additional parameter `--next` can be used to either initialize or update a project with changes for an upcoming hard-fork if available.
5 changes: 3 additions & 2 deletions docs/cli/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -45,7 +46,7 @@ aeSdk = utils.getSdk();
Get the filesystem definition for (custom) `includes` of the given contract:

```js
const filesystem = utils.getFilesystem(EXAMPLE_CONTRACT_SOURCE);
const fileSystem = await getFileSystem(EXAMPLE_CONTRACT_SOURCE);
```

Read the contract source from the filesystem:
Expand All @@ -57,7 +58,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:
Expand Down
6 changes: 0 additions & 6 deletions docs/lib.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,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);
```
Expand Down
17 changes: 17 additions & 0 deletions docs/migration-from-4.x.x-to-5.x.x.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Migration from 4.x.x to 5.x.x

## Changes

**AEproject** `v5.0.0` underwent some minor but breaking changes.

Install the new AEproject version

```
npm install -g @aeternity/aeproject
```

### Removed from libs

Following utils have been removed and cannot be used anymore:

- `utils.getFilesystem()` discontinued, as it is now natively available in the sdk via import, e.g. `const { getFileSystem } = require("@aeternity/aepp-sdk");`
6 changes: 3 additions & 3 deletions docs/next-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Aeproject can already be used for testing and setup with the upcoming node versi

Use `aeproject init --next ` to initialize a new project that has the necessary adjustments to use the latest versions.

Use `aeproject init --update --next` to update an existing project with the adjustments to use the latest versions.
Use `aeproject init --update --next` to update an existing project with the adjustments to use the latest versions.

### Manual update

- change occurrences of `utils.getSdk()` to use `utils.getSdk({ ignoreVersion: true })` if needed or use the same option for manually initialized sdk `Node` and `CompilerHttp`
- update `docker-compose.yml` to use the `latest` node and compiler tags or specify it manually in running with `aeproject env --nodeVersion latest --compilerVersion latest`
- change occurrences of `utils.getSdk()` to use `utils.getSdk({ ignoreVersion: true })` if needed or use the same option for manually initialized sdk `Node` and `CompilerHttp`
- update `docker-compose.yml` to use the `latest` node and compiler tags or specify it manually in running with `aeproject env --nodeVersion latest --compilerVersion latest`
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ nav:
- cli/test.md
- lib.md
- migration-from-3.x.x-to-4.x.x.md
- migration-from-4.x.x-to-5.x.x.md
- next-support.md
3 changes: 2 additions & 1 deletion src/init/update-artifacts/test/exampleTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { assert } = require("chai");
const { utils } = require("@aeternity/aeproject");
const chaiAsPromised = require("chai-as-promised");
const chai = require("chai");
const { getFileSystem } = require("@aeternity/aepp-sdk");

chai.use(chaiAsPromised);

Expand All @@ -15,7 +16,7 @@ describe("ExampleContract", () => {
aeSdk = 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);
Expand Down
53 changes: 0 additions & 53 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,6 @@ export function getContractContent(contractPath: string): string {
return fs.readFileSync(contractPath, "utf8");
}

export function getFilesystem(contractPath: string): { [key: string]: string } {
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 function getDefaultAccounts(): MemoryAccount[] {
return wallets.map((keypair) => new MemoryAccount(keypair.secretKey));
}
Expand Down
Loading