Skip to content

Commit 70a2339

Browse files
author
Thordata
committed
chore(js): improve live examples (tsx scripts, better outputs) and keep CI stable
1 parent a20b858 commit 70a2339

File tree

8 files changed

+33
-11
lines changed

8 files changed

+33
-11
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ coverage/
3939

4040
# Lock files (optional, some prefer to commit)
4141
# package-lock.json
42+
universal_output.html

.llm_cache/meta.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
"max_single_file_bytes": 3000000,
77
"ignore_lock_files": true,
88
"bundle_count": 1,
9-
"bundle_files": [
10-
"bundle_0001.txt"
11-
],
9+
"bundle_files": ["bundle_0001.txt"],
1210
"files_included": 65,
1311
"build_seconds": 0.037
14-
}
12+
}

examples/basic_scraper_task.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,19 @@ async function main() {
3131

3232
let parameters: any;
3333
try {
34-
parameters = JSON.parse(parametersJson);
34+
const raw = JSON.parse(parametersJson);
35+
36+
// Dashboard curl uses spider_parameters as an ARRAY string: [{...}]
37+
// Accept both "{...}" and "[{...}]". SDK createScraperTask expects ONE parameter object.
38+
if (Array.isArray(raw)) {
39+
if (raw.length === 0) {
40+
console.error("THORDATA_TASK_PARAMETERS_JSON must not be an empty array");
41+
process.exit(1);
42+
}
43+
parameters = raw[0];
44+
} else {
45+
parameters = raw;
46+
}
3547
} catch {
3648
console.error("THORDATA_TASK_PARAMETERS_JSON must be valid JSON");
3749
process.exit(1);

examples/internal/example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ export function printJSON(v: unknown) {
2525
export function truncate(s: string, n: number) {
2626
if (n <= 0) return "";
2727
return s.length <= n ? s : s.slice(0, n) + "...";
28-
}
28+
}

examples/locations_basic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ async function main() {
2020
main().catch((e) => {
2121
console.error(e);
2222
process.exit(1);
23-
});
23+
});

examples/serp_basic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ async function main() {
2525
main().catch((e) => {
2626
console.error(e);
2727
process.exit(1);
28-
});
28+
});

examples/universal_basic.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { loadEnv, skipIfMissing, truncate } from "./internal/example.js";
44
import { ThordataClient } from "../src/index.js";
5+
import fs from "node:fs";
56

67
async function main() {
78
loadEnv();
@@ -19,8 +20,11 @@ async function main() {
1920
js_render: false,
2021
});
2122

22-
const s = typeof out === "string" ? out : JSON.stringify(out);
23-
console.log("preview:", truncate(s, 300));
23+
const html = typeof out === "string" ? out : JSON.stringify(out, null, 2);
24+
fs.writeFileSync("universal_output.html", html, "utf8");
25+
console.log("saved: universal_output.html");
26+
console.log("length:", html.length);
27+
console.log("preview:", truncate(html, 300));
2428
}
2529

2630
main().catch((e) => {

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,14 @@
2525
"format:check": "prettier -c .",
2626
"prepack": "npm run build",
2727
"prepublishOnly": "npm run format:check && npm run lint && npm test",
28-
"example:verify": "npm run build && node dist/examples/verify_new_features.js"
28+
"example:verify": "npm run build && node dist/examples/verify_new_features.js",
29+
"example:serp": "tsx examples/serp_basic.ts",
30+
"example:universal": "tsx examples/universal_basic.ts",
31+
"example:task": "tsx examples/basic_scraper_task.ts",
32+
"example:proxy:residential": "tsx examples/proxy_residential.ts",
33+
"example:proxy:mobile": "tsx examples/proxy_mobile.ts",
34+
"example:proxy:datacenter": "tsx examples/proxy_datacenter.ts",
35+
"example:proxy:isp": "tsx examples/proxy_isp.ts"
2936
},
3037
"keywords": [
3138
"thordata",

0 commit comments

Comments
 (0)