sb-mig 5.0.0 → 5.0.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/dist/api/managementApi.d.ts +7 -0
- package/dist/api/managementApi.js +2 -0
- package/dist/api/plugins/index.d.ts +1 -1
- package/dist/api/plugins/index.js +1 -1
- package/dist/api/stories/index.d.ts +1 -0
- package/dist/api/stories/index.js +1 -0
- package/dist/cli/commands/backup.js +20 -15
- package/dist/cli/commands/debug.js +1 -0
- package/dist/cli/commands/init.js +3 -3
- package/dist/cli/commands/remove.js +5 -2
- package/dist/cli/commands/revert.js +3 -4
- package/dist/cli/commands/sync.js +8 -11
- package/package.json +1 -3
|
@@ -36,6 +36,7 @@ export declare const managementApi: {
|
|
|
36
36
|
updatePlugin: import("./plugins/plugins.types.js").UpdatePlugin;
|
|
37
37
|
createPlugin: import("./plugins/plugins.types.js").CreatePlugin;
|
|
38
38
|
getPluginDetails: import("./plugins/plugins.types.js").GetPluginDetails;
|
|
39
|
+
syncProvidedPlugins: import("./plugins/plugins.types.js").SyncProvidedPlugins;
|
|
39
40
|
};
|
|
40
41
|
presets: {
|
|
41
42
|
getComponentPresets: (componentName: string | undefined, config: import("./utils/request.js").RequestBaseConfig) => Promise<false | any[]>;
|
|
@@ -62,5 +63,11 @@ export declare const managementApi: {
|
|
|
62
63
|
updateStories: import("./stories/stories.types.js").UpdateStories;
|
|
63
64
|
getAllStories: import("./stories/stories.types.js").GetAllStories;
|
|
64
65
|
removeAllStories: import("./stories/stories.types.js").RemoveAllStories;
|
|
66
|
+
backupStories: import("./stories/stories.types.js").BackupStories;
|
|
67
|
+
};
|
|
68
|
+
spaces: {
|
|
69
|
+
getAllSpaces: import("./spaces/spaces.types.js").GetAllSpaces;
|
|
70
|
+
getSpace: import("./spaces/spaces.types.js").GetSpace;
|
|
71
|
+
updateSpace: import("./spaces/spaces.types.js").UpdateSpace;
|
|
65
72
|
};
|
|
66
73
|
};
|
|
@@ -5,6 +5,7 @@ import * as datasources from "./datasources/index.js";
|
|
|
5
5
|
import * as plugins from "./plugins/index.js";
|
|
6
6
|
import * as presets from "./presets/index.js";
|
|
7
7
|
import * as roles from "./roles/index.js";
|
|
8
|
+
import * as spaces from "./spaces/index.js";
|
|
8
9
|
import * as stories from "./stories/index.js";
|
|
9
10
|
export const managementApi = {
|
|
10
11
|
assets: { ...assets },
|
|
@@ -15,4 +16,5 @@ export const managementApi = {
|
|
|
15
16
|
presets: { ...presets },
|
|
16
17
|
roles: { ...roles },
|
|
17
18
|
stories: { ...stories },
|
|
19
|
+
spaces: { ...spaces },
|
|
18
20
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { getAllPlugins, getPlugin, updatePlugin, createPlugin, getPluginDetails, } from "./plugins.js";
|
|
1
|
+
export { getAllPlugins, getPlugin, updatePlugin, createPlugin, getPluginDetails, syncProvidedPlugins, } from "./plugins.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { getAllPlugins, getPlugin, updatePlugin, createPlugin, getPluginDetails, } from "./plugins.js";
|
|
1
|
+
export { getAllPlugins, getPlugin, updatePlugin, createPlugin, getPluginDetails, syncProvidedPlugins, } from "./plugins.js";
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import { getAllDatasources, getDatasource, } from "../../api/datasources/index.js";
|
|
2
1
|
import { managementApi } from "../../api/managementApi.js";
|
|
3
|
-
import { getAllPlugins, getPlugin } from "../../api/plugins/plugins.js";
|
|
4
|
-
import { getComponentPresets } from "../../api/presets/componentPresets.js";
|
|
5
|
-
import { getAllPresets, getPreset } from "../../api/presets/presets.js";
|
|
6
|
-
import { getAllRoles, getRole } from "../../api/roles/roles.js";
|
|
7
2
|
import { backupStories } from "../../api/stories/backup.js";
|
|
8
3
|
import storyblokConfig from "../../config/config.js";
|
|
9
4
|
import { createAndSaveToFile } from "../../utils/files.js";
|
|
@@ -128,7 +123,8 @@ export const backup = async (props) => {
|
|
|
128
123
|
break;
|
|
129
124
|
case BACKUP_COMMANDS.datasources:
|
|
130
125
|
if (flags["all"]) {
|
|
131
|
-
|
|
126
|
+
managementApi.datasources
|
|
127
|
+
.getAllDatasources(apiConfig)
|
|
132
128
|
.then(async (res) => {
|
|
133
129
|
await createAndSaveToFile({
|
|
134
130
|
ext: "json",
|
|
@@ -145,7 +141,8 @@ export const backup = async (props) => {
|
|
|
145
141
|
}
|
|
146
142
|
if (isIt("empty")) {
|
|
147
143
|
const datasourceToBackup = unpackOne(input);
|
|
148
|
-
|
|
144
|
+
managementApi.datasources
|
|
145
|
+
.getDatasource({ datasourceName: datasourceToBackup }, apiConfig)
|
|
149
146
|
.then(async (res) => {
|
|
150
147
|
if (res) {
|
|
151
148
|
await createAndSaveToFile({
|
|
@@ -166,7 +163,8 @@ export const backup = async (props) => {
|
|
|
166
163
|
break;
|
|
167
164
|
case BACKUP_COMMANDS.roles:
|
|
168
165
|
if (flags["all"]) {
|
|
169
|
-
|
|
166
|
+
managementApi.roles
|
|
167
|
+
.getAllRoles(apiConfig)
|
|
170
168
|
.then(async (res) => {
|
|
171
169
|
await createAndSaveToFile({
|
|
172
170
|
ext: "json",
|
|
@@ -183,7 +181,8 @@ export const backup = async (props) => {
|
|
|
183
181
|
}
|
|
184
182
|
if (isIt("empty")) {
|
|
185
183
|
const roleToBackup = unpackOne(input);
|
|
186
|
-
|
|
184
|
+
managementApi.roles
|
|
185
|
+
.getRole(roleToBackup, apiConfig)
|
|
187
186
|
.then(async (res) => {
|
|
188
187
|
if (res) {
|
|
189
188
|
await createAndSaveToFile({
|
|
@@ -204,7 +203,8 @@ export const backup = async (props) => {
|
|
|
204
203
|
break;
|
|
205
204
|
case BACKUP_COMMANDS.presets:
|
|
206
205
|
if (flags["all"]) {
|
|
207
|
-
|
|
206
|
+
managementApi.presets
|
|
207
|
+
.getAllPresets(apiConfig)
|
|
208
208
|
.then(async (res) => {
|
|
209
209
|
await createAndSaveToFile({
|
|
210
210
|
ext: "json",
|
|
@@ -221,7 +221,8 @@ export const backup = async (props) => {
|
|
|
221
221
|
}
|
|
222
222
|
if (isIt("empty")) {
|
|
223
223
|
const presetToBackup = unpackOne(input);
|
|
224
|
-
|
|
224
|
+
managementApi.presets
|
|
225
|
+
.getPreset(presetToBackup, apiConfig)
|
|
225
226
|
.then(async (res) => {
|
|
226
227
|
await createAndSaveToFile({
|
|
227
228
|
ext: "json",
|
|
@@ -241,7 +242,8 @@ export const backup = async (props) => {
|
|
|
241
242
|
case BACKUP_COMMANDS.componentPresets:
|
|
242
243
|
if (isIt("empty")) {
|
|
243
244
|
const componentPresetToBackup = unpackOne(input);
|
|
244
|
-
|
|
245
|
+
managementApi.presets
|
|
246
|
+
.getComponentPresets(componentPresetToBackup, apiConfig)
|
|
245
247
|
.then(async (res) => {
|
|
246
248
|
await createAndSaveToFile({
|
|
247
249
|
ext: "json",
|
|
@@ -265,7 +267,8 @@ export const backup = async (props) => {
|
|
|
265
267
|
};
|
|
266
268
|
}
|
|
267
269
|
allRemoteComponents.forEach(async (component) => {
|
|
268
|
-
|
|
270
|
+
managementApi.presets
|
|
271
|
+
.getComponentPresets(component.name, apiConfig)
|
|
269
272
|
.then(async (res) => {
|
|
270
273
|
if (res) {
|
|
271
274
|
await createAndSaveToFile({
|
|
@@ -286,7 +289,8 @@ export const backup = async (props) => {
|
|
|
286
289
|
case BACKUP_COMMANDS.plugins:
|
|
287
290
|
if (isIt("empty")) {
|
|
288
291
|
const pluginToBackup = unpackOne(input);
|
|
289
|
-
|
|
292
|
+
managementApi.plugins
|
|
293
|
+
.getPlugin(pluginToBackup, apiConfig)
|
|
290
294
|
.then(async (res) => {
|
|
291
295
|
if (res) {
|
|
292
296
|
await createAndSaveToFile({
|
|
@@ -306,7 +310,8 @@ export const backup = async (props) => {
|
|
|
306
310
|
Logger.log("Backing up provided plugins...");
|
|
307
311
|
}
|
|
308
312
|
if (flags["all"]) {
|
|
309
|
-
|
|
313
|
+
managementApi.plugins
|
|
314
|
+
.getAllPlugins(apiConfig)
|
|
310
315
|
.then(async (res) => {
|
|
311
316
|
await createAndSaveToFile({
|
|
312
317
|
ext: "json",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as fs from "fs";
|
|
2
2
|
import StoryblokClient from "storyblok-js-client";
|
|
3
3
|
import { v4 as uuidv4 } from "uuid";
|
|
4
|
-
import {
|
|
4
|
+
import { managementApi } from "../../api/managementApi.js";
|
|
5
5
|
import storyblokConfig from "../../config/config.js";
|
|
6
6
|
import Logger from "../../utils/logger.js";
|
|
7
7
|
import { apiConfig } from "../api-config.js";
|
|
@@ -23,7 +23,7 @@ export const init = async (props) => {
|
|
|
23
23
|
gtmToken,
|
|
24
24
|
});
|
|
25
25
|
const localSbApi = new StoryblokClient({ oauthToken }, storyblokApiUrl);
|
|
26
|
-
const spaceData = await getSpace(spaceId, apiConfig);
|
|
26
|
+
const spaceData = await managementApi.spaces.getSpace(spaceId, apiConfig);
|
|
27
27
|
const STORYBLOK_SPACE_ID = spaceId;
|
|
28
28
|
const STORYBLOK_OAUTH_TOKEN = oauthToken;
|
|
29
29
|
const NEXT_PUBLIC_GTM_ID = gtmToken ?? "put-your-gtm-token-here";
|
|
@@ -46,7 +46,7 @@ export const init = async (props) => {
|
|
|
46
46
|
console.log(e);
|
|
47
47
|
}
|
|
48
48
|
try {
|
|
49
|
-
await updateSpace({
|
|
49
|
+
await managementApi.spaces.updateSpace({
|
|
50
50
|
spaceId,
|
|
51
51
|
params: {
|
|
52
52
|
domain: `https://localhost:3000/api/preview/preview?secret=${STORYBLOK_PREVIEW_SECRET}&slug=`,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { managementApi } from "../../api/managementApi.js";
|
|
1
2
|
import { removeAllComponents, removeSpecifiedComponents, } from "../../api/migrate.js";
|
|
2
|
-
import { removeAllStories } from "../../api/stories/index.js";
|
|
3
3
|
import Logger from "../../utils/logger.js";
|
|
4
4
|
import { unpackElements } from "../../utils/main.js";
|
|
5
5
|
import { apiConfig } from "../api-config.js";
|
|
@@ -35,7 +35,10 @@ export const remove = async (props) => {
|
|
|
35
35
|
case REMOVE_COMMANDS.story:
|
|
36
36
|
Logger.warning(`Removing all stories from: ${flags.from}`);
|
|
37
37
|
if (flags["all"] && flags["from"]) {
|
|
38
|
-
await removeAllStories({
|
|
38
|
+
await managementApi.stories.removeAllStories({
|
|
39
|
+
...apiConfig,
|
|
40
|
+
spaceId: flags.from,
|
|
41
|
+
});
|
|
39
42
|
}
|
|
40
43
|
break;
|
|
41
44
|
default:
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { updateStories } from "../../api/stories/stories.js";
|
|
1
|
+
import { managementApi } from "../../api/managementApi.js";
|
|
3
2
|
import { discoverStories, LOOKUP_TYPE, SCOPE } from "../../utils/discover.js";
|
|
4
3
|
import Logger from "../../utils/logger.js";
|
|
5
4
|
import { getFilesContentWithRequire, isItFactory } from "../../utils/main.js";
|
|
@@ -28,7 +27,7 @@ export const revert = async (props) => {
|
|
|
28
27
|
const to = getTo(flags);
|
|
29
28
|
await askForConfirmation("Are you sure you want to revert migration of content (stories) in your space ? (it will overwrite stories)", async () => {
|
|
30
29
|
Logger.warning("Preparing to migrate...");
|
|
31
|
-
await backupStories({
|
|
30
|
+
await managementApi.stories.backupStories({
|
|
32
31
|
filename: `${to}--backup-before-revert`,
|
|
33
32
|
suffix: ".sb.stories",
|
|
34
33
|
spaceId: to,
|
|
@@ -41,7 +40,7 @@ export const revert = async (props) => {
|
|
|
41
40
|
const stories = getFilesContentWithRequire({
|
|
42
41
|
files: allLocalStories,
|
|
43
42
|
});
|
|
44
|
-
await updateStories({
|
|
43
|
+
await managementApi.stories.updateStories({
|
|
45
44
|
stories,
|
|
46
45
|
spaceId: to,
|
|
47
46
|
options: { publish: false },
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { managementApi } from "../../api/managementApi.js";
|
|
2
2
|
import { removeAllComponents, syncAllComponents, syncContent, syncProvidedComponents, } from "../../api/migrate.js";
|
|
3
|
-
import { syncProvidedPlugins } from "../../api/plugins/plugins.js";
|
|
4
|
-
import { syncAllRoles, syncProvidedRoles } from "../../api/roles/roles.js";
|
|
5
|
-
import { removeAllStories } from "../../api/stories/index.js";
|
|
6
3
|
import storyblokConfig from "../../config/config.js";
|
|
7
4
|
import Logger from "../../utils/logger.js";
|
|
8
5
|
import { isItFactory, unpackElements } from "../../utils/main.js";
|
|
@@ -63,23 +60,23 @@ export const sync = async (props) => {
|
|
|
63
60
|
case SYNC_COMMANDS.roles:
|
|
64
61
|
if (isIt("all")) {
|
|
65
62
|
Logger.log("Syncing all roles...");
|
|
66
|
-
syncAllRoles(apiConfig);
|
|
63
|
+
managementApi.roles.syncAllRoles(apiConfig);
|
|
67
64
|
}
|
|
68
65
|
if (isIt("empty")) {
|
|
69
66
|
Logger.log("Syncing provided roles...");
|
|
70
67
|
const rolesToSync = unpackElements(input);
|
|
71
|
-
syncProvidedRoles({ roles: rolesToSync }, apiConfig);
|
|
68
|
+
managementApi.roles.syncProvidedRoles({ roles: rolesToSync }, apiConfig);
|
|
72
69
|
}
|
|
73
70
|
break;
|
|
74
71
|
case SYNC_COMMANDS.datasources:
|
|
75
72
|
if (isIt("all")) {
|
|
76
73
|
Logger.log("Syncing all datasources with extension...");
|
|
77
|
-
syncAllDatasources(apiConfig);
|
|
74
|
+
managementApi.datasources.syncAllDatasources(apiConfig);
|
|
78
75
|
}
|
|
79
76
|
if (!flags["all"]) {
|
|
80
77
|
Logger.log("Syncing provided datasources with extension...");
|
|
81
78
|
const datasourcesToSync = unpackElements(input);
|
|
82
|
-
syncProvidedDatasources({ datasources: datasourcesToSync }, apiConfig);
|
|
79
|
+
managementApi.datasources.syncProvidedDatasources({ datasources: datasourcesToSync }, apiConfig);
|
|
83
80
|
}
|
|
84
81
|
break;
|
|
85
82
|
case SYNC_COMMANDS.content:
|
|
@@ -117,7 +114,7 @@ export const sync = async (props) => {
|
|
|
117
114
|
syncDirection: "fromSpaceToFile",
|
|
118
115
|
}, apiConfig);
|
|
119
116
|
// Remove all stories from 'to' space
|
|
120
|
-
await removeAllStories({
|
|
117
|
+
await managementApi.stories.removeAllStories({
|
|
121
118
|
...apiConfig,
|
|
122
119
|
spaceId: to,
|
|
123
120
|
});
|
|
@@ -173,7 +170,7 @@ export const sync = async (props) => {
|
|
|
173
170
|
syncDirection: "fromSpaceToFile",
|
|
174
171
|
}, apiConfig);
|
|
175
172
|
// Remove all stories from 'to' space
|
|
176
|
-
await removeAllStories({
|
|
173
|
+
await managementApi.stories.removeAllStories({
|
|
177
174
|
...apiConfig,
|
|
178
175
|
spaceId: to,
|
|
179
176
|
});
|
|
@@ -212,7 +209,7 @@ export const sync = async (props) => {
|
|
|
212
209
|
if (!flags["all"]) {
|
|
213
210
|
Logger.warning("Synchronizing PROVIDED plugins...");
|
|
214
211
|
const pluginsToSync = unpackElements(input);
|
|
215
|
-
await syncProvidedPlugins({
|
|
212
|
+
await managementApi.plugins.syncProvidedPlugins({
|
|
216
213
|
plugins: pluginsToSync,
|
|
217
214
|
}, apiConfig);
|
|
218
215
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sb-mig",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.3",
|
|
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",
|
|
@@ -47,7 +47,6 @@
|
|
|
47
47
|
"test": "mocha ./dist-tests/__tests__ --require esm",
|
|
48
48
|
"start": "yarn build && ./dist/cli/index.js",
|
|
49
49
|
"debug": "yarn build && ./dist/cli/index.js sync components accordion accordion-item",
|
|
50
|
-
"version": "conventional-changelog -p eslint -i CHANGELOG.md -s",
|
|
51
50
|
"semantic-release": "semantic-release",
|
|
52
51
|
"prepare": "husky install"
|
|
53
52
|
},
|
|
@@ -88,7 +87,6 @@
|
|
|
88
87
|
"@typescript-eslint/parser": "^5.59.11",
|
|
89
88
|
"chai": "^4.3.7",
|
|
90
89
|
"chokidar-cli": "^3.0.0",
|
|
91
|
-
"conventional-changelog-cli": "^3.0.0",
|
|
92
90
|
"eslint": "^8.42.0",
|
|
93
91
|
"eslint-config-prettier": "^8.8.0",
|
|
94
92
|
"eslint-plugin-import": "^2.27.5",
|