@zktx.io/walrus-sites-preview 0.1.0 → 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/README.md +19 -7
- package/package.json +3 -3
- package/preview.mjs +26 -3
package/README.md
CHANGED
|
@@ -24,14 +24,24 @@ A short demo showing how to preview a deployed Walrus Site locally:
|
|
|
24
24
|
|
|
25
25
|
https://github.com/user-attachments/assets/c28c033a-92c5-4ee9-82e0-1406319842c7
|
|
26
26
|
|
|
27
|
+
The preview URL used in the demo is `http://localhost:3000`.
|
|
28
|
+
|
|
27
29
|
---
|
|
28
30
|
|
|
29
31
|
## Quickstart (one-liner)
|
|
30
32
|
|
|
31
|
-
Preview a deployed Walrus Site in a single command
|
|
33
|
+
Preview a deployed Walrus Site in a single command.
|
|
34
|
+
|
|
35
|
+
For mainnet:
|
|
32
36
|
|
|
33
37
|
```sh
|
|
34
|
-
npx @zktx.io/walrus-sites-preview
|
|
38
|
+
npx @zktx.io/walrus-sites-preview 0xYOUR_SITE_OBJECT_ID
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
For testnet:
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
npx @zktx.io/walrus-sites-preview -testnet 0xYOUR_SITE_OBJECT_ID
|
|
35
45
|
```
|
|
36
46
|
|
|
37
47
|
Then open:
|
|
@@ -43,7 +53,7 @@ http://localhost:3000
|
|
|
43
53
|
You can also add `--open` to open the browser automatically:
|
|
44
54
|
|
|
45
55
|
```sh
|
|
46
|
-
npx @zktx.io/walrus-sites-preview
|
|
56
|
+
npx @zktx.io/walrus-sites-preview 0xYOUR_SITE_OBJECT_ID --open
|
|
47
57
|
```
|
|
48
58
|
|
|
49
59
|
---
|
|
@@ -111,8 +121,8 @@ Add an npm script to your project so teammates can run a familiar command:
|
|
|
111
121
|
```json
|
|
112
122
|
{
|
|
113
123
|
"scripts": {
|
|
114
|
-
"preview:testnet": "preview -testnet
|
|
115
|
-
"preview:mainnet": "
|
|
124
|
+
"preview:testnet": "walrus-sites-preview -testnet 0xYOUR_SITE_OBJECT_ID -port 3000",
|
|
125
|
+
"preview:mainnet": "walrus-sites-preview 0xYOUR_SITE_OBJECT_ID -port 3000"
|
|
116
126
|
}
|
|
117
127
|
}
|
|
118
128
|
```
|
|
@@ -181,6 +191,8 @@ When using `-testnet` or `-mainnet`, the following values are filled automatical
|
|
|
181
191
|
- `aggregatorUrl`
|
|
182
192
|
- `sitePackage`
|
|
183
193
|
|
|
194
|
+
The positional one-liner defaults to mainnet. Pass `-testnet` for testnet sites.
|
|
195
|
+
|
|
184
196
|
### Supported fields
|
|
185
197
|
|
|
186
198
|
- `siteObjectId` (required)
|
|
@@ -217,7 +229,7 @@ Add a pass-through script:
|
|
|
217
229
|
```json
|
|
218
230
|
{
|
|
219
231
|
"scripts": {
|
|
220
|
-
"preview": "preview"
|
|
232
|
+
"preview": "walrus-sites-preview"
|
|
221
233
|
}
|
|
222
234
|
}
|
|
223
235
|
```
|
|
@@ -225,7 +237,7 @@ Add a pass-through script:
|
|
|
225
237
|
Then run:
|
|
226
238
|
|
|
227
239
|
```sh
|
|
228
|
-
npm run preview -- -testnet
|
|
240
|
+
npm run preview -- -testnet 0xYOUR_SITE_OBJECT_ID -port 3000
|
|
229
241
|
```
|
|
230
242
|
|
|
231
243
|
---
|
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.1.
|
|
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"
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"cli"
|
|
35
35
|
],
|
|
36
36
|
"author": "daoauth",
|
|
37
|
-
"license": "
|
|
37
|
+
"license": "MIT",
|
|
38
38
|
"repository": {
|
|
39
39
|
"type": "git",
|
|
40
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
|
|
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
|
|
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
|
}
|