diff --git a/packages/scripts/src/commands/workflow/run.ts b/packages/scripts/src/commands/workflow/run.ts index 85233f480d..afb972e2f3 100644 --- a/packages/scripts/src/commands/workflow/run.ts +++ b/packages/scripts/src/commands/workflow/run.ts @@ -84,7 +84,7 @@ export class WorkflowRunnerClass { if (workflow.options) { this.activeWorkflowOptions = { ...this.activeWorkflowOptions, - ...this.parseWorkflowOptions(workflow.options), + ...this.parseWorkflowOptions(workflow.options, args), }; } return this.executeWorkflow(workflow, workflowArgs); @@ -119,21 +119,30 @@ export class WorkflowRunnerClass { /** * Generate a child commander instance that can dynamically parse options as defined * within a workflow + * @param options list of arg options to use in the workflow, e.g. {flag: 's, --skip-download'} + * @param args string array to be evaluated from options, e.g. ['--skip-download'] => {skipDownload: true} */ - private parseWorkflowOptions(options: IWorkflow["options"] = []) { + private parseWorkflowOptions(options: IWorkflow["options"] = [], args: string[]) { let parsedOptions: { [name: string]: string | boolean } = {}; const subProgram = new Command().allowUnknownOption(); + // create a dynamic list of cli options using those listed in the workflow for (const option of options) { const { flags, description, defaultValue } = option; subProgram.option(flags, description, defaultValue); } - subProgram.action((o) => { - parsedOptions = o; + // add a default workflow action, so that when triggered the included parsed command + // options are stored as a variable for return + subProgram.action((cmdOptions) => { + parsedOptions = cmdOptions; }); - if (process.argv.find((arg) => ["--help", "h"].includes(arg))) { + if (args.find((arg) => ["--help", "h"].includes(arg))) { logProgramHelp(subProgram); } - subProgram.parse(process.argv); + // run the command with args parsed. Include 2 additional placeholder args + // as these will be sliced out during processing. This will trigger the action above + // and use commander's parsing methods to process the args list + const [sysArg1, sysArg2] = process.argv; + subProgram.parse([sysArg1, sysArg2, ...args]); return parsedOptions; } diff --git a/packages/scripts/src/tasks/providers/appData.ts b/packages/scripts/src/tasks/providers/appData.ts index 2bc17704b5..7d8668203a 100644 --- a/packages/scripts/src/tasks/providers/appData.ts +++ b/packages/scripts/src/tasks/providers/appData.ts @@ -6,23 +6,23 @@ import { SRC_ASSETS_PATH } from "../../paths"; import { IContentsEntry, replicateDir } from "../../utils"; /** Prepare sourcely cached assets for population to app */ -const postProcessAssets = (options: { sourceAssetsFolder: string }) => { +const postProcessAssets = async (options: { sourceAssetsFolder: string }) => { const { sourceAssetsFolder } = options; let args = `--source-assets-folder ${sourceAssetsFolder}`; let cmd = `app-data post-process assets ${args}`; - parseCommand(`${cmd}`); + await parseCommand(`${cmd}`); }; /** Prepare sourcely cached seets for population to app */ -const postProcessSheets = (options: { +const postProcessSheets = async (options: { sourceSheetsFolder: string; sourceTranslationsFolder: string; }) => { const { sourceSheetsFolder, sourceTranslationsFolder } = options; let args = `--source-sheets-folder ${sourceSheetsFolder} --source-translations-folder ${sourceTranslationsFolder}`; let cmd = `app-data post-process sheets ${args}`; - parseCommand(`${cmd}`); + await parseCommand(`${cmd}`); }; /** diff --git a/packages/scripts/src/tasks/providers/workflow.ts b/packages/scripts/src/tasks/providers/workflow.ts index b889ba2549..91e142e89f 100644 --- a/packages/scripts/src/tasks/providers/workflow.ts +++ b/packages/scripts/src/tasks/providers/workflow.ts @@ -10,12 +10,16 @@ const runWorkflow = async (options: { parent: IWorkflowContext; args?: string[]; }) => { - const { name, args, parent } = options; - let cmd = `workflow run ${name} --parent ${parent.name}`; + const { name, parent, args } = options; + const parentName = parent ? Object.values(parent)[0].name : null; + let cmd = `workflow run ${name}`; + if (parentName) { + cmd += ` --parent ${parentName}`; + } if (args) { cmd += ` ${args.join(" ")}`; } - parseCommand(cmd); + await parseCommand(cmd); }; export default { runWorkflow }; diff --git a/packages/workflows/src/sync.workflows.ts b/packages/workflows/src/sync.workflows.ts index 58b3bb811d..c0f4ea82ef 100644 --- a/packages/workflows/src/sync.workflows.ts +++ b/packages/workflows/src/sync.workflows.ts @@ -117,9 +117,7 @@ const workflows: IDeploymentWorkflows = { steps: [ { name: "sync_local", - function: async (context) => { - processLocalFiles(context); - }, + function: async (context) => processLocalFiles(context), }, { name: "watch_changes", @@ -130,7 +128,7 @@ const workflows: IDeploymentWorkflows = { const { assets_path, sheets_path } = context.config.local_drive; const only_sheets = normalize(filepath).startsWith(normalize(sheets_path)); const only_assets = normalize(filepath).startsWith(normalize(assets_path)); - processLocalFiles(context, { only_assets, only_sheets }); + await processLocalFiles(context, { only_assets, only_sheets }); }, }), }, diff --git a/packages/workflows/src/workflow.model.ts b/packages/workflows/src/workflow.model.ts index 23ae0a45d3..f298a5aa4c 100644 --- a/packages/workflows/src/workflow.model.ts +++ b/packages/workflows/src/workflow.model.ts @@ -7,7 +7,7 @@ import type { IDeploymentConfigJson } from "data-models"; import type { ITasks } from "../../scripts/src/tasks"; export interface IWorkflowContext { - [step_name: string]: { output: any }; + [step_name: string]: IWorkflowStep & { output: any }; } interface IWorkflowStep {