Skip to content

Commit

Permalink
Add help and wire up --output
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Nov 7, 2024
1 parent 02ba724 commit d6cb59e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
43 changes: 41 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -17,6 +18,10 @@ let { positionals, values } = parseArgs({
target: {
type: "string",
},
output: {
type: "string",
default: ".",
},
quiet: {
type: "boolean",
default: false,
Expand All @@ -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) {
Expand All @@ -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);
Expand Down

0 comments on commit d6cb59e

Please sign in to comment.