-
Notifications
You must be signed in to change notification settings - Fork 0
/
applySnapshot.js
64 lines (53 loc) · 1.38 KB
/
applySnapshot.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const fs = require("fs");
const { spawn } = require("child_process");
const file = process.argv[2];
const myjson = require(`${file}`);
const newjson = {
version: myjson.version,
directus: myjson.directus,
collections: [],
fields: [],
relations: myjson.relations,
};
const tmp = myjson;
tmp.collections.forEach((e) => {
e.meta.group = null;
newjson.collections.push(e);
});
tmp.fields.forEach((e) => {
e.meta.group = null;
newjson.fields.push(e);
});
const applySnapshot = () => {
const noGroups = spawn("npx", [
"directus",
"schema",
"apply",
"-y",
"./snapshotWithoutGroups.json",
]);
noGroups.stdout.on("data", (data) => {
console.log(`${data}`);
});
noGroups.stderr.on("data", (data) => {
console.error(`${data}`);
});
noGroups.on("exit", function (code, signal) {
if(code != 0){return}
const withGroups = spawn("npx", ["directus", "schema", "apply",'-y', file]);
withGroups.stdout.on("data", (data) => {
console.log(`${data}`);
});
withGroups.stderr.on("data", (data) => {
console.error(`${data}`);
});
withGroups.on("exit", function (code, signal) {
console.log("exit " + code);
fs.unlink("./snapshotWithoutGroups.json", (err) => {
if(err){console.error(err)}
});
});
});
};
fs.writeFileSync("./snapshotWithoutGroups.json", JSON.stringify(newjson));
applySnapshot()