storyblok 3.32.3 → 3.33.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/cli.mjs +53 -31
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1888,7 +1888,7 @@ const pullComponents = async (api, options) => {
|
|
|
1888
1888
|
return;
|
|
1889
1889
|
}
|
|
1890
1890
|
const file = `components.${fileName}.json`;
|
|
1891
|
-
const data = JSON.stringify({ components }, null, 2);
|
|
1891
|
+
const data = JSON.stringify({ components, component_groups: componentGroups }, null, 2);
|
|
1892
1892
|
console.log(`${chalk.green("\u2713")} We've saved your components in the file: ${file}`);
|
|
1893
1893
|
saveFileFactory(file, data, path);
|
|
1894
1894
|
if (presets.length === 0)
|
|
@@ -1929,6 +1929,7 @@ const pullLanguages = async (api, options) => {
|
|
|
1929
1929
|
|
|
1930
1930
|
const { isEmpty: isEmpty$3 } = lodash;
|
|
1931
1931
|
const isUrl$1 = (source) => source.indexOf("http") === 0;
|
|
1932
|
+
const listOfGroups = [];
|
|
1932
1933
|
const getGroupByName = (groups, name) => {
|
|
1933
1934
|
return groups.find((group) => group.name === name) || {};
|
|
1934
1935
|
};
|
|
@@ -1972,41 +1973,62 @@ const pushComponents = async (api, { source, presetsSource }) => {
|
|
|
1972
1973
|
const components = createContentList$1(rawComponents, "components");
|
|
1973
1974
|
const rawPresets = await getDataFromPath$1(presetsSource);
|
|
1974
1975
|
const presets = createContentList$1(rawPresets, "presets");
|
|
1975
|
-
|
|
1976
|
+
const componentGroups = createContentList$1(rawComponents, "component_groups");
|
|
1977
|
+
return push(api, components, componentGroups, presets);
|
|
1976
1978
|
} catch (err) {
|
|
1977
1979
|
console.error(`${chalk.red("X")} Can not push invalid json - please provide a valid json file`);
|
|
1978
1980
|
return Promise.reject(new Error("Can not push invalid json - please provide a valid json file"));
|
|
1979
1981
|
}
|
|
1980
1982
|
};
|
|
1981
|
-
const
|
|
1982
|
-
const
|
|
1983
|
+
const buildComponentsGroupsTree = (groups) => {
|
|
1984
|
+
const map = /* @__PURE__ */ new Map();
|
|
1985
|
+
const roots = [];
|
|
1986
|
+
groups.forEach((component) => {
|
|
1987
|
+
map.set(component.id, { ...component, children: [] });
|
|
1988
|
+
});
|
|
1989
|
+
groups.forEach((component) => {
|
|
1990
|
+
if (component.parent_id === null) {
|
|
1991
|
+
roots.push(map.get(component.id));
|
|
1992
|
+
} else {
|
|
1993
|
+
const parent = map.get(component.parent_id);
|
|
1994
|
+
if (parent) {
|
|
1995
|
+
parent.children.push(map.get(component.id));
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
});
|
|
1999
|
+
return roots;
|
|
2000
|
+
};
|
|
2001
|
+
const pushComponentsGroups = async (api, group) => {
|
|
2002
|
+
const groupName = group.name;
|
|
1983
2003
|
try {
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
if (!currentGroup.name) {
|
|
1990
|
-
try {
|
|
1991
|
-
console.log(`${chalk.blue("-")} Creating the ${groupName} component group...`);
|
|
1992
|
-
const newGroup = await api.post("component_groups", {
|
|
1993
|
-
component_group: {
|
|
1994
|
-
name: groupName
|
|
1995
|
-
}
|
|
1996
|
-
});
|
|
1997
|
-
componentsGroups.push({
|
|
1998
|
-
...newGroup.data.component_group,
|
|
1999
|
-
source_uuid: components[i].component_group_uuid
|
|
2000
|
-
});
|
|
2001
|
-
} catch (err) {
|
|
2002
|
-
console.log(
|
|
2003
|
-
`${chalk.yellow("-")} Components group ${groupName} already exists...`
|
|
2004
|
-
);
|
|
2005
|
-
}
|
|
2006
|
-
} else {
|
|
2007
|
-
currentGroup.source_uuid = components[i].component_group_uuid;
|
|
2008
|
-
}
|
|
2004
|
+
console.log(`${chalk.blue("-")} Creating the ${groupName} component group...`);
|
|
2005
|
+
const newGroup = await api.post("component_groups", {
|
|
2006
|
+
component_group: {
|
|
2007
|
+
name: groupName,
|
|
2008
|
+
parent_id: group.parent_id
|
|
2009
2009
|
}
|
|
2010
|
+
});
|
|
2011
|
+
listOfGroups.push(newGroup.data.component_group);
|
|
2012
|
+
for (const child of group.children) {
|
|
2013
|
+
const children = {
|
|
2014
|
+
...child,
|
|
2015
|
+
parent_id: newGroup.data.component_group.id
|
|
2016
|
+
};
|
|
2017
|
+
await pushComponentsGroups(api, children);
|
|
2018
|
+
}
|
|
2019
|
+
} catch (err) {
|
|
2020
|
+
console.log(err);
|
|
2021
|
+
console.log(
|
|
2022
|
+
`${chalk.yellow("-")} Components group ${groupName} already exists...`
|
|
2023
|
+
);
|
|
2024
|
+
}
|
|
2025
|
+
};
|
|
2026
|
+
const push = async (api, components, componentsGroups = [], presets = []) => {
|
|
2027
|
+
const presetsLib = new PresetsLib({ oauthToken: api.accessToken, targetSpaceId: api.spaceId });
|
|
2028
|
+
try {
|
|
2029
|
+
const componentGroupsTree = buildComponentsGroupsTree(componentsGroups);
|
|
2030
|
+
for (const rootComponent of componentGroupsTree) {
|
|
2031
|
+
await pushComponentsGroups(api, rootComponent);
|
|
2010
2032
|
}
|
|
2011
2033
|
const apiComponents = await api.getComponents();
|
|
2012
2034
|
for (let i = 0; i < components.length; i++) {
|
|
@@ -2015,7 +2037,7 @@ const push = async (api, components, presets = []) => {
|
|
|
2015
2037
|
delete components[i].id;
|
|
2016
2038
|
delete components[i].created_at;
|
|
2017
2039
|
const groupName = components[i].component_group_name;
|
|
2018
|
-
const groupData = getGroupByName(
|
|
2040
|
+
const groupData = getGroupByName(listOfGroups, groupName);
|
|
2019
2041
|
if (groupName) {
|
|
2020
2042
|
components[i].component_group_uuid = groupData.uuid;
|
|
2021
2043
|
delete components[i].component_group_name;
|
|
@@ -2025,7 +2047,7 @@ const push = async (api, components, presets = []) => {
|
|
|
2025
2047
|
Object.keys(schema).forEach((field) => {
|
|
2026
2048
|
if (schema[field].component_group_whitelist) {
|
|
2027
2049
|
schema[field].component_group_whitelist = schema[field].component_group_whitelist.map(
|
|
2028
|
-
(uuid) => getGroupByUuid(
|
|
2050
|
+
(uuid) => getGroupByUuid(listOfGroups, uuid) ? getGroupByUuid(listOfGroups, uuid).uuid : uuid
|
|
2029
2051
|
);
|
|
2030
2052
|
}
|
|
2031
2053
|
});
|