@twin.org/move-to-json 0.0.1-next.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +21 -0
- package/bin/index.js +8 -0
- package/dist/cjs/index.cjs +248 -0
- package/dist/esm/index.mjs +242 -0
- package/dist/locales/en.json +281 -0
- package/dist/types/cli.d.ts +23 -0
- package/dist/types/commands/moveToJson.d.ts +17 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/models/ICompiledModules.d.ts +18 -0
- package/dist/types/models/platformTypes.d.ts +17 -0
- package/docs/changelog.md +5 -0
- package/docs/examples.md +109 -0
- package/docs/reference/classes/CLI.md +83 -0
- package/docs/reference/functions/actionCommandMoveToJson.md +33 -0
- package/docs/reference/functions/buildCommandMoveToJson.md +17 -0
- package/docs/reference/index.md +22 -0
- package/docs/reference/interfaces/ICompiledModules.md +7 -0
- package/docs/reference/type-aliases/PlatformTypes.md +5 -0
- package/docs/reference/variables/PlatformTypes.md +19 -0
- package/locales/en.json +60 -0
- package/package.json +46 -0
package/docs/examples.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# @twin.org/move-to-json - Examples
|
|
2
|
+
|
|
3
|
+
## Move to JSON CLI
|
|
4
|
+
|
|
5
|
+
This CLI compiles one or more Move contracts (for either IOTA or SUI) into Base64-encoded modules, computes a package ID (SHA3-256), and merges the resulting data into a JSON file.
|
|
6
|
+
|
|
7
|
+
First install the tool with the following script.
|
|
8
|
+
|
|
9
|
+
```shell
|
|
10
|
+
npm install @twin.org/move-to-json
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Requirements
|
|
14
|
+
|
|
15
|
+
- IOTA Move CLI or SUI Move CLI installed in your PATH (for compilation). You can download the IOTA CLI by visiting the [IOTA CLI GitHub Releases](https://github.com/iotaledger/iota/releases) page and downloading the appropriate version for your operating system.
|
|
16
|
+
|
|
17
|
+
You can then run the tool from the command line e.g.
|
|
18
|
+
|
|
19
|
+
```shell
|
|
20
|
+
move-to-json
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
You should see the following response:
|
|
24
|
+
|
|
25
|
+
```shell
|
|
26
|
+
Starting Move to JSON
|
|
27
|
+
=====================
|
|
28
|
+
|
|
29
|
+
Usage:
|
|
30
|
+
move-to-json <inputGlob> <outputJson> [--platform=<platform>]
|
|
31
|
+
Error: You must specify both input glob and output JSON path
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
As you can see, you must provide both an input glob pattern that matches your Move source files and an output JSON file path.
|
|
35
|
+
|
|
36
|
+
## Example Usage
|
|
37
|
+
|
|
38
|
+
A typical command looks like this:
|
|
39
|
+
|
|
40
|
+
```shell
|
|
41
|
+
move-to-json "./src/contracts/**/*.move" ./src/contracts/compiled-modules.json --platform=iota
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
This will:
|
|
45
|
+
|
|
46
|
+
- Find all .move files in src/contracts and its subdirectories
|
|
47
|
+
- Compile each file using the IOTA Move compiler (or SUI if --platform=sui)
|
|
48
|
+
- Create or update compiled-modules.json with the compiled bytecode
|
|
49
|
+
|
|
50
|
+
## Expected Project Structure
|
|
51
|
+
|
|
52
|
+
The tool expects a standard Move project structure:
|
|
53
|
+
|
|
54
|
+
```markdown
|
|
55
|
+
myProject/
|
|
56
|
+
Move.toml
|
|
57
|
+
sources/
|
|
58
|
+
myContract.move
|
|
59
|
+
myOtherContract.move
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Where “myProject” is considered the “project root”:
|
|
63
|
+
|
|
64
|
+
- The CLI runs “iota move build” or “sui move build” in the project root (the folder containing Move.toml).
|
|
65
|
+
- The compiled .mv bytecode modules are placed under build/<snake_case_package_name>/bytecode_modules.
|
|
66
|
+
- The CLI loads these .mv files, computes a package ID (SHA3-256), and Base64-encodes them.
|
|
67
|
+
|
|
68
|
+
However, you can pass any glob pattern that matches one or more .move files. For each file, the CLI will move up one directory from wherever that file is located until it finds the Move.toml. As long as each .move file resides in a standard Move project folder (meaning you do have a Move.toml in its parent directory or above), this tool can find and build the contract.
|
|
69
|
+
|
|
70
|
+
For example, if your source is:
|
|
71
|
+
|
|
72
|
+
```markdown
|
|
73
|
+
./somewhere/nested/sources/myContract.move
|
|
74
|
+
./somewhere/nested/Move.toml
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Then your glob might look like:
|
|
78
|
+
|
|
79
|
+
```shell
|
|
80
|
+
move-to-json "./somewhere/nested/sources/*.move" ./build/contracts.json
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The CLI will automatically detect the project root as “./somewhere/nested” and run the Move compiler there.
|
|
84
|
+
|
|
85
|
+
## Output JSON Format
|
|
86
|
+
|
|
87
|
+
The resulting JSON file (e.g. ./src/contracts/contracts.json) will be updated with an entry for each contract file. The key is the kebab-cased file name (e.g. myContract.move → “my-contract”).
|
|
88
|
+
|
|
89
|
+
Each entry has:
|
|
90
|
+
|
|
91
|
+
- packageId – A 0x-prefix hex string (computed SHA3-256 of all compiled modules).
|
|
92
|
+
- package – Either a single Base64-encoded string (if there is one compiled module) or an array of Base64 strings (if multiple modules).
|
|
93
|
+
|
|
94
|
+
An example snippet of the final JSON might look like:
|
|
95
|
+
|
|
96
|
+
```json
|
|
97
|
+
{
|
|
98
|
+
"my-contract": {
|
|
99
|
+
"packageId": "0xabc123...4f9",
|
|
100
|
+
"package": "AAECAPN..."
|
|
101
|
+
},
|
|
102
|
+
"my-other-contract": {
|
|
103
|
+
"packageId": "0xdef456ff...b81",
|
|
104
|
+
"package": ["AAAEFW...", "AAABUK..."]
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
If the JSON file already exists, the newly compiled contracts are merged in (existing entries are preserved unless they share the same key, in which case they are overwritten).
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Class: CLI
|
|
2
|
+
|
|
3
|
+
The main entry point for the Move to JSON CLI.
|
|
4
|
+
|
|
5
|
+
## Extends
|
|
6
|
+
|
|
7
|
+
- `CLIBase`
|
|
8
|
+
|
|
9
|
+
## Constructors
|
|
10
|
+
|
|
11
|
+
### new CLI()
|
|
12
|
+
|
|
13
|
+
> **new CLI**(): [`CLI`](CLI.md)
|
|
14
|
+
|
|
15
|
+
#### Returns
|
|
16
|
+
|
|
17
|
+
[`CLI`](CLI.md)
|
|
18
|
+
|
|
19
|
+
#### Inherited from
|
|
20
|
+
|
|
21
|
+
`CLIBase.constructor`
|
|
22
|
+
|
|
23
|
+
## Methods
|
|
24
|
+
|
|
25
|
+
### run()
|
|
26
|
+
|
|
27
|
+
> **run**(`argv`, `localesDirectory`?, `options`?): `Promise`\<`number`\>
|
|
28
|
+
|
|
29
|
+
Run the app.
|
|
30
|
+
|
|
31
|
+
#### Parameters
|
|
32
|
+
|
|
33
|
+
##### argv
|
|
34
|
+
|
|
35
|
+
`string`[]
|
|
36
|
+
|
|
37
|
+
The process arguments.
|
|
38
|
+
|
|
39
|
+
##### localesDirectory?
|
|
40
|
+
|
|
41
|
+
`string`
|
|
42
|
+
|
|
43
|
+
The directory for the locales, default to relative to the script.
|
|
44
|
+
|
|
45
|
+
##### options?
|
|
46
|
+
|
|
47
|
+
Additional options.
|
|
48
|
+
|
|
49
|
+
###### overrideOutputWidth
|
|
50
|
+
|
|
51
|
+
`number`
|
|
52
|
+
|
|
53
|
+
Override the output width.
|
|
54
|
+
|
|
55
|
+
#### Returns
|
|
56
|
+
|
|
57
|
+
`Promise`\<`number`\>
|
|
58
|
+
|
|
59
|
+
The exit code.
|
|
60
|
+
|
|
61
|
+
***
|
|
62
|
+
|
|
63
|
+
### configureRoot()
|
|
64
|
+
|
|
65
|
+
> `protected` **configureRoot**(`program`): `void`
|
|
66
|
+
|
|
67
|
+
Configure any options or actions at the root program level.
|
|
68
|
+
|
|
69
|
+
#### Parameters
|
|
70
|
+
|
|
71
|
+
##### program
|
|
72
|
+
|
|
73
|
+
`Command`
|
|
74
|
+
|
|
75
|
+
The root program command.
|
|
76
|
+
|
|
77
|
+
#### Returns
|
|
78
|
+
|
|
79
|
+
`void`
|
|
80
|
+
|
|
81
|
+
#### Overrides
|
|
82
|
+
|
|
83
|
+
`CLIBase.configureRoot`
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Function: actionCommandMoveToJson()
|
|
2
|
+
|
|
3
|
+
> **actionCommandMoveToJson**(`inputGlob`, `outputJson`, `opts`): `Promise`\<`void`\>
|
|
4
|
+
|
|
5
|
+
Action the root command.
|
|
6
|
+
|
|
7
|
+
## Parameters
|
|
8
|
+
|
|
9
|
+
### inputGlob
|
|
10
|
+
|
|
11
|
+
`string`
|
|
12
|
+
|
|
13
|
+
A glob pattern that matches one or more Move files
|
|
14
|
+
|
|
15
|
+
### outputJson
|
|
16
|
+
|
|
17
|
+
`string`
|
|
18
|
+
|
|
19
|
+
Where we store the final compiled modules.
|
|
20
|
+
|
|
21
|
+
### opts
|
|
22
|
+
|
|
23
|
+
Additional options, e.g. platform.
|
|
24
|
+
|
|
25
|
+
#### platform
|
|
26
|
+
|
|
27
|
+
[`PlatformTypes`](../type-aliases/PlatformTypes.md)
|
|
28
|
+
|
|
29
|
+
The platform type.
|
|
30
|
+
|
|
31
|
+
## Returns
|
|
32
|
+
|
|
33
|
+
`Promise`\<`void`\>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Function: buildCommandMoveToJson()
|
|
2
|
+
|
|
3
|
+
> **buildCommandMoveToJson**(`program`): `void`
|
|
4
|
+
|
|
5
|
+
Build the root command to be consumed by the CLI.
|
|
6
|
+
|
|
7
|
+
## Parameters
|
|
8
|
+
|
|
9
|
+
### program
|
|
10
|
+
|
|
11
|
+
`Command`
|
|
12
|
+
|
|
13
|
+
The command to build on.
|
|
14
|
+
|
|
15
|
+
## Returns
|
|
16
|
+
|
|
17
|
+
`void`
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# @twin.org/move-to-json
|
|
2
|
+
|
|
3
|
+
## Classes
|
|
4
|
+
|
|
5
|
+
- [CLI](classes/CLI.md)
|
|
6
|
+
|
|
7
|
+
## Interfaces
|
|
8
|
+
|
|
9
|
+
- [ICompiledModules](interfaces/ICompiledModules.md)
|
|
10
|
+
|
|
11
|
+
## Type Aliases
|
|
12
|
+
|
|
13
|
+
- [PlatformTypes](type-aliases/PlatformTypes.md)
|
|
14
|
+
|
|
15
|
+
## Variables
|
|
16
|
+
|
|
17
|
+
- [PlatformTypes](variables/PlatformTypes.md)
|
|
18
|
+
|
|
19
|
+
## Functions
|
|
20
|
+
|
|
21
|
+
- [buildCommandMoveToJson](functions/buildCommandMoveToJson.md)
|
|
22
|
+
- [actionCommandMoveToJson](functions/actionCommandMoveToJson.md)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Variable: PlatformTypes
|
|
2
|
+
|
|
3
|
+
> `const` **PlatformTypes**: `object`
|
|
4
|
+
|
|
5
|
+
The platform types.
|
|
6
|
+
|
|
7
|
+
## Type declaration
|
|
8
|
+
|
|
9
|
+
### Iota
|
|
10
|
+
|
|
11
|
+
> `readonly` **Iota**: `"iota"` = `"iota"`
|
|
12
|
+
|
|
13
|
+
IOTA.
|
|
14
|
+
|
|
15
|
+
### Sui
|
|
16
|
+
|
|
17
|
+
> `readonly` **Sui**: `"sui"` = `"sui"`
|
|
18
|
+
|
|
19
|
+
SUI.
|
package/locales/en.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"error": {
|
|
3
|
+
"commands": {
|
|
4
|
+
"move-to-json": {
|
|
5
|
+
"failedReadingOutputJson": "Failed to read output JSON file: {file}",
|
|
6
|
+
"contractProcessingFailed": "Failed to process contract: {file}",
|
|
7
|
+
"mkdirFailed": "Failed to create output directory: {dir}",
|
|
8
|
+
"buildFailed": "Build failed on platform {platform} for file {file}",
|
|
9
|
+
"sdkNotInstalled": "The {platform} SDK is not installed. Please install it first."
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"commands": {
|
|
14
|
+
"move-to-json": {
|
|
15
|
+
"options": {
|
|
16
|
+
"inputGlob": {
|
|
17
|
+
"param": "'<'inputGlob'>'",
|
|
18
|
+
"description": "The directory (or glob) containing Move contracts."
|
|
19
|
+
},
|
|
20
|
+
"outputJson": {
|
|
21
|
+
"param": "'<'outputJson'>'",
|
|
22
|
+
"description": "The JSON file that will contain compiled modules."
|
|
23
|
+
},
|
|
24
|
+
"platform": {
|
|
25
|
+
"param": "--platform '<'platform'>'",
|
|
26
|
+
"description": "Which toolchain to use"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"warnings": {
|
|
30
|
+
"noMoveFilesFound": "No .move files found for the provided path: {inputGlob}"
|
|
31
|
+
},
|
|
32
|
+
"progress": {
|
|
33
|
+
"searchingFiles": "Searching for .move files...",
|
|
34
|
+
"processingMoveFile": "Processing file.",
|
|
35
|
+
"writingJsonFile": "Writing compiled modules JSON..."
|
|
36
|
+
},
|
|
37
|
+
"section": {
|
|
38
|
+
"start": "Starting Move to JSON"
|
|
39
|
+
},
|
|
40
|
+
"labels": {
|
|
41
|
+
"inputGlob": "Input Glob",
|
|
42
|
+
"outputJson": "Output JSON",
|
|
43
|
+
"platform": "Platform",
|
|
44
|
+
"matchedFilesCount": "Matched Files Count",
|
|
45
|
+
"mergingWithExistingJson": "Merging with existing JSON",
|
|
46
|
+
"noMoveFilesFound": "No .move files found for the provided path: {inputGlob}",
|
|
47
|
+
"noExistingJsonFound": "No existing JSON found",
|
|
48
|
+
"creatingNewJson": "Creating new JSON",
|
|
49
|
+
"contractName": "Contract Name",
|
|
50
|
+
"compileCmd": "Compile Command",
|
|
51
|
+
"workingDir": "Working Directory",
|
|
52
|
+
"compileOutput": "Compile Output",
|
|
53
|
+
"compileResult": "Compile Result",
|
|
54
|
+
"noBytecodeModulesFolderFound": "No bytecode_modules folder found for input file: {contractName}",
|
|
55
|
+
"noMvFilesFound": "No .mv files found for contract: {contractName}",
|
|
56
|
+
"computedPackageId": "Computed Package ID"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@twin.org/move-to-json",
|
|
3
|
+
"version": "0.0.1-next.12",
|
|
4
|
+
"description": "Tool to convert Move source files to JSON schemas",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/twinfoundation/dlt.git",
|
|
8
|
+
"directory": "packages/move-to-json"
|
|
9
|
+
},
|
|
10
|
+
"author": "cornel.filip@iota.org",
|
|
11
|
+
"license": "Apache-2.0",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=20.0.0"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@twin.org/cli-core": "next",
|
|
18
|
+
"@twin.org/core": "next",
|
|
19
|
+
"@twin.org/crypto": "next",
|
|
20
|
+
"@twin.org/nameof": "next",
|
|
21
|
+
"commander": "13.0.0",
|
|
22
|
+
"fast-glob": "3.3.3"
|
|
23
|
+
},
|
|
24
|
+
"main": "./dist/cjs/index.cjs",
|
|
25
|
+
"module": "./dist/esm/index.mjs",
|
|
26
|
+
"types": "./dist/types/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"require": "./dist/cjs/index.cjs",
|
|
30
|
+
"import": "./dist/esm/index.mjs",
|
|
31
|
+
"types": "./dist/types/index.d.ts"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"bin",
|
|
36
|
+
"dist/cjs",
|
|
37
|
+
"dist/esm",
|
|
38
|
+
"dist/locales",
|
|
39
|
+
"dist/types",
|
|
40
|
+
"locales",
|
|
41
|
+
"docs"
|
|
42
|
+
],
|
|
43
|
+
"bin": {
|
|
44
|
+
"move-to-json": "bin/index.js"
|
|
45
|
+
}
|
|
46
|
+
}
|