Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion command-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"command": "orchestrator:rules:eval",
"flagAliases": [],
"flagChars": ["d", "o", "r", "v"],
"flags": ["api-version", "document", "flags-dir", "json", "rules", "target-org", "variables"],
"flags": ["api-version", "document", "flags-dir", "json", "rules", "target-org", "values"],
"plugin": "@salesforce/plugin-orchestrator"
},
{
Expand Down
12 changes: 6 additions & 6 deletions messages/orchestrator.rules.eval.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ Path to JSON document file to transform.

Path to the JSON document file (dashboard, lens, etc.) that will be transformed by the rules.

# flags.variables.summary
# flags.values.summary

Path to Analytics variables.json file.
Path to values JSON file.

# flags.variables.description
# flags.values.description

Path to the variables.json file containing variable definitions used in transformations. The file should contain a flat JSON object with key-value pairs. The CLI will automatically wrap these in the required Variables structure.
Path to the JSON file containing values used in transformations. Can contain any JSON structure that matches your transformation rules.

# flags.rules.summary

Expand All @@ -49,7 +49,7 @@ Path to the rules.json file containing transformation rules and macro definition
# examples

- Test JSON transformation with Analytics files:
<%= config.bin %> <%= command.id %> --document ./dashboard.json --variables ./variables.json --rules ./rules.json --target-org myorg
<%= config.bin %> <%= command.id %> --document ./dashboard.json --values ./values.json --rules ./rules.json --target-org myorg

- Test with specific API version:
<%= config.bin %> <%= command.id %> --document ./dashboard.json --variables ./variables.json --rules ./rules.json --target-org myorg --api-version 60.0
<%= config.bin %> <%= command.id %> --document ./dashboard.json --values ./values.json --rules ./rules.json --target-org myorg --api-version 60.0
30 changes: 12 additions & 18 deletions src/commands/orchestrator/rules/eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ type TransformationPayload = {
namespace: string;
};
};
values: {
Variables: {
hello: string;
};
};
values: Record<string, unknown>;
definition: {
rules: Array<{
name: string;
Expand Down Expand Up @@ -91,10 +87,10 @@ export default class TemplateEval extends SfCommand<TemplatePreviewResult> {
description: messages.getMessage('flags.document.description'),
required: true,
}),
variables: Flags.file({
values: Flags.file({
char: 'v',
summary: messages.getMessage('flags.variables.summary'),
description: messages.getMessage('flags.variables.description'),
summary: messages.getMessage('flags.values.summary'),
description: messages.getMessage('flags.values.description'),
required: true,
}),
rules: Flags.file({
Expand Down Expand Up @@ -159,16 +155,16 @@ export default class TemplateEval extends SfCommand<TemplatePreviewResult> {
}
}

private async getTemplatePayload(flags: { document: string; variables: string; rules: string }): Promise<{
private async getTemplatePayload(flags: { document: string; values: string; rules: string }): Promise<{
template: TemplateInfo;
payload: TransformationPayload;
}> {
return this.getDirectFilePayload(flags.document, flags.variables, flags.rules);
return this.getDirectFilePayload(flags.document, flags.values, flags.rules);
}

private async getDirectFilePayload(
documentFile: string,
variablesFile: string,
valuesFile: string,
rulesFile: string
): Promise<{
template: TemplateInfo;
Expand All @@ -180,12 +176,10 @@ export default class TemplateEval extends SfCommand<TemplatePreviewResult> {
const documentContent = await fs.readFile(documentFile, 'utf8');
const document = JSON.parse(documentContent) as unknown;

// Read variables file
this.log(`Loading variables: ${variablesFile}`);
const variablesContent = await fs.readFile(variablesFile, 'utf8');
const variablesData = JSON.parse(variablesContent) as Record<string, unknown>;

const values = { Variables: variablesData };
// Read values file
this.log(`Loading values: ${valuesFile}`);
const valuesContent = await fs.readFile(valuesFile, 'utf8');
const values = JSON.parse(valuesContent) as Record<string, unknown>;

// Read rules file
this.log(`Loading rules: ${rulesFile}`);
Expand All @@ -200,7 +194,7 @@ export default class TemplateEval extends SfCommand<TemplatePreviewResult> {
},
payload: {
document: document as TransformationPayload['document'],
values: values as TransformationPayload['values'],
values,
definition: definition as TransformationPayload['definition'],
},
};
Expand Down
Loading