···22sourceMapSupport.install(options)
33import path from "path"
44import { PerfTimer } from "./util/perf"
55-import { rimraf } from "rimraf"
55+import { rm } from "fs/promises"
66import { GlobbyFilterFunction, isGitIgnored } from "globby"
77-import chalk from "chalk"
77+import { styleText } from "util"
88import { parseMarkdown } from "./processors/parse"
99import { filterContent } from "./processors/filter"
1010import { emitContent } from "./processors/emit"
···67676868 const release = await mut.acquire()
6969 perf.addEvent("clean")
7070- await rimraf(path.join(output, "*"), { glob: true })
7070+ await rm(output, { recursive: true, force: true })
7171 console.log(`Cleaned output directory \`${output}\` in ${perf.timeSince("clean")}`)
72727373 perf.addEvent("glob")
···8585 const filteredContent = filterContent(ctx, parsedFiles)
86868787 await emitContent(ctx, filteredContent)
8888- console.log(chalk.green(`Done processing ${markdownPaths.length} files in ${perf.timeSince()}`))
8888+ console.log(
8989+ styleText("green", `Done processing ${markdownPaths.length} files in ${perf.timeSince()}`),
9090+ )
8991 release()
90929193 if (argv.watch) {
···186188187189 const perf = new PerfTimer()
188190 perf.addEvent("rebuild")
189189- console.log(chalk.yellow("Detected change, rebuilding..."))
191191+ console.log(styleText("yellow", "Detected change, rebuilding..."))
190192191193 // update changesSinceLastBuild
192194 for (const change of changes) {
···281283 }
282284283285 console.log(`Emitted ${emittedFiles} files to \`${argv.output}\` in ${perf.timeSince("rebuild")}`)
284284- console.log(chalk.green(`Done rebuilding in ${perf.timeSince()}`))
286286+ console.log(styleText("green", `Done rebuilding in ${perf.timeSince()}`))
285287 changes.splice(0, numChangesInBuild)
286288 clientRefresh()
287289 release()
+50-33
quartz/cli/handlers.js
···11import { promises } from "fs"
22import path from "path"
33import esbuild from "esbuild"
44-import chalk from "chalk"
44+import { styleText } from "util"
55import { sassPlugin } from "esbuild-sass-plugin"
66import fs from "fs"
77import { intro, outro, select, text } from "@clack/prompts"
88-import { rimraf } from "rimraf"
88+import { rm } from "fs/promises"
99import chokidar from "chokidar"
1010import prettyBytes from "pretty-bytes"
1111import { execSync, spawnSync } from "child_process"
···4848 */
4949export async function handleCreate(argv) {
5050 console.log()
5151- intro(chalk.bgGreen.black(` Quartz v${version} `))
5151+ intro(styleText(["bgGreen", "black"], ` Quartz v${version} `))
5252 const contentFolder = resolveContentPath(argv.directory)
5353 let setupStrategy = argv.strategy?.toLowerCase()
5454 let linkResolutionStrategy = argv.links?.toLowerCase()
···6161 // Error handling
6262 if (!sourceDirectory) {
6363 outro(
6464- chalk.red(
6565- `Setup strategies (arg '${chalk.yellow(
6464+ styleText(
6565+ "red",
6666+ `Setup strategies (arg '${styleText(
6767+ "yellow",
6668 `-${CreateArgv.strategy.alias[0]}`,
6767- )}') other than '${chalk.yellow(
6969+ )}') other than '${styleText(
7070+ "yellow",
6871 "new",
6969- )}' require content folder argument ('${chalk.yellow(
7272+ )}' require content folder argument ('${styleText(
7373+ "yellow",
7074 `-${CreateArgv.source.alias[0]}`,
7175 )}') to be set`,
7276 ),
···7579 } else {
7680 if (!fs.existsSync(sourceDirectory)) {
7781 outro(
7878- chalk.red(
7979- `Input directory to copy/symlink 'content' from not found ('${chalk.yellow(
8282+ styleText(
8383+ "red",
8484+ `Input directory to copy/symlink 'content' from not found ('${styleText(
8585+ "yellow",
8086 sourceDirectory,
8181- )}', invalid argument "${chalk.yellow(`-${CreateArgv.source.alias[0]}`)})`,
8787+ )}', invalid argument "${styleText("yellow", `-${CreateArgv.source.alias[0]}`)})`,
8288 ),
8389 )
8490 process.exit(1)
8591 } else if (!fs.lstatSync(sourceDirectory).isDirectory()) {
8692 outro(
8787- chalk.red(
8888- `Source directory to copy/symlink 'content' from is not a directory (found file at '${chalk.yellow(
9393+ styleText(
9494+ "red",
9595+ `Source directory to copy/symlink 'content' from is not a directory (found file at '${styleText(
9696+ "yellow",
8997 sourceDirectory,
9090- )}', invalid argument ${chalk.yellow(`-${CreateArgv.source.alias[0]}`)}")`,
9898+ )}', invalid argument ${styleText("yellow", `-${CreateArgv.source.alias[0]}`)}")`,
9199 ),
92100 )
93101 process.exit(1)
···119127 if (contentStat.isSymbolicLink()) {
120128 await fs.promises.unlink(contentFolder)
121129 } else {
122122- await rimraf(contentFolder)
130130+ await rm(contentFolder, { recursive: true, force: true })
123131 }
124132 }
125133···229237 argv.watch = true
230238 }
231239232232- console.log(chalk.bgGreen.black(`\n Quartz v${version} \n`))
240240+ console.log(`\n${styleText(["bgGreen", "black"], ` Quartz v${version} `)} \n`)
233241 const ctx = await esbuild.context({
234242 entryPoints: [fp],
235243 outfile: cacheFile,
···304312 }
305313306314 if (cleanupBuild) {
307307- console.log(chalk.yellow("Detected a source code change, doing a hard rebuild..."))
315315+ console.log(styleText("yellow", "Detected a source code change, doing a hard rebuild..."))
308316 await cleanupBuild()
309317 }
310318311319 const result = await ctx.rebuild().catch((err) => {
312312- console.error(`${chalk.red("Couldn't parse Quartz configuration:")} ${fp}`)
313313- console.log(`Reason: ${chalk.grey(err)}`)
320320+ console.error(`${styleText("red", "Couldn't parse Quartz configuration:")} ${fp}`)
321321+ console.log(`Reason: ${styleText("grey", err)}`)
314322 process.exit(1)
315323 })
316324 release()
···348356 const server = http.createServer(async (req, res) => {
349357 if (argv.baseDir && !req.url?.startsWith(argv.baseDir)) {
350358 console.log(
351351- chalk.red(
359359+ styleText(
360360+ "red",
352361 `[404] ${req.url} (warning: link outside of site, this is likely a Quartz bug)`,
353362 ),
354363 )
···383392 })
384393 const status = res.statusCode
385394 const statusString =
386386- status >= 200 && status < 300 ? chalk.green(`[${status}]`) : chalk.red(`[${status}]`)
387387- console.log(statusString + chalk.grey(` ${argv.baseDir}${req.url}`))
395395+ status >= 200 && status < 300
396396+ ? styleText("green", `[${status}]`)
397397+ : styleText("red", `[${status}]`)
398398+ console.log(statusString + styleText("grey", ` ${argv.baseDir}${req.url}`))
388399 release()
389400 }
390401···393404 res.writeHead(302, {
394405 Location: newFp,
395406 })
396396- console.log(chalk.yellow("[302]") + chalk.grey(` ${argv.baseDir}${req.url} -> ${newFp}`))
407407+ console.log(
408408+ styleText("yellow", "[302]") +
409409+ styleText("grey", ` ${argv.baseDir}${req.url} -> ${newFp}`),
410410+ )
397411 res.end()
398412 }
399413···443457 const wss = new WebSocketServer({ port: argv.wsPort })
444458 wss.on("connection", (ws) => connections.push(ws))
445459 console.log(
446446- chalk.cyan(
460460+ styleText(
461461+ "cyan",
447462 `Started a Quartz server listening at http://localhost:${argv.port}${argv.baseDir}`,
448463 ),
449464 )
···467482 .on("change", () => build(clientRefresh))
468483 .on("unlink", () => build(clientRefresh))
469484470470- console.log(chalk.grey("hint: exit with ctrl+c"))
485485+ console.log(styleText("grey", "hint: exit with ctrl+c"))
471486 }
472487}
473488···477492 */
478493export async function handleUpdate(argv) {
479494 const contentFolder = resolveContentPath(argv.directory)
480480- console.log(chalk.bgGreen.black(`\n Quartz v${version} \n`))
495495+ console.log(`\n${styleText(["bgGreen", "black"], ` Quartz v${version} `)} \n`)
481496 console.log("Backing up your content")
482497 execSync(
483498 `git remote show upstream || git remote add upstream https://github.com/jackyzha0/quartz.git`,
···490505 try {
491506 gitPull(UPSTREAM_NAME, QUARTZ_SOURCE_BRANCH)
492507 } catch {
493493- console.log(chalk.red("An error occurred above while pulling updates."))
508508+ console.log(styleText("red", "An error occurred above while pulling updates."))
494509 await popContentFolder(contentFolder)
495510 return
496511 }
···517532518533 const res = spawnSync("npm", ["i"], opts)
519534 if (res.status === 0) {
520520- console.log(chalk.green("Done!"))
535535+ console.log(styleText("green", "Done!"))
521536 } else {
522522- console.log(chalk.red("An error occurred above while installing dependencies."))
537537+ console.log(styleText("red", "An error occurred above while installing dependencies."))
523538 }
524539}
525540···538553 */
539554export async function handleSync(argv) {
540555 const contentFolder = resolveContentPath(argv.directory)
541541- console.log(chalk.bgGreen.black(`\n Quartz v${version} \n`))
556556+ console.log(`\n${styleText(["bgGreen", "black"], ` Quartz v${version} `)}\n`)
542557 console.log("Backing up your content")
543558544559 if (argv.commit) {
545560 const contentStat = await fs.promises.lstat(contentFolder)
546561 if (contentStat.isSymbolicLink()) {
547562 const linkTarg = await fs.promises.readlink(contentFolder)
548548- console.log(chalk.yellow("Detected symlink, trying to dereference before committing"))
563563+ console.log(styleText("yellow", "Detected symlink, trying to dereference before committing"))
549564550565 // stash symlink file
551566 await stashContentFolder(contentFolder)
···580595 try {
581596 gitPull(ORIGIN_NAME, QUARTZ_SOURCE_BRANCH)
582597 } catch {
583583- console.log(chalk.red("An error occurred above while pulling updates."))
598598+ console.log(styleText("red", "An error occurred above while pulling updates."))
584599 await popContentFolder(contentFolder)
585600 return
586601 }
···594609 stdio: "inherit",
595610 })
596611 if (res.status !== 0) {
597597- console.log(chalk.red(`An error occurred above while pushing to remote ${ORIGIN_NAME}.`))
612612+ console.log(
613613+ styleText("red", `An error occurred above while pushing to remote ${ORIGIN_NAME}.`),
614614+ )
598615 return
599616 }
600617 }
601618602602- console.log(chalk.green("Done!"))
619619+ console.log(styleText("green", "Done!"))
603620}
+4-4
quartz/cli/helpers.js
···11import { isCancel, outro } from "@clack/prompts"
22-import chalk from "chalk"
22+import { styleText } from "util"
33import { contentCacheFolder } from "./constants.js"
44import { spawnSync } from "child_process"
55import fs from "fs"
···14141515export function exitIfCancel(val) {
1616 if (isCancel(val)) {
1717- outro(chalk.red("Exiting"))
1717+ outro(styleText("red", "Exiting"))
1818 process.exit(0)
1919 } else {
2020 return val
···3636 const flags = ["--no-rebase", "--autostash", "-s", "recursive", "-X", "ours", "--no-edit"]
3737 const out = spawnSync("git", ["pull", ...flags, origin, branch], { stdio: "inherit" })
3838 if (out.stderr) {
3939- throw new Error(chalk.red(`Error while pulling updates: ${out.stderr}`))
3939+ throw new Error(styleText("red", `Error while pulling updates: ${out.stderr}`))
4040 } else if (out.status !== 0) {
4141- throw new Error(chalk.red("Error while pulling updates"))
4141+ throw new Error(styleText("red", "Error while pulling updates"))
4242 }
4343}
4444
+4-2
quartz/plugins/emitters/cname.ts
···11import { FilePath, joinSegments } from "../../util/path"
22import { QuartzEmitterPlugin } from "../types"
33import fs from "fs"
44-import chalk from "chalk"
44+import { styleText } from "util"
5566export function extractDomainFromBaseUrl(baseUrl: string) {
77 const url = new URL(`https://${baseUrl}`)
···1212 name: "CNAME",
1313 async emit({ argv, cfg }) {
1414 if (!cfg.configuration.baseUrl) {
1515- console.warn(chalk.yellow("CNAME emitter requires `baseUrl` to be set in your configuration"))
1515+ console.warn(
1616+ styleText("yellow", "CNAME emitter requires `baseUrl` to be set in your configuration"),
1717+ )
1618 return []
1719 }
1820 const path = joinSegments(argv.output, "CNAME")
+3-2
quartz/plugins/emitters/contentPage.tsx
···88import { pathToRoot } from "../../util/path"
99import { defaultContentPageLayout, sharedPageComponents } from "../../../quartz.layout"
1010import { Content } from "../../components"
1111-import chalk from "chalk"
1111+import { styleText } from "util"
1212import { write } from "./helpers"
1313import { BuildCtx } from "../../util/ctx"
1414import { Node } from "unist"
···90909191 if (!containsIndex) {
9292 console.log(
9393- chalk.yellow(
9393+ styleText(
9494+ "yellow",
9495 `\nWarning: you seem to be missing an \`index.md\` home page file at the root of your \`${ctx.argv.directory}\` folder (\`${path.join(ctx.argv.directory, "index.md")} does not exist\`). This may cause errors when deploying.`,
9596 ),
9697 )
+2-2
quartz/plugins/emitters/ogImage.tsx
···1111import { BuildCtx } from "../../util/ctx"
1212import { QuartzPluginData } from "../vfile"
1313import fs from "node:fs/promises"
1414-import chalk from "chalk"
1414+import { styleText } from "util"
15151616const defaultOptions: SocialImageOptions = {
1717 colorScheme: "lightMode",
···3636 const iconData = await fs.readFile(iconPath)
3737 iconBase64 = `data:image/png;base64,${iconData.toString("base64")}`
3838 } catch (err) {
3939- console.warn(chalk.yellow(`Warning: Could not find icon at ${iconPath}`))
3939+ console.warn(styleText("yellow", `Warning: Could not find icon at ${iconPath}`))
4040 }
41414242 const imageComponent = userOpts.imageStructure({
+9-4
quartz/plugins/transformers/lastmod.ts
···11import fs from "fs"
22import { Repository } from "@napi-rs/simple-git"
33import { QuartzTransformerPlugin } from "../types"
44-import chalk from "chalk"
54import path from "path"
55+import { styleText } from "util"
6677export interface Options {
88 priority: ("frontmatter" | "git" | "filesystem")[]
···1717 const invalidDate = isNaN(dt.getTime()) || dt.getTime() === 0
1818 if (invalidDate && d !== undefined) {
1919 console.log(
2020- chalk.yellow(
2020+ styleText(
2121+ "yellow",
2122 `\nWarning: found invalid date "${d}" in \`${fp}\`. Supported formats: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#date_time_string_format`,
2223 ),
2324 )
···4243 repositoryWorkdir = repo.workdir() ?? ctx.argv.directory
4344 } catch (e) {
4445 console.log(
4545- chalk.yellow(`\nWarning: couldn't find git repository for ${ctx.argv.directory}`),
4646+ styleText(
4747+ "yellow",
4848+ `\nWarning: couldn't find git repository for ${ctx.argv.directory}`,
4949+ ),
4650 )
4751 }
4852 }
···6973 modified ||= await repo.getFileLatestModifiedDateAsync(relativePath)
7074 } catch {
7175 console.log(
7272- chalk.yellow(
7676+ styleText(
7777+ "yellow",
7378 `\nWarning: ${file.data.filePath!} isn't yet tracked by git, dates will be inaccurate`,
7479 ),
7580 )