putout
Version:
🐊 Pluggable and configurable code transformer with built-in ESLint, Babel and support of js, jsx, typescript, flow, markdown, yaml and json
84 lines (74 loc) • 1.82 kB
JavaScript
import {initProcessFile as _initProcessFile} from '@putout/cli-process-file';
import {runWriter} from './writer.js';
export const run = async (overrides) => {
const {
transform,
plugins,
noConfig,
readFile,
writeFile,
exit,
isStop,
wasStop,
names,
write,
log,
rulesdir,
fix,
processorRunners,
fileCache,
currentFormat,
formatterOptions,
options,
raw,
trace,
initProcessFile = _initProcessFile,
report,
getOptions,
runProcessors,
} = overrides;
const processFile = initProcessFile(options);
const {length} = names;
const places = [];
for (let index = 0; index < length; index++) {
if (wasStop())
break;
wasStop(isStop());
const currentIndex = isStop() ? length - 1 : index;
const name = names[index];
const {exited, places: currentPlaces = []} = await runWriter({
readFile,
writeFile,
exit,
fix,
processorRunners,
rulesdir,
currentFormat,
formatterOptions,
index: currentIndex,
name,
count: length,
processFile,
fileCache,
raw,
write,
log,
report,
noConfig,
plugins,
transform,
trace,
getOptions,
runProcessors,
});
places.push(...currentPlaces);
if (exited)
return {
exited,
places,
};
}
return {
places,
};
};