-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_create-specs.js
121 lines (91 loc) · 3.08 KB
/
_create-specs.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
require('dotenv').config();
const { writeFileSync } = require('fs');
const { resolve } = require('path');
const { Bootstrapper } = require('@osspim/import-utilities');
if (
!process.env.OSSPIM_ACCESS_TOKEN_ID ||
!process.env.OSSPIM_ACCESS_TOKEN_SECRET
) {
throw new Error(
'OSSPIM_ACCESS_TOKEN_ID and OSSPIM_ACCESS_TOKEN_SECRET must be set'
);
}
function getFullSpec(instanceIdentifier) {
const bootstrapper = new Bootstrapper();
bootstrapper.setAccessToken(
process.env.OSSPIM_ACCESS_TOKEN_ID,
process.env.OSSPIM_ACCESS_TOKEN_SECRET
);
bootstrapper.setInstanceIdentifier(instanceIdentifier);
console.log('⏳ Getting the full spec for ' + instanceIdentifier);
return bootstrapper.createSpec();
}
function removeItemCatalogPath(item) {
delete item.catalogPath;
if (item.children) {
item.children.forEach(removeItemCatalogPath);
}
}
async function furniture() {
const spec = await getFullSpec('furniture');
const itemShop = spec.items.find((i) => i.catalogPath === '/shop');
const itemStories = spec.items.find((i) => i.catalogPath === '/stories');
const itemAbout = spec.items.find((i) => i.catalogPath === '/about');
const itemAssets = spec.items.find((i) => i.catalogPath === '/assets');
const itemFrontpage = spec.items.find(
(i) => i.catalogPath === '/frontpage-2021'
);
// Only include a few shop sub folders
itemShop.children = itemShop.children.filter((c) =>
['/shop/plants', '/shop/chairs'].includes(c.catalogPath)
);
spec.items = [itemShop, itemStories, itemAbout, itemFrontpage, itemAssets];
// Remove references as we do not want to update existing items
spec.items.forEach(removeItemCatalogPath);
writeFileSync(
resolve(__dirname, `./src/journeys/_shared/specs/furniture.json`),
JSON.stringify(spec, null, 1),
'utf-8'
);
console.log(`✔ furniture done`);
}
async function voyage() {
const spec = await getFullSpec('voyage');
// Remove references as we do not want to update existing items
spec.items.forEach(removeItemCatalogPath);
writeFileSync(
resolve(__dirname, `./src/journeys/_shared/specs/voyage.json`),
JSON.stringify(spec, null, 1),
'utf-8'
);
console.log(`✔ voyage done`);
}
async function photofinder() {
const spec = await getFullSpec('photofinder');
// Remove references as we do not want to update existing items
spec.items.forEach(removeItemCatalogPath);
writeFileSync(
resolve(__dirname, `./src/journeys/_shared/specs/photofinder.json`),
JSON.stringify(spec, null, 1),
'utf-8'
);
console.log(`✔ photofinder done`);
}
async function conference() {
const spec = await getFullSpec('conference-boilerplate');
// Remove references as we do not want to update existing items
spec.items.forEach(removeItemCatalogPath);
writeFileSync(
resolve(__dirname, `./src/journeys/_shared/specs/conference-boilerplate.json`),
JSON.stringify(spec, null, 1),
'utf-8'
);
console.log(`✔ conference done`);
}
(async function createSpecs() {
await furniture();
await voyage();
await photofinder();
await conference();
process.exit(0);
})();