From da1b1859df235fecb77973de10453ee2f1690037 Mon Sep 17 00:00:00 2001 From: Joonas Tiala Date: Mon, 29 May 2023 23:08:52 +0300 Subject: [PATCH] feat: Add support for running the script with npx --- README.md | 16 ++++++---------- package.json | 1 + src/wpdl.js | 4 +--- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 3793538..b28543b 100644 --- a/README.md +++ b/README.md @@ -12,30 +12,26 @@ Scrape pages, posts, images and other data from a WordPress instance using the W ## Pre-requisites -Node.js v19 or newer (for native fetch support) - -## Installation - -```bash -npm i -``` +Node.js v19 or newer (for native fetch support). ## Usage examples +Recommended way of using wpdl is with `npx`. You can also clone this repo and run locally, just replace `npx wpdl` with `npm run scrape -- `. Note: the double dash is needed to pass the arguments to the script. + Scrape pages and posts ```bash -npm run scrape -- --url https://your-wp-instance.com --pages --posts +npx wpdl --url https://your-wp-instance.com --pages --posts ``` Scrape pages and clean up the html by filtering out all `img` elements and elements with the class `foo`. Also remove all elements without text content. From the json files, remove all the Jetpack and Yoast SEO data. ```bash -npm run scrape -- --url https://your-wp-instance.com --pages --elementFilter img --classFilter foo --jsonFilter "jetpack_*" --jsonFilter "yoast_*" --removeEmptyElements +npx wpdl -- --url https://your-wp-instance.com --pages --elementFilter img --classFilter foo --jsonFilter "jetpack_*" --jsonFilter "yoast_*" --removeEmptyElements ``` To see full usage, run ```bash -npm run help +npx wpdl -h ``` diff --git a/package.json b/package.json index fd37e45..98ecfc7 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "license": "MIT", "main": "wpdl.js", "type": "module", + "bin": "./src/wpdl.js", "scripts": { "scrape": "./src/wpdl.js", "help": "./src/wpdl.js --help", diff --git a/src/wpdl.js b/src/wpdl.js index aeffb1a..f925fcd 100755 --- a/src/wpdl.js +++ b/src/wpdl.js @@ -11,9 +11,7 @@ import { error, info } from "./utils/log.js"; import { getSiteNameFromUrl, isValidUrl } from "./utils/url.js"; const argv = yargs(hideBin(process.argv)) - .usage( - "Usage: npm run scrape -- --url https://your-wp-instance.com [options]" - ) + .usage("Usage: npx wpdl --url https://your-wp-instance.com [options]") .option("url", { alias: "u", type: "string",