sb-mig 6.0.0 → 6.0.1-beta.1
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/contentHubApi.js +14 -4
- package/dist/cli/commands/init.js +10 -1
- package/dist/cli/index.js +0 -0
- package/dist/utils/path-utils.js +6 -2
- package/dist/utils/url-utils.d.ts +8 -0
- package/dist/utils/url-utils.js +12 -0
- package/dist-cjs/utils/path-utils.js +6 -2
- package/package.json +1 -1
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
import Logger from "../utils/logger.js";
|
|
2
|
+
import { buildUrl } from "../utils/url-utils.js";
|
|
2
3
|
const getAllStories = async (args, config) => {
|
|
3
4
|
const { spaceId, storiesFilename } = args;
|
|
4
5
|
Logger.warning("Trying to get all stories from Content Hub...");
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
if (!config.contentHubOriginUrl) {
|
|
7
|
+
throw new Error("contentHubOriginUrl is required to fetch stories.");
|
|
8
|
+
}
|
|
9
|
+
const url = buildUrl({
|
|
10
|
+
baseUrl: config.contentHubOriginUrl,
|
|
11
|
+
pathname: "getStories",
|
|
12
|
+
searchParams: {
|
|
13
|
+
spaceId,
|
|
14
|
+
...(storiesFilename ? { storiesFilename } : {}),
|
|
15
|
+
},
|
|
16
|
+
});
|
|
7
17
|
const authorizationToken = config.contentHubAuthorizationToken;
|
|
8
18
|
if (config.debug) {
|
|
9
|
-
console.log("This is url: ", url);
|
|
19
|
+
console.log("This is url: ", url.toString());
|
|
10
20
|
}
|
|
11
21
|
try {
|
|
12
|
-
const response = await fetch(url, {
|
|
22
|
+
const response = await fetch(url.toString(), {
|
|
13
23
|
method: "GET",
|
|
14
24
|
headers: {
|
|
15
25
|
Authorization: authorizationToken,
|
|
@@ -4,6 +4,7 @@ import { v4 as uuidv4 } from "uuid";
|
|
|
4
4
|
import { managementApi } from "../../api/managementApi.js";
|
|
5
5
|
import { storyblokApiMapping } from "../../config/constants.js";
|
|
6
6
|
import Logger from "../../utils/logger.js";
|
|
7
|
+
import { buildUrl } from "../../utils/url-utils.js";
|
|
7
8
|
import { apiConfig } from "../api-config.js";
|
|
8
9
|
const INIT_COMMANDS = {
|
|
9
10
|
project: "project",
|
|
@@ -59,10 +60,18 @@ export const init = async (props) => {
|
|
|
59
60
|
console.log(e);
|
|
60
61
|
}
|
|
61
62
|
try {
|
|
63
|
+
const previewDomainUrl = buildUrl({
|
|
64
|
+
baseUrl: "https://localhost:3000",
|
|
65
|
+
pathname: "api/preview/preview",
|
|
66
|
+
searchParams: {
|
|
67
|
+
secret: STORYBLOK_PREVIEW_SECRET,
|
|
68
|
+
slug: "",
|
|
69
|
+
},
|
|
70
|
+
});
|
|
62
71
|
await managementApi.spaces.updateSpace({
|
|
63
72
|
spaceId,
|
|
64
73
|
params: {
|
|
65
|
-
domain:
|
|
74
|
+
domain: previewDomainUrl.toString(),
|
|
66
75
|
},
|
|
67
76
|
}, { ...apiConfig, sbApi: localSbApi });
|
|
68
77
|
Logger.success("Successfully updated space domain");
|
package/dist/cli/index.js
CHANGED
|
File without changes
|
package/dist/utils/path-utils.js
CHANGED
|
@@ -22,6 +22,10 @@ export const extractComponentName = (filePath) => {
|
|
|
22
22
|
const lastElement = normalized.substring(normalized.lastIndexOf("/") + 1);
|
|
23
23
|
return lastElement.replace(/\.ts$/, "");
|
|
24
24
|
};
|
|
25
|
+
const getFileName = (filePath) => {
|
|
26
|
+
const normalized = filePath.replace(/\\/g, "/");
|
|
27
|
+
return normalized.substring(normalized.lastIndexOf("/") + 1);
|
|
28
|
+
};
|
|
25
29
|
/**
|
|
26
30
|
* Normalizes an array of directory segments for glob pattern usage.
|
|
27
31
|
* Handles the glob.sync quirk where single segments don't need braces,
|
|
@@ -102,13 +106,13 @@ export const exactFilesPatterns = ({ mainDirectory, componentDirectories, fileNa
|
|
|
102
106
|
export const compare = (request) => {
|
|
103
107
|
const { local, external } = request;
|
|
104
108
|
const splittedLocal = local.map((p) => ({
|
|
105
|
-
name:
|
|
109
|
+
name: getFileName(p),
|
|
106
110
|
p,
|
|
107
111
|
}));
|
|
108
112
|
const localNames = new Set(splittedLocal.map((file) => file.name));
|
|
109
113
|
const splittedExternal = external
|
|
110
114
|
.map((p) => ({
|
|
111
|
-
name:
|
|
115
|
+
name: getFileName(p),
|
|
112
116
|
p,
|
|
113
117
|
}))
|
|
114
118
|
.filter((file) => {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type SearchParamValue = string | number | boolean | null | undefined;
|
|
2
|
+
type BuildUrlArgs = {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
pathname?: string;
|
|
5
|
+
searchParams?: Record<string, SearchParamValue>;
|
|
6
|
+
};
|
|
7
|
+
export declare const buildUrl: ({ baseUrl, pathname, searchParams, }: BuildUrlArgs) => URL;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const withTrailingSlash = (value) => value.endsWith("/") ? value : `${value}/`;
|
|
2
|
+
const normalizePathname = (pathname = "") => pathname.replace(/^\/+/, "");
|
|
3
|
+
export const buildUrl = ({ baseUrl, pathname, searchParams = {}, }) => {
|
|
4
|
+
const url = new URL(normalizePathname(pathname), withTrailingSlash(baseUrl));
|
|
5
|
+
for (const [key, value] of Object.entries(searchParams)) {
|
|
6
|
+
if (value === undefined || value === null) {
|
|
7
|
+
continue;
|
|
8
|
+
}
|
|
9
|
+
url.searchParams.set(key, String(value));
|
|
10
|
+
}
|
|
11
|
+
return url;
|
|
12
|
+
};
|
|
@@ -29,6 +29,10 @@ const extractComponentName = (filePath) => {
|
|
|
29
29
|
return lastElement.replace(/\.ts$/, "");
|
|
30
30
|
};
|
|
31
31
|
exports.extractComponentName = extractComponentName;
|
|
32
|
+
const getFileName = (filePath) => {
|
|
33
|
+
const normalized = filePath.replace(/\\/g, "/");
|
|
34
|
+
return normalized.substring(normalized.lastIndexOf("/") + 1);
|
|
35
|
+
};
|
|
32
36
|
/**
|
|
33
37
|
* Normalizes an array of directory segments for glob pattern usage.
|
|
34
38
|
* Handles the glob.sync quirk where single segments don't need braces,
|
|
@@ -112,13 +116,13 @@ exports.exactFilesPatterns = exactFilesPatterns;
|
|
|
112
116
|
const compare = (request) => {
|
|
113
117
|
const { local, external } = request;
|
|
114
118
|
const splittedLocal = local.map((p) => ({
|
|
115
|
-
name:
|
|
119
|
+
name: getFileName(p),
|
|
116
120
|
p,
|
|
117
121
|
}));
|
|
118
122
|
const localNames = new Set(splittedLocal.map((file) => file.name));
|
|
119
123
|
const splittedExternal = external
|
|
120
124
|
.map((p) => ({
|
|
121
|
-
name:
|
|
125
|
+
name: getFileName(p),
|
|
122
126
|
p,
|
|
123
127
|
}))
|
|
124
128
|
.filter((file) => {
|