Skip to content

Commit b15355c

Browse files
committed
metadata recipe: improved to actually use passed parameters
see #78207
1 parent fef3e67 commit b15355c

4 files changed

Lines changed: 71 additions & 3 deletions

File tree

fas_config/cookbook_metadata_example.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ recipes:
3535
commands:
3636
- prog: node
3737
args:
38-
- "-e"
39-
# read request_only_metadata.json (arg 1) and write to example_metadata.json (arg 2)
40-
- "console.error('Current working directory:', process.cwd()); const fs = require('fs'); fs.writeFileSync(process.argv[2], fs.readFileSync(process.argv[1], 'utf8').replaceAll('_custom_de_', '%custom_de%').replaceAll('_custom_en_', '%custom_en%').replaceAll('_extra_', '%extra%'));"
38+
- type: "value"
39+
value: "%_exec.pluginDir%/fas_config/custom_metadata.js"
40+
- type: "value"
41+
value: "%info.json%"
4142
- "%_exec.pluginDir%/fas_config/request_only_metadata.json"
4243
- type: file_out
4344
file:

fas_config/custom_metadata.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
// Get command line arguments
5+
const infoJson = process.argv[2]; // path to info.json
6+
const inputJsonPath = process.argv[3]; // path to request_only_metadata.json
7+
const outputJsonPath = process.argv[4]; // path to example_metadata.json (or whatever output you want)
8+
9+
console.error('Current working directory:', process.cwd());
10+
console.error('Input template:', inputJsonPath);
11+
console.error('Output file:', outputJsonPath);
12+
13+
try {
14+
// 1. Read and parse info.json
15+
const info = JSON.parse(infoJson);
16+
17+
// const tempFileName = `/tmp/info_parsed.json`;
18+
// fs.writeFileSync(tempFileName, JSON.stringify(info, null, 2), 'utf8');
19+
// console.error(`📄 Formatted info.json written to: ${tempFileName}`);
20+
21+
// 2. Get the recipe_configs object and extract the custom values
22+
const recipeParams = info.recipe_params || {};
23+
24+
const customDE = recipeParams['custom_de'] ?? '<missing custom_de>'; // fallback if not found
25+
const customEN = recipeParams['custom_en'] ?? '<missing custom_en>';
26+
const extra = recipeParams['extra'] ?? '<missing extra>';
27+
28+
// 3. Read the template JSON (request_only_metadata.json)
29+
let template = fs.readFileSync(inputJsonPath, 'utf8');
30+
31+
// 4. Perform the replacements
32+
template = template
33+
.replaceAll('_custom_de_', customDE)
34+
.replaceAll('_custom_en_', customEN)
35+
.replaceAll('_extra_', extra);
36+
37+
// 5. Write the result to the output file
38+
fs.writeFileSync(outputJsonPath, template, 'utf8');
39+
40+
console.error('✅ Successfully wrote custom metadata to:', outputJsonPath);
41+
42+
} catch (err) {
43+
console.error('❌ Error in custom_metadata.js:', err.message);
44+
process.exit(1);
45+
}

fas_config/recipe_dynamic_request_only.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@
5555
},
5656
"json_import": "plugin-example.chat-gpt.fields.keywords",
5757
"json_import_type": "text_l10n"
58+
},
59+
{
60+
"name": "yes_no",
61+
"displayname": {
62+
"de-DE": "Ja / Nein",
63+
"en-US": "Yes / No"
64+
},
65+
"json_import": "plugin-example.chat-gpt.fields.yes_no",
66+
"json_import_type": "boolean"
67+
},
68+
{
69+
"name": "datetime",
70+
"displayname": {
71+
"de-DE": "Datetime",
72+
"en-US": "Datetime"
73+
},
74+
"json_import": "plugin-example.chat-gpt.fields.datetime",
75+
"json_import_type": "datetime"
5876
}
5977
]
6078
}

fas_config/request_only_metadata.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
"de-DE": "_custom_de_: Das Bild zeigt ein Gemälde eines weißen Trabant-Autos, das durch eine Wand bricht. Die Illusion von zerbrochenem Putz und Ziegeln verstärkt den Eindruck einer Durchbrechung. Auf dem Nummernschild steht 'NOV 9-89', ein Hinweis auf den Tag des Mauerfalls in Berlin. Das Kunstwerk ist von Birgit Kinder signiert.",
88
"en-US": "_custom_en_: The image (_extra_) shows a painting of a white Trabant car breaking through a wall. The illusion of broken plaster and bricks enhances the impression of the car crashing through. The license plate reads 'NOV 9-89', referencing the date of the Berlin Wall's fall. The artwork is signed by Birgit Kinder."
99
},
10+
"yes_no": true,
11+
"datetime": {
12+
"value": "1972-06-27 05:10"
13+
},
1014
"keywords": [
1115
{
1216
"de-DE": "Trabant",

0 commit comments

Comments
 (0)