Skip to content

Commit

Permalink
Tiny refactor: single level of detail in executeConfig()
Browse files Browse the repository at this point in the history
  • Loading branch information
irskep committed Aug 30, 2024
1 parent de75f58 commit 28296ff
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/engine/executeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ import { DocSet } from "./docset.js";
import { parseDjot } from "../input/parseDjot.js";
import {
DjockeyConfigResolved,
DjockeyDoc,
DjockeyOutputFormat,
DjockeyPlugin,
DjockeyPluginModule,
DjockeyRenderer,
} from "../types.js";
import { makeRenderer } from "../renderers/makeRenderer.js";
import { loadDocTree } from "./doctree.js";
Expand All @@ -28,18 +26,14 @@ export async function executeConfig(
outputFormats: DjockeyOutputFormat[]
) {
const docSet = await readDocSet(config);
for (let i = 0; i < config.num_passes; i++) {
const loader = print.spin(
`Transform pass ${i + 1} of ${config.num_passes}`
);
loader.start();
await docSet.runPasses();
loader.succeed();
}

await applyPlugins(config, docSet);

const connectSpinner = print.spin("Connecting pages");
connectSpinner.start();
docSet.tree = loadDocTree(docSet.docs);
connectSpinner.succeed();

await writeDocSet(docSet, outputFormats);
}

Expand Down Expand Up @@ -70,7 +64,6 @@ export async function readDocSet(
}

const loader = print.spin("Setting up plugins");
loader.start();
const plugins = [...makeBuiltinPlugins(config), ...userPlugins];
for (const plugin of plugins) {
if (plugin.setup) {
Expand All @@ -82,6 +75,20 @@ export async function readDocSet(
return new DocSet(config, plugins, docs);
}

export async function applyPlugins(
config: DjockeyConfigResolved,
docSet: DocSet
) {
for (let i = 0; i < config.num_passes; i++) {
const loader = print.spin(
`Transform pass ${i + 1} of ${config.num_passes}`
);
loader.start();
await docSet.runPasses();
loader.succeed();
}
}

export async function writeDocSet(
docSet: DocSet,
outputFormats: DjockeyOutputFormat[]
Expand Down

0 comments on commit 28296ff

Please sign in to comment.