|
@@ -13,6 +13,21 @@ import path from "path"
|
|
|
import process from "node:process"
|
|
import process from "node:process"
|
|
|
import { getLogger } from "./logging.js"
|
|
import { getLogger } from "./logging.js"
|
|
|
|
|
|
|
|
|
|
+function buildOutputPath(outDir, outputDir, pathsToStrip, inputPath, outputFileExtension) {
|
|
|
|
|
+ return path.join(
|
|
|
|
|
+ outDir,
|
|
|
|
|
+ outputDir || "",
|
|
|
|
|
+ replaceFileExtension(
|
|
|
|
|
+ removeBasePaths(pathsToStrip, inputPath),
|
|
|
|
|
+ outputFileExtension,
|
|
|
|
|
+ ),
|
|
|
|
|
+ )
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function getPathsToStrip(config) {
|
|
|
|
|
+ return (config.stripPaths || []).map(p => expandTilde(p))
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
export async function getConfig() {
|
|
export async function getConfig() {
|
|
|
const args = process.argv.slice(2)
|
|
const args = process.argv.slice(2)
|
|
|
const defaultPath = path.join(process.cwd(), "rhedyn.config.js")
|
|
const defaultPath = path.join(process.cwd(), "rhedyn.config.js")
|
|
@@ -38,8 +53,7 @@ export async function getConfig() {
|
|
|
const config = await import(configPath)
|
|
const config = await import(configPath)
|
|
|
return config.default || config
|
|
return config.default || config
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
|
- console.error(`Error reading config file at ${configPath}:`, err)
|
|
|
|
|
- throw new Error("Failed reading config file")
|
|
|
|
|
|
|
+ throw new Error(`Failed reading config file at ${configPath}: ${err.message}`, { cause: err })
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
return
|
|
return
|
|
@@ -121,20 +135,18 @@ async function runTask({ meta, config, jobId }) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function selectFiles(patternsToInclude, config) {
|
|
function selectFiles(patternsToInclude, config) {
|
|
|
- const pathsToStrip = (config.stripPaths || []).map(path => expandTilde(path))
|
|
|
|
|
- const outputDir = config.outputDir || ""
|
|
|
|
|
|
|
+ const pathsToStrip = getPathsToStrip(config)
|
|
|
|
|
|
|
|
return async meta => {
|
|
return async meta => {
|
|
|
const filesToProcess = await readFilesByGlob(patternsToInclude)
|
|
const filesToProcess = await readFilesByGlob(patternsToInclude)
|
|
|
|
|
|
|
|
return filesToProcess.map(filePath => {
|
|
return filesToProcess.map(filePath => {
|
|
|
- const fileOutputPath = path.join(
|
|
|
|
|
|
|
+ const fileOutputPath = buildOutputPath(
|
|
|
meta.opts.outDir,
|
|
meta.opts.outDir,
|
|
|
- outputDir,
|
|
|
|
|
- replaceFileExtension(
|
|
|
|
|
- removeBasePaths(pathsToStrip, filePath),
|
|
|
|
|
- config.outputFileExtension,
|
|
|
|
|
- ),
|
|
|
|
|
|
|
+ config.outputDir,
|
|
|
|
|
+ pathsToStrip,
|
|
|
|
|
+ filePath,
|
|
|
|
|
+ config.outputFileExtension,
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
@@ -169,6 +181,9 @@ function selectState(stateToSelect, meta) {
|
|
|
return stateToSelect
|
|
return stateToSelect
|
|
|
.map(property => {
|
|
.map(property => {
|
|
|
const values = getValueAtPath(meta, property)
|
|
const values = getValueAtPath(meta, property)
|
|
|
|
|
+ if (values == null) {
|
|
|
|
|
+ return []
|
|
|
|
|
+ }
|
|
|
const expandedValues = Array.isArray(values)
|
|
const expandedValues = Array.isArray(values)
|
|
|
? values
|
|
? values
|
|
|
: Object.values(values)
|
|
: Object.values(values)
|
|
@@ -185,24 +200,22 @@ function selectState(stateToSelect, meta) {
|
|
|
|
|
|
|
|
async function expandStateTask(stateToExpand, config, meta) {
|
|
async function expandStateTask(stateToExpand, config, meta) {
|
|
|
const stateToProcess = selectState(stateToExpand, meta)
|
|
const stateToProcess = selectState(stateToExpand, meta)
|
|
|
- const pathsToStrip = (config.stripPaths || []).map(path => expandTilde(path))
|
|
|
|
|
- const outputDir = config.outputDir || ""
|
|
|
|
|
|
|
+ const pathsToStrip = getPathsToStrip(config)
|
|
|
return await Promise.all(
|
|
return await Promise.all(
|
|
|
stateToProcess.map(async (stateJob, index) => {
|
|
stateToProcess.map(async (stateJob, index) => {
|
|
|
const decorations = {
|
|
const decorations = {
|
|
|
...(Array.isArray(stateJob.value)
|
|
...(Array.isArray(stateJob.value)
|
|
|
? { inputs: stateJob.value }
|
|
? { inputs: stateJob.value }
|
|
|
- : stateJob.value.detail),
|
|
|
|
|
|
|
+ : stateJob.value?.detail || {}),
|
|
|
|
|
|
|
|
...(config.buildFilePath
|
|
...(config.buildFilePath
|
|
|
? {
|
|
? {
|
|
|
- fileOutputPath: path.join(
|
|
|
|
|
|
|
+ fileOutputPath: buildOutputPath(
|
|
|
meta.opts.outDir,
|
|
meta.opts.outDir,
|
|
|
- outputDir,
|
|
|
|
|
- replaceFileExtension(
|
|
|
|
|
- removeBasePaths(pathsToStrip, stateJob.key || String(index)),
|
|
|
|
|
- config.outputFileExtension,
|
|
|
|
|
- ),
|
|
|
|
|
|
|
+ config.outputDir,
|
|
|
|
|
+ pathsToStrip,
|
|
|
|
|
+ stateJob.key || String(index),
|
|
|
|
|
+ config.outputFileExtension,
|
|
|
),
|
|
),
|
|
|
}
|
|
}
|
|
|
: {}),
|
|
: {}),
|
|
@@ -242,27 +255,19 @@ export async function expandAndRunTask(meta, config) {
|
|
|
|
|
|
|
|
if (config.stateSelectors) {
|
|
if (config.stateSelectors) {
|
|
|
if (config.expand === false) {
|
|
if (config.expand === false) {
|
|
|
- const pathsToStrip = (config.stripPaths || []).map(path =>
|
|
|
|
|
- expandTilde(path),
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ const pathsToStrip = getPathsToStrip(config)
|
|
|
const inputs = selectState(config.stateSelectors, meta).map(stateItem => {
|
|
const inputs = selectState(config.stateSelectors, meta).map(stateItem => {
|
|
|
- return stateItem.value.detail
|
|
|
|
|
- ? stateItem.value.detail
|
|
|
|
|
- : stateItem.value
|
|
|
|
|
|
|
+ return stateItem.value?.detail ?? stateItem.value
|
|
|
})
|
|
})
|
|
|
const decorations = {
|
|
const decorations = {
|
|
|
...(config.buildFilePath
|
|
...(config.buildFilePath
|
|
|
? {
|
|
? {
|
|
|
- fileOutputPath: path.join(
|
|
|
|
|
|
|
+ fileOutputPath: buildOutputPath(
|
|
|
meta.opts.outDir,
|
|
meta.opts.outDir,
|
|
|
config.outputDir,
|
|
config.outputDir,
|
|
|
- replaceFileExtension(
|
|
|
|
|
- removeBasePaths(
|
|
|
|
|
- pathsToStrip,
|
|
|
|
|
- config.outputFileName || config.name,
|
|
|
|
|
- ),
|
|
|
|
|
- config.outputFileExtension,
|
|
|
|
|
- ),
|
|
|
|
|
|
|
+ pathsToStrip,
|
|
|
|
|
+ config.outputFileName || config.name,
|
|
|
|
|
+ config.outputFileExtension,
|
|
|
),
|
|
),
|
|
|
}
|
|
}
|
|
|
: {}),
|
|
: {}),
|