@cartesi/cli 2.0.0-alpha.4 → 2.0.0-alpha.5
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/dist/base.d.ts +14 -0
- package/dist/base.d.ts.map +1 -0
- package/dist/base.js +77 -0
- package/dist/commands/address-book.d.ts +2 -8
- package/dist/commands/address-book.d.ts.map +1 -1
- package/dist/commands/address-book.js +15 -14
- package/dist/commands/build.d.ts +2 -11
- package/dist/commands/build.d.ts.map +1 -1
- package/dist/commands/build.js +16 -28
- package/dist/commands/clean.d.ts +2 -7
- package/dist/commands/clean.d.ts.map +1 -1
- package/dist/commands/clean.js +9 -10
- package/dist/commands/create.d.ts +2 -14
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +37 -51
- package/dist/commands/deploy/build.d.ts +2 -14
- package/dist/commands/deploy/build.d.ts.map +1 -1
- package/dist/commands/deploy/build.js +41 -47
- package/dist/commands/deploy.d.ts +3 -0
- package/dist/commands/deploy.d.ts.map +1 -0
- package/dist/commands/{deploy/index.js → deploy.js} +26 -28
- package/dist/commands/doctor.d.ts +2 -12
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +83 -90
- package/dist/commands/hash.d.ts +2 -9
- package/dist/commands/hash.d.ts.map +1 -1
- package/dist/commands/hash.js +14 -14
- package/dist/commands/run.d.ts +2 -21
- package/dist/commands/run.d.ts.map +1 -1
- package/dist/commands/run.js +46 -88
- package/dist/commands/send/erc20.d.ts +2 -13
- package/dist/commands/send/erc20.d.ts.map +1 -1
- package/dist/commands/send/erc20.js +55 -52
- package/dist/commands/send/erc721.d.ts +2 -13
- package/dist/commands/send/erc721.d.ts.map +1 -1
- package/dist/commands/send/erc721.js +49 -46
- package/dist/commands/send/ether.d.ts +2 -12
- package/dist/commands/send/ether.d.ts.map +1 -1
- package/dist/commands/send/ether.js +23 -21
- package/dist/commands/send/generic.d.ts +2 -14
- package/dist/commands/send/generic.d.ts.map +1 -1
- package/dist/commands/send/generic.js +91 -97
- package/dist/commands/send.d.ts +21 -0
- package/dist/commands/send.d.ts.map +1 -0
- package/dist/commands/send.js +67 -0
- package/dist/commands/shell.d.ts +2 -14
- package/dist/commands/shell.d.ts.map +1 -1
- package/dist/commands/shell.js +21 -43
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +51 -1
- package/package.json +6 -25
- package/bin/dev.cmd +0 -3
- package/bin/dev.js +0 -25
- package/bin/run.cmd +0 -3
- package/bin/run.js +0 -8
- package/dist/baseCommand.d.ts +0 -22
- package/dist/baseCommand.d.ts.map +0 -1
- package/dist/baseCommand.js +0 -92
- package/dist/commands/deploy/index.d.ts +0 -12
- package/dist/commands/deploy/index.d.ts.map +0 -1
- package/dist/commands/send/index.d.ts +0 -28
- package/dist/commands/send/index.d.ts.map +0 -1
- package/dist/commands/send/index.js +0 -102
- package/dist/flags.d.ts +0 -17
- package/dist/flags.d.ts.map +0 -1
- package/dist/flags.js +0 -28
- package/oclif.manifest.json +0 -883
package/dist/base.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Address, Hash } from "viem";
|
|
2
|
+
import { Config } from "./config.js";
|
|
3
|
+
export declare const getContextPath: (...paths: string[]) => string;
|
|
4
|
+
export declare const getMachineHash: () => Hash | undefined;
|
|
5
|
+
export declare const getApplicationConfig: (configPath: string) => Config;
|
|
6
|
+
export declare const getApplicationAddress: () => Promise<Address>;
|
|
7
|
+
export type AddressBook = Record<string, Address>;
|
|
8
|
+
export declare const getAddressBook: () => Promise<AddressBook>;
|
|
9
|
+
export declare const logPrompt: ({ title, value, }: {
|
|
10
|
+
title: string;
|
|
11
|
+
value: string;
|
|
12
|
+
}) => void;
|
|
13
|
+
export declare const getServiceState: (projectName: string, serviceName: string) => Promise<string | undefined>;
|
|
14
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAc,IAAI,EAAU,MAAM,MAAM,CAAC;AACzD,OAAO,EAAE,MAAM,EAAS,MAAM,aAAa,CAAC;AAiB5C,eAAO,MAAM,cAAc,aAAc,MAAM,EAAE,KAAG,MAEnD,CAAC;AAEF,eAAO,MAAM,cAAc,QAAO,IAAI,GAAG,SAUxC,CAAC;AAEF,eAAO,MAAM,oBAAoB,eAAgB,MAAM,KAAG,MAIzD,CAAC;AAEF,eAAO,MAAM,qBAAqB,QAAa,OAAO,CAAC,OAAO,CAG7D,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAElD,eAAO,MAAM,cAAc,QAAa,OAAO,CAAC,WAAW,CA+B1D,CAAC;AAEF,eAAO,MAAM,SAAS,sBAGnB;IACC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACjB,SAEA,CAAC;AAEF,eAAO,MAAM,eAAe,gBACX,MAAM,eACN,MAAM,KACpB,OAAO,CAAC,MAAM,GAAG,SAAS,CAa5B,CAAC"}
|
package/dist/base.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { execa } from "execa";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { getAddress, isHash } 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
|
+
export const getContextPath = (...paths) => {
|
|
9
|
+
return path.join(".cartesi", ...paths);
|
|
10
|
+
};
|
|
11
|
+
export const getMachineHash = () => {
|
|
12
|
+
// read hash of the cartesi machine snapshot, if one exists
|
|
13
|
+
const hashPath = getContextPath("image", "hash");
|
|
14
|
+
if (fs.existsSync(hashPath)) {
|
|
15
|
+
const hash = fs.readFileSync(hashPath).toString("hex");
|
|
16
|
+
if (isHash(`0x${hash}`)) {
|
|
17
|
+
return `0x${hash}`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return undefined;
|
|
21
|
+
};
|
|
22
|
+
export const getApplicationConfig = (configPath) => {
|
|
23
|
+
return fs.existsSync(configPath)
|
|
24
|
+
? parse(fs.readFileSync(configPath).toString())
|
|
25
|
+
: parse("");
|
|
26
|
+
};
|
|
27
|
+
export const getApplicationAddress = async () => {
|
|
28
|
+
// fixed value, as we do deterministic deployment with a zero hash
|
|
29
|
+
return getAddress("0xab7528bb862fb57e8a2bcd567a2e929a0be56a5e");
|
|
30
|
+
};
|
|
31
|
+
export const getAddressBook = async () => {
|
|
32
|
+
const applicationAddress = await getApplicationAddress();
|
|
33
|
+
// build rollups contracts address book
|
|
34
|
+
const contracts = {
|
|
35
|
+
Application: applicationAddress,
|
|
36
|
+
ApplicationFactory: applicationFactoryAddress,
|
|
37
|
+
AuthorityFactory: authorityFactoryAddress,
|
|
38
|
+
EntryPointV06: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789",
|
|
39
|
+
EntryPointV07: "0x0000000071727De22E5E9d8BAf0edAc6f37da032",
|
|
40
|
+
ERC1155BatchPortal: erc1155BatchPortalAddress,
|
|
41
|
+
ERC1155SinglePortal: erc1155SinglePortalAddress,
|
|
42
|
+
ERC20Portal: erc20PortalAddress,
|
|
43
|
+
ERC721Portal: erc721PortalAddress,
|
|
44
|
+
EtherPortal: etherPortalAddress,
|
|
45
|
+
InputBox: inputBoxAddress,
|
|
46
|
+
LightAccountFactory: "0x00004EC70002a32400f8ae005A26081065620D20",
|
|
47
|
+
SelfHostedApplicationFactory: selfHostedApplicationFactoryAddress,
|
|
48
|
+
SimpleAccountFactory: "0x9406Cc6185a346906296840746125a0E44976454",
|
|
49
|
+
SmartAccountFactory: "0x000000a56Aaca3e9a4C479ea6b6CD0DbcB6634F5",
|
|
50
|
+
KernelFactoryV2: "0x5de4839a76cf55d0c90e2061ef4386d962E15ae3",
|
|
51
|
+
KernelFactoryV3: "0x6723b44Abeec4E71eBE3232BD5B455805baDD22f",
|
|
52
|
+
KernelFactoryV3_1: "0xaac5D4240AF87249B3f71BC8E4A2cae074A3E419",
|
|
53
|
+
TestToken: testTokenAddress,
|
|
54
|
+
TestNFT: testNftAddress,
|
|
55
|
+
TestMultiToken: testMultiTokenAddress,
|
|
56
|
+
VerifyingPaymasterV06: "0x28ec0633192d0cBd9E1156CE05D5FdACAcB93947",
|
|
57
|
+
VerifyingPaymasterV07: "0xc5c97885C67F7361aBAfD2B95067a5bBdA603608",
|
|
58
|
+
};
|
|
59
|
+
return contracts;
|
|
60
|
+
};
|
|
61
|
+
export const logPrompt = ({ title, value, }) => {
|
|
62
|
+
console.log(`${chalk.green("?")} ${title} ${chalk.cyan(value)}`);
|
|
63
|
+
};
|
|
64
|
+
export const getServiceState = async (projectName, serviceName) => {
|
|
65
|
+
// get service information
|
|
66
|
+
const { stdout } = await execa("docker", [
|
|
67
|
+
"compose",
|
|
68
|
+
"--project-name",
|
|
69
|
+
projectName,
|
|
70
|
+
"ps",
|
|
71
|
+
serviceName,
|
|
72
|
+
"--format",
|
|
73
|
+
"json",
|
|
74
|
+
]);
|
|
75
|
+
const ps = stdout ? JSON.parse(stdout) : undefined;
|
|
76
|
+
return ps?.State;
|
|
77
|
+
};
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
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 registerAddressBookCommand: (program: Command) => void;
|
|
9
3
|
//# 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":"
|
|
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,0BAA0B,YAAa,OAAO,SAuC1D,CAAC"}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import Table from "cli-table3";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { getAddressBook } from "../base.js";
|
|
3
|
+
export const registerAddressBookCommand = (program) => {
|
|
4
|
+
program
|
|
5
|
+
.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
|
+
.action(async ({ json }) => {
|
|
9
|
+
const addressBook = await getAddressBook();
|
|
10
|
+
if (!json) {
|
|
7
11
|
// print as a table
|
|
8
12
|
const table = new Table({
|
|
9
13
|
head: ["Contract", "Address"],
|
|
@@ -29,12 +33,9 @@ class AddressBook extends BaseCommand {
|
|
|
29
33
|
table.push(...Object.entries(addressBook));
|
|
30
34
|
console.log(table.toString());
|
|
31
35
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
AddressBook.examples = ["<%= config.bin %> <%= command.id %>"];
|
|
39
|
-
AddressBook.enableJsonFlag = true;
|
|
40
|
-
export default AddressBook;
|
|
36
|
+
else {
|
|
37
|
+
// print as json
|
|
38
|
+
process.stdout.write(JSON.stringify(addressBook));
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
};
|
package/dist/commands/build.d.ts
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
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 registerBuildCommand: (program: Command) => void;
|
|
12
3
|
//# sourceMappingURL=build.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/commands/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAwCtD,eAAO,MAAM,oBAAoB,YAAa,OAAO,SAqDpD,CAAC"}
|
package/dist/commands/build.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { Flags } from "@oclif/core";
|
|
2
1
|
import fs from "fs-extra";
|
|
3
2
|
import path from "path";
|
|
4
3
|
import tmp from "tmp";
|
|
5
|
-
import {
|
|
4
|
+
import { getApplicationConfig, getContextPath } from "../base.js";
|
|
6
5
|
import { buildDirectory, buildDocker, buildEmpty, buildNone, buildTar, } from "../builder/index.js";
|
|
7
6
|
import { bootMachine } from "../machine.js";
|
|
8
7
|
const buildDrive = async (name, drive, sdkImage, destination) => {
|
|
@@ -24,25 +23,29 @@ const buildDrive = async (name, drive, sdkImage, destination) => {
|
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
25
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
export const registerBuildCommand = (program) => {
|
|
27
|
+
program
|
|
28
|
+
.command("build")
|
|
29
|
+
.description("Build application by building Cartesi machine drives, configuring a machine and booting it.")
|
|
30
|
+
.option("-c, --config <config>", "path to the configuration file", "cartesi.toml")
|
|
31
|
+
.option("-d, --drives-only", "only build drives, do not boot machine")
|
|
32
|
+
.action(async ({ config, drivesOnly }) => {
|
|
30
33
|
// clean up temp files we create along the process
|
|
31
34
|
tmp.setGracefulCleanup();
|
|
32
35
|
// get application configuration from 'cartesi.toml'
|
|
33
|
-
const
|
|
36
|
+
const c = getApplicationConfig(config);
|
|
34
37
|
// destination directory for image and intermediate files
|
|
35
|
-
const destination = path.resolve(
|
|
38
|
+
const destination = path.resolve(getContextPath());
|
|
36
39
|
// prepare context directory
|
|
37
40
|
await fs.emptyDir(destination); // XXX: make it less error prone
|
|
38
41
|
// start build of all drives simultaneously
|
|
39
|
-
const results = Object.entries(
|
|
40
|
-
acc[name] = buildDrive(name, drive,
|
|
42
|
+
const results = Object.entries(c.drives).reduce((acc, [name, drive]) => {
|
|
43
|
+
acc[name] = buildDrive(name, drive, c.sdk, destination);
|
|
41
44
|
return acc;
|
|
42
45
|
}, {});
|
|
43
46
|
// await for all drives to be built
|
|
44
47
|
await Promise.all(Object.values(results));
|
|
45
|
-
if (
|
|
48
|
+
if (drivesOnly) {
|
|
46
49
|
// only build drives, so quit here
|
|
47
50
|
return;
|
|
48
51
|
}
|
|
@@ -50,24 +53,9 @@ class Build extends BaseCommand {
|
|
|
50
53
|
const root = await results["root"];
|
|
51
54
|
const imageInfo = root || undefined;
|
|
52
55
|
// path of machine snapshot
|
|
53
|
-
const snapshotPath =
|
|
56
|
+
const snapshotPath = getContextPath("image");
|
|
54
57
|
// create machine snapshot
|
|
55
|
-
await bootMachine(
|
|
58
|
+
await bootMachine(c, imageInfo, destination);
|
|
56
59
|
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
|
-
}),
|
|
60
|
+
});
|
|
72
61
|
};
|
|
73
|
-
export default Build;
|
package/dist/commands/clean.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
static summary: string;
|
|
4
|
-
static description: string;
|
|
5
|
-
static examples: string[];
|
|
6
|
-
run(): Promise<void>;
|
|
7
|
-
}
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
export declare const registerCleanCommand: (program: Command) => void;
|
|
8
3
|
//# sourceMappingURL=clean.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../src/commands/clean.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../src/commands/clean.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAItD,eAAO,MAAM,oBAAoB,YAAa,OAAO,SAOpD,CAAC"}
|
package/dist/commands/clean.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import fs from "fs-extra";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export default Clean;
|
|
2
|
+
import { getContextPath } from "../base.js";
|
|
3
|
+
export const registerCleanCommand = (program) => {
|
|
4
|
+
program
|
|
5
|
+
.command("clean")
|
|
6
|
+
.description("Deletes all cached build artifacts of application.")
|
|
7
|
+
.action(async () => {
|
|
8
|
+
await fs.emptyDir(getContextPath());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
2
|
export declare const DEFAULT_TEMPLATES_BRANCH = "sdk-0.9";
|
|
3
|
-
export
|
|
4
|
-
static description: string;
|
|
5
|
-
static examples: string[];
|
|
6
|
-
static args: {
|
|
7
|
-
name: import("@oclif/core/lib/interfaces/parser.js").Arg<string, Record<string, unknown>>;
|
|
8
|
-
};
|
|
9
|
-
static flags: {
|
|
10
|
-
template: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
11
|
-
branch: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
12
|
-
};
|
|
13
|
-
private download;
|
|
14
|
-
run(): Promise<void>;
|
|
15
|
-
}
|
|
3
|
+
export declare const registerCreateCommand: (program: Command) => void;
|
|
16
4
|
//# sourceMappingURL=create.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/commands/create.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/commands/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAU,MAAM,6BAA6B,CAAC;AAM9D,eAAO,MAAM,wBAAwB,YAAY,CAAC;AAmClD,eAAO,MAAM,qBAAqB,YAAa,OAAO,SA2BrD,CAAC"}
|
package/dist/commands/create.js
CHANGED
|
@@ -1,30 +1,46 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Option } from "@commander-js/extra-typings";
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import { downloadTemplate } from "giget";
|
|
4
4
|
import ora from "ora";
|
|
5
|
-
import { BaseCommand } from "../baseCommand.js";
|
|
6
5
|
export const DEFAULT_TEMPLATES_BRANCH = "sdk-0.9";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
const TEMPLATES = [
|
|
7
|
+
"cpp",
|
|
8
|
+
"cpp-low-level",
|
|
9
|
+
"go",
|
|
10
|
+
"javascript",
|
|
11
|
+
"lua",
|
|
12
|
+
"python",
|
|
13
|
+
"ruby",
|
|
14
|
+
"rust",
|
|
15
|
+
"typescript",
|
|
16
|
+
];
|
|
17
|
+
const download = async (template, branch, out) => {
|
|
18
|
+
const cartesiProvider = async (input) => {
|
|
19
|
+
return {
|
|
20
|
+
name: "cartesi",
|
|
21
|
+
subdir: input,
|
|
22
|
+
url: "https://github.com/cartesi/application-templates",
|
|
23
|
+
tar: `https://codeload.github.com/cartesi/application-templates/tar.gz/refs/heads/${branch}`,
|
|
16
24
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
};
|
|
26
|
+
const input = `cartesi:${template}`;
|
|
27
|
+
return downloadTemplate(input, {
|
|
28
|
+
dir: out,
|
|
29
|
+
providers: { cartesi: cartesiProvider },
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
export const registerCreateCommand = (program) => {
|
|
33
|
+
program
|
|
34
|
+
.command("create")
|
|
35
|
+
.argument("<name>", "application and directory name")
|
|
36
|
+
.addOption(new Option("-t, --template <template>", "template name to use")
|
|
37
|
+
.choices(TEMPLATES)
|
|
38
|
+
.makeOptionMandatory())
|
|
39
|
+
.option("-b, --branch <branch>", "cartesi/application-templates repository branch name to use", DEFAULT_TEMPLATES_BRANCH)
|
|
40
|
+
.action(async (name, { branch, template }) => {
|
|
25
41
|
const spinner = ora("Creating application...").start();
|
|
26
42
|
try {
|
|
27
|
-
const { dir } = await
|
|
43
|
+
const { dir } = await download(template, branch, name);
|
|
28
44
|
spinner.succeed(`Application created at ${chalk.cyan(dir)}`);
|
|
29
45
|
}
|
|
30
46
|
catch (e) {
|
|
@@ -32,35 +48,5 @@ class CreateCommand extends BaseCommand {
|
|
|
32
48
|
? `Error creating application: ${chalk.red(e.message)}`
|
|
33
49
|
: String(e));
|
|
34
50
|
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
CreateCommand.description = "Create application";
|
|
38
|
-
CreateCommand.examples = ["<%= config.bin %> <%= command.id %>"];
|
|
39
|
-
CreateCommand.args = {
|
|
40
|
-
name: Args.string({
|
|
41
|
-
description: "application and directory name",
|
|
42
|
-
required: true,
|
|
43
|
-
}),
|
|
44
|
-
};
|
|
45
|
-
CreateCommand.flags = {
|
|
46
|
-
template: Flags.string({
|
|
47
|
-
description: "template name to use",
|
|
48
|
-
required: true,
|
|
49
|
-
options: [
|
|
50
|
-
"cpp",
|
|
51
|
-
"cpp-low-level",
|
|
52
|
-
"go",
|
|
53
|
-
"javascript",
|
|
54
|
-
"lua",
|
|
55
|
-
"python",
|
|
56
|
-
"ruby",
|
|
57
|
-
"rust",
|
|
58
|
-
"typescript",
|
|
59
|
-
],
|
|
60
|
-
}),
|
|
61
|
-
branch: Flags.string({
|
|
62
|
-
description: `cartesi/application-templates repository branch name to use`,
|
|
63
|
-
default: DEFAULT_TEMPLATES_BRANCH,
|
|
64
|
-
}),
|
|
51
|
+
});
|
|
65
52
|
};
|
|
66
|
-
export default CreateCommand;
|
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
static summary: string;
|
|
4
|
-
static description: string;
|
|
5
|
-
static examples: string[];
|
|
6
|
-
static flags: {
|
|
7
|
-
platform: import("@oclif/core/lib/interfaces/parser.js").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser.js").CustomOptions>;
|
|
8
|
-
};
|
|
9
|
-
static enableJsonFlag: boolean;
|
|
10
|
-
private buildRollupsImage;
|
|
11
|
-
run(): Promise<{
|
|
12
|
-
image: string;
|
|
13
|
-
}>;
|
|
14
|
-
}
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
export declare const registerBuildCommand: (program: Command) => void;
|
|
15
3
|
//# sourceMappingURL=build.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/commands/deploy/build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/commands/deploy/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAU,MAAM,6BAA6B,CAAC;AAoC9D,eAAO,MAAM,oBAAoB,YAAa,OAAO,SAsCpD,CAAC"}
|
|
@@ -1,62 +1,56 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Option } from "@commander-js/extra-typings";
|
|
2
2
|
import { execa } from "execa";
|
|
3
3
|
import fs from "fs-extra";
|
|
4
4
|
import path from "path";
|
|
5
5
|
import { tmpNameSync } from "tmp";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (platform) {
|
|
26
|
-
args.push("--platform", platform);
|
|
27
|
-
}
|
|
28
|
-
await execa("docker", args, { stdio: "inherit" });
|
|
29
|
-
return fs.readFileSync(buildResult, "utf8");
|
|
6
|
+
import { getContextPath, getMachineHash, logPrompt } from "../../base.js";
|
|
7
|
+
const buildRollupsImage = async (platform) => {
|
|
8
|
+
const buildResult = tmpNameSync();
|
|
9
|
+
const imagePath = getContextPath("image");
|
|
10
|
+
const binPath = path.join(path.dirname(new URL(import.meta.url).pathname), "..", "..");
|
|
11
|
+
const dockerfile = path.join(binPath, "node", "DockerfileDeploy.txt");
|
|
12
|
+
const args = [
|
|
13
|
+
"buildx",
|
|
14
|
+
"build",
|
|
15
|
+
"-f",
|
|
16
|
+
dockerfile,
|
|
17
|
+
"--load",
|
|
18
|
+
"--iidfile",
|
|
19
|
+
buildResult,
|
|
20
|
+
imagePath,
|
|
21
|
+
];
|
|
22
|
+
// optional platform, default to not defining, which will build for the host platform
|
|
23
|
+
if (platform) {
|
|
24
|
+
args.push("--platform", platform);
|
|
30
25
|
}
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
await execa("docker", args, { stdio: "inherit" });
|
|
27
|
+
return fs.readFileSync(buildResult, "utf8");
|
|
28
|
+
};
|
|
29
|
+
export const registerBuildCommand = (program) => {
|
|
30
|
+
program
|
|
31
|
+
.command("build")
|
|
32
|
+
.description("Package the application in a Docker image ready to be deployed.")
|
|
33
|
+
.addOption(new Option("--platform <platform>", "Docker image target platform").choices(["linux/amd64", "linux/arm64"]))
|
|
34
|
+
.option("--json", "Format output as json.")
|
|
35
|
+
.action(async ({ platform, json }, command) => {
|
|
33
36
|
// print machine hash
|
|
34
|
-
const templateHash =
|
|
37
|
+
const templateHash = getMachineHash();
|
|
35
38
|
if (!templateHash) {
|
|
36
|
-
|
|
39
|
+
command.error(`Cartesi machine snapshot not found, run 'build'`);
|
|
40
|
+
return;
|
|
37
41
|
}
|
|
38
|
-
|
|
42
|
+
logPrompt({
|
|
39
43
|
title: "Cartesi machine templateHash",
|
|
40
44
|
value: templateHash,
|
|
41
45
|
});
|
|
42
|
-
|
|
43
|
-
const image = await
|
|
44
|
-
|
|
46
|
+
console.log("Building application node Docker image...");
|
|
47
|
+
const image = await buildRollupsImage(platform);
|
|
48
|
+
logPrompt({
|
|
45
49
|
title: "Application node Docker image",
|
|
46
50
|
value: image,
|
|
47
51
|
});
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
DeployBuild.description = "Package the application in a Docker image ready to be deployed.";
|
|
53
|
-
DeployBuild.examples = ["<%= config.bin %> <%= command.id %>"];
|
|
54
|
-
DeployBuild.flags = {
|
|
55
|
-
platform: Flags.string({
|
|
56
|
-
options: ["linux/amd64", "linux/arm64"],
|
|
57
|
-
summary: "Docker image target platform",
|
|
58
|
-
description: "Select the target platform for the produced Docker image. It depends on the platform where the application node will be deployed.",
|
|
59
|
-
}),
|
|
52
|
+
if (json) {
|
|
53
|
+
process.stdout.write(JSON.stringify({ image }));
|
|
54
|
+
}
|
|
55
|
+
});
|
|
60
56
|
};
|
|
61
|
-
DeployBuild.enableJsonFlag = true;
|
|
62
|
-
export default DeployBuild;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/commands/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAU,MAAM,6BAA6B,CAAC;AAQ9D,eAAO,MAAM,qBAAqB,YAAa,OAAO,SAwFrD,CAAC"}
|