@le-space/node 0.1.17 → 0.1.18
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/index.js +5 -1
- package/package.json +4 -4
- package/reference/publish-static-site.py +65 -0
package/index.js
CHANGED
|
@@ -3009,6 +3009,7 @@ if (import.meta.url === pathToFileURL2(process.argv[1] ?? "").href) {
|
|
|
3009
3009
|
// src/site-runner.ts
|
|
3010
3010
|
import process2 from "process";
|
|
3011
3011
|
import { spawn as spawn2 } from "child_process";
|
|
3012
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
3012
3013
|
async function runCapture(command, args, options = {}) {
|
|
3013
3014
|
return await new Promise((resolve, reject) => {
|
|
3014
3015
|
const child = spawn2(command, args, {
|
|
@@ -3061,6 +3062,9 @@ async function waitForAlephMessage(itemHash, env = process2.env) {
|
|
|
3061
3062
|
}
|
|
3062
3063
|
throw new Error(`Aleph STORE message ${itemHash} did not become processed in time.`);
|
|
3063
3064
|
}
|
|
3065
|
+
function defaultSitePublishScriptPath() {
|
|
3066
|
+
return fileURLToPath2(new URL("../reference/publish-static-site.py", import.meta.url));
|
|
3067
|
+
}
|
|
3064
3068
|
function mergedAddrs(env = process2.env) {
|
|
3065
3069
|
const combined = [];
|
|
3066
3070
|
for (const key of ["PROBE_MULTIADDRS_JSON", "BROWSER_BOOTSTRAP_MULTIADDRS_JSON"]) {
|
|
@@ -3076,7 +3080,7 @@ function mergedAddrs(env = process2.env) {
|
|
|
3076
3080
|
}
|
|
3077
3081
|
async function runSitePublishMode(env = process2.env) {
|
|
3078
3082
|
const projectDir = requiredEnv("ALEPH_SITE_PROJECT_DIR", env);
|
|
3079
|
-
const publishScript = optionalEnv("ALEPH_SITE_PUBLISH_SCRIPT",
|
|
3083
|
+
const publishScript = optionalEnv("ALEPH_SITE_PUBLISH_SCRIPT", defaultSitePublishScriptPath(), env);
|
|
3080
3084
|
const siteDirectory = requiredEnv("ALEPH_SITE_DIRECTORY", env);
|
|
3081
3085
|
const pythonBin = optionalEnv("ALEPH_SITE_PYTHON", "python3", env);
|
|
3082
3086
|
const alephBin = optionalEnv("ALEPH_SITE_ALEPH_BIN", "aleph", env);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@le-space/node",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"description": "Node and GitHub Actions adapters for shared Aleph tooling.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@le-space/core": "0.1.
|
|
20
|
-
"@le-space/shared-types": "0.1.
|
|
21
|
-
"@le-space/rootfs": "0.1.
|
|
19
|
+
"@le-space/core": "0.1.18",
|
|
20
|
+
"@le-space/shared-types": "0.1.18",
|
|
21
|
+
"@le-space/rootfs": "0.1.18",
|
|
22
22
|
"ethers": "^6.15.0"
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
import json
|
|
3
|
+
import sys
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
import requests
|
|
7
|
+
from cid import make_cid
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def upload_directory(folder: Path, gateway: str) -> dict[str, str]:
|
|
11
|
+
url = f"{gateway.rstrip('/')}/api/v0/add"
|
|
12
|
+
params = {
|
|
13
|
+
"recursive": "true",
|
|
14
|
+
"wrap-with-directory": "true",
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
handles = []
|
|
18
|
+
files = []
|
|
19
|
+
try:
|
|
20
|
+
for path in sorted(folder.rglob("*")):
|
|
21
|
+
if not path.is_file():
|
|
22
|
+
continue
|
|
23
|
+
relative_path = path.relative_to(folder)
|
|
24
|
+
handle = path.open("rb")
|
|
25
|
+
handles.append(handle)
|
|
26
|
+
files.append(("file", (str(relative_path), handle)))
|
|
27
|
+
|
|
28
|
+
if not files:
|
|
29
|
+
raise RuntimeError(f"No files found under {folder}")
|
|
30
|
+
|
|
31
|
+
response = requests.post(url, params=params, files=files, timeout=300)
|
|
32
|
+
response.raise_for_status()
|
|
33
|
+
|
|
34
|
+
cid_v0 = None
|
|
35
|
+
for line in response.text.strip().splitlines():
|
|
36
|
+
entry = json.loads(line)
|
|
37
|
+
cid_v0 = entry.get("Hash") or cid_v0
|
|
38
|
+
|
|
39
|
+
if not cid_v0:
|
|
40
|
+
raise RuntimeError("CID not found in IPFS response")
|
|
41
|
+
|
|
42
|
+
cid_v1 = make_cid(cid_v0).to_v1().encode("base32").decode()
|
|
43
|
+
return {"cid_v0": cid_v0, "cid_v1": cid_v1}
|
|
44
|
+
finally:
|
|
45
|
+
for handle in handles:
|
|
46
|
+
handle.close()
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def main() -> int:
|
|
50
|
+
if len(sys.argv) != 2:
|
|
51
|
+
print("usage: publish-static-site.py <directory>", file=sys.stderr)
|
|
52
|
+
return 2
|
|
53
|
+
|
|
54
|
+
directory = Path(sys.argv[1]).resolve()
|
|
55
|
+
if not directory.is_dir():
|
|
56
|
+
print(f"Error: path must be a directory: {directory}", file=sys.stderr)
|
|
57
|
+
return 1
|
|
58
|
+
|
|
59
|
+
result = upload_directory(directory, "https://ipfs-2.aleph.im")
|
|
60
|
+
print(json.dumps(result))
|
|
61
|
+
return 0
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
if __name__ == "__main__":
|
|
65
|
+
raise SystemExit(main())
|