Skip to content

Commit

Permalink
Merge pull request #2041 from IDEMSInternational/fix/sync-local-workflow
Browse files Browse the repository at this point in the history
fix: sync_local workflow
  • Loading branch information
chrismclarke authored Aug 23, 2023
2 parents 1238dee + 8b7898e commit 76ed06a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
21 changes: 15 additions & 6 deletions packages/scripts/src/commands/workflow/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
8 changes: 4 additions & 4 deletions packages/scripts/src/tasks/providers/appData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
};

/**
Expand Down
10 changes: 7 additions & 3 deletions packages/scripts/src/tasks/providers/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
6 changes: 2 additions & 4 deletions packages/workflows/src/sync.workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ const workflows: IDeploymentWorkflows = {
steps: [
{
name: "sync_local",
function: async (context) => {
processLocalFiles(context);
},
function: async (context) => processLocalFiles(context),
},
{
name: "watch_changes",
Expand All @@ -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 });
},
}),
},
Expand Down
2 changes: 1 addition & 1 deletion packages/workflows/src/workflow.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 76ed06a

Please sign in to comment.