sb-mig 2.9.13 → 3.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/index.js +52 -0
- package/package.json +42 -62
- package/bin/run +0 -5
- package/bin/run.cmd +0 -3
- package/lib/api/apiConfig.d.ts +0 -2
- package/lib/api/apiConfig.js +0 -9
- package/lib/api/componentPresets.d.ts +0 -1
- package/lib/api/componentPresets.js +0 -22
- package/lib/api/components.d.ts +0 -5
- package/lib/api/components.js +0 -71
- package/lib/api/datasources.d.ts +0 -24
- package/lib/api/datasources.js +0 -193
- package/lib/api/migrate.d.ts +0 -19
- package/lib/api/migrate.js +0 -220
- package/lib/api/mutateComponents.d.ts +0 -2
- package/lib/api/mutateComponents.js +0 -50
- package/lib/api/presets.d.ts +0 -4
- package/lib/api/presets.js +0 -59
- package/lib/api/resolvePresets.d.ts +0 -2
- package/lib/api/resolvePresets.js +0 -40
- package/lib/api/roles.d.ts +0 -14
- package/lib/api/roles.js +0 -133
- package/lib/api/spaces.d.ts +0 -2
- package/lib/api/spaces.js +0 -29
- package/lib/commands/backup.d.ts +0 -22
- package/lib/commands/backup.js +0 -217
- package/lib/commands/debug.d.ts +0 -9
- package/lib/commands/debug.js +0 -27
- package/lib/commands/sync.d.ts +0 -26
- package/lib/commands/sync.js +0 -93
- package/lib/config/StoryblokComponentsConfig.d.ts +0 -68
- package/lib/config/StoryblokComponentsConfig.js +0 -220
- package/lib/config/config.d.ts +0 -37
- package/lib/config/config.js +0 -36
- package/lib/core.d.ts +0 -16
- package/lib/core.js +0 -75
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -5
- package/lib/types/storyblokTypes.d.ts +0 -171
- package/lib/types/storyblokTypes.js +0 -3
- package/lib/utils/discover.d.ts +0 -4
- package/lib/utils/discover.js +0 -96
- package/lib/utils/discover2.d.ts +0 -63
- package/lib/utils/discover2.js +0 -424
- package/lib/utils/files.d.ts +0 -6
- package/lib/utils/files.js +0 -54
- package/lib/utils/logger.d.ts +0 -11
- package/lib/utils/logger.js +0 -30
- package/lib/utils/others.d.ts +0 -1
- package/lib/utils/others.js +0 -5
- package/oclif.manifest.json +0 -1
package/lib/api/migrate.js
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.syncAllComponents = exports.sync2AllComponents = exports.syncProvidedComponents = exports.syncComponents = exports.sync2Components = void 0;
|
|
4
|
-
const logger_1 = require("../utils/logger");
|
|
5
|
-
const discover_1 = require("../utils/discover");
|
|
6
|
-
const config_1 = require("../config/config");
|
|
7
|
-
const components_1 = require("./components");
|
|
8
|
-
const mutateComponents_1 = require("./mutateComponents");
|
|
9
|
-
const discover2_1 = require("../utils/discover2");
|
|
10
|
-
const { componentDirectory } = config_1.default;
|
|
11
|
-
const _uniqueValuesFrom = (array) => [...new Set(array)];
|
|
12
|
-
const _checkAndPrepareGroups = async (groupsToCheck) => {
|
|
13
|
-
const componentsGroups = await (0, components_1.getAllComponentsGroups)();
|
|
14
|
-
const groupExist = (groupName) => componentsGroups.component_groups.find((group) => group.name === groupName);
|
|
15
|
-
groupsToCheck.forEach(async (groupName) => {
|
|
16
|
-
if (!groupExist(groupName)) {
|
|
17
|
-
await (0, components_1.createComponentsGroup)(groupName);
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
const _resolveGroups = async (component, existedGroups, remoteComponentsGroups) => {
|
|
22
|
-
if (!component.component_group_name) {
|
|
23
|
-
return { ...component, component_group_uuid: null };
|
|
24
|
-
}
|
|
25
|
-
const componentsGroup = existedGroups.find((group) => component.component_group_name === group);
|
|
26
|
-
if (componentsGroup) {
|
|
27
|
-
const component_group_uuid = remoteComponentsGroups.component_groups.find((remoteComponentsGroup) => remoteComponentsGroup.name === componentsGroup).uuid;
|
|
28
|
-
return { ...component, component_group_uuid };
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
const sync2Components = async ({ specifiedComponents, presets }) => {
|
|
32
|
-
logger_1.default.log('sync2Components: ');
|
|
33
|
-
const specifiedComponentsContent = specifiedComponents.map(component => (0, discover2_1.getFileContent)({ file: component.path }));
|
|
34
|
-
const groupsToCheck = _uniqueValuesFrom(specifiedComponentsContent
|
|
35
|
-
.filter(component => component.component_group_name)
|
|
36
|
-
.map(component => component.component_group_name));
|
|
37
|
-
await _checkAndPrepareGroups(groupsToCheck);
|
|
38
|
-
// after checkAndPrepareGroups remoteComponents will have synced groups with local groups
|
|
39
|
-
// updates of the groups had to happen before creation of them, cause creation/updates of components
|
|
40
|
-
// happens async, so if one component will have the same group, as other one
|
|
41
|
-
// it will be race of condition kinda issue - we will never now, if the group for current processed component
|
|
42
|
-
// already exist or is being created by other request
|
|
43
|
-
const remoteComponents = await (0, components_1.getAllComponents)();
|
|
44
|
-
const componentsToUpdate = [];
|
|
45
|
-
const componentsToCreate = [];
|
|
46
|
-
for (const component of specifiedComponentsContent) {
|
|
47
|
-
const shouldBeUpdated = remoteComponents.components.find((remoteComponent) => component.name === remoteComponent.name);
|
|
48
|
-
if (shouldBeUpdated) {
|
|
49
|
-
componentsToUpdate.push({ id: shouldBeUpdated.id, ...component });
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
componentsToCreate.push(component);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const componentsGroups = await (0, components_1.getAllComponentsGroups)();
|
|
56
|
-
componentsToUpdate.length > 0 && Promise.all(componentsToUpdate
|
|
57
|
-
.map(component => _resolveGroups(component, groupsToCheck, componentsGroups))).then(res => {
|
|
58
|
-
logger_1.default.log('Components to update after check: ');
|
|
59
|
-
res.map(component => {
|
|
60
|
-
logger_1.default.warning(` ${component.name}`);
|
|
61
|
-
(0, mutateComponents_1.updateComponent)(component, presets);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
componentsToCreate.length > 0 && Promise.all(componentsToCreate
|
|
65
|
-
.map(component => _resolveGroups(component, groupsToCheck, componentsGroups))).then(res => {
|
|
66
|
-
logger_1.default.log('Components to create after check: ');
|
|
67
|
-
res.map(component => {
|
|
68
|
-
logger_1.default.warning(` ${component.name}`);
|
|
69
|
-
(0, mutateComponents_1.createComponent)(component, presets);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
|
-
exports.sync2Components = sync2Components;
|
|
74
|
-
const syncComponents = async (specifiedComponents, ext, presets, packageName, local) => {
|
|
75
|
-
if (packageName) {
|
|
76
|
-
specifiedComponents = (0, discover_1.findComponentsByPackageName)(ext, specifiedComponents, local);
|
|
77
|
-
}
|
|
78
|
-
logger_1.default.log(`Trying to sync specified components from '${componentDirectory}'`);
|
|
79
|
-
let localComponents;
|
|
80
|
-
if (ext) {
|
|
81
|
-
localComponents = (0, discover_1.findComponentsWithExt)(ext);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
localComponents = (0, discover_1.findComponents)(componentDirectory);
|
|
85
|
-
}
|
|
86
|
-
const groupsToCheck = _uniqueValuesFrom(localComponents
|
|
87
|
-
.filter(component => component.component_group_name)
|
|
88
|
-
.map(component => component.component_group_name));
|
|
89
|
-
await _checkAndPrepareGroups(groupsToCheck);
|
|
90
|
-
// after checkAndPrepareGroups remoteComponents will have synced groups with local groups
|
|
91
|
-
// updates of the groups had to happen before creation of them, cause creation/updates of components
|
|
92
|
-
// happens async, so if one component will have the same group, as other one
|
|
93
|
-
// it will be race of condition kinda issue - we will never now, if the group for current processed component
|
|
94
|
-
// already exist or is being created by other request
|
|
95
|
-
const remoteComponents = await (0, components_1.getAllComponents)();
|
|
96
|
-
const componentsToUpdate = [];
|
|
97
|
-
const componentsToCreate = [];
|
|
98
|
-
for (const component of localComponents) {
|
|
99
|
-
const shouldBeUpdated = remoteComponents.components.find((remoteComponent) => component.name === remoteComponent.name);
|
|
100
|
-
if (shouldBeUpdated) {
|
|
101
|
-
componentsToUpdate.push({ id: shouldBeUpdated.id, ...component });
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
componentsToCreate.push(component);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
const componentsGroups = await (0, components_1.getAllComponentsGroups)();
|
|
108
|
-
Promise.all(componentsToUpdate
|
|
109
|
-
.filter(c => {
|
|
110
|
-
const temp = specifiedComponents.find((component) => component === c.name);
|
|
111
|
-
if (temp) {
|
|
112
|
-
specifiedComponents = specifiedComponents.filter((component) => component !== temp);
|
|
113
|
-
}
|
|
114
|
-
return temp;
|
|
115
|
-
})
|
|
116
|
-
.map(component => _resolveGroups(component, groupsToCheck, componentsGroups))).then(res => {
|
|
117
|
-
logger_1.default.log('Components to update after check: ');
|
|
118
|
-
res.map(component => {
|
|
119
|
-
logger_1.default.warning(` ${component.name}`);
|
|
120
|
-
(0, mutateComponents_1.updateComponent)(component, presets);
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
Promise.all(componentsToCreate
|
|
124
|
-
.filter(c => {
|
|
125
|
-
const temp = specifiedComponents.find((component) => component === c.name);
|
|
126
|
-
return temp;
|
|
127
|
-
})
|
|
128
|
-
.map(component => _resolveGroups(component, groupsToCheck, componentsGroups))).then(res => {
|
|
129
|
-
logger_1.default.log('Components to create after check: ');
|
|
130
|
-
res.map(component => {
|
|
131
|
-
logger_1.default.warning(` ${component.name}`);
|
|
132
|
-
(0, mutateComponents_1.createComponent)(component, presets);
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
};
|
|
136
|
-
exports.syncComponents = syncComponents;
|
|
137
|
-
const syncProvidedComponents = ({ components, presets, packageName }) => {
|
|
138
|
-
if (!packageName) {
|
|
139
|
-
// #1: discover all external .sb.js files
|
|
140
|
-
const allLocalSbComponentsSchemaFiles = (0, discover2_1.discoverMany)({
|
|
141
|
-
scope: discover2_1.SCOPE.local,
|
|
142
|
-
type: discover2_1.LOOKUP_TYPE.fileName,
|
|
143
|
-
fileNames: components,
|
|
144
|
-
});
|
|
145
|
-
// #2: discover all local .sb.js files
|
|
146
|
-
const allExternalSbComponentsSchemaFiles = (0, discover2_1.discoverMany)({
|
|
147
|
-
scope: discover2_1.SCOPE.external,
|
|
148
|
-
type: discover2_1.LOOKUP_TYPE.fileName,
|
|
149
|
-
fileNames: components,
|
|
150
|
-
});
|
|
151
|
-
// #3: compare results, prefer local ones (so we have to create final external paths array and local array of things to sync from where)
|
|
152
|
-
const { local, external } = (0, discover2_1.compare)({
|
|
153
|
-
local: allLocalSbComponentsSchemaFiles,
|
|
154
|
-
external: allExternalSbComponentsSchemaFiles,
|
|
155
|
-
});
|
|
156
|
-
// #4: sync - do all stuff already done (groups resolving, and so on)
|
|
157
|
-
(0, exports.sync2Components)({
|
|
158
|
-
presets,
|
|
159
|
-
specifiedComponents: [...local, ...external],
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
// implement discovering and syncrhonizing with packageName
|
|
164
|
-
// #1: discover all external .sb.js files
|
|
165
|
-
const allLocalSbComponentsSchemaFiles = (0, discover2_1.discoverManyByPackageName)({
|
|
166
|
-
scope: discover2_1.SCOPE.local,
|
|
167
|
-
packageNames: components,
|
|
168
|
-
});
|
|
169
|
-
// #2: discover all local .sb.js files
|
|
170
|
-
const allExternalSbComponentsSchemaFiles = (0, discover2_1.discoverManyByPackageName)({
|
|
171
|
-
scope: discover2_1.SCOPE.external,
|
|
172
|
-
packageNames: components,
|
|
173
|
-
});
|
|
174
|
-
// #3: compare results, prefer local ones (so we have to create final external paths array and local array of things to sync from where)
|
|
175
|
-
const { local, external } = (0, discover2_1.compare)({
|
|
176
|
-
local: allLocalSbComponentsSchemaFiles,
|
|
177
|
-
external: allExternalSbComponentsSchemaFiles,
|
|
178
|
-
});
|
|
179
|
-
// #4: sync - do all stuff already done (groups resolving, and so on)
|
|
180
|
-
(0, exports.sync2Components)({
|
|
181
|
-
presets,
|
|
182
|
-
specifiedComponents: [...local, ...external],
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
exports.syncProvidedComponents = syncProvidedComponents;
|
|
187
|
-
const sync2AllComponents = ({ presets }) => {
|
|
188
|
-
// #1: discover all external .sb.js files
|
|
189
|
-
const allLocalSbComponentsSchemaFiles = (0, discover2_1.discover)({
|
|
190
|
-
scope: discover2_1.SCOPE.local,
|
|
191
|
-
type: discover2_1.LOOKUP_TYPE.fileName,
|
|
192
|
-
});
|
|
193
|
-
// #2: discover all local .sb.js files
|
|
194
|
-
const allExternalSbComponentsSchemaFiles = (0, discover2_1.discover)({
|
|
195
|
-
scope: discover2_1.SCOPE.external,
|
|
196
|
-
type: discover2_1.LOOKUP_TYPE.fileName,
|
|
197
|
-
});
|
|
198
|
-
// #3: compare results, prefare local ones (so we have to create final external paths array and local array of things to sync from where)
|
|
199
|
-
const { local, external } = (0, discover2_1.compare)({
|
|
200
|
-
local: allLocalSbComponentsSchemaFiles,
|
|
201
|
-
external: allExternalSbComponentsSchemaFiles,
|
|
202
|
-
});
|
|
203
|
-
// #4: sync - do all stuff already done (groups resolving, and so on)
|
|
204
|
-
(0, exports.sync2Components)({
|
|
205
|
-
presets,
|
|
206
|
-
specifiedComponents: [...local, ...external],
|
|
207
|
-
});
|
|
208
|
-
};
|
|
209
|
-
exports.sync2AllComponents = sync2AllComponents;
|
|
210
|
-
const syncAllComponents = (ext, presets) => {
|
|
211
|
-
let specifiedComponents;
|
|
212
|
-
if (ext) {
|
|
213
|
-
specifiedComponents = (0, discover_1.findComponentsWithExt)(ext).map(component => component.name);
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
specifiedComponents = (0, discover_1.findComponents)(componentDirectory).map((component) => component.name);
|
|
217
|
-
}
|
|
218
|
-
(0, exports.syncComponents)(specifiedComponents, ext, presets, false);
|
|
219
|
-
};
|
|
220
|
-
exports.syncAllComponents = syncAllComponents;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createComponent = exports.updateComponent = void 0;
|
|
4
|
-
const logger_1 = require("../utils/logger");
|
|
5
|
-
const config_1 = require("../config/config");
|
|
6
|
-
const apiConfig_1 = require("./apiConfig");
|
|
7
|
-
const resolvePresets_1 = require("./resolvePresets");
|
|
8
|
-
const { spaceId } = config_1.default;
|
|
9
|
-
// UPDATE
|
|
10
|
-
const updateComponent = (component, presets) => {
|
|
11
|
-
logger_1.default.log(`Trying to update '${component.name}' with id ${component.id}`);
|
|
12
|
-
const componentWithPresets = component;
|
|
13
|
-
const { all_presets, ...componentWithoutPresets } = componentWithPresets;
|
|
14
|
-
apiConfig_1.sbApi
|
|
15
|
-
.put(`spaces/${spaceId}/components/${component.id}`, {
|
|
16
|
-
component: componentWithoutPresets,
|
|
17
|
-
})
|
|
18
|
-
.then(res => {
|
|
19
|
-
logger_1.default.success(`Component '${component.name}' has been updated.`);
|
|
20
|
-
if (presets) {
|
|
21
|
-
(0, resolvePresets_1.default)(res, all_presets, component);
|
|
22
|
-
}
|
|
23
|
-
})
|
|
24
|
-
.catch(err => {
|
|
25
|
-
logger_1.default.error('error happened... :(');
|
|
26
|
-
console.log(`${err.message} in migration of ${component.name} in updateComponent function`);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
exports.updateComponent = updateComponent;
|
|
30
|
-
// CREATE
|
|
31
|
-
const createComponent = (component, presets) => {
|
|
32
|
-
logger_1.default.log(`Trying to create '${component.name}'`);
|
|
33
|
-
const componentWithPresets = component;
|
|
34
|
-
const { all_presets, ...componentWithoutPresets } = componentWithPresets;
|
|
35
|
-
apiConfig_1.sbApi
|
|
36
|
-
.post(`spaces/${spaceId}/components/`, {
|
|
37
|
-
component: componentWithoutPresets,
|
|
38
|
-
})
|
|
39
|
-
.then(res => {
|
|
40
|
-
logger_1.default.success(`Component '${component.name}' has been created.`);
|
|
41
|
-
if (presets) {
|
|
42
|
-
(0, resolvePresets_1.default)(res, all_presets, component);
|
|
43
|
-
}
|
|
44
|
-
})
|
|
45
|
-
.catch(err => {
|
|
46
|
-
logger_1.default.error('error happened... :(');
|
|
47
|
-
console.log(`${err.message} in migration of ${component.name} in createComponent function`);
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
exports.createComponent = createComponent;
|
package/lib/api/presets.d.ts
DELETED
package/lib/api/presets.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updatePreset = exports.createPreset = exports.getAllPresets = exports.getPreset = void 0;
|
|
4
|
-
const logger_1 = require("../utils/logger");
|
|
5
|
-
const config_1 = require("../config/config");
|
|
6
|
-
const apiConfig_1 = require("./apiConfig");
|
|
7
|
-
const { spaceId } = config_1.default;
|
|
8
|
-
// GET
|
|
9
|
-
const getPreset = (presetId) => {
|
|
10
|
-
logger_1.default.log(`Trying to get preset by id: ${presetId}`);
|
|
11
|
-
return apiConfig_1.sbApi
|
|
12
|
-
.get(`spaces/${spaceId}/presets/${presetId}`)
|
|
13
|
-
.then(response => response.data)
|
|
14
|
-
.then(response => {
|
|
15
|
-
if (Array.isArray(response.presets)) {
|
|
16
|
-
logger_1.default.warning(`There is no preset for '${presetId}' preset id`);
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
return response;
|
|
20
|
-
})
|
|
21
|
-
.catch(err => logger_1.default.error(err));
|
|
22
|
-
};
|
|
23
|
-
exports.getPreset = getPreset;
|
|
24
|
-
const getAllPresets = () => {
|
|
25
|
-
logger_1.default.log('Trying to get all Presets.');
|
|
26
|
-
return apiConfig_1.sbApi
|
|
27
|
-
.get(`spaces/${spaceId}/presets/`)
|
|
28
|
-
.then(response => response.data)
|
|
29
|
-
.catch(err => logger_1.default.error(err));
|
|
30
|
-
};
|
|
31
|
-
exports.getAllPresets = getAllPresets;
|
|
32
|
-
// CREATE
|
|
33
|
-
const createPreset = (p) => {
|
|
34
|
-
apiConfig_1.sbApi
|
|
35
|
-
.post(`spaces/${spaceId}/presets/`, {
|
|
36
|
-
preset: p.preset,
|
|
37
|
-
})
|
|
38
|
-
.then(res => {
|
|
39
|
-
logger_1.default.warning(`Preset: '${p.preset.name}' has been created.`);
|
|
40
|
-
})
|
|
41
|
-
.catch(err => {
|
|
42
|
-
logger_1.default.error(`Error happened. Preset: '${p.preset.name}' has been not created.`);
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
exports.createPreset = createPreset;
|
|
46
|
-
// UPDATE
|
|
47
|
-
const updatePreset = (p) => {
|
|
48
|
-
apiConfig_1.sbApi
|
|
49
|
-
.put(`spaces/${spaceId}/presets/${p.preset.id}`, {
|
|
50
|
-
preset: p.preset,
|
|
51
|
-
})
|
|
52
|
-
.then(res => {
|
|
53
|
-
logger_1.default.warning(`Preset: '${p.preset.name}' with '${p.preset.id}' id has been updated.`);
|
|
54
|
-
})
|
|
55
|
-
.catch(err => {
|
|
56
|
-
logger_1.default.error(`Error happened. Preset: '${p.preset.name}' with '${p.preset.id}' id has been not updated.`);
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
exports.updatePreset = updatePreset;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const logger_1 = require("../utils/logger");
|
|
4
|
-
const presets_1 = require("./presets");
|
|
5
|
-
const componentPresets_1 = require("./componentPresets");
|
|
6
|
-
const _resolvePresets = async (res, all_presets, component) => {
|
|
7
|
-
const componentId = res.data.component.id;
|
|
8
|
-
if (all_presets && all_presets.length > 0) {
|
|
9
|
-
const all_presets_modified = all_presets.map((p) => {
|
|
10
|
-
return { preset: { ...p.preset, component_id: componentId } };
|
|
11
|
-
});
|
|
12
|
-
logger_1.default.log(`Checking preset for '${component.name}' component`);
|
|
13
|
-
const allRemoteComponentPresets = await (0, componentPresets_1.getComponentPresets)(component.name);
|
|
14
|
-
const presetsToUpdate = [];
|
|
15
|
-
const presetsToCreate = [];
|
|
16
|
-
for (const componentPreset of all_presets_modified) {
|
|
17
|
-
const shouldBeUpdated = allRemoteComponentPresets &&
|
|
18
|
-
allRemoteComponentPresets.find((remotePreset) => componentPreset.preset.name === remotePreset.preset.name);
|
|
19
|
-
if (shouldBeUpdated) {
|
|
20
|
-
presetsToUpdate.push({
|
|
21
|
-
...componentPreset,
|
|
22
|
-
preset: { id: shouldBeUpdated.preset.id, ...componentPreset.preset },
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
presetsToCreate.push(componentPreset);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
presetsToUpdate.map(preset => {
|
|
30
|
-
(0, presets_1.updatePreset)(preset);
|
|
31
|
-
});
|
|
32
|
-
presetsToCreate.map(preset => {
|
|
33
|
-
(0, presets_1.createPreset)(preset);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
logger_1.default.warning('There are no presets for this component.');
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
exports.default = _resolvePresets;
|
package/lib/api/roles.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { OneComponent } from '../utils/discover2';
|
|
2
|
-
export declare const createRole: (role: any) => void;
|
|
3
|
-
export declare const updateRole: (role: any) => void;
|
|
4
|
-
export declare const getAllRoles: () => Promise<any>;
|
|
5
|
-
export declare const getRole: (roleName: string) => Promise<any>;
|
|
6
|
-
interface SyncRoles {
|
|
7
|
-
specifiedRoles: OneComponent[];
|
|
8
|
-
}
|
|
9
|
-
export declare const syncRoles: ({ specifiedRoles }: SyncRoles) => Promise<void>;
|
|
10
|
-
export declare const syncAllRoles: () => Promise<void>;
|
|
11
|
-
export declare const syncProvidedRoles: ({ roles }: {
|
|
12
|
-
roles: string[];
|
|
13
|
-
}) => void;
|
|
14
|
-
export {};
|
package/lib/api/roles.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.syncProvidedRoles = exports.syncAllRoles = exports.syncRoles = exports.getRole = exports.getAllRoles = exports.updateRole = exports.createRole = void 0;
|
|
4
|
-
const logger_1 = require("../utils/logger");
|
|
5
|
-
const config_1 = require("../config/config");
|
|
6
|
-
const apiConfig_1 = require("./apiConfig");
|
|
7
|
-
const discover2_1 = require("../utils/discover2");
|
|
8
|
-
const { spaceId } = config_1.default;
|
|
9
|
-
// POST
|
|
10
|
-
const createRole = (role) => {
|
|
11
|
-
apiConfig_1.sbApi
|
|
12
|
-
.post(`spaces/${spaceId}/space_roles/`, {
|
|
13
|
-
space_role: role,
|
|
14
|
-
})
|
|
15
|
-
.then(res => {
|
|
16
|
-
logger_1.default.success(`Role '${role.role}' has been created.`);
|
|
17
|
-
})
|
|
18
|
-
.catch(err => {
|
|
19
|
-
logger_1.default.error('error happened... :(');
|
|
20
|
-
console.log(`${err.message} in migration of ${role.role} in createRole function`);
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
exports.createRole = createRole;
|
|
24
|
-
// PUT
|
|
25
|
-
const updateRole = (role) => {
|
|
26
|
-
apiConfig_1.sbApi
|
|
27
|
-
.put(`spaces/${spaceId}/space_roles/${role.id}`, {
|
|
28
|
-
space_role: role,
|
|
29
|
-
})
|
|
30
|
-
.then(res => {
|
|
31
|
-
logger_1.default.success(`Role '${role.role}' has been updated.`);
|
|
32
|
-
})
|
|
33
|
-
.catch(err => {
|
|
34
|
-
logger_1.default.error('error happened... :(');
|
|
35
|
-
console.log(`${err.message} in migration of ${role.role} in updateRole function`);
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
exports.updateRole = updateRole;
|
|
39
|
-
// GET
|
|
40
|
-
const getAllRoles = async () => {
|
|
41
|
-
return apiConfig_1.sbApi
|
|
42
|
-
.get(`spaces/${spaceId}/space_roles/`)
|
|
43
|
-
.then(({ data }) => data)
|
|
44
|
-
.catch(err => {
|
|
45
|
-
if (err.response.status === 404) {
|
|
46
|
-
logger_1.default.error(`There is no roles in your Storyblok ${spaceId} space.`);
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
logger_1.default.error(err);
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
exports.getAllRoles = getAllRoles;
|
|
55
|
-
// GET
|
|
56
|
-
const getRole = async (roleName) => {
|
|
57
|
-
logger_1.default.log(`Trying to get '${roleName}' role.`);
|
|
58
|
-
return (0, exports.getAllRoles)()
|
|
59
|
-
.then(res => res.space_roles.filter((role) => role.role === roleName))
|
|
60
|
-
.then(res => {
|
|
61
|
-
if (Array.isArray(res) && res.length === 0) {
|
|
62
|
-
logger_1.default.warning(`There is no role named '${roleName}'`);
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
return res;
|
|
66
|
-
})
|
|
67
|
-
.catch(err => logger_1.default.error(err));
|
|
68
|
-
};
|
|
69
|
-
exports.getRole = getRole;
|
|
70
|
-
const syncRoles = async ({ specifiedRoles }) => {
|
|
71
|
-
const specifiedRolesContent = specifiedRoles.map(roles => (0, discover2_1.getFileContent)({ file: roles.path }));
|
|
72
|
-
const { space_roles } = await (0, exports.getAllRoles)();
|
|
73
|
-
const rolesToUpdate = [];
|
|
74
|
-
const rolesToCreate = [];
|
|
75
|
-
for (const role of specifiedRolesContent) {
|
|
76
|
-
const shouldBeUpdated = space_roles.find((remoteRole) => role.role === remoteRole.role);
|
|
77
|
-
if (shouldBeUpdated) {
|
|
78
|
-
rolesToUpdate.push({ id: shouldBeUpdated.id, ...role });
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
rolesToCreate.push(role);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
rolesToUpdate.map(async (role) => {
|
|
85
|
-
await (0, exports.updateRole)(role);
|
|
86
|
-
});
|
|
87
|
-
rolesToCreate.map(async (role) => {
|
|
88
|
-
await (0, exports.createRole)(role);
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
exports.syncRoles = syncRoles;
|
|
92
|
-
const syncAllRoles = async () => {
|
|
93
|
-
// #1: discover all external .roles.sb.js files
|
|
94
|
-
const allLocalSbComponentsSchemaFiles = (0, discover2_1.discoverRoles)({
|
|
95
|
-
scope: discover2_1.SCOPE.local,
|
|
96
|
-
type: discover2_1.LOOKUP_TYPE.fileName,
|
|
97
|
-
});
|
|
98
|
-
// #2: discover all local .roles.sb.js files
|
|
99
|
-
const allExternalSbComponentsSchemaFiles = (0, discover2_1.discoverRoles)({
|
|
100
|
-
scope: discover2_1.SCOPE.external,
|
|
101
|
-
type: discover2_1.LOOKUP_TYPE.fileName,
|
|
102
|
-
});
|
|
103
|
-
// #3: compare results, prefare local ones (so we have to create final external paths array and local array of things to sync from where)
|
|
104
|
-
const { local, external } = (0, discover2_1.compare)({
|
|
105
|
-
local: allLocalSbComponentsSchemaFiles,
|
|
106
|
-
external: allExternalSbComponentsSchemaFiles,
|
|
107
|
-
});
|
|
108
|
-
// #4: sync - do all stuff already done (groups resolving, and so on)
|
|
109
|
-
(0, exports.syncRoles)({ specifiedRoles: [...local, ...external] });
|
|
110
|
-
};
|
|
111
|
-
exports.syncAllRoles = syncAllRoles;
|
|
112
|
-
const syncProvidedRoles = ({ roles }) => {
|
|
113
|
-
// #1: discover all external .sb.js files
|
|
114
|
-
const allLocalSbComponentsSchemaFiles = (0, discover2_1.discoverManyRoles)({
|
|
115
|
-
scope: discover2_1.SCOPE.local,
|
|
116
|
-
type: discover2_1.LOOKUP_TYPE.fileName,
|
|
117
|
-
fileNames: roles,
|
|
118
|
-
});
|
|
119
|
-
// #2: discover all local .sb.js files
|
|
120
|
-
const allExternalSbComponentsSchemaFiles = (0, discover2_1.discoverManyRoles)({
|
|
121
|
-
scope: discover2_1.SCOPE.external,
|
|
122
|
-
type: discover2_1.LOOKUP_TYPE.fileName,
|
|
123
|
-
fileNames: roles,
|
|
124
|
-
});
|
|
125
|
-
// #3: compare results, prefer local ones (so we have to create final external paths array and local array of things to sync from where)
|
|
126
|
-
const { local, external } = (0, discover2_1.compare)({
|
|
127
|
-
local: allLocalSbComponentsSchemaFiles,
|
|
128
|
-
external: allExternalSbComponentsSchemaFiles,
|
|
129
|
-
});
|
|
130
|
-
// #4: sync - do all stuff already done (groups resolving, and so on)
|
|
131
|
-
(0, exports.syncRoles)({ specifiedRoles: [...local, ...external] });
|
|
132
|
-
};
|
|
133
|
-
exports.syncProvidedRoles = syncProvidedRoles;
|
package/lib/api/spaces.d.ts
DELETED
package/lib/api/spaces.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSpace = exports.createSpace = void 0;
|
|
4
|
-
const logger_1 = require("../utils/logger");
|
|
5
|
-
const apiConfig_1 = require("./apiConfig");
|
|
6
|
-
// CREATE
|
|
7
|
-
const createSpace = (spaceName) => {
|
|
8
|
-
logger_1.default.warning(`Trying to create space ${spaceName}...`);
|
|
9
|
-
return apiConfig_1.sbApi
|
|
10
|
-
.post('spaces/', {
|
|
11
|
-
space: {
|
|
12
|
-
name: spaceName,
|
|
13
|
-
domain: 'http://localhost:8000/editor?path=',
|
|
14
|
-
},
|
|
15
|
-
})
|
|
16
|
-
.then(res => {
|
|
17
|
-
return res;
|
|
18
|
-
})
|
|
19
|
-
.catch(err => {
|
|
20
|
-
logger_1.default.error('Error happened. Can\'t create space');
|
|
21
|
-
console.log(err.message);
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
exports.createSpace = createSpace;
|
|
25
|
-
// GET
|
|
26
|
-
const getSpace = (spaceId) => {
|
|
27
|
-
return apiConfig_1.sbApi.get(`spaces/${spaceId}`).then(res => res);
|
|
28
|
-
};
|
|
29
|
-
exports.getSpace = getSpace;
|
package/lib/commands/backup.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { flags } from '@oclif/command';
|
|
2
|
-
import Command from '../core';
|
|
3
|
-
export default class Backup extends Command {
|
|
4
|
-
static description: string;
|
|
5
|
-
static flags: {
|
|
6
|
-
help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
|
|
7
|
-
allComponents: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
8
|
-
oneComponent: flags.IOptionFlag<string | undefined>;
|
|
9
|
-
allComponentsGroups: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
10
|
-
oneComponentsGroup: flags.IOptionFlag<string | undefined>;
|
|
11
|
-
oneComponentPresets: flags.IOptionFlag<string | undefined>;
|
|
12
|
-
allPresets: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
13
|
-
onePreset: flags.IOptionFlag<string | undefined>;
|
|
14
|
-
allDatasources: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
15
|
-
oneDatasource: flags.IOptionFlag<string | undefined>;
|
|
16
|
-
datasourceEntries: flags.IOptionFlag<string | undefined>;
|
|
17
|
-
allRoles: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
18
|
-
oneRole: flags.IOptionFlag<string | undefined>;
|
|
19
|
-
};
|
|
20
|
-
static args: never[];
|
|
21
|
-
run(): Promise<boolean | void>;
|
|
22
|
-
}
|