@zktx.io/walrus-sites-preview 0.0.3 → 0.1.1

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/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@zktx.io/walrus-sites-preview",
3
3
  "description": "Local preview CLI for Walrus Sites (fetch from Sui + Walrus, or serve bundled static portal dist).",
4
- "version": "0.0.3",
4
+ "version": "0.1.1",
5
5
  "type": "module",
6
6
  "bin": {
7
- "preview": "preview.mjs"
7
+ "walrus-sites-preview": "preview.mjs"
8
8
  },
9
9
  "engines": {
10
10
  "node": ">=18"
@@ -15,6 +15,9 @@
15
15
  "format": "prettier . --write",
16
16
  "format:check": "prettier . --check",
17
17
  "build": "node ./build-dist.mjs",
18
+ "test": "node ./scripts/verify-maintenance.mjs",
19
+ "verify": "node ./scripts/verify-maintenance.mjs",
20
+ "upstream:download": "node ./scripts/sync-walrus-upstream.mjs",
18
21
  "start:mainnet": "node ./preview.mjs -mainnet",
19
22
  "prepack": "npm run build"
20
23
  },
@@ -31,7 +34,7 @@
31
34
  "cli"
32
35
  ],
33
36
  "author": "daoauth",
34
- "license": "ISC",
37
+ "license": "MIT",
35
38
  "repository": {
36
39
  "type": "git",
37
40
  "url": "git+https://github.com/zktx-io/walrus-sites-preview.git"
package/preview.mjs CHANGED
@@ -8,7 +8,7 @@ import childProcess from "node:child_process";
8
8
  const __filename = fileURLToPath(import.meta.url);
9
9
  const __dirname = path.dirname(__filename);
10
10
 
11
- const CLI_NAME = "preview";
11
+ const CLI_NAME = "walrus-sites-preview";
12
12
  const defaultDistDir = path.resolve(__dirname, "./dist");
13
13
 
14
14
  const NETWORK_DEFAULTS = {
@@ -31,10 +31,12 @@ function usage() {
31
31
  "Walrus Sites (standalone preview)",
32
32
  "",
33
33
  "Usage:",
34
+ ` ${CLI_NAME} <siteObjectId> [-testnet|-mainnet] [-port 3000] [--open]`,
34
35
  ` ${CLI_NAME} [-testnet|-mainnet] -id <0x...> [-port 3000] [--open]`,
35
36
  ` ${CLI_NAME} --mode static [--dist ./dist] [-port 3000] [--open]`,
36
37
  "",
37
38
  "Site mode options:",
39
+ " <siteObjectId> Site object ID; defaults to mainnet unless a network is set",
38
40
  " --config <path> Path to config.json (default: ./config.json)",
39
41
  " -testnet / -mainnet Apply built-in defaults (rpc/aggregator/sitePackage)",
40
42
  " -id, --id <0x...> Site object ID",
@@ -55,6 +57,10 @@ function usage() {
55
57
  ].join("\n");
56
58
  }
57
59
 
60
+ function isSuiObjectId(value) {
61
+ return /^0x[0-9a-fA-F]+$/.test(value);
62
+ }
63
+
58
64
  function parsePort(value) {
59
65
  const port = Number(value);
60
66
  if (!Number.isInteger(port) || port <= 0 || port > 65535) {
@@ -75,6 +81,7 @@ function parseArgs(argv) {
75
81
  aggregatorUrl: undefined,
76
82
  sitePackage: undefined,
77
83
  siteObjectId: undefined,
84
+ siteObjectIdFromPositional: false,
78
85
  mainnet: false,
79
86
  testnet: false,
80
87
  open: false,
@@ -149,6 +156,14 @@ function parseArgs(argv) {
149
156
  options.port = parsePort(takeValue());
150
157
  continue;
151
158
  }
159
+ if (!arg.startsWith("-") && isSuiObjectId(arg)) {
160
+ if (options.siteObjectId) {
161
+ throw new Error("Site object ID was provided more than once");
162
+ }
163
+ options.siteObjectId = arg;
164
+ options.siteObjectIdFromPositional = true;
165
+ continue;
166
+ }
152
167
 
153
168
  unknown.push(arg);
154
169
  }
@@ -318,7 +333,15 @@ function loadConfigFromFileAndCli() {
318
333
  }
319
334
 
320
335
  function applyNetworkDefaults(config) {
321
- const which = cli.testnet ? "testnet" : cli.mainnet ? "mainnet" : null;
336
+ const configuredNetwork =
337
+ typeof config.network === "string" ? config.network.toLowerCase() : null;
338
+ const positionalDefault =
339
+ cli.siteObjectIdFromPositional && NETWORK_DEFAULTS[configuredNetwork]
340
+ ? configuredNetwork
341
+ : cli.siteObjectIdFromPositional
342
+ ? "mainnet"
343
+ : null;
344
+ const which = cli.testnet ? "testnet" : cli.mainnet ? "mainnet" : positionalDefault;
322
345
  if (!which) return config;
323
346
 
324
347
  const defaults = NETWORK_DEFAULTS[which];
@@ -681,7 +704,7 @@ if (mode === "static") {
681
704
  if (missing.length) {
682
705
  console.error(`Missing config fields for site mode: ${missing.join(", ")}`);
683
706
  console.error(
684
- `Pass CLI flags (e.g. \`${CLI_NAME} -testnet -id 0x...\`) or create ./config.json.`,
707
+ `Pass a site object ID (e.g. \`${CLI_NAME} 0x...\`), add network flags, or create ./config.json.`,
685
708
  );
686
709
  process.exit(1);
687
710
  }