-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
update-script.js
32 lines (28 loc) · 1.01 KB
/
update-script.js
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
import farmOS from '../src/index.js';
import localServerConfig from '../local-server-config.js';
import { writeSchema } from './fs-utils.js';
const $idURI = (entity, bundle) =>
// Eventually, this should point to a location on farmos.org or docs.farmos.org
`https://raw.githubusercontent.com/farmOS/farmOS.js/main/core_schemata/${entity}/${bundle}.json`;
const makeReplacer = (entity, bundle) => (key, value) => {
if (key === '$id' && value.includes('localhost')) {
return $idURI(entity, bundle);
}
return value;
};
const {
host, clientId, username, password,
} = localServerConfig;
const farm = farmOS({
remote: { options: { host, clientId } },
});
farm.remote.authorize(username, password)
.then(() => farm.schema.fetch())
.then((schemata) => {
Object.entries(schemata).forEach(([entity, bundles]) => {
Object.entries(bundles).forEach(([bundle, schema]) => {
const replacer = makeReplacer(entity, bundle);
writeSchema(entity, bundle, schema, replacer, 2);
});
});
});