Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 3 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@ just-scrape/
├── src/
│ ├── cli.ts # Entry point, citty main command + subcommands
│ ├── lib/
│ │ ├── env.ts # Zod-parsed env config (API key, debug, timeout)
│ │ ├── env.ts # Env config (API key, JUST_SCRAPE_* → SGAI_* bridge)
│ │ ├── folders.ts # API key resolution + interactive prompt
│ │ ├── scrapegraphai.ts # SDK layer — all API functions (typed responses)
│ │ ├── schemas.ts # Zod validation schemas
│ │ └── log.ts # Logger factory + syntax-highlighted JSON output
│ ├── types/
│ │ └── index.ts # Zod-derived types + ApiResult + response types
│ ├── commands/
│ │ ├── smart-scraper.ts
│ │ ├── search-scraper.ts
Expand All @@ -45,8 +41,6 @@ just-scrape/
│ │ └── validate.ts
│ └── utils/
│ └── banner.ts # ASCII banner + version from package.json
├── tests/
│ └── scrapegraphai.test.ts # SDK layer tests (mocked fetch)
├── dist/ # Build output (git-ignored)
│ └── cli.mjs # Bundled ESM with shebang
├── package.json
Expand All @@ -64,6 +58,7 @@ pnpm add -g just-scrape # pnpm
yarn global add just-scrape # yarn
bun add -g just-scrape # bun
npx just-scrape --help # or run without installing
bunx just-scrape --help # bun equivalent
```

Package: [just-scrape](https://www.npmjs.com/package/just-scrape) on npm.
Expand Down Expand Up @@ -396,10 +391,9 @@ bun run dev --help
| CLI Framework | **citty** (unjs) |
| Prompts | **@clack/prompts** |
| Styling | **chalk** v5 (ESM) |
| Validation | **zod** v4 |
| SDK | **scrapegraph-js** |
| Env | **dotenv** |
| Lint / Format | **Biome** |
| Testing | **Bun test** (built-in) |
| Target | **Node.js 22+**, ESM-only |

### Scripts
Expand All @@ -409,16 +403,9 @@ bun run dev # Run CLI from TS source
bun run build # Bundle ESM to dist/cli.mjs
bun run lint # Lint + format check
bun run format # Auto-format
bun test # Run tests
bun run check # Type-check + lint
```

### Testing

Tests mock all API calls via `spyOn(globalThis, "fetch")` — no network, no API key needed.

Covers: success paths, polling, HTTP error mapping (401/402/422/429/500), Zod validation, timeouts, and network failures.

## License

ISC
Expand Down
6 changes: 3 additions & 3 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "just-scrape",
"version": "0.1.9",
"version": "0.2.0",
"description": "ScrapeGraph AI CLI tool",
"type": "module",
"main": "dist/cli.mjs",
Expand Down Expand Up @@ -28,7 +28,7 @@
"chalk": "^5.4.1",
"citty": "^0.1.6",
"dotenv": "^17.2.4",
"zod": "^4.3.6"
"scrapegraph-js": "^1.0.0"
},
"devDependencies": {
"@biomejs/biome": "^1.9.4",
Expand Down
1 change: 1 addition & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "dotenv/config";
import "./lib/env.js";
import { defineCommand, runMain } from "citty";
import { getVersion, showBanner } from "./utils/banner.js";

Expand Down
7 changes: 3 additions & 4 deletions src/commands/agentic-scraper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineCommand } from "citty";
import * as scrapegraphai from "scrapegraph-js";
import { resolveApiKey } from "../lib/folders.js";
import * as log from "../lib/log.js";
import * as scrapegraphai from "../lib/scrapegraphai.js";

export default defineCommand({
meta: {
Expand Down Expand Up @@ -34,9 +34,8 @@ export default defineCommand({
out.docs("https://docs.scrapegraphai.com/services/agenticscraper");
const key = await resolveApiKey(!!args.json);

const params: scrapegraphai.AgenticScraperParams = { url: args.url };

if (args.steps) params.steps = args.steps.split(",").map((s) => s.trim());
const steps = args.steps ? args.steps.split(",").map((s) => s.trim()) : [];
const params: scrapegraphai.AgenticScraperParams = { url: args.url, steps };
if (args.prompt) params.user_prompt = args.prompt;
if (args.schema) params.output_schema = JSON.parse(args.schema);
if (args["ai-extraction"]) params.ai_extraction = true;
Expand Down
25 changes: 15 additions & 10 deletions src/commands/crawl.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineCommand } from "citty";
import * as scrapegraphai from "scrapegraph-js";
import { resolveApiKey } from "../lib/folders.js";
import * as log from "../lib/log.js";
import * as scrapegraphai from "../lib/scrapegraphai.js";

export default defineCommand({
meta: {
Expand Down Expand Up @@ -36,16 +36,21 @@ export default defineCommand({
out.docs("https://docs.scrapegraphai.com/services/smartcrawler");
const key = await resolveApiKey(!!args.json);

const params: scrapegraphai.CrawlParams = { url: args.url };
const base: Record<string, unknown> = { url: args.url };
if (args["max-pages"]) base.max_pages = Number(args["max-pages"]);
if (args.depth) base.depth = Number(args.depth);
if (args.rules) base.rules = JSON.parse(args.rules);
if (args["no-sitemap"]) base.sitemap = false;
if (args.stealth) base.stealth = true;

if (args.prompt) params.prompt = args.prompt;
if (args["no-extraction"]) params.extraction_mode = false;
if (args["max-pages"]) params.max_pages = Number(args["max-pages"]);
if (args.depth) params.depth = Number(args.depth);
if (args.schema) params.schema = JSON.parse(args.schema);
if (args.rules) params.rules = JSON.parse(args.rules);
if (args["no-sitemap"]) params.sitemap = false;
if (args.stealth) params.stealth = true;
if (args["no-extraction"]) {
base.extraction_mode = false;
} else {
if (args.prompt) base.prompt = args.prompt;
if (args.schema) base.schema = JSON.parse(args.schema);
}

const params = base as scrapegraphai.CrawlParams;

out.start("Crawling");
const result = await scrapegraphai.crawl(key, params, out.poll);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/credits.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineCommand } from "citty";
import * as scrapegraphai from "scrapegraph-js";
import { resolveApiKey } from "../lib/folders.js";
import * as log from "../lib/log.js";
import * as scrapegraphai from "../lib/scrapegraphai.js";

export default defineCommand({
meta: {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/generate-schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineCommand } from "citty";
import * as scrapegraphai from "scrapegraph-js";
import { resolveApiKey } from "../lib/folders.js";
import * as log from "../lib/log.js";
import * as scrapegraphai from "../lib/scrapegraphai.js";

export default defineCommand({
meta: {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/history.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as p from "@clack/prompts";
import chalk from "chalk";
import { defineCommand } from "citty";
import { HISTORY_SERVICES } from "scrapegraph-js";
import * as scrapegraphai from "scrapegraph-js";
import { resolveApiKey } from "../lib/folders.js";
import * as log from "../lib/log.js";
import { HISTORY_SERVICES } from "../lib/schemas.js";
import * as scrapegraphai from "../lib/scrapegraphai.js";

const VALID = HISTORY_SERVICES.join(", ");
const LOAD_MORE = "__load_more__";
Expand Down
2 changes: 1 addition & 1 deletion src/commands/markdownify.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineCommand } from "citty";
import * as scrapegraphai from "scrapegraph-js";
import { resolveApiKey } from "../lib/folders.js";
import * as log from "../lib/log.js";
import * as scrapegraphai from "../lib/scrapegraphai.js";

export default defineCommand({
meta: {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/scrape.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineCommand } from "citty";
import * as scrapegraphai from "scrapegraph-js";
import { resolveApiKey } from "../lib/folders.js";
import * as log from "../lib/log.js";
import * as scrapegraphai from "../lib/scrapegraphai.js";

export default defineCommand({
meta: {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/search-scraper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineCommand } from "citty";
import * as scrapegraphai from "scrapegraph-js";
import { resolveApiKey } from "../lib/folders.js";
import * as log from "../lib/log.js";
import * as scrapegraphai from "../lib/scrapegraphai.js";

export default defineCommand({
meta: {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/sitemap.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineCommand } from "citty";
import * as scrapegraphai from "scrapegraph-js";
import { resolveApiKey } from "../lib/folders.js";
import * as log from "../lib/log.js";
import * as scrapegraphai from "../lib/scrapegraphai.js";

export default defineCommand({
meta: {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/smart-scraper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineCommand } from "citty";
import * as scrapegraphai from "scrapegraph-js";
import { resolveApiKey } from "../lib/folders.js";
import * as log from "../lib/log.js";
import * as scrapegraphai from "../lib/scrapegraphai.js";

export default defineCommand({
meta: {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/validate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineCommand } from "citty";
import * as scrapegraphai from "scrapegraph-js";
import { resolveApiKey } from "../lib/folders.js";
import * as log from "../lib/log.js";
import * as scrapegraphai from "../lib/scrapegraphai.js";

export default defineCommand({
meta: {
Expand Down
28 changes: 13 additions & 15 deletions src/lib/env.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { existsSync, readFileSync } from "node:fs";
import { homedir } from "node:os";
import { join } from "node:path";
import { z } from "zod";

export const CONFIG_DIR = join(homedir(), ".scrapegraphai");
export const CONFIG_PATH = join(CONFIG_DIR, "config.json");

if (process.env.JUST_SCRAPE_API_URL && !process.env.SGAI_API_URL)
process.env.SGAI_API_URL = process.env.JUST_SCRAPE_API_URL;

if (process.env.JUST_SCRAPE_DEBUG === "1" && !process.env.SGAI_DEBUG) process.env.SGAI_DEBUG = "1";

if (process.env.JUST_SCRAPE_TIMEOUT_S && !process.env.SGAI_TIMEOUT_S)
process.env.SGAI_TIMEOUT_S = process.env.JUST_SCRAPE_TIMEOUT_S;

function loadConfigFile(): Record<string, unknown> {
if (!existsSync(CONFIG_PATH)) return {};
try {
Expand All @@ -15,24 +22,15 @@ function loadConfigFile(): Record<string, unknown> {
}
}

const EnvSchema = z.object({
apiKey: z.string().optional(),
debug: z.boolean().default(false),
timeoutS: z.number().int().positive().default(120),
});

export type Env = z.infer<typeof EnvSchema>;
export type Env = {
apiKey?: string;
};

function resolve(): Env {
const config = loadConfigFile();

return EnvSchema.parse({
return {
apiKey: process.env.SGAI_API_KEY || (config["api-key"] as string) || undefined,
debug: process.env.JUST_SCRAPE_DEBUG === "1",
timeoutS: process.env.JUST_SCRAPE_TIMEOUT_S
? Number(process.env.JUST_SCRAPE_TIMEOUT_S)
: 60 * 2,
});
};
}

export const env = resolve();
90 changes: 0 additions & 90 deletions src/lib/schemas.ts

This file was deleted.

Loading