11ty / eleventy

A simpler site generator. Transforms a directory of templates (of varying types) into HTML.
https://www.11ty.dev/
MIT License
17.29k stars 496 forks source link

CLI prompt to re-run a full build #3506

Open zachleat opened 1 month ago

zachleat commented 1 month ago

The ava test runner has a nice option to rerun tests with r and it’d be nice to have something similar in Eleventy (especially with incremental builds)

1297 tests passed, 19 tests skipped, Type `r` and press enter to rerun tests, Type `u` and press enter to update snapshots
zachleat commented 1 month ago

interesting Node.js pattern here: https://www.linkedin.com/posts/mapocock_til-you-can-prompt-folks-on-your-cli-without-activity-7255214390419894272-SXMi

image
Ryuno-Ki commented 1 month ago
import { stdin, stdout } from "node:process";
import { createInterface } from "node:readline/promises";

// 1. Create an interface, taking in stdin and stdout
const rl = createInterface({
  input: stdin,
  output: stdout,
});

// 2. Ask the user a question, and await the result!
const answer = await rl.question(
  "How attractive is Matt Pocock? ",
);

// 3. Get access to the answer immediately
console.log(
  `Thank you for your valuable feedback: ${answer}`,
);

// 4. Close the interface
rl.close();

Transcribed, because blind people should be able to learn as well :)

Node.js API documentation on the subject

I would expect some signal handling (Ctrl+C and friends). Perhaps best to have a try-catch around the question?

Node itself has a learning module with some recommendations on handling sensitive data. Keep in mind that the callback version should work better for larger data (because RAM limitations and streaming).