Skip to content
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
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ pnpm install @limechain/renderers-dart
"args": [
"generated",
{
"libraryName": "myProject",
"deleteFolderBeforeRendering": true,
"formatCode": true
"formatCode": true,
"generateBorsh": true
}
]
}
Expand All @@ -53,15 +53,13 @@ pnpm install @limechain/renderers-dart
}
```

An object can be passed as a second argument to further configure the renderer. See the [Options](#options) section below for more details.

### 3.2. Run code generation

```sh
pnpm codama run dart
```

### 3.3. Run Dart Borsh code generation
### 3.3. (Only if `generateBorsh` is set to `false`) Run Dart Borsh code generation

```sh
cd generated
Expand Down Expand Up @@ -102,11 +100,10 @@ lib/

The `renderVisitor` accepts the following options.

| Name | Type | Default | Description |
| ----------------------------- | -------- | ------- | --------------------------------------------------------------- |
| `libraryName` | `string` | `'lib'` | The name of the generated Dart library. |
| `outputDirectory` | `string` | `'lib'` | The directory where generated files will be placed. |
| `deleteFolderBeforeRendering` | `bool` | `true` | Flag for deleting the output folder before generating it again. |
| `formatCode` | `bool` | `true` | Flag for formatting the Dart code after generation |
| Name | Type | Default | Description |
| ----------------------------- | ------ | ------- | --------------------------------------------------------------- |
| `deleteFolderBeforeRendering` | `bool` | `true` | Flag for deleting the output folder before generating it again. |
| `formatCode` | `bool` | `true` | Flag for formatting the Dart code after generation |
| `generateBorsh` | `bool` | `true` | Flag for running Borsh code generation after rendering |

<hr/>
26 changes: 12 additions & 14 deletions src/fragments/accountPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@ export function getAccountPageFragment(
return getStructAccountFragment(node, scope, className);
}

const typeInfo = getTypeInfo(dataTypeNode, scope.nameApi);
const borshAnnotation = getBorshAnnotation(dataTypeNode, scope.nameApi);
const allImports = [
'package:borsh_annotation_extended/borsh_annotation_extended.dart',
...typeInfo.imports,
];
const typeInfo = getTypeInfo(dataTypeNode, scope.nameApi, programNode.definedTypes);
const borshAnnotation = getBorshAnnotation(dataTypeNode, scope.nameApi, programNode.definedTypes);
const allImports = ['package:borsh_annotation_extended/borsh_annotation_extended.dart', ...typeInfo.imports];

const content = `part '${node.name}.g.dart';

Expand Down Expand Up @@ -68,21 +65,22 @@ function getStructAccountFragment(
const dataTypeNode = resolveNestedTypeNode(node.data);
const fields = isNode(dataTypeNode, 'structTypeNode') ? dataTypeNode.fields : [];

const programNode = findProgramNodeFromPath(scope.accountPath);
const programDefinedTypes = programNode?.definedTypes || [];

const allImports = new Set(['package:borsh_annotation_extended/borsh_annotation_extended.dart']);
const factoryParams = fields
.map(field => {
const typeInfo = getTypeInfo(field.type, scope.nameApi);
const borshAnnotation = getBorshAnnotation(field.type, scope.nameApi);
const typeInfo = getTypeInfo(field.type, scope.nameApi, programDefinedTypes);
const borshAnnotation = getBorshAnnotation(field.type, scope.nameApi, programDefinedTypes);
const fieldName = scope.nameApi.accountField(field.name);

typeInfo.imports.forEach(imp => allImports.add(imp));

return ` ${borshAnnotation} required ${typeInfo.dartType} ${fieldName},`;
})
.join('\n');

const allImports = new Set(['package:borsh_annotation_extended/borsh_annotation_extended.dart']);
fields.forEach(field => {
const typeInfo = getTypeInfo(field.type, scope.nameApi);
typeInfo.imports.forEach(imp => allImports.add(imp));
});

const content = `part '${node.name}.g.dart';

@BorshSerializable()
Expand Down
Loading