sb-mig 5.3.0 → 5.4.0
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/dist/api/migrate.d.ts +5 -0
- package/dist/api/migrate.js +46 -19
- package/dist/cli/commands/sync.js +12 -3
- package/package.json +2 -2
package/dist/api/migrate.d.ts
CHANGED
|
@@ -8,3 +8,8 @@ export declare const syncAllComponents: SyncAllComponents;
|
|
|
8
8
|
export declare const syncProvidedComponents: SyncProvidedComponents;
|
|
9
9
|
export declare const syncAssets: SyncAssets;
|
|
10
10
|
export declare const syncContent: SyncContentFunction;
|
|
11
|
+
export declare const setComponentDefaultPreset: ({ presets, componentsToSync, apiConfig, }: {
|
|
12
|
+
presets: boolean;
|
|
13
|
+
componentsToSync?: string[] | undefined;
|
|
14
|
+
apiConfig: RequestBaseConfig;
|
|
15
|
+
}) => Promise<false | any[]>;
|
package/dist/api/migrate.js
CHANGED
|
@@ -93,22 +93,24 @@ export const syncComponents = async (specifiedComponents, presets, config) => {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
const componentsGroups = await managementApi.components.getAllComponentsGroups(config);
|
|
96
|
-
componentsToUpdate.length > 0 &&
|
|
97
|
-
Promise.all(componentsToUpdate.map((component) => _resolveGroups(component, groupsToCheck, componentsGroups, config)))
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
});
|
|
111
|
-
|
|
96
|
+
const groupsResolvedForComponentsToUpdate = componentsToUpdate.length > 0 &&
|
|
97
|
+
(await Promise.all(componentsToUpdate.map((component) => _resolveGroups(component, groupsToCheck, componentsGroups, config))));
|
|
98
|
+
Logger.log("Components to update after check: ");
|
|
99
|
+
if (groupsResolvedForComponentsToUpdate) {
|
|
100
|
+
await Promise.allSettled(groupsResolvedForComponentsToUpdate.map((component) => {
|
|
101
|
+
Logger.warning(` ${component.name}`);
|
|
102
|
+
return managementApi.components.updateComponent(component, presets, config);
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
const groupsResolvedForComponentToCreate = componentsToCreate.length > 0 &&
|
|
106
|
+
(await Promise.all(componentsToCreate.map((component) => _resolveGroups(component, groupsToCheck, componentsGroups, config))));
|
|
107
|
+
Logger.log("Components to create after check: ");
|
|
108
|
+
if (groupsResolvedForComponentToCreate) {
|
|
109
|
+
await Promise.allSettled(groupsResolvedForComponentToCreate.map((component) => {
|
|
110
|
+
Logger.warning(` ${component.name}`);
|
|
111
|
+
return managementApi.components.createComponent(component, presets, config);
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
112
114
|
};
|
|
113
115
|
export const syncAllComponents = async (presets, config) => {
|
|
114
116
|
// #1: discover all external .sb.js files
|
|
@@ -127,7 +129,7 @@ export const syncAllComponents = async (presets, config) => {
|
|
|
127
129
|
external: allExternalSbComponentsSchemaFiles,
|
|
128
130
|
});
|
|
129
131
|
// #4: sync - do all stuff already done (groups resolving, and so on)
|
|
130
|
-
syncComponents([...local, ...external], presets, config);
|
|
132
|
+
return await syncComponents([...local, ...external], presets, config);
|
|
131
133
|
};
|
|
132
134
|
export const syncProvidedComponents = async (presets, components, packageName, config) => {
|
|
133
135
|
if (!packageName) {
|
|
@@ -149,7 +151,7 @@ export const syncProvidedComponents = async (presets, components, packageName, c
|
|
|
149
151
|
external: allExternalSbComponentsSchemaFiles,
|
|
150
152
|
});
|
|
151
153
|
// #4: sync - do all stuff already done (groups resolving, and so on)
|
|
152
|
-
syncComponents([...local, ...external], presets, config);
|
|
154
|
+
return await syncComponents([...local, ...external], presets, config);
|
|
153
155
|
}
|
|
154
156
|
else {
|
|
155
157
|
// implement discovering and syncrhonizing with packageName
|
|
@@ -169,7 +171,7 @@ export const syncProvidedComponents = async (presets, components, packageName, c
|
|
|
169
171
|
external: allExternalSbComponentsSchemaFiles,
|
|
170
172
|
});
|
|
171
173
|
// #4: sync - do all stuff already done (groups resolving, and so on)
|
|
172
|
-
syncComponents([...local, ...external], presets, config);
|
|
174
|
+
return syncComponents([...local, ...external], presets, config);
|
|
173
175
|
}
|
|
174
176
|
};
|
|
175
177
|
export const syncAssets = async ({ transmission: { from, to }, syncDirection }, config) => {
|
|
@@ -264,3 +266,28 @@ export const syncContent = async ({ type, transmission, syncDirection, filename
|
|
|
264
266
|
throw Error("This should never happen!");
|
|
265
267
|
}
|
|
266
268
|
};
|
|
269
|
+
const setToDefaultPreset = (allPresets) => {
|
|
270
|
+
return allPresets.find((preset) => preset.name === "Default");
|
|
271
|
+
};
|
|
272
|
+
export const setComponentDefaultPreset = async ({ presets, componentsToSync, apiConfig, }) => {
|
|
273
|
+
if (presets) {
|
|
274
|
+
Logger.warning("Setting default presets for components...");
|
|
275
|
+
const remoteComponents = await managementApi.components.getAllComponents(apiConfig);
|
|
276
|
+
const filteredRemoteComponents = componentsToSync
|
|
277
|
+
? remoteComponents.filter((component) => componentsToSync.includes(component.name))
|
|
278
|
+
: remoteComponents;
|
|
279
|
+
const finalRemoteComponents = filteredRemoteComponents.map((component) => {
|
|
280
|
+
return {
|
|
281
|
+
...component,
|
|
282
|
+
preset_id: setToDefaultPreset(component.all_presets)?.id,
|
|
283
|
+
};
|
|
284
|
+
});
|
|
285
|
+
Logger.warning("Updating componet with default presets...");
|
|
286
|
+
return Promise.all(finalRemoteComponents.map((component) => {
|
|
287
|
+
managementApi.components.updateComponent(component, false, apiConfig);
|
|
288
|
+
}));
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { managementApi } from "../../api/managementApi.js";
|
|
2
|
-
import { removeAllComponents, syncAllComponents, syncContent, syncProvidedComponents, } from "../../api/migrate.js";
|
|
2
|
+
import { removeAllComponents, syncAllComponents, syncContent, syncProvidedComponents, setComponentDefaultPreset, } from "../../api/migrate.js";
|
|
3
3
|
import storyblokConfig from "../../config/config.js";
|
|
4
4
|
import Logger from "../../utils/logger.js";
|
|
5
5
|
import { isItFactory, unpackElements } from "../../utils/main.js";
|
|
@@ -42,12 +42,21 @@ export const sync = async (props) => {
|
|
|
42
42
|
if (isIt("all")) {
|
|
43
43
|
Logger.log(`Syncing ALL components with ${storyblokConfig.schemaFileExt} extension...`);
|
|
44
44
|
const presets = flags["presets"] || false;
|
|
45
|
-
syncAllComponents(presets, apiConfig);
|
|
45
|
+
await syncAllComponents(presets, apiConfig);
|
|
46
|
+
await setComponentDefaultPreset({
|
|
47
|
+
presets: Boolean(flags.presets),
|
|
48
|
+
apiConfig,
|
|
49
|
+
});
|
|
46
50
|
}
|
|
47
51
|
if (isIt("empty")) {
|
|
48
52
|
Logger.warning("Synchronizing PROVIDED components...");
|
|
49
53
|
const componentsToSync = unpackElements(input);
|
|
50
|
-
syncProvidedComponents(Boolean(flags.presets), componentsToSync, flags.packageName, apiConfig);
|
|
54
|
+
await syncProvidedComponents(Boolean(flags.presets), componentsToSync, flags.packageName, apiConfig);
|
|
55
|
+
await setComponentDefaultPreset({
|
|
56
|
+
presets: Boolean(flags.presets),
|
|
57
|
+
componentsToSync,
|
|
58
|
+
apiConfig,
|
|
59
|
+
});
|
|
51
60
|
}
|
|
52
61
|
if (isIt("allWithSSOT")) {
|
|
53
62
|
Logger.warning("Synchronizing ALL components as Single Source of Truth...");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sb-mig",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.0",
|
|
4
4
|
"description": "CLI to rule the world. (and handle stuff related to Storyblok CMS)",
|
|
5
5
|
"author": "Marcin Krawczyk <marckraw@icloud.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"rollup-plugin-ts": "^3.4.4",
|
|
68
68
|
"semver": "^7.6.2",
|
|
69
69
|
"storyblok-js-client": "^5.12.0",
|
|
70
|
-
"storyblok-schema-types": "^1.
|
|
70
|
+
"storyblok-schema-types": "^1.2.4",
|
|
71
71
|
"typescript": "^5.1.6",
|
|
72
72
|
"uuid": "^9.0.0"
|
|
73
73
|
},
|