Update plugin shape
This commit is contained in:
parent
504c1e6f3c
commit
ae1b9e262e
12 changed files with 181 additions and 149 deletions
|
@ -1,6 +1,7 @@
|
|||
import { parseArgs } from "node:util";
|
||||
import chalk from "chalk";
|
||||
import { type Binding, loadBinding } from "#core/binding";
|
||||
import { loadBinding } from "#core/binding";
|
||||
import type { MusePlugin } from "#core/plugins";
|
||||
import { MuseError } from "#errors";
|
||||
import { version } from "../../package.json";
|
||||
|
||||
|
@ -68,50 +69,46 @@ function parseCLIArguments(argv: string[]): [string, CLIFlags] {
|
|||
return [args[0] ?? "./", options];
|
||||
}
|
||||
|
||||
function getStepLogLine(plugin: MusePlugin): string {
|
||||
const { name, description } = plugin;
|
||||
let processorLogLine = chalk.bold(`↪ ${name}`);
|
||||
|
||||
if (description && description.length > 0) {
|
||||
processorLogLine += chalk.dim(` (${description})`);
|
||||
}
|
||||
|
||||
return processorLogLine;
|
||||
}
|
||||
|
||||
async function processBinding(
|
||||
inputFilePath: string,
|
||||
flags: CLIFlags,
|
||||
{ log, verbose }: Loggers,
|
||||
) {
|
||||
// Load the binding
|
||||
const binding = await loadBinding(inputFilePath);
|
||||
|
||||
let binding = await loadBinding(inputFilePath);
|
||||
verbose(`Binding ${binding.bindingPath}`);
|
||||
|
||||
const stepWord = binding.processors.length === 1 ? "step" : "steps";
|
||||
log(
|
||||
`Processing ${binding.entries.length} entries with ${binding.processors.length} ${stepWord}`,
|
||||
);
|
||||
const entryCount = binding.entries.length;
|
||||
const stepCount = binding.plugins.length;
|
||||
const stepWord = stepCount === 1 ? "step" : "steps";
|
||||
log(`Processing ${entryCount} entries with ${stepCount} ${stepWord}`);
|
||||
|
||||
const processStart = performance.now();
|
||||
|
||||
// Run the data through all processors
|
||||
const processedSteps: Binding[] = [binding];
|
||||
for (const processor of binding.processors) {
|
||||
const lastStep = processedSteps[processedSteps.length - 1];
|
||||
|
||||
const { process, name, description } = processor;
|
||||
|
||||
let processorLogLine = chalk.bold(`↪ ${name}`);
|
||||
|
||||
if (description && description.length > 0) {
|
||||
processorLogLine += chalk.dim(` (${description})`);
|
||||
}
|
||||
|
||||
log(processorLogLine);
|
||||
const thisStep = await process(lastStep, binding.options);
|
||||
processedSteps.push(thisStep);
|
||||
// Run the data through relevant plugins
|
||||
for (const plugin of binding.plugins) {
|
||||
log(getStepLogLine(plugin));
|
||||
const { step } = plugin;
|
||||
binding = await step(binding);
|
||||
}
|
||||
|
||||
const processEnd = performance.now();
|
||||
const processTime = ((processEnd - processStart) / 1000).toFixed(2);
|
||||
verbose(`Processing completed in ${processTime}s`);
|
||||
|
||||
const finalState = processedSteps[processedSteps.length - 1];
|
||||
const serialized = JSON.stringify(finalState.entries, null, 2);
|
||||
|
||||
if (flags.stdout) {
|
||||
console.log(serialized);
|
||||
console.log(JSON.stringify(binding, null, 2));
|
||||
}
|
||||
return ExitCode.Success;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue