@cartesi/cli 2.0.0-alpha.2 → 2.0.0-alpha.21

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.
Files changed (169) hide show
  1. package/dist/base.d.ts +28 -0
  2. package/dist/base.d.ts.map +1 -0
  3. package/dist/base.js +109 -0
  4. package/dist/builder/directory.d.ts +2 -2
  5. package/dist/builder/directory.d.ts.map +1 -1
  6. package/dist/builder/directory.js +5 -3
  7. package/dist/builder/docker.d.ts +2 -2
  8. package/dist/builder/docker.d.ts.map +1 -1
  9. package/dist/builder/docker.js +39 -37
  10. package/dist/builder/empty.d.ts +1 -1
  11. package/dist/builder/empty.d.ts.map +1 -1
  12. package/dist/builder/empty.js +1 -1
  13. package/dist/builder/none.d.ts +1 -1
  14. package/dist/builder/none.d.ts.map +1 -1
  15. package/dist/builder/none.js +1 -1
  16. package/dist/builder/tar.d.ts +1 -1
  17. package/dist/builder/tar.d.ts.map +1 -1
  18. package/dist/builder/tar.js +1 -1
  19. package/dist/commands/address-book.d.ts +5 -8
  20. package/dist/commands/address-book.d.ts.map +1 -1
  21. package/dist/commands/address-book.js +18 -14
  22. package/dist/commands/build.d.ts +7 -11
  23. package/dist/commands/build.d.ts.map +1 -1
  24. package/dist/commands/build.js +82 -58
  25. package/dist/commands/clean.d.ts +2 -7
  26. package/dist/commands/clean.d.ts.map +1 -1
  27. package/dist/commands/clean.js +9 -10
  28. package/dist/commands/create.d.ts +6 -15
  29. package/dist/commands/create.d.ts.map +1 -1
  30. package/dist/commands/create.js +25 -54
  31. package/dist/commands/deploy/build.d.ts +2 -14
  32. package/dist/commands/deploy/build.d.ts.map +1 -1
  33. package/dist/commands/deploy/build.js +8 -61
  34. package/dist/commands/deploy.d.ts +3 -0
  35. package/dist/commands/deploy.d.ts.map +1 -0
  36. package/dist/commands/deploy.js +12 -0
  37. package/dist/commands/deposit/erc1155.d.ts +18 -0
  38. package/dist/commands/deposit/erc1155.d.ts.map +1 -0
  39. package/dist/commands/deposit/erc1155.js +254 -0
  40. package/dist/commands/deposit/erc20.d.ts +10 -0
  41. package/dist/commands/deposit/erc20.d.ts.map +1 -0
  42. package/dist/commands/deposit/erc20.js +125 -0
  43. package/dist/commands/deposit/erc721.d.ts +10 -0
  44. package/dist/commands/deposit/erc721.d.ts.map +1 -0
  45. package/dist/commands/deposit/erc721.js +143 -0
  46. package/dist/commands/deposit/ether.d.ts +10 -0
  47. package/dist/commands/deposit/ether.d.ts.map +1 -0
  48. package/dist/commands/deposit/ether.js +65 -0
  49. package/dist/commands/deposit.d.ts +9 -0
  50. package/dist/commands/deposit.d.ts.map +1 -0
  51. package/dist/commands/deposit.js +37 -0
  52. package/dist/commands/doctor.d.ts +2 -12
  53. package/dist/commands/doctor.d.ts.map +1 -1
  54. package/dist/commands/doctor.js +90 -91
  55. package/dist/commands/hash.d.ts +4 -9
  56. package/dist/commands/hash.d.ts.map +1 -1
  57. package/dist/commands/hash.js +14 -14
  58. package/dist/commands/logs.d.ts +9 -0
  59. package/dist/commands/logs.d.ts.map +1 -0
  60. package/dist/commands/logs.js +34 -0
  61. package/dist/commands/run.d.ts +14 -20
  62. package/dist/commands/run.d.ts.map +1 -1
  63. package/dist/commands/run.js +193 -182
  64. package/dist/commands/send.d.ts +10 -0
  65. package/dist/commands/send.d.ts.map +1 -0
  66. package/dist/commands/send.js +130 -0
  67. package/dist/commands/shell.d.ts +6 -14
  68. package/dist/commands/shell.d.ts.map +1 -1
  69. package/dist/commands/shell.js +34 -51
  70. package/dist/commands/status.d.ts +6 -0
  71. package/dist/commands/status.d.ts.map +1 -0
  72. package/dist/commands/status.js +50 -0
  73. package/dist/compose/default.env +36 -0
  74. package/dist/compose/docker-compose-anvil.yaml +39 -0
  75. package/dist/compose/docker-compose-bundler.yaml +71 -0
  76. package/dist/{node → compose}/docker-compose-database.yaml +4 -2
  77. package/dist/compose/docker-compose-explorer.yaml +96 -0
  78. package/dist/compose/docker-compose-node-cpus.yaml +6 -0
  79. package/dist/compose/docker-compose-node-memory.yaml +6 -0
  80. package/dist/compose/docker-compose-node.yaml +50 -0
  81. package/dist/compose/docker-compose-passkey-server.yaml +37 -0
  82. package/dist/compose/docker-compose-paymaster.yaml +40 -0
  83. package/dist/compose/docker-compose-proxy.yaml +24 -0
  84. package/dist/config.d.ts +30 -9
  85. package/dist/config.d.ts.map +1 -1
  86. package/dist/config.js +93 -53
  87. package/dist/contracts.d.ts +1695 -1636
  88. package/dist/contracts.d.ts.map +1 -1
  89. package/dist/contracts.js +632 -592
  90. package/dist/exec/cartesi-machine.d.ts +2 -2
  91. package/dist/exec/cartesi-machine.d.ts.map +1 -1
  92. package/dist/exec/cartesi-machine.js +3 -5
  93. package/dist/exec/genext2fs.d.ts +6 -3
  94. package/dist/exec/genext2fs.d.ts.map +1 -1
  95. package/dist/exec/genext2fs.js +5 -5
  96. package/dist/exec/index.d.ts +0 -1
  97. package/dist/exec/index.d.ts.map +1 -1
  98. package/dist/exec/index.js +0 -1
  99. package/dist/exec/mksquashfs.d.ts +2 -2
  100. package/dist/exec/mksquashfs.d.ts.map +1 -1
  101. package/dist/exec/mksquashfs.js +4 -2
  102. package/dist/exec/rollups.d.ts +105 -0
  103. package/dist/exec/rollups.d.ts.map +1 -0
  104. package/dist/exec/rollups.js +375 -0
  105. package/dist/exec/util.d.ts +1 -16
  106. package/dist/exec/util.d.ts.map +1 -1
  107. package/dist/exec/util.js +3 -50
  108. package/dist/index.d.ts +2 -1
  109. package/dist/index.d.ts.map +1 -1
  110. package/dist/index.js +57 -1
  111. package/dist/machine.d.ts +8 -2
  112. package/dist/machine.d.ts.map +1 -1
  113. package/dist/machine.js +26 -16
  114. package/dist/prompts.d.ts +13 -2
  115. package/dist/prompts.d.ts.map +1 -1
  116. package/dist/prompts.js +60 -26
  117. package/dist/template.d.ts +3 -0
  118. package/dist/template.d.ts.map +1 -0
  119. package/dist/template.js +16 -0
  120. package/dist/wallet.d.ts +9222 -21
  121. package/dist/wallet.d.ts.map +1 -1
  122. package/dist/wallet.js +35 -198
  123. package/package.json +39 -57
  124. package/bin/dev.cmd +0 -3
  125. package/bin/dev.js +0 -25
  126. package/bin/run.cmd +0 -3
  127. package/bin/run.js +0 -8
  128. package/dist/baseCommand.d.ts +0 -22
  129. package/dist/baseCommand.d.ts.map +0 -1
  130. package/dist/baseCommand.js +0 -92
  131. package/dist/commands/deploy/index.d.ts +0 -12
  132. package/dist/commands/deploy/index.d.ts.map +0 -1
  133. package/dist/commands/deploy/index.js +0 -78
  134. package/dist/commands/send/erc20.d.ts +0 -14
  135. package/dist/commands/send/erc20.d.ts.map +0 -1
  136. package/dist/commands/send/erc20.js +0 -70
  137. package/dist/commands/send/erc721.d.ts +0 -14
  138. package/dist/commands/send/erc721.d.ts.map +0 -1
  139. package/dist/commands/send/erc721.js +0 -73
  140. package/dist/commands/send/ether.d.ts +0 -13
  141. package/dist/commands/send/ether.d.ts.map +0 -1
  142. package/dist/commands/send/ether.js +0 -32
  143. package/dist/commands/send/generic.d.ts +0 -15
  144. package/dist/commands/send/generic.d.ts.map +0 -1
  145. package/dist/commands/send/generic.js +0 -119
  146. package/dist/commands/send/index.d.ts +0 -28
  147. package/dist/commands/send/index.d.ts.map +0 -1
  148. package/dist/commands/send/index.js +0 -102
  149. package/dist/exec/crane.d.ts +0 -15
  150. package/dist/exec/crane.d.ts.map +0 -1
  151. package/dist/exec/crane.js +0 -17
  152. package/dist/flags.d.ts +0 -17
  153. package/dist/flags.d.ts.map +0 -1
  154. package/dist/flags.js +0 -28
  155. package/dist/node/DockerfileDeploy.txt +0 -4
  156. package/dist/node/default.env +0 -27
  157. package/dist/node/docker-compose-anvil.yaml +0 -50
  158. package/dist/node/docker-compose-bundler.yaml +0 -57
  159. package/dist/node/docker-compose-envfile.yaml +0 -4
  160. package/dist/node/docker-compose-explorer.yaml +0 -88
  161. package/dist/node/docker-compose-host.yaml +0 -30
  162. package/dist/node/docker-compose-paymaster.yaml +0 -33
  163. package/dist/node/docker-compose-prompt.yaml +0 -17
  164. package/dist/node/docker-compose-proxy.yaml +0 -48
  165. package/dist/node/docker-compose-snapshot-volume.yaml +0 -8
  166. package/dist/node/docker-compose-validator-cpus.yaml +0 -6
  167. package/dist/node/docker-compose-validator-memory.yaml +0 -6
  168. package/dist/node/docker-compose-validator.yaml +0 -59
  169. package/oclif.manifest.json +0 -876
package/dist/base.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ import { type Address, type Hash } from "viem";
2
+ import { type Config } from "./config.js";
3
+ import type { PsResponse } from "./types/docker.js";
4
+ export declare const getContextPath: (...paths: string[]) => string;
5
+ export declare const getMachineHash: () => Hash | undefined;
6
+ export declare const getApplicationConfig: (configPaths: string[]) => Config;
7
+ export declare const getProjectName: (options: {
8
+ projectName?: string;
9
+ }) => string;
10
+ export type AddressBook = Record<string, Address>;
11
+ export declare const getAddressBook: (options: {
12
+ projectName?: string;
13
+ }) => Promise<AddressBook>;
14
+ export declare const getServiceInfo: (options: {
15
+ projectName: string;
16
+ service: string;
17
+ }) => Promise<PsResponse | undefined>;
18
+ export declare const getServiceState: (options: {
19
+ projectName: string;
20
+ service: string;
21
+ }) => Promise<string | undefined>;
22
+ export declare const getServiceHealth: (options: {
23
+ projectName: string;
24
+ service: string;
25
+ }) => Promise<string | undefined>;
26
+ export declare const parseAddress: (value: string) => Address | undefined;
27
+ export declare const parseHash: (value: string) => Hash;
28
+ //# sourceMappingURL=base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AAIA,OAAO,EACH,KAAK,OAAO,EAEZ,KAAK,IAAI,EAIZ,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,KAAK,MAAM,EAAS,MAAM,aAAa,CAAC;AAgBjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,eAAO,MAAM,cAAc,GAAI,GAAG,OAAO,MAAM,EAAE,KAAG,MAEnD,CAAC;AAEF,eAAO,MAAM,cAAc,QAAO,IAAI,GAAG,SAUxC,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAI,aAAa,MAAM,EAAE,KAAG,MAW5D,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,SAAS;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,WAE/D,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAElD,eAAO,MAAM,cAAc,GAAU,SAAS;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB,KAAG,OAAO,CAAC,WAAW,CAkCtB,CAAC;AAEF,eAAO,MAAM,cAAc,GAAU,SAAS;IAC1C,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACnB,KAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAcjC,CAAC;AAEF,eAAO,MAAM,eAAe,GAAU,SAAS;IAC3C,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACnB,KAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAG7B,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAU,SAAS;IAC5C,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACnB,KAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAG7B,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,KAAG,OAAO,GAAG,SAQtD,CAAC;AAEF,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,KAAG,IAQzC,CAAC"}
package/dist/base.js ADDED
@@ -0,0 +1,109 @@
1
+ import { InvalidArgumentError } from "@commander-js/extra-typings";
2
+ import { execa } from "execa";
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import { getAddress, isAddress, isHash, zeroHash, } from "viem";
6
+ import { parse } from "./config.js";
7
+ import { applicationFactoryAddress, authorityFactoryAddress, erc1155BatchPortalAddress, erc1155SinglePortalAddress, erc20PortalAddress, erc721PortalAddress, etherPortalAddress, inputBoxAddress, selfHostedApplicationFactoryAddress, testMultiTokenAddress, testNftAddress, testTokenAddress, } from "./contracts.js";
8
+ import { getApplicationAddress } from "./exec/rollups.js";
9
+ export const getContextPath = (...paths) => {
10
+ return path.join(".cartesi", ...paths);
11
+ };
12
+ export const getMachineHash = () => {
13
+ // read hash of the cartesi machine snapshot, if one exists
14
+ const hashPath = getContextPath("image", "hash");
15
+ if (fs.existsSync(hashPath)) {
16
+ const hash = fs.readFileSync(hashPath).toString("hex");
17
+ if (isHash(`0x${hash}`)) {
18
+ return `0x${hash}`;
19
+ }
20
+ }
21
+ return undefined;
22
+ };
23
+ export const getApplicationConfig = (configPaths) => {
24
+ const tomls = configPaths.map((configPath) => {
25
+ if (fs.existsSync(configPath)) {
26
+ return fs.readFileSync(configPath).toString();
27
+ }
28
+ if (configPath === "cartesi.toml") {
29
+ return "";
30
+ }
31
+ throw new Error(`Config file ${configPath} does not exist`);
32
+ });
33
+ return parse(tomls);
34
+ };
35
+ export const getProjectName = (options) => {
36
+ return options.projectName ?? path.basename(process.cwd());
37
+ };
38
+ export const getAddressBook = async (options) => {
39
+ const applicationAddress = await getApplicationAddress(options);
40
+ // build rollups contracts address book
41
+ const contracts = {
42
+ ApplicationFactory: applicationFactoryAddress,
43
+ AuthorityFactory: authorityFactoryAddress,
44
+ EntryPointV06: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
45
+ EntryPointV07: "0x0000000071727De22E5E9d8BAf0edAc6f37da032",
46
+ ERC1155BatchPortal: erc1155BatchPortalAddress,
47
+ ERC1155SinglePortal: erc1155SinglePortalAddress,
48
+ ERC20Portal: erc20PortalAddress,
49
+ ERC721Portal: erc721PortalAddress,
50
+ EtherPortal: etherPortalAddress,
51
+ InputBox: inputBoxAddress,
52
+ LightAccountFactory: "0x00004EC70002a32400f8ae005A26081065620D20",
53
+ SelfHostedApplicationFactory: selfHostedApplicationFactoryAddress,
54
+ SimpleAccountFactory: "0x9406Cc6185a346906296840746125a0E44976454",
55
+ SmartAccountFactory: "0x000000a56Aaca3e9a4C479ea6b6CD0DbcB6634F5",
56
+ KernelFactoryV2: "0x5de4839a76cf55d0c90e2061ef4386d962E15ae3",
57
+ KernelFactoryV3: "0x6723b44Abeec4E71eBE3232BD5B455805baDD22f",
58
+ KernelFactoryV3_1: "0xaac5D4240AF87249B3f71BC8E4A2cae074A3E419",
59
+ TestToken: testTokenAddress,
60
+ TestNFT: testNftAddress,
61
+ TestMultiToken: testMultiTokenAddress,
62
+ VerifyingPaymasterV06: "0x28ec0633192d0cBd9E1156CE05D5FdACAcB93947",
63
+ VerifyingPaymasterV07: "0xc5c97885C67F7361aBAfD2B95067a5bBdA603608",
64
+ };
65
+ if (applicationAddress) {
66
+ contracts.Application = applicationAddress;
67
+ }
68
+ return contracts;
69
+ };
70
+ export const getServiceInfo = async (options) => {
71
+ const { projectName, service } = options;
72
+ // get service information
73
+ const { stdout } = await execa("docker", [
74
+ "compose",
75
+ "--project-name",
76
+ projectName,
77
+ "ps",
78
+ service,
79
+ "--format",
80
+ "json",
81
+ ]);
82
+ return stdout ? JSON.parse(stdout) : undefined;
83
+ };
84
+ export const getServiceState = async (options) => {
85
+ const info = await getServiceInfo(options);
86
+ return info?.State;
87
+ };
88
+ export const getServiceHealth = async (options) => {
89
+ const info = await getServiceInfo(options);
90
+ return info?.Health;
91
+ };
92
+ export const parseAddress = (value) => {
93
+ if (isAddress(value)) {
94
+ return getAddress(value);
95
+ }
96
+ if (value !== "") {
97
+ throw new InvalidArgumentError(`Invalid address: ${value}`);
98
+ }
99
+ return undefined;
100
+ };
101
+ export const parseHash = (value) => {
102
+ if (isHash(value)) {
103
+ return value;
104
+ }
105
+ if (value !== "") {
106
+ throw new InvalidArgumentError(`Invalid hash: ${value}`);
107
+ }
108
+ return zeroHash;
109
+ };
@@ -1,3 +1,3 @@
1
- import { DirectoryDriveConfig } from "../config.js";
2
- export declare const build: (name: string, drive: DirectoryDriveConfig, sdkImage: string, destination: string) => Promise<void>;
1
+ import type { DirectoryDriveConfig } from "../config.js";
2
+ export declare const build: (name: string, drive: DirectoryDriveConfig, sdkImage: string, destination: string, debug: boolean) => Promise<void>;
3
3
  //# sourceMappingURL=directory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"directory.d.ts","sourceRoot":"","sources":["../../src/builder/directory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAGpD,eAAO,MAAM,KAAK,SACR,MAAM,SACL,oBAAoB,YACjB,MAAM,eACH,MAAM,KACpB,OAAO,CAAC,IAAI,CAkCd,CAAC"}
1
+ {"version":3,"file":"directory.d.ts","sourceRoot":"","sources":["../../src/builder/directory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAGzD,eAAO,MAAM,KAAK,GACd,MAAM,MAAM,EACZ,OAAO,oBAAoB,EAC3B,UAAU,MAAM,EAChB,aAAa,MAAM,EACnB,OAAO,OAAO,KACf,OAAO,CAAC,IAAI,CAoCd,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import fs from "fs-extra";
2
- import path from "path";
2
+ import path from "node:path";
3
3
  import { genext2fs, mksquashfs } from "../exec/index.js";
4
- export const build = async (name, drive, sdkImage, destination) => {
4
+ export const build = async (name, drive, sdkImage, destination, debug) => {
5
5
  const filename = `${name}.${drive.format}`;
6
6
  // copy directory to destination
7
7
  const dest = path.join(destination, name);
@@ -32,6 +32,8 @@ export const build = async (name, drive, sdkImage, destination) => {
32
32
  }
33
33
  finally {
34
34
  // delete copied
35
- await fs.remove(dest);
35
+ if (!debug) {
36
+ await fs.remove(dest);
37
+ }
36
38
  }
37
39
  };
@@ -1,10 +1,10 @@
1
- import { DockerDriveConfig } from "../config.js";
1
+ import type { DockerDriveConfig } from "../config.js";
2
2
  type ImageInfo = {
3
3
  cmd: string[];
4
4
  entrypoint: string[];
5
5
  env: string[];
6
6
  workdir: string;
7
7
  };
8
- export declare const build: (name: string, drive: DockerDriveConfig, sdkImage: string, destination: string) => Promise<ImageInfo | undefined>;
8
+ export declare const build: (name: string, drive: DockerDriveConfig, sdkImage: string, destination: string, debug: boolean) => Promise<ImageInfo | undefined>;
9
9
  export {};
10
10
  //# sourceMappingURL=docker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"docker.d.ts","sourceRoot":"","sources":["../../src/builder/docker.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAQjD,KAAK,SAAS,GAAG;IACb,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACnB,CAAC;AA+DF,eAAO,MAAM,KAAK,SACR,MAAM,SACL,iBAAiB,YACd,MAAM,eACH,MAAM,KACpB,OAAO,CAAC,SAAS,GAAG,SAAS,CA4D/B,CAAC"}
1
+ {"version":3,"file":"docker.d.ts","sourceRoot":"","sources":["../../src/builder/docker.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAQtD,KAAK,SAAS,GAAG;IACb,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACnB,CAAC;AAiFF,eAAO,MAAM,KAAK,GACd,MAAM,MAAM,EACZ,OAAO,iBAAiB,EACxB,UAAU,MAAM,EAChB,aAAa,MAAM,EACnB,OAAO,OAAO,KACf,OAAO,CAAC,SAAS,GAAG,SAAS,CAsD/B,CAAC"}
@@ -1,33 +1,39 @@
1
1
  import { execa } from "execa";
2
2
  import fs from "fs-extra";
3
- import path from "path";
4
- import tmp from "tmp";
5
- import { crane, genext2fs, mksquashfs } from "../exec/index.js";
3
+ import path from "node:path";
4
+ import { genext2fs, mksquashfs } from "../exec/index.js";
6
5
  /**
7
6
  * Build Docker image (linux/riscv64). Returns image id.
8
7
  */
9
8
  const buildImage = async (options) => {
10
- const { context, dockerfile, tags, target } = options;
11
- const buildResult = tmp.tmpNameSync();
9
+ const { buildArgs, context, destination, dockerfile, dockerfileContent, tags, target, } = options;
10
+ // if dockerfileContext is specified, use it as the dockerfile passed through stdin
12
11
  const args = [
13
12
  "buildx",
14
13
  "build",
15
14
  "--platform",
16
15
  "linux/riscv64",
17
16
  "--file",
18
- dockerfile,
19
- "--load",
20
- "--iidfile",
21
- buildResult,
22
- context,
17
+ dockerfileContent ? "-" : dockerfile,
18
+ "--output",
19
+ "type=docker",
20
+ "--output",
21
+ `type=tar,dest=${destination}`,
22
+ "--progress",
23
+ "quiet",
23
24
  ];
24
25
  // set tags for the image built
25
- args.push(...tags.map((tag) => ["--tag", tag]).flat());
26
+ args.push(...tags.flatMap((tag) => ["--tag", tag]));
27
+ // set build args
28
+ args.push(...buildArgs.flatMap((arg) => ["--build-arg", arg]));
26
29
  if (target) {
27
30
  args.push("--target", target);
28
31
  }
29
- await execa("docker", args, { stdio: "inherit" });
30
- return fs.readFileSync(buildResult, "utf8");
32
+ args.push(context);
33
+ const { stdout: imageId } = await execa("docker", args, {
34
+ input: dockerfileContent,
35
+ });
36
+ return imageId;
31
37
  };
32
38
  /**
33
39
  * Query the image using docker image inspect
@@ -43,44 +49,39 @@ const getImageInfo = async (image) => {
43
49
  // parse image info from docker inspect output
44
50
  const [imageInfo] = JSON.parse(jsonStr);
45
51
  // validate image architecture (must be riscv64)
46
- if (imageInfo["Architecture"] !== "riscv64") {
47
- throw new Error(`Invalid image Architecture: ${imageInfo["Architecture"]}. Expected riscv64`);
52
+ if (imageInfo.Architecture !== "riscv64") {
53
+ throw new Error(`Invalid image Architecture: ${imageInfo.Architecture}. Expected riscv64`);
48
54
  }
49
55
  const info = {
50
- cmd: imageInfo["Config"]["Cmd"] ?? [],
51
- entrypoint: imageInfo["Config"]["Entrypoint"] ?? [],
52
- env: imageInfo["Config"]["Env"] || [],
53
- workdir: imageInfo["Config"]["WorkingDir"],
56
+ cmd: imageInfo.Config.Cmd ?? [],
57
+ entrypoint: imageInfo.Config.Entrypoint ?? [],
58
+ env: imageInfo.Config.Env || [],
59
+ workdir: imageInfo.Config.WorkingDir,
54
60
  };
55
61
  return info;
56
62
  };
57
- export const build = async (name, drive, sdkImage, destination) => {
63
+ export const build = async (name, drive, sdkImage, destination, debug) => {
58
64
  const { format } = drive;
59
- const ocitar = `${name}.oci.tar`;
60
65
  const tar = `${name}.tar`;
61
66
  const filename = `${name}.${format}`;
62
67
  // use pre-existing image or build docker image
63
68
  let image;
64
69
  if (drive.image) {
65
- image = drive.image;
66
- await execa("docker", ["image", "pull", image]);
70
+ // build a docker image with `FROM <image>`
71
+ image = await buildImage({
72
+ ...drive,
73
+ destination: path.join(destination, tar),
74
+ dockerfileContent: `FROM ${drive.image}`,
75
+ });
67
76
  }
68
77
  else {
69
- image = await buildImage(drive);
78
+ image = await buildImage({
79
+ ...drive,
80
+ destination: path.join(destination, tar),
81
+ });
70
82
  }
71
- // get image info
72
83
  const imageInfo = await getImageInfo(image);
73
84
  try {
74
- // create OCI Docker tarball from Docker image
75
- await execa("docker", ["image", "save", image, "-o", ocitar], {
76
- cwd: destination,
77
- });
78
- // create rootfs tar from OCI tar
79
- await crane.exportImage({
80
- stdin: fs.openSync(path.join(destination, ocitar), "r"),
81
- stdout: fs.openSync(path.join(destination, tar), "w"),
82
- image: sdkImage,
83
- });
84
85
  switch (format) {
85
86
  case "ext2": {
86
87
  await genext2fs.fromTar({
@@ -105,8 +106,9 @@ export const build = async (name, drive, sdkImage, destination) => {
105
106
  }
106
107
  finally {
107
108
  // delete intermediate files
108
- await fs.remove(path.join(destination, ocitar));
109
- await fs.remove(path.join(destination, tar));
109
+ if (!debug) {
110
+ await fs.remove(path.join(destination, tar));
111
+ }
110
112
  }
111
113
  return imageInfo;
112
114
  };
@@ -1,3 +1,3 @@
1
- import { EmptyDriveConfig } from "../config.js";
1
+ import type { EmptyDriveConfig } from "../config.js";
2
2
  export declare const build: (name: string, drive: EmptyDriveConfig, sdkImage: string, destination: string) => Promise<void>;
3
3
  //# sourceMappingURL=empty.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"empty.d.ts","sourceRoot":"","sources":["../../src/builder/empty.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGhD,eAAO,MAAM,KAAK,SACR,MAAM,SACL,gBAAgB,YACb,MAAM,eACH,MAAM,KACpB,OAAO,CAAC,IAAI,CAoBd,CAAC"}
1
+ {"version":3,"file":"empty.d.ts","sourceRoot":"","sources":["../../src/builder/empty.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGrD,eAAO,MAAM,KAAK,GACd,MAAM,MAAM,EACZ,OAAO,gBAAgB,EACvB,UAAU,MAAM,EAChB,aAAa,MAAM,KACpB,OAAO,CAAC,IAAI,CAoBd,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import fs from "fs-extra";
2
- import path from "path";
2
+ import path from "node:path";
3
3
  import { genext2fs } from "../exec/index.js";
4
4
  export const build = async (name, drive, sdkImage, destination) => {
5
5
  const filename = `${name}.${drive.format}`;
@@ -1,3 +1,3 @@
1
- import { ExistingDriveConfig } from "../config.js";
1
+ import { type ExistingDriveConfig } from "../config.js";
2
2
  export declare const build: (name: string, drive: ExistingDriveConfig, destination: string) => Promise<void>;
3
3
  //# sourceMappingURL=none.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"none.d.ts","sourceRoot":"","sources":["../../src/builder/none.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAkB,MAAM,cAAc,CAAC;AAEnE,eAAO,MAAM,KAAK,SACR,MAAM,SACL,mBAAmB,eACb,MAAM,KACpB,OAAO,CAAC,IAAI,CAQd,CAAC"}
1
+ {"version":3,"file":"none.d.ts","sourceRoot":"","sources":["../../src/builder/none.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,mBAAmB,EAAkB,MAAM,cAAc,CAAC;AAExE,eAAO,MAAM,KAAK,GACd,MAAM,MAAM,EACZ,OAAO,mBAAmB,EAC1B,aAAa,MAAM,KACpB,OAAO,CAAC,IAAI,CAQd,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import fs from "fs-extra";
2
- import path from "path";
2
+ import path from "node:path";
3
3
  import { getDriveFormat } from "../config.js";
4
4
  export const build = async (name, drive, destination) => {
5
5
  // no need to build, drive already exists
@@ -1,3 +1,3 @@
1
- import { TarDriveConfig } from "../config.js";
1
+ import type { TarDriveConfig } from "../config.js";
2
2
  export declare const build: (name: string, drive: TarDriveConfig, sdkImage: string, destination: string) => Promise<void>;
3
3
  //# sourceMappingURL=tar.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tar.d.ts","sourceRoot":"","sources":["../../src/builder/tar.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAG9C,eAAO,MAAM,KAAK,SACR,MAAM,SACL,cAAc,YACX,MAAM,eACH,MAAM,KACpB,OAAO,CAAC,IAAI,CA4Bd,CAAC"}
1
+ {"version":3,"file":"tar.d.ts","sourceRoot":"","sources":["../../src/builder/tar.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAGnD,eAAO,MAAM,KAAK,GACd,MAAM,MAAM,EACZ,OAAO,cAAc,EACrB,UAAU,MAAM,EAChB,aAAa,MAAM,KACpB,OAAO,CAAC,IAAI,CA4Bd,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import fs from "fs-extra";
2
- import path from "path";
2
+ import path from "node:path";
3
3
  import { genext2fs, mksquashfs } from "../exec/index.js";
4
4
  export const build = async (name, drive, sdkImage, destination) => {
5
5
  const tar = `${name}.tar`;
@@ -1,9 +1,6 @@
1
- import { AddressBook as AddressBookType, BaseCommand } from "../baseCommand.js";
2
- export default class AddressBook extends BaseCommand<typeof AddressBook> {
3
- static summary: string;
4
- static description: string;
5
- static examples: string[];
6
- static enableJsonFlag: boolean;
7
- run(): Promise<AddressBookType>;
8
- }
1
+ import { Command } from "@commander-js/extra-typings";
2
+ export declare const createAddressBookCommand: () => Command<[], {
3
+ json?: true | undefined;
4
+ projectName?: string | undefined;
5
+ }, {}>;
9
6
  //# sourceMappingURL=address-book.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"address-book.d.ts","sourceRoot":"","sources":["../../src/commands/address-book.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,IAAI,eAAe,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhF,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,WAAW,CAAC,OAAO,WAAW,CAAC;IACpE,MAAM,CAAC,OAAO,SAAmD;IAEjE,MAAM,CAAC,WAAW,SACwF;IAE1G,MAAM,CAAC,QAAQ,WAA2C;IAE1D,OAAc,cAAc,UAAQ;IAEvB,GAAG,IAAI,OAAO,CAAC,eAAe,CAAC;CA+B/C"}
1
+ {"version":3,"file":"address-book.d.ts","sourceRoot":"","sources":["../../src/commands/address-book.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAItD,eAAO,MAAM,wBAAwB;;;MA4CpC,CAAC"}
@@ -1,9 +1,16 @@
1
+ import { Command } from "@commander-js/extra-typings";
1
2
  import Table from "cli-table3";
2
- import { BaseCommand } from "../baseCommand.js";
3
- class AddressBook extends BaseCommand {
4
- async run() {
5
- const addressBook = await super.getAddressBook();
6
- if (!this.jsonEnabled()) {
3
+ import { getAddressBook, getProjectName } from "../base.js";
4
+ export const createAddressBookCommand = () => {
5
+ return new Command("address-book")
6
+ .description("Prints the addresses of all smart contracts deployed to the runtime environment of the application.")
7
+ .option("--json", "Format output as json.")
8
+ .option("--project-name <string>", "name of project (used by docker compose and cartesi-rollups-node)")
9
+ .action(async (options) => {
10
+ const { json } = options;
11
+ const projectName = getProjectName(options);
12
+ const addressBook = await getAddressBook({ projectName });
13
+ if (!json) {
7
14
  // print as a table
8
15
  const table = new Table({
9
16
  head: ["Contract", "Address"],
@@ -29,12 +36,9 @@ class AddressBook extends BaseCommand {
29
36
  table.push(...Object.entries(addressBook));
30
37
  console.log(table.toString());
31
38
  }
32
- // return (as json)
33
- return addressBook;
34
- }
35
- }
36
- AddressBook.summary = "Prints addresses of smart contracts deployed.";
37
- AddressBook.description = "Prints the addresses of all smart contracts deployed to the runtime environment of the application.";
38
- AddressBook.examples = ["<%= config.bin %> <%= command.id %>"];
39
- AddressBook.enableJsonFlag = true;
40
- export default AddressBook;
39
+ else {
40
+ // print as json
41
+ process.stdout.write(JSON.stringify(addressBook));
42
+ }
43
+ });
44
+ };
@@ -1,12 +1,8 @@
1
- import { BaseCommand } from "../baseCommand.js";
2
- export default class Build extends BaseCommand<typeof Build> {
3
- static summary: string;
4
- static description: string;
5
- static examples: string[];
6
- static flags: {
7
- config: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
8
- "drives-only": import("@oclif/core/lib/interfaces/parser.js").BooleanFlag<boolean>;
9
- };
10
- run(): Promise<void>;
11
- }
1
+ import { Command } from "@commander-js/extra-typings";
2
+ export declare const createBuildCommand: () => Command<[], {
3
+ config: string[];
4
+ debug: boolean;
5
+ drivesOnly?: true | undefined;
6
+ verbose: boolean;
7
+ }, {}>;
12
8
  //# sourceMappingURL=build.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAoChD,MAAM,CAAC,OAAO,OAAO,KAAM,SAAQ,WAAW,CAAC,OAAO,KAAK,CAAC;IACxD,MAAM,CAAC,OAAO,SAAwB;IAEtC,MAAM,CAAC,WAAW,SAC+E;IAEjG,MAAM,CAAC,QAAQ,WAA2C;IAE1D,MAAM,CAAC,KAAK;;;MAUV;IAEW,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CA2CpC"}
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAU,MAAM,6BAA6B,CAAC;AAqE9D,eAAO,MAAM,kBAAkB;;;;;MAqF9B,CAAC"}
@@ -1,73 +1,97 @@
1
- import { Flags } from "@oclif/core";
1
+ import { Command, Option } from "@commander-js/extra-typings";
2
+ import chalk from "chalk";
2
3
  import fs from "fs-extra";
3
- import path from "path";
4
+ import { Listr } from "listr2";
5
+ import path from "node:path";
4
6
  import tmp from "tmp";
5
- import { BaseCommand } from "../baseCommand.js";
7
+ import { getApplicationConfig, getContextPath } from "../base.js";
6
8
  import { buildDirectory, buildDocker, buildEmpty, buildNone, buildTar, } from "../builder/index.js";
7
9
  import { bootMachine } from "../machine.js";
8
- const buildDrive = async (name, drive, sdkImage, destination) => {
9
- switch (drive.builder) {
10
- case "directory": {
11
- return buildDirectory(name, drive, sdkImage, destination);
10
+ const buildDriveTask = (name, drive) => ({
11
+ title: `Building drive ${chalk.cyan(name)}`,
12
+ task: async (ctx, task) => {
13
+ const { config, debug, destination } = ctx;
14
+ const sdk = config.sdk;
15
+ switch (drive.builder) {
16
+ case "directory": {
17
+ await buildDirectory(name, drive, sdk, destination, debug);
18
+ break;
19
+ }
20
+ case "docker": {
21
+ const imageInfo = await buildDocker(name, drive, sdk, destination, debug);
22
+ if (imageInfo && name === "root") {
23
+ // only set image info for root drive
24
+ ctx.imageInfo = imageInfo;
25
+ }
26
+ break;
27
+ }
28
+ case "empty": {
29
+ await buildEmpty(name, drive, sdk, destination);
30
+ break;
31
+ }
32
+ case "tar": {
33
+ await buildTar(name, drive, sdk, destination);
34
+ break;
35
+ }
36
+ case "none": {
37
+ await buildNone(name, drive, destination);
38
+ break;
39
+ }
12
40
  }
13
- case "docker": {
14
- return buildDocker(name, drive, sdkImage, destination);
15
- }
16
- case "empty": {
17
- return buildEmpty(name, drive, sdkImage, destination);
18
- }
19
- case "tar": {
20
- return buildTar(name, drive, sdkImage, destination);
21
- }
22
- case "none": {
23
- return buildNone(name, drive, destination);
24
- }
25
- }
26
- };
27
- class Build extends BaseCommand {
28
- async run() {
29
- const { flags } = await this.parse(Build);
41
+ task.title = `Build drive ${chalk.cyan(name)}`;
42
+ },
43
+ });
44
+ export const createBuildCommand = () => {
45
+ return new Command("build")
46
+ .description("Build application by building Cartesi machine drives, configuring a machine and booting it.")
47
+ .option("-c, --config <config>", "path to the configuration file", (value, prev) => prev.concat([value]), ["cartesi.toml"])
48
+ .addOption(new Option("--debug", "enable debug mode (do not remove intermediate files)")
49
+ .default(false)
50
+ .hideHelp())
51
+ .option("-d, --drives-only", "only build drives, do not boot machine")
52
+ .option("-v, --verbose", "verbose output", false)
53
+ .action(async (options) => {
54
+ const { debug, drivesOnly, verbose } = options;
30
55
  // clean up temp files we create along the process
31
56
  tmp.setGracefulCleanup();
32
57
  // get application configuration from 'cartesi.toml'
33
- const config = this.getApplicationConfig(flags.config);
58
+ const config = getApplicationConfig(options.config);
34
59
  // destination directory for image and intermediate files
35
- const destination = path.resolve(this.getContextPath());
60
+ const destination = path.resolve(getContextPath());
36
61
  // prepare context directory
37
62
  await fs.emptyDir(destination); // XXX: make it less error prone
38
- // start build of all drives simultaneously
39
- const results = Object.entries(config.drives).reduce((acc, [name, drive]) => {
40
- acc[name] = buildDrive(name, drive, config.sdk, destination);
41
- return acc;
42
- }, {});
43
- // await for all drives to be built
44
- await Promise.all(Object.values(results));
45
- if (flags["drives-only"]) {
46
- // only build drives, so quit here
63
+ // build context
64
+ const ctx = { config, debug, destination, imageInfo: undefined };
65
+ // tasks to build drives
66
+ const driveTasks = Object.entries(config.drives).map(([name, drive]) => buildDriveTask(name, drive));
67
+ const builds = new Listr([
68
+ {
69
+ title: "Build drives",
70
+ task: async (_ctx, task) => {
71
+ return task.newListr(driveTasks, {
72
+ concurrent: true,
73
+ rendererOptions: {
74
+ collapseSubtasks: false,
75
+ },
76
+ ctx,
77
+ });
78
+ },
79
+ },
80
+ ], { ctx, renderer: verbose ? "verbose" : "default" });
81
+ const result = await builds.run();
82
+ // if only build drives, quit here
83
+ if (drivesOnly) {
47
84
  return;
48
85
  }
49
- // get image info of root drive
50
- const root = await results["root"];
51
- const imageInfo = root || undefined;
52
- // path of machine snapshot
53
- const snapshotPath = this.getContextPath("image");
54
86
  // create machine snapshot
55
- await bootMachine(config, imageInfo, destination);
56
- await fs.chmod(snapshotPath, 0o755);
57
- }
58
- }
59
- Build.summary = "Build application.";
60
- Build.description = "Build application by building Cartesi machine drives, configuring a machine and booting it";
61
- Build.examples = ["<%= config.bin %> <%= command.id %>"];
62
- Build.flags = {
63
- config: Flags.file({
64
- char: "c",
65
- default: "cartesi.toml",
66
- summary: "path to the configuration file",
67
- }),
68
- "drives-only": Flags.boolean({
69
- default: false,
70
- summary: "only build drives",
71
- }),
87
+ await bootMachine(config, result.imageInfo, {
88
+ finalHash: true,
89
+ store: "image",
90
+ }, {
91
+ cwd: destination,
92
+ stdio: "inherit",
93
+ });
94
+ // make snapshot readable by all users, because cartesi-machine sets to 600
95
+ await fs.chmod(path.join(destination, "image"), 0o755);
96
+ });
72
97
  };
73
- export default Build;