sb-mig 5.6.1-beta.1 → 5.6.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.
@@ -49,7 +49,7 @@ export const getDatasourceEntries = async (args, config) => {
49
49
  };
50
50
  export const createDatasourceEntries = (args, config) => {
51
51
  const { datasource_entries, remoteDatasourceEntries, data } = args;
52
- Promise.all(datasource_entries.map((datasourceEntry) => {
52
+ return Promise.all(datasource_entries.map((datasourceEntry) => {
53
53
  const datasourceToBeUpdated = remoteDatasourceEntries.datasource_entries.find((remoteDatasourceEntry) => remoteDatasourceEntry.name ===
54
54
  Object.values(datasourceEntry)[0]);
55
55
  if (datasourceToBeUpdated) {
@@ -13,11 +13,11 @@ import { resolveGlobalTransformations } from "./utils/resolverTransformations.js
13
13
  const _checkAndPrepareGroups = async (groupsToCheck, config) => {
14
14
  const componentsGroups = await managementApi.components.getAllComponentsGroups(config);
15
15
  const groupExist = (groupName) => componentsGroups.find((group) => group.name === groupName);
16
- groupsToCheck.forEach(async (groupName) => {
16
+ for (const groupName of groupsToCheck) {
17
17
  if (!groupExist(groupName)) {
18
18
  await managementApi.components.createComponentsGroup(groupName, config);
19
19
  }
20
- });
20
+ }
21
21
  };
22
22
  export const removeAllComponents = async (config) => {
23
23
  const components = await managementApi.components.getAllComponents(config);
@@ -40,7 +40,7 @@ export const removeSpecifiedComponents = async (components, config) => {
40
40
  });
41
41
  return (componentsToRemove.length > 0 &&
42
42
  Promise.all(componentsToRemove.map((component) => {
43
- managementApi.components.removeComponent(component, config);
43
+ return managementApi.components.removeComponent(component, config);
44
44
  })));
45
45
  };
46
46
  const _resolveGroups = async (component, existedGroups, remoteComponentsGroups) => {
@@ -131,14 +131,14 @@ export const syncProvidedComponents = async (presets, components, packageName, c
131
131
  export const syncAssets = async ({ transmission: { from, to }, syncDirection }, config) => {
132
132
  Logger.log(`We would try to migrate Assets data from: ${from} to: ${to}`);
133
133
  const allAssets = await getAllAssets({ spaceId: from }, config);
134
- allAssets.assets.map((asset) => {
134
+ await Promise.all(allAssets.assets.map((asset) => {
135
135
  const { id, created_at, updated_at, ...newAssetPayload } = asset;
136
- migrateAsset({
136
+ return migrateAsset({
137
137
  migrateTo: to,
138
138
  payload: newAssetPayload,
139
139
  syncDirection,
140
140
  }, config);
141
- });
141
+ }));
142
142
  };
143
143
  const syncStories = async ({ transmission: { from, to }, stories, toSpaceId }, config) => {
144
144
  Logger.log(`We would try to migrate Stories data from: ${from} to: ${to}`);
@@ -238,7 +238,7 @@ export const setComponentDefaultPreset = async ({ presets, componentsToSync, api
238
238
  });
239
239
  Logger.warning("Updating componet with default presets...");
240
240
  return Promise.all(finalRemoteComponents.map((component) => {
241
- managementApi.components.updateComponent(component, false, apiConfig);
241
+ return managementApi.components.updateComponent(component, false, apiConfig);
242
242
  }));
243
243
  }
244
244
  else {
@@ -21,9 +21,9 @@ const buildTree = (nodes, parentId = null, storiesToUpdate = []) => {
21
21
  });
22
22
  return tree;
23
23
  };
24
- export const traverseAndCreate = (input, config) => {
24
+ export const traverseAndCreate = async (input, config) => {
25
25
  const { tree, realParentId, spaceId } = input;
26
- tree.forEach(async (node) => {
26
+ for (const node of tree) {
27
27
  try {
28
28
  const { action, story } = node;
29
29
  const { parent, ...content } = story;
@@ -37,7 +37,7 @@ export const traverseAndCreate = (input, config) => {
37
37
  storyId = result.story.id;
38
38
  }
39
39
  if (node.children) {
40
- traverseAndCreate({
40
+ await traverseAndCreate({
41
41
  tree: node.children,
42
42
  realParentId: storyId,
43
43
  spaceId,
@@ -48,5 +48,5 @@ export const traverseAndCreate = (input, config) => {
48
48
  Logger.error("Error happened");
49
49
  Logger.error(e);
50
50
  }
51
- });
51
+ }
52
52
  };
@@ -12,4 +12,4 @@ export type TraverseAndCreate = (input: {
12
12
  realParentId: number | null;
13
13
  defaultRoot?: any;
14
14
  spaceId: string;
15
- }, config: RequestBaseConfig) => void;
15
+ }, config: RequestBaseConfig) => Promise<void>;
@@ -77,7 +77,7 @@ export const backup = async (props) => {
77
77
  case BACKUP_COMMANDS.stories:
78
78
  Logger.warning(`back up stories... with command: ${command}`);
79
79
  if (flags["all"]) {
80
- backupStories({
80
+ await backupStories({
81
81
  filename: "all-stories-backup",
82
82
  suffix: ".stories",
83
83
  spaceId: storyblokConfig.spaceId,
@@ -267,10 +267,9 @@ export const backup = async (props) => {
267
267
  metadata: extractFields(pkgJson, storyblokConfig.metadataSelection),
268
268
  };
269
269
  }
270
- allRemoteComponents.forEach(async (component) => {
271
- managementApi.presets
272
- .getComponentPresets(component.name, apiConfig)
273
- .then(async (res) => {
270
+ for (const component of allRemoteComponents) {
271
+ try {
272
+ const res = await managementApi.presets.getComponentPresets(component.name, apiConfig);
274
273
  if (res) {
275
274
  await createAndSaveToFile({
276
275
  ext: "json",
@@ -282,12 +281,12 @@ export const backup = async (props) => {
282
281
  sbmigWorkingDirectory: ".",
283
282
  });
284
283
  }
285
- })
286
- .catch((err) => {
284
+ }
285
+ catch (err) {
287
286
  console.log(err);
288
287
  Logger.error("error happened... :(");
289
- });
290
- });
288
+ }
289
+ }
291
290
  }
292
291
  break;
293
292
  case BACKUP_COMMANDS.plugins:
@@ -21,7 +21,7 @@ export const remove = async (props) => {
21
21
  if (!flags["all"]) {
22
22
  Logger.warning("Removing PROVIDED components...");
23
23
  const componentToRemove = unpackElements(input);
24
- removeSpecifiedComponents({
24
+ await removeSpecifiedComponents({
25
25
  components: componentToRemove,
26
26
  }, apiConfig);
27
27
  }
@@ -71,12 +71,12 @@ export const sync = async (props) => {
71
71
  case SYNC_COMMANDS.roles:
72
72
  if (isIt("all")) {
73
73
  Logger.log("Syncing all roles...");
74
- syncAllRoles(apiConfig);
74
+ await syncAllRoles(apiConfig);
75
75
  }
76
76
  if (isIt("empty")) {
77
77
  Logger.log("Syncing provided roles...");
78
78
  const rolesToSync = unpackElements(input);
79
- syncProvidedRoles({ roles: rolesToSync }, apiConfig);
79
+ await syncProvidedRoles({ roles: rolesToSync }, apiConfig);
80
80
  }
81
81
  break;
82
82
  case SYNC_COMMANDS.datasources:
@@ -1 +1 @@
1
- export declare const askForConfirmation: (message: string, resolveYes: () => void, resolveNo: () => void, ci?: boolean) => Promise<void>;
1
+ export declare const askForConfirmation: (message: string, resolveYes: () => void | Promise<void>, resolveNo: () => void | Promise<void>, ci?: boolean) => Promise<void>;
@@ -2,7 +2,7 @@ import readline from "node:readline/promises";
2
2
  import chalk from "chalk";
3
3
  export const askForConfirmation = async (message, resolveYes, resolveNo, ci) => {
4
4
  if (ci) {
5
- resolveYes();
5
+ await resolveYes();
6
6
  return;
7
7
  }
8
8
  // This section has to be changed, it was fast solution to asking for confirmation
@@ -22,12 +22,12 @@ export const askForConfirmation = async (message, resolveYes, resolveNo, ci) =>
22
22
  rl.prompt();
23
23
  for await (const deletionConfirmation of rl) {
24
24
  if (deletionConfirmation.trim() !== "y") {
25
- resolveNo();
25
+ await resolveNo();
26
26
  process.exit(0);
27
27
  }
28
28
  else {
29
29
  if (deletionConfirmation) {
30
- resolveYes();
30
+ await resolveYes();
31
31
  break;
32
32
  }
33
33
  }
package/dist/cli/index.js CHANGED
File without changes
@@ -38,7 +38,7 @@ export const discoverManyByPackageName = (request) => {
38
38
  follow: true,
39
39
  });
40
40
  listOfFiles = listOfPackagesJsonFiles
41
- .filter(async (file) => request.packageNames.includes(await getFileContentWithRequire({ file }).name)) // filter only package.json from provided request.packageNames
41
+ .filter((file) => request.packageNames.includes(getFileContentWithRequire({ file }).name)) // filter only package.json from provided request.packageNames
42
42
  .map((file) => {
43
43
  // get path to folder in which current package.json is
44
44
  const fileFolderPath = file
@@ -13,27 +13,35 @@ export const buildOnTheFly = async ({ files }) => {
13
13
  }
14
14
  const projectDir = process.cwd();
15
15
  const cacheDir = path.join(`${projectDir}`, `${storyblokConfig.cacheDir}`, `sb-mig`);
16
- await Promise.all(files.map(async (filePath) => {
17
- const inputOptions = {
18
- input: filePath,
19
- plugins: [
20
- ts({
21
- transpileOnly: true,
22
- transpiler: "swc",
23
- }),
24
- ],
25
- };
26
- const outputOptionsList = [
27
- {
28
- file: path.join(`${cacheDir}`, `${_extractComponentName(filePath)}.cjs`),
29
- format: "cjs",
30
- },
31
- {
32
- file: path.join(`${cacheDir}`, `${_extractComponentName(filePath)}.js`),
33
- format: "es",
34
- },
35
- ];
36
- await build({ inputOptions, outputOptionsList });
37
- }));
38
- Logger.success("Precompile successfull!.");
16
+ const BATCH_SIZE = 5;
17
+ const total = files.length;
18
+ Logger.log(`Compiling ${total} schema files...`);
19
+ for (let i = 0; i < total; i += BATCH_SIZE) {
20
+ const batch = files.slice(i, i + BATCH_SIZE);
21
+ const batchEnd = Math.min(i + BATCH_SIZE, total);
22
+ Logger.log(`[${i + 1}-${batchEnd}/${total}] Compiling batch...`);
23
+ await Promise.all(batch.map(async (filePath) => {
24
+ const inputOptions = {
25
+ input: filePath,
26
+ plugins: [
27
+ ts({
28
+ transpileOnly: true,
29
+ transpiler: "swc",
30
+ }),
31
+ ],
32
+ };
33
+ const outputOptionsList = [
34
+ {
35
+ file: path.join(`${cacheDir}`, `${_extractComponentName(filePath)}.cjs`),
36
+ format: "cjs",
37
+ },
38
+ {
39
+ file: path.join(`${cacheDir}`, `${_extractComponentName(filePath)}.js`),
40
+ format: "es",
41
+ },
42
+ ];
43
+ await build({ inputOptions, outputOptionsList });
44
+ }));
45
+ }
46
+ Logger.success(`Precompile successful! (${total} files)`);
39
47
  };
@@ -1,20 +1,20 @@
1
1
  import { rollup } from "rollup";
2
2
  export async function build({ inputOptions, outputOptionsList }) {
3
3
  let bundle;
4
- let buildFailed = false;
5
4
  try {
6
5
  bundle = await rollup(inputOptions);
7
6
  await generateOutputs({ bundle, outputOptionsList });
8
7
  return [];
9
8
  }
10
9
  catch (error) {
11
- buildFailed = true;
12
10
  console.error(error);
11
+ throw error;
13
12
  }
14
- if (bundle) {
15
- await bundle.close();
13
+ finally {
14
+ if (bundle) {
15
+ await bundle.close();
16
+ }
16
17
  }
17
- process.exit(buildFailed ? 1 : 0);
18
18
  }
19
19
  async function generateOutputs({ bundle, outputOptionsList }) {
20
20
  for (const outputOptions of outputOptionsList) {
@@ -56,7 +56,7 @@ const getDatasourceEntries = async (args, config) => {
56
56
  exports.getDatasourceEntries = getDatasourceEntries;
57
57
  const createDatasourceEntries = (args, config) => {
58
58
  const { datasource_entries, remoteDatasourceEntries, data } = args;
59
- Promise.all(datasource_entries.map((datasourceEntry) => {
59
+ return Promise.all(datasource_entries.map((datasourceEntry) => {
60
60
  const datasourceToBeUpdated = remoteDatasourceEntries.datasource_entries.find((remoteDatasourceEntry) => remoteDatasourceEntry.name ===
61
61
  Object.values(datasourceEntry)[0]);
62
62
  if (datasourceToBeUpdated) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sb-mig",
3
- "version": "5.6.1-beta.1",
3
+ "version": "5.6.1",
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",