|
|
@@ -120,12 +120,14 @@ async function runTask({ meta, config, jobId }) {
|
|
|
return taskResult
|
|
|
}
|
|
|
|
|
|
-async function expandFileTask(patternsToInclude, config, meta) {
|
|
|
- const filesToProcess = await readFilesByGlob(patternsToInclude)
|
|
|
+function selectFiles(patternsToInclude, config) {
|
|
|
const pathsToStrip = (config.stripPaths || []).map(path => expandTilde(path))
|
|
|
const outputDir = config.outputDir || ""
|
|
|
- return await Promise.all(
|
|
|
- filesToProcess.map(async filePath => {
|
|
|
+
|
|
|
+ return async meta => {
|
|
|
+ const filesToProcess = await readFilesByGlob(patternsToInclude)
|
|
|
+
|
|
|
+ return filesToProcess.map(filePath => {
|
|
|
const fileOutputPath = path.join(
|
|
|
meta.opts.outDir,
|
|
|
outputDir,
|
|
|
@@ -135,38 +137,80 @@ async function expandFileTask(patternsToInclude, config, meta) {
|
|
|
),
|
|
|
)
|
|
|
|
|
|
- const fileOutputDir = path.dirname(fileOutputPath)
|
|
|
- const jobConfig = {
|
|
|
- ...config,
|
|
|
+ return {
|
|
|
filePath,
|
|
|
- fileOutputDir,
|
|
|
fileOutputPath,
|
|
|
+ fileOutputDir: path.dirname(fileOutputPath),
|
|
|
}
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+async function expandFileTask(patternsToInclude, config, meta) {
|
|
|
+ const filesToProcess = await selectFiles(patternsToInclude, config)(meta)
|
|
|
+
|
|
|
+ return await Promise.all(
|
|
|
+ filesToProcess.map(async fileJob => {
|
|
|
+ const jobConfig = {
|
|
|
+ ...config,
|
|
|
+ ...fileJob,
|
|
|
+ }
|
|
|
+
|
|
|
return runTask({
|
|
|
meta,
|
|
|
config: jobConfig,
|
|
|
- jobId: `${config.name} @ ${filePath}`,
|
|
|
+ jobId: `${config.name} @ ${fileJob.filePath}`,
|
|
|
})
|
|
|
}),
|
|
|
)
|
|
|
}
|
|
|
|
|
|
-async function expandStateTask(stateToExpand, config, meta) {
|
|
|
- const stateToProcess = stateToExpand
|
|
|
+function selectState(stateToSelect, meta) {
|
|
|
+ return stateToSelect
|
|
|
.map(property => {
|
|
|
const values = getValueAtPath(meta, property)
|
|
|
const expandedValues = Array.isArray(values)
|
|
|
? values
|
|
|
: Object.values(values)
|
|
|
- return expandedValues.map((value, index) => ({ property, index, value }))
|
|
|
+ const keys = Object.keys(values)
|
|
|
+ return expandedValues.map((value, index) => ({
|
|
|
+ property,
|
|
|
+ index,
|
|
|
+ value,
|
|
|
+ key: keys[index],
|
|
|
+ }))
|
|
|
})
|
|
|
.flat()
|
|
|
+}
|
|
|
|
|
|
+async function expandStateTask(stateToExpand, config, meta) {
|
|
|
+ const stateToProcess = selectState(stateToExpand, meta)
|
|
|
+ const pathsToStrip = (config.stripPaths || []).map(path => expandTilde(path))
|
|
|
+ const outputDir = config.outputDir || ""
|
|
|
return await Promise.all(
|
|
|
- stateToProcess.map(async stateJob => {
|
|
|
+ stateToProcess.map(async (stateJob, index) => {
|
|
|
+ const decorations = {
|
|
|
+ ...(Array.isArray(stateJob.value)
|
|
|
+ ? { inputs: stateJob.value }
|
|
|
+ : stateJob.value.detail),
|
|
|
+
|
|
|
+ ...(config.buildFilePath
|
|
|
+ ? {
|
|
|
+ fileOutputPath: path.join(
|
|
|
+ meta.opts.outDir,
|
|
|
+ outputDir,
|
|
|
+ replaceFileExtension(
|
|
|
+ removeBasePaths(pathsToStrip, stateJob.key || String(index)),
|
|
|
+ config.outputFileExtension,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ }
|
|
|
+ : {}),
|
|
|
+ }
|
|
|
const jobConfig = {
|
|
|
...config,
|
|
|
- ...stateJob.value.detail,
|
|
|
+ ...decorations,
|
|
|
+ stateKey: stateJob.key,
|
|
|
}
|
|
|
return runTask({
|
|
|
meta,
|
|
|
@@ -182,10 +226,34 @@ export async function expandAndRunTask(meta, config) {
|
|
|
const patternsToInclude = [...(config?.inputFiles || []), ...includes]
|
|
|
|
|
|
if (patternsToInclude.length) {
|
|
|
+ if (config.expand === false) {
|
|
|
+ const inputs = selectFiles(patternsToInclude, config)
|
|
|
+ const jobId = config.jobId || config.name
|
|
|
+ const taskResult = await runTask({
|
|
|
+ meta,
|
|
|
+ config: { ...config, inputs },
|
|
|
+ jobId,
|
|
|
+ })
|
|
|
+ return [taskResult]
|
|
|
+ }
|
|
|
+
|
|
|
return expandFileTask(patternsToInclude, config, meta)
|
|
|
}
|
|
|
|
|
|
if (config.stateSelectors) {
|
|
|
+ if (config.expand === false) {
|
|
|
+ const inputs = selectState(config.stateSelectors, meta).map(
|
|
|
+ stateItem => stateItem.value.detail,
|
|
|
+ )
|
|
|
+ const jobId = config.jobId || config.name
|
|
|
+ const taskResult = await runTask({
|
|
|
+ meta,
|
|
|
+ config: { ...config, inputs },
|
|
|
+ jobId,
|
|
|
+ })
|
|
|
+ return [taskResult]
|
|
|
+ }
|
|
|
+
|
|
|
return expandStateTask(config.stateSelectors, config, meta)
|
|
|
}
|
|
|
|