|
|
@@ -101,6 +101,23 @@ function getIndexPropertyLabel(propertyPath) {
|
|
|
return label.replace(/\b\w/g, char => char.toUpperCase())
|
|
|
}
|
|
|
|
|
|
+export function getTaskKey(task) {
|
|
|
+ return task?.key || task?.name
|
|
|
+}
|
|
|
+
|
|
|
+export function getTaskName(task) {
|
|
|
+ return task?.name || task?.key || "unnamed task"
|
|
|
+}
|
|
|
+
|
|
|
+function getTaskIdentity(task) {
|
|
|
+ const key = getTaskKey(task)
|
|
|
+ const name = getTaskName(task)
|
|
|
+ if (!key) {
|
|
|
+ throw new Error("Task must define `key` (or legacy `name`).")
|
|
|
+ }
|
|
|
+ return { key, name }
|
|
|
+}
|
|
|
+
|
|
|
export async function getConfig() {
|
|
|
const args = process.argv.slice(2)
|
|
|
const defaultPath = path.join(process.cwd(), "rhedyn.config.js")
|
|
|
@@ -235,6 +252,7 @@ function selectFiles(patternsToInclude, jobConfig) {
|
|
|
|
|
|
async function expandFileTask(patternsToInclude, task, jobConfig, actionConfig, meta) {
|
|
|
const filesToProcess = await selectFiles(patternsToInclude, jobConfig)(meta)
|
|
|
+ const { key: taskKey } = getTaskIdentity(task)
|
|
|
|
|
|
return await Promise.all(
|
|
|
filesToProcess.map(async fileJob => {
|
|
|
@@ -249,7 +267,7 @@ async function expandFileTask(patternsToInclude, task, jobConfig, actionConfig,
|
|
|
action: task.action,
|
|
|
jobConfig,
|
|
|
actionConfig: jobActionConfig,
|
|
|
- jobId: `${task.name} @ ${fileJob.filePath}`,
|
|
|
+ jobId: `${taskKey} @ ${fileJob.filePath}`,
|
|
|
})
|
|
|
}),
|
|
|
)
|
|
|
@@ -278,6 +296,7 @@ function selectState(stateToSelect, meta) {
|
|
|
|
|
|
async function expandStateTask(stateToExpand, task, jobConfig, actionConfig, meta) {
|
|
|
const stateToProcess = selectState(stateToExpand, meta)
|
|
|
+ const { key: taskKey } = getTaskIdentity(task)
|
|
|
const pathsToStrip = getPathsToStrip(jobConfig)
|
|
|
const itemsPerPage = jobConfig.itemsPerPage ?? meta.opts.itemsPerPage
|
|
|
const shouldSetIndexTitle = jobConfig.buildFilePath && actionConfig.writeOut
|
|
|
@@ -359,25 +378,25 @@ async function expandStateTask(stateToExpand, task, jobConfig, actionConfig, met
|
|
|
})
|
|
|
|
|
|
const jobPromises = jobs.map(async ({ stateJob, page, decorations }) => {
|
|
|
- const fileOutputDir = decorations.fileOutputPath
|
|
|
- ? path.dirname(decorations.fileOutputPath)
|
|
|
- : undefined
|
|
|
- const jobActionConfig = {
|
|
|
- ...actionConfig,
|
|
|
- ...decorations,
|
|
|
- stateKey: stateJob.key,
|
|
|
- ...(fileOutputDir ? { fileOutputDir } : {}),
|
|
|
- outputFileExtension: jobConfig.outputFileExtension,
|
|
|
- }
|
|
|
- const pageInfo = page > 1 ? `:page-${page}` : ""
|
|
|
- return runTask({
|
|
|
- meta,
|
|
|
- action: task.action,
|
|
|
- jobConfig,
|
|
|
- actionConfig: jobActionConfig,
|
|
|
- jobId: `${task.name} @ ${stateJob.property}:${stateJob.index}${pageInfo}`,
|
|
|
- })
|
|
|
+ const fileOutputDir = decorations.fileOutputPath
|
|
|
+ ? path.dirname(decorations.fileOutputPath)
|
|
|
+ : undefined
|
|
|
+ const jobActionConfig = {
|
|
|
+ ...actionConfig,
|
|
|
+ ...decorations,
|
|
|
+ stateKey: stateJob.key,
|
|
|
+ ...(fileOutputDir ? { fileOutputDir } : {}),
|
|
|
+ outputFileExtension: jobConfig.outputFileExtension,
|
|
|
+ }
|
|
|
+ const pageInfo = page > 1 ? `:page-${page}` : ""
|
|
|
+ return runTask({
|
|
|
+ meta,
|
|
|
+ action: task.action,
|
|
|
+ jobConfig,
|
|
|
+ actionConfig: jobActionConfig,
|
|
|
+ jobId: `${taskKey} @ ${stateJob.property}:${stateJob.index}${pageInfo}`,
|
|
|
})
|
|
|
+ })
|
|
|
|
|
|
if (shouldBuildIndexList) {
|
|
|
const indexPropertyLabel = getIndexPropertyLabel(stateToProcess[0]?.property)
|
|
|
@@ -431,7 +450,7 @@ async function expandStateTask(stateToExpand, task, jobConfig, actionConfig, met
|
|
|
action: task.action,
|
|
|
jobConfig,
|
|
|
actionConfig: indexJobActionConfig,
|
|
|
- jobId: `${task.name} @ index-list`,
|
|
|
+ jobId: `${taskKey} @ index-list`,
|
|
|
}),
|
|
|
)
|
|
|
}
|
|
|
@@ -440,18 +459,20 @@ async function expandStateTask(stateToExpand, task, jobConfig, actionConfig, met
|
|
|
}
|
|
|
|
|
|
export async function expandAndRunTask(meta, task) {
|
|
|
+ const { key: taskKey, name: taskName } = getTaskIdentity(task)
|
|
|
const jobConfig = task.jobConfig || {}
|
|
|
const actionConfig = {
|
|
|
...(task.actionConfig || {}),
|
|
|
- name: task.name,
|
|
|
+ name: taskName,
|
|
|
+ key: taskKey,
|
|
|
}
|
|
|
- const includes = meta.opts?.include?.[task.name] || []
|
|
|
+ const includes = meta.opts?.include?.[taskKey] || meta.opts?.include?.[taskName] || []
|
|
|
const patternsToInclude = [...(jobConfig?.inputFiles || []), ...includes]
|
|
|
|
|
|
if (patternsToInclude.length) {
|
|
|
if (jobConfig.expand === false) {
|
|
|
const inputs = selectFiles(patternsToInclude, jobConfig)
|
|
|
- const jobId = jobConfig.jobId || task.name
|
|
|
+ const jobId = jobConfig.jobId || taskKey
|
|
|
const jobActionConfig = {
|
|
|
...actionConfig,
|
|
|
inputs,
|
|
|
@@ -486,7 +507,7 @@ export async function expandAndRunTask(meta, task) {
|
|
|
meta.opts.outDir,
|
|
|
jobConfig.outputDir,
|
|
|
pathsToStrip,
|
|
|
- jobConfig.outputFileName || task.name,
|
|
|
+ jobConfig.outputFileName || taskKey,
|
|
|
jobConfig.outputFileExtension,
|
|
|
)
|
|
|
: null
|
|
|
@@ -508,7 +529,7 @@ export async function expandAndRunTask(meta, task) {
|
|
|
outputFileExtension: jobConfig.outputFileExtension,
|
|
|
...(actionConfig.isIndexList == null ? { isIndexList: true } : {}),
|
|
|
}
|
|
|
- const jobId = jobConfig.jobId || task.name
|
|
|
+ const jobId = jobConfig.jobId || taskKey
|
|
|
const taskResult = await runTask({
|
|
|
meta,
|
|
|
action: task.action,
|
|
|
@@ -537,7 +558,7 @@ export async function expandAndRunTask(meta, task) {
|
|
|
outputFileExtension: jobConfig.outputFileExtension,
|
|
|
...(actionConfig.isIndexList == null ? { isIndexList: true } : {}),
|
|
|
}
|
|
|
- const jobId = jobConfig.jobId || task.name
|
|
|
+ const jobId = jobConfig.jobId || taskKey
|
|
|
const taskResult = await runTask({
|
|
|
meta,
|
|
|
action: task.action,
|
|
|
@@ -551,7 +572,7 @@ export async function expandAndRunTask(meta, task) {
|
|
|
const basePathForPagination = basePath
|
|
|
? basePath.replace(meta.opts.outDir, "/")
|
|
|
: null
|
|
|
- const baseJobId = jobConfig.jobId || task.name
|
|
|
+ const baseJobId = jobConfig.jobId || taskKey
|
|
|
return await Promise.all(
|
|
|
pages.map(({ items: pageItems, page, totalPages }) => {
|
|
|
const fileOutputPath = basePath
|
|
|
@@ -599,7 +620,7 @@ export async function expandAndRunTask(meta, task) {
|
|
|
return expandStateTask(jobConfig.stateSelectors, task, jobConfig, actionConfig, meta)
|
|
|
}
|
|
|
|
|
|
- const jobId = jobConfig.jobId || task.name
|
|
|
+ const jobId = jobConfig.jobId || taskKey
|
|
|
const taskResult = await runTask({
|
|
|
meta,
|
|
|
action: task.action,
|
|
|
@@ -611,7 +632,8 @@ export async function expandAndRunTask(meta, task) {
|
|
|
}
|
|
|
|
|
|
export async function processTask(meta, task) {
|
|
|
- const log = getLogger(meta.opts.logLevel, task.name)
|
|
|
+ const { key: taskKey, name: taskName } = getTaskIdentity(task)
|
|
|
+ const log = getLogger(meta.opts.logLevel, taskName)
|
|
|
const startTime = performance.now()
|
|
|
const taskResult = await expandAndRunTask(meta, task)
|
|
|
const cached = taskResult.filter(taskResult => taskResult.fromCache)
|
|
|
@@ -648,7 +670,8 @@ export async function processTask(meta, task) {
|
|
|
} | ${hrTime}`,
|
|
|
)
|
|
|
return {
|
|
|
- name: task.name,
|
|
|
+ key: taskKey,
|
|
|
+ name: taskName,
|
|
|
taskResult,
|
|
|
cached,
|
|
|
processed,
|