From d6cb59e826f4c15d001fc2c8f0f5b69cd8475e5e Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Thu, 7 Nov 2024 16:47:37 -0600 Subject: [PATCH] Add help and wire up --output --- README.md | 4 ++-- cli.js | 43 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 53e04db..d2c4260 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # `@11ty/import` -A small utility (and CLI) to import content files from various content sources.. Requires Node 18 or newer. +A small utility (and CLI) to import content files from various content sources. Requires Node 18 or newer. ```sh -npx @11ty/import wordpress blog.fontawesome.com +npx @11ty/import wordpress https://blog.fontawesome.com ``` Installation happens on-the-fly via `npx` and we needn’t put this in a package.json. diff --git a/cli.js b/cli.js index 63ee62e..2eb82b0 100644 --- a/cli.js +++ b/cli.js @@ -5,6 +5,7 @@ import kleur from "kleur"; import { Importer } from "./src/Importer.js"; import { Logger } from "./src/Logger.js"; +import { createRequire } from "node:module"; let { positionals, values } = parseArgs({ allowPositionals: true, @@ -17,6 +18,10 @@ let { positionals, values } = parseArgs({ target: { type: "string", }, + output: { + type: "string", + default: ".", + }, quiet: { type: "boolean", default: false, @@ -25,11 +30,45 @@ let { positionals, values } = parseArgs({ type: "boolean", default: false, }, + help: { + type: "boolean", + default: false, + }, + version: { + type: "boolean", + default: false, + }, }, }); let [ type, target ] = positionals; -let { quiet, dryrun } = values; +let { quiet, dryrun, output, help, version } = values; + +if(version) { + const require = createRequire(import.meta.url); + let pkg = require("./package.json"); + Logger.log(pkg.version); + process.exit(); +} + +if(help) { + Logger.log(`Usage: + + npx @11ty/import --help + npx @11ty/import --version + + # Import content + npx @11ty/import [type] [target] + + # Quietly + npx @11ty/import [type] [target] --quiet + + # Change the output folder + npx @11ty/import [type] [target] --output=dist +`); + + process.exit(); +} // Input checking if(!type || !target) { @@ -46,7 +85,7 @@ importer.setVerbose(!quiet); // TODO wire these up to CLI importer.setCacheDuration("4h"); importer.setDraftsFolder("drafts"); -importer.setOutputFolder("dist"); +importer.setOutputFolder(output); importer.setDryRun(dryrun); importer.addSource(type, target);