@holochain/hc-spin 0.200.3 → 0.200.4
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/README.md +20 -0
- package/dist/main/index.js +28 -72
- package/package.json +1 -1
- package/src/main/index.ts +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
CLI to run Holochain apps in development mode.
|
|
4
4
|
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
To install the latest version compatible with **holochain 0.1.x**:
|
|
8
|
+
|
|
9
|
+
⚠️ Requires `@holochain/client 0.12.6` or newer ⚠️
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
npm install --save-dev @holochain/hc-spin@">=0.100.0 <0.200.0"
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
To install the latest version compatible with **holochain 0.2.x**:
|
|
16
|
+
|
|
17
|
+
⚠️ Requires `@holochain/client 0.16.2` or newer ⚠️
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
npm install --save-dev @holochain/hc-spin@">=0.200.0 <0.300.0"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage (holochain 0.2)
|
|
24
|
+
|
|
5
25
|
```
|
|
6
26
|
Usage: hc-spin [options] <path>
|
|
7
27
|
|
package/dist/main/index.js
CHANGED
|
@@ -7,11 +7,11 @@ const commander = require("commander");
|
|
|
7
7
|
const contextMenu = require("electron-context-menu");
|
|
8
8
|
const split = require("split");
|
|
9
9
|
const childProcess = require("child_process");
|
|
10
|
+
const msgpack = require("@msgpack/msgpack");
|
|
10
11
|
const url = require("url");
|
|
11
12
|
const utils = require("@electron-toolkit/utils");
|
|
12
13
|
const net$1 = require("node:net");
|
|
13
14
|
const os = require("node:os");
|
|
14
|
-
const msgpack = require("@msgpack/msgpack");
|
|
15
15
|
const require$$0$3 = require("events");
|
|
16
16
|
const require$$1$1 = require("https");
|
|
17
17
|
const require$$2$1 = require("http");
|
|
@@ -11735,36 +11735,37 @@ function validateCliArgs(cliArgs, cliOpts, appDataRootDir) {
|
|
|
11735
11735
|
appId,
|
|
11736
11736
|
holochainPath,
|
|
11737
11737
|
numAgents,
|
|
11738
|
-
networkSeed: cliOpts.networkSeed,
|
|
11739
11738
|
uiSource: cliOpts.uiPath ? { type: "path", path: cliOpts.uiPath } : cliOpts.uiPort ? { type: "port", port: cliOpts.uiPort } : { type: "path", path: path.join(appDataRootDir, "apps", appId, "ui") },
|
|
11740
|
-
singalingUrl: cliOpts.signalingUrl,
|
|
11741
|
-
bootstrapUrl: cliOpts.bootstrapUrl,
|
|
11742
11739
|
happOrWebhappPath: isHapp ? { type: "happ", path: happOrWebhappPath } : { type: "webhapp", path: happOrWebhappPath }
|
|
11743
11740
|
};
|
|
11744
11741
|
}
|
|
11745
11742
|
const rustUtils = require("@holochain/hc-spin-rust-utils");
|
|
11746
11743
|
const cli = new commander.Command();
|
|
11747
|
-
cli.name("hc-spin").description("CLI to run Holochain
|
|
11744
|
+
cli.name("hc-spin").description("CLI to run Holochain apps during development.").version(`0.100.0 (for holochain 0.1.x)`).argument(
|
|
11748
11745
|
"<path>",
|
|
11749
11746
|
"Path to .webhapp or .happ file to launch. If a .happ file is passed, either a UI path must be specified via --ui-path or a port pointing to a localhost server via --ui-port"
|
|
11750
11747
|
).option(
|
|
11751
11748
|
"--app-id <string>",
|
|
11752
11749
|
"Install the app with a specific app id. By default the app id is derived from the name of the .webhapp/.happ file that you pass but this option allows you to set it explicitly"
|
|
11753
|
-
).option(
|
|
11754
|
-
"--bootstrap-url <url>",
|
|
11755
|
-
"Url of the bootstrap server to use. By default, hc spin spins up a local development bootstrap server for you but this argument allows you to specify a custom one."
|
|
11756
11750
|
).option("--holochain-path <path>", "Set the path to the holochain binary [default: holochain].").addOption(
|
|
11757
11751
|
new commander.Option("-n, --num-agents <number>", "How many agents to spawn the app for.").argParser(
|
|
11758
11752
|
parseInt
|
|
11759
11753
|
)
|
|
11760
|
-
).option("--
|
|
11754
|
+
).option("--ui-path <path>", "Path to the folder containing the index.html of the webhapp's UI.").option(
|
|
11761
11755
|
"--ui-port <number>",
|
|
11762
11756
|
"Port pointing to a localhost dev server that serves your UI assets."
|
|
11763
|
-
).option(
|
|
11764
|
-
"--signaling-url <url>",
|
|
11765
|
-
"Url of the signaling server to use. By default, hc spin spins up a local development signaling server for you but this argument allows you to specify a custom one."
|
|
11766
11757
|
);
|
|
11767
11758
|
cli.parse();
|
|
11759
|
+
const rl = require("readline").createInterface({
|
|
11760
|
+
input: process.stdin,
|
|
11761
|
+
output: process.stdout
|
|
11762
|
+
});
|
|
11763
|
+
rl.on("SIGINT", function() {
|
|
11764
|
+
process.emit("SIGINT");
|
|
11765
|
+
});
|
|
11766
|
+
process.on("SIGINT", () => {
|
|
11767
|
+
electron.app.quit();
|
|
11768
|
+
});
|
|
11768
11769
|
const files = fs.readdirSync(electron.app.getPath("temp"));
|
|
11769
11770
|
const hcSpinFolders = files.filter((file) => file.startsWith(`hc-spin-`));
|
|
11770
11771
|
for (const folder of hcSpinFolders) {
|
|
@@ -11826,36 +11827,7 @@ const handleSignZomeCallLegacy = async (e, request) => {
|
|
|
11826
11827
|
return Promise.reject("Agent public key unauthorized.");
|
|
11827
11828
|
return windowInfo.zomeCallSigner.signZomeCall(request);
|
|
11828
11829
|
};
|
|
11829
|
-
async function
|
|
11830
|
-
const localServicesHandle = childProcess__namespace.spawn("hc", ["run-local-services"]);
|
|
11831
|
-
return new Promise((resolve) => {
|
|
11832
|
-
let bootStrapUrl;
|
|
11833
|
-
let signalUrl;
|
|
11834
|
-
let bootstrapRunning = false;
|
|
11835
|
-
let signalRunnig = false;
|
|
11836
|
-
localServicesHandle.stdout.pipe(split()).on("data", async (line) => {
|
|
11837
|
-
console.log(`[hc-spin] | [hc run-local-services]: ${line}`);
|
|
11838
|
-
if (line.includes("HC BOOTSTRAP - ADDR:")) {
|
|
11839
|
-
bootStrapUrl = line.split("# HC BOOTSTRAP - ADDR:")[1].trim();
|
|
11840
|
-
}
|
|
11841
|
-
if (line.includes("HC SIGNAL - ADDR:")) {
|
|
11842
|
-
signalUrl = line.split("# HC SIGNAL - ADDR:")[1].trim();
|
|
11843
|
-
}
|
|
11844
|
-
if (line.includes("HC BOOTSTRAP - RUNNING")) {
|
|
11845
|
-
bootstrapRunning = true;
|
|
11846
|
-
}
|
|
11847
|
-
if (line.includes("HC SIGNAL - RUNNING")) {
|
|
11848
|
-
signalRunnig = true;
|
|
11849
|
-
}
|
|
11850
|
-
if (bootstrapRunning && signalRunnig)
|
|
11851
|
-
resolve([bootStrapUrl, signalUrl]);
|
|
11852
|
-
});
|
|
11853
|
-
localServicesHandle.stderr.pipe(split()).on("data", async (line) => {
|
|
11854
|
-
console.log(`[hc-spin] | [hc run-local-services] ERROR: ${line}`);
|
|
11855
|
-
});
|
|
11856
|
-
});
|
|
11857
|
-
}
|
|
11858
|
-
async function spawnSandboxes(nAgents, happPath, bootStrapUrl, signalUrl, appId, networkSeed) {
|
|
11830
|
+
async function spawnSandboxes(nAgents, happPath, appId) {
|
|
11859
11831
|
const generateArgs = [
|
|
11860
11832
|
"sandbox",
|
|
11861
11833
|
"--piped",
|
|
@@ -11863,22 +11835,18 @@ async function spawnSandboxes(nAgents, happPath, bootStrapUrl, signalUrl, appId,
|
|
|
11863
11835
|
"--num-sandboxes",
|
|
11864
11836
|
nAgents.toString(),
|
|
11865
11837
|
"--app-id",
|
|
11866
|
-
appId
|
|
11867
|
-
"--run"
|
|
11838
|
+
appId
|
|
11868
11839
|
];
|
|
11869
|
-
|
|
11840
|
+
const appPorts = [];
|
|
11841
|
+
let appPortsString = "";
|
|
11870
11842
|
for (var i = 1; i <= nAgents; i++) {
|
|
11871
11843
|
const appPort = await getPorts();
|
|
11872
|
-
|
|
11873
|
-
|
|
11874
|
-
generateArgs.push(appPorts.slice(0, appPorts.length - 1));
|
|
11875
|
-
if (networkSeed) {
|
|
11876
|
-
generateArgs.push("--network-seed");
|
|
11877
|
-
generateArgs.push(networkSeed);
|
|
11844
|
+
appPortsString += `${appPort},`;
|
|
11845
|
+
appPorts.push(appPort);
|
|
11878
11846
|
}
|
|
11879
|
-
generateArgs.push(
|
|
11847
|
+
generateArgs.push("--run", appPortsString.slice(0, appPortsString.length - 1));
|
|
11848
|
+
generateArgs.push(happPath, "network", "mdns");
|
|
11880
11849
|
let readyConductors = 0;
|
|
11881
|
-
const portsInfo = {};
|
|
11882
11850
|
const sandboxPaths = [];
|
|
11883
11851
|
const sandboxHandle = childProcess__namespace.spawn("hc", generateArgs);
|
|
11884
11852
|
sandboxHandle.stdin.write("pass");
|
|
@@ -11890,17 +11858,10 @@ async function spawnSandboxes(nAgents, happPath, bootStrapUrl, signalUrl, appId,
|
|
|
11890
11858
|
const sanboxPath = line.split("\x1B[1;4;48;5;254;38;5;4m")[1].split("\x1B[0m \x1B[1m")[0].trim();
|
|
11891
11859
|
sandboxPaths.push(sanboxPath);
|
|
11892
11860
|
}
|
|
11893
|
-
if (line.includes("
|
|
11894
|
-
line.split("#")[2].trim();
|
|
11895
|
-
}
|
|
11896
|
-
if (line.includes("Conductor launched")) {
|
|
11897
|
-
const split1 = line.split("{");
|
|
11898
|
-
const ports = JSON.parse(`{${split1[1]}`);
|
|
11899
|
-
const conductorNum = split1[0].split("#!")[1].trim();
|
|
11900
|
-
portsInfo[conductorNum] = ports;
|
|
11861
|
+
if (line.includes("Running conductor on admin port")) {
|
|
11901
11862
|
readyConductors += 1;
|
|
11902
11863
|
if (readyConductors === nAgents)
|
|
11903
|
-
resolve([sandboxHandle, sandboxPaths,
|
|
11864
|
+
resolve([sandboxHandle, sandboxPaths, appPorts]);
|
|
11904
11865
|
}
|
|
11905
11866
|
});
|
|
11906
11867
|
sandboxHandle.stderr.pipe(split()).on("data", async (line) => {
|
|
@@ -11922,14 +11883,12 @@ electron.app.whenReady().then(async () => {
|
|
|
11922
11883
|
happTargetDir
|
|
11923
11884
|
);
|
|
11924
11885
|
}
|
|
11925
|
-
const [
|
|
11926
|
-
const [sandboxHandle, sandboxPaths, portsInfo] = await spawnSandboxes(
|
|
11886
|
+
const [sandboxHandle, sandboxPaths, appPorts] = await spawnSandboxes(
|
|
11927
11887
|
CLI_OPTS.numAgents,
|
|
11928
11888
|
happTargetDir ? happTargetDir : CLI_OPTS.happOrWebhappPath.path,
|
|
11929
|
-
CLI_OPTS.bootstrapUrl ? CLI_OPTS.bootstrapUrl : bootstrapUrl,
|
|
11930
|
-
CLI_OPTS.singalingUrl ? CLI_OPTS.singalingUrl : signalingUrl,
|
|
11931
11889
|
CLI_OPTS.appId
|
|
11932
11890
|
);
|
|
11891
|
+
console.log("Got app ports: ", appPorts);
|
|
11933
11892
|
const lairUrls = [];
|
|
11934
11893
|
sandboxPaths.forEach((sandbox) => {
|
|
11935
11894
|
const conductorConfigPath = path.join(sandbox, "conductor-config.yaml");
|
|
@@ -11946,15 +11905,14 @@ electron.app.whenReady().then(async () => {
|
|
|
11946
11905
|
SANDBOX_PROCESSES.push(sandboxHandle);
|
|
11947
11906
|
for (var i = 0; i < cli.opts().numAgents; i++) {
|
|
11948
11907
|
const zomeCallSigner = await rustUtils.ZomeCallSigner.connect(lairUrls[i], "pass");
|
|
11949
|
-
const
|
|
11950
|
-
const appWs = await AppWebsocket.connect(new URL(`ws://127.0.0.1:${appPort}`));
|
|
11908
|
+
const appWs = await AppWebsocket.connect(new URL(`ws://127.0.0.1:${appPorts[i]}`));
|
|
11951
11909
|
const appInfo = await appWs.appInfo({ installed_app_id: CLI_OPTS.appId });
|
|
11952
11910
|
const happWindow = await createHappWindow(
|
|
11953
11911
|
CLI_OPTS.uiSource,
|
|
11954
11912
|
CLI_OPTS.happOrWebhappPath,
|
|
11955
11913
|
CLI_OPTS.appId,
|
|
11956
11914
|
i + 1,
|
|
11957
|
-
|
|
11915
|
+
appPorts[i],
|
|
11958
11916
|
DATA_ROOT_DIR
|
|
11959
11917
|
);
|
|
11960
11918
|
WINDOW_INFO_MAP[happWindow.webContents.id] = {
|
|
@@ -11964,9 +11922,7 @@ electron.app.whenReady().then(async () => {
|
|
|
11964
11922
|
}
|
|
11965
11923
|
});
|
|
11966
11924
|
electron.app.on("window-all-closed", () => {
|
|
11967
|
-
|
|
11968
|
-
electron.app.quit();
|
|
11969
|
-
}
|
|
11925
|
+
electron.app.quit();
|
|
11970
11926
|
});
|
|
11971
11927
|
electron.app.on("quit", () => {
|
|
11972
11928
|
fs.writeFileSync(
|
package/package.json
CHANGED
package/src/main/index.ts
CHANGED
|
@@ -27,7 +27,7 @@ const cli = new Command();
|
|
|
27
27
|
cli
|
|
28
28
|
.name('hc-spin')
|
|
29
29
|
.description('CLI to run Holochain aps during development.')
|
|
30
|
-
.version(`0.200.
|
|
30
|
+
.version(`0.200.4 (for holochain 0.2.x)`)
|
|
31
31
|
.argument(
|
|
32
32
|
'<path>',
|
|
33
33
|
'Path to .webhapp or .happ file to launch. If a .happ file is passed, either a UI path must be specified via --ui-path or a port pointing to a localhost server via --ui-port',
|