mirror of https://github.com/ghostfolio/ghostfolio
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
45 lines
1.1 KiB
import {parseConfig} from './helpers/config.js'
|
|
import {logDryRun} from './helpers/handlers.js'
|
|
import {pathsSync, pathsAsync} from './helpers/paths.js'
|
|
import {processSync, processAsync} from './helpers/process.js'
|
|
|
|
/**
|
|
* Process a file (async)
|
|
*/
|
|
export async function processFile(config) {
|
|
|
|
//Parse config
|
|
config = parseConfig(config)
|
|
const {files, processor, processorAsync, dry, verbose} = config
|
|
|
|
//Dry run?
|
|
logDryRun(dry && verbose)
|
|
|
|
//Find paths and process them
|
|
const paths = await pathsAsync(files, config)
|
|
const promises = paths.map(path => processAsync(path, processor ?? processorAsync, config))
|
|
const results = await Promise.all(promises)
|
|
|
|
//Return results
|
|
return results
|
|
}
|
|
|
|
/**
|
|
* Process a file (sync)
|
|
*/
|
|
export function processFileSync(config) {
|
|
|
|
//Parse config
|
|
config = parseConfig(config)
|
|
const {files, processor, dry, verbose} = config
|
|
|
|
//Dry run?
|
|
logDryRun(dry && verbose)
|
|
|
|
//Find paths and process them
|
|
const paths = pathsSync(files, config)
|
|
const results = paths.map(path => processSync(path, processor, config))
|
|
|
|
//Return results
|
|
return results
|
|
}
|
|
|