-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fields.mjs
43 lines (33 loc) · 1020 Bytes
/
build.fields.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import fs from 'fs';
import config from './public/config.json' assert { type: 'json' };
const CONTEXT_SEPARATOR = '->';
const getLabel = (field) => {
const label = [];
if (field.context) {
label.push(field.context);
label.push(CONTEXT_SEPARATOR);
}
label.push(field.label);
return label.join(' ');
};
/**
* Pull in fields/labels from "/projects/:project_id/descriptors".
*
* @returns {Promise<void>}
*/
const init = async () => {
const fields = {};
for (const projectId of config.core_data.project_ids) {
const url = `${config.core_data.url}/core_data/public/v1/projects/${projectId}/descriptors`;
const payload = await fetch(url).then((response) => response.json());
payload?.descriptors?.forEach((field) => {
fields[field.identifier] = {
tinaLabel: getLabel(field),
defaultValue: field.label
};
});
}
const content = JSON.stringify(fields, null, 2);
fs.writeFileSync('./src/i18n/userDefinedFields.json', content, 'utf8');
};
init();