sb-mig 5.5.4-beta.1 → 5.6.0-beta.2

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.
Files changed (175) hide show
  1. package/README.md +20 -19
  2. package/dist/api/assets/assets.js +1 -14
  3. package/dist/api/components/components.js +2 -1
  4. package/dist/api/components/components.sync.d.ts +8 -0
  5. package/dist/api/components/components.sync.js +193 -0
  6. package/dist/api/data-migration/component-data-migration.d.ts +6 -2
  7. package/dist/api/data-migration/component-data-migration.js +35 -11
  8. package/dist/api/datasources/datasource-entries.js +4 -5
  9. package/dist/api/datasources/datasources.d.ts +5 -2
  10. package/dist/api/datasources/datasources.js +42 -35
  11. package/dist/api/datasources/datasources.sync.d.ts +2 -0
  12. package/dist/api/datasources/datasources.sync.js +11 -0
  13. package/dist/api/datasources/datasources.types.d.ts +1 -1
  14. package/dist/api/datasources/index.d.ts +2 -1
  15. package/dist/api/datasources/index.js +2 -1
  16. package/dist/api/managementApi.d.ts +2 -2
  17. package/dist/api/migrate.d.ts +1 -1
  18. package/dist/api/migrate.js +3 -48
  19. package/dist/api/plugins/index.d.ts +2 -1
  20. package/dist/api/plugins/index.js +2 -1
  21. package/dist/api/plugins/plugins.d.ts +7 -2
  22. package/dist/api/plugins/plugins.js +28 -15
  23. package/dist/api/plugins/plugins.sync.d.ts +2 -0
  24. package/dist/api/plugins/plugins.sync.js +11 -0
  25. package/dist/api/roles/index.d.ts +2 -1
  26. package/dist/api/roles/index.js +2 -1
  27. package/dist/api/roles/roles.d.ts +5 -2
  28. package/dist/api/roles/roles.js +34 -11
  29. package/dist/api/roles/roles.sync.d.ts +2 -0
  30. package/dist/api/roles/roles.sync.js +6 -0
  31. package/dist/api/roles/roles.types.d.ts +1 -1
  32. package/dist/api/stories/stories.js +5 -13
  33. package/dist/api/sync/sync.types.d.ts +30 -0
  34. package/dist/api/sync/sync.types.js +1 -0
  35. package/dist/api/testApi.d.ts +2 -2
  36. package/dist/api/utils/helper-functions.d.ts +5 -1
  37. package/dist/api/utils/helper-functions.js +6 -1
  38. package/dist/api/utils/request.d.ts +1 -1
  39. package/dist/api/utils/request.js +11 -2
  40. package/dist/api/utils/resolverTransformations.js +2 -57
  41. package/dist/api-v2/assets/index.d.ts +13 -0
  42. package/dist/api-v2/assets/index.js +25 -0
  43. package/dist/api-v2/auth/index.d.ts +3 -0
  44. package/dist/api-v2/auth/index.js +8 -0
  45. package/dist/api-v2/client.d.ts +13 -0
  46. package/dist/api-v2/client.js +17 -0
  47. package/dist/api-v2/components/index.d.ts +10 -0
  48. package/dist/api-v2/components/index.js +29 -0
  49. package/dist/api-v2/datasources/index.d.ts +8 -0
  50. package/dist/api-v2/datasources/index.js +58 -0
  51. package/dist/api-v2/discover/discover.d.ts +36 -0
  52. package/dist/api-v2/discover/discover.js +281 -0
  53. package/dist/api-v2/discover/index.d.ts +2 -0
  54. package/dist/api-v2/discover/index.js +1 -0
  55. package/dist/api-v2/index.d.ts +19 -0
  56. package/dist/api-v2/index.js +21 -0
  57. package/dist/api-v2/plugins/index.d.ts +9 -0
  58. package/dist/api-v2/plugins/index.js +42 -0
  59. package/dist/api-v2/precompile/index.d.ts +2 -0
  60. package/dist/api-v2/precompile/index.js +1 -0
  61. package/dist/api-v2/precompile/precompile.d.ts +65 -0
  62. package/dist/api-v2/precompile/precompile.js +127 -0
  63. package/dist/api-v2/presets/index.d.ts +13 -0
  64. package/dist/api-v2/presets/index.js +25 -0
  65. package/dist/api-v2/requestConfig.d.ts +5 -0
  66. package/dist/api-v2/requestConfig.js +34 -0
  67. package/dist/api-v2/roles/index.d.ts +5 -0
  68. package/dist/api-v2/roles/index.js +35 -0
  69. package/dist/api-v2/spaces/index.d.ts +7 -0
  70. package/dist/api-v2/spaces/index.js +11 -0
  71. package/dist/api-v2/stories/index.d.ts +34 -0
  72. package/dist/api-v2/stories/index.js +172 -0
  73. package/dist/api-v2/stories/types.d.ts +28 -0
  74. package/dist/api-v2/stories/types.js +1 -0
  75. package/dist/api-v2/sync/index.d.ts +24 -0
  76. package/dist/api-v2/sync/index.js +109 -0
  77. package/dist/api-v2/sync/types.d.ts +1 -0
  78. package/dist/api-v2/sync/types.js +1 -0
  79. package/dist/api-v2/test.d.ts +15 -0
  80. package/dist/api-v2/test.js +21 -0
  81. package/dist/cli/cli-descriptions.d.ts +1 -1
  82. package/dist/cli/cli-descriptions.js +4 -0
  83. package/dist/cli/commands/backup.js +7 -3
  84. package/dist/cli/commands/copy.js +2 -2
  85. package/dist/cli/commands/migrate.js +13 -2
  86. package/dist/cli/commands/migrations.js +2 -2
  87. package/dist/cli/commands/remove.js +1 -1
  88. package/dist/cli/commands/revert.js +2 -2
  89. package/dist/cli/commands/sync.js +1 -2
  90. package/dist/cli/index.js +8 -1
  91. package/dist/cli/utils/cli-utils.d.ts +69 -0
  92. package/dist/cli/utils/cli-utils.js +100 -0
  93. package/dist/cli/utils/discover.d.ts +3 -22
  94. package/dist/cli/utils/discover.js +4 -51
  95. package/dist/config/config.d.ts +2 -39
  96. package/dist/config/config.types.d.ts +40 -0
  97. package/dist/config/config.types.js +1 -0
  98. package/dist/config/defaultConfig.d.ts +1 -1
  99. package/dist/config/defaultConfig.js +2 -2
  100. package/dist/utils/array-utils.d.ts +20 -0
  101. package/dist/utils/array-utils.js +20 -0
  102. package/dist/utils/async-utils.d.ts +13 -0
  103. package/dist/utils/async-utils.js +13 -0
  104. package/dist/utils/date-utils.d.ts +14 -0
  105. package/dist/utils/date-utils.js +21 -0
  106. package/dist/utils/files.d.ts +35 -0
  107. package/dist/utils/files.js +57 -2
  108. package/dist/utils/main.d.ts +8 -18
  109. package/dist/utils/main.js +12 -104
  110. package/dist/utils/migrations.d.ts +9 -3
  111. package/dist/utils/object-utils.d.ts +46 -0
  112. package/dist/utils/object-utils.js +71 -0
  113. package/dist/utils/others.d.ts +6 -9
  114. package/dist/utils/others.js +8 -15
  115. package/dist/utils/path-utils.d.ts +89 -0
  116. package/dist/utils/path-utils.js +106 -0
  117. package/dist/utils/pkg.d.ts +16 -2
  118. package/dist/utils/pkg.js +16 -3
  119. package/dist/utils/string-utils.d.ts +33 -0
  120. package/dist/utils/string-utils.js +45 -0
  121. package/dist/utils/transform-utils.d.ts +62 -0
  122. package/dist/utils/transform-utils.js +113 -0
  123. package/dist-cjs/api/auth/auth.js +28 -0
  124. package/dist-cjs/api/auth/auth.types.js +2 -0
  125. package/dist-cjs/api/components/components.js +202 -0
  126. package/dist-cjs/api/components/components.sync.js +199 -0
  127. package/dist-cjs/api/components/components.types.js +2 -0
  128. package/dist-cjs/api/datasources/datasource-entries.js +166 -0
  129. package/dist-cjs/api/datasources/datasources.js +166 -0
  130. package/dist-cjs/api/datasources/datasources.types.js +2 -0
  131. package/dist-cjs/api/plugins/plugins.js +132 -0
  132. package/dist-cjs/api/plugins/plugins.types.js +2 -0
  133. package/dist-cjs/api/presets/componentPresets.js +25 -0
  134. package/dist-cjs/api/presets/presets.js +92 -0
  135. package/dist-cjs/api/presets/presets.types.js +2 -0
  136. package/dist-cjs/api/presets/resolvePresets.js +49 -0
  137. package/dist-cjs/api/roles/roles.js +131 -0
  138. package/dist-cjs/api/roles/roles.types.js +2 -0
  139. package/dist-cjs/api/spaces/spaces.js +34 -0
  140. package/dist-cjs/api/spaces/spaces.types.js +2 -0
  141. package/dist-cjs/api/stories/stories.js +214 -0
  142. package/dist-cjs/api/stories/stories.types.js +2 -0
  143. package/dist-cjs/api/sync/sync.types.js +2 -0
  144. package/dist-cjs/api/utils/request.js +48 -0
  145. package/dist-cjs/api/utils/resolvers.types.js +2 -0
  146. package/dist-cjs/api-v2/assets/index.js +30 -0
  147. package/dist-cjs/api-v2/auth/index.js +12 -0
  148. package/dist-cjs/api-v2/client.js +23 -0
  149. package/dist-cjs/api-v2/components/index.js +40 -0
  150. package/dist-cjs/api-v2/datasources/index.js +64 -0
  151. package/dist-cjs/api-v2/discover/discover.js +321 -0
  152. package/dist-cjs/api-v2/discover/index.js +9 -0
  153. package/dist-cjs/api-v2/index.js +60 -0
  154. package/dist-cjs/api-v2/plugins/index.js +49 -0
  155. package/dist-cjs/api-v2/precompile/index.js +7 -0
  156. package/dist-cjs/api-v2/precompile/precompile.js +136 -0
  157. package/dist-cjs/api-v2/presets/index.js +33 -0
  158. package/dist-cjs/api-v2/requestConfig.js +37 -0
  159. package/dist-cjs/api-v2/roles/index.js +41 -0
  160. package/dist-cjs/api-v2/spaces/index.js +16 -0
  161. package/dist-cjs/api-v2/stories/index.js +180 -0
  162. package/dist-cjs/api-v2/stories/types.js +2 -0
  163. package/dist-cjs/api-v2/sync/index.js +115 -0
  164. package/dist-cjs/api-v2/sync/types.js +2 -0
  165. package/dist-cjs/api-v2/test.js +25 -0
  166. package/dist-cjs/config/config.types.js +2 -0
  167. package/dist-cjs/config/constants.js +29 -0
  168. package/dist-cjs/package.json +3 -0
  169. package/dist-cjs/utils/array-utils.js +24 -0
  170. package/dist-cjs/utils/logger.js +32 -0
  171. package/dist-cjs/utils/object-utils.js +77 -0
  172. package/dist-cjs/utils/path-utils.js +115 -0
  173. package/package.json +37 -20
  174. package/dist/utils/pkg-require.d.ts +0 -2
  175. package/dist/utils/pkg-require.js +0 -4
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Simple test function with no dependencies to verify ESM/CJS interop
3
+ */
4
+ export function testConnection() {
5
+ return {
6
+ success: true,
7
+ message: "sb-mig api-v2 connection successful!",
8
+ timestamp: new Date().toISOString(),
9
+ };
10
+ }
11
+ /**
12
+ * Async test function to verify async imports work
13
+ */
14
+ export async function testAsyncConnection() {
15
+ // Simulate a small delay
16
+ await new Promise((resolve) => setTimeout(resolve, 100));
17
+ return {
18
+ success: true,
19
+ message: "sb-mig api-v2 async connection successful!",
20
+ };
21
+ }
@@ -1,7 +1,7 @@
1
1
  export declare const mainDescription = "\n USAGE\n $ sb-mig [command]\n \n COMMANDS\n sync Synchronize components, datasources, roles, stories, assets with Storyblok space.\n discover Discover components and write to file or stdout.\n backup Command for backing up anything related to Storyblok\n migrate Migrate content from space to space, or from file to space.\n debug Output extra debugging information\n help This screen\n \n Examples\n $ sb-mig sync components --all\n $ sb-mig debug \n";
2
2
  export declare const syncDescription = "\n Usage\n $ sb-mig sync [components|roles|datasources|plugins|content] [space separated file names] or --all\n \n Description\n Synchronize components, roles, datasources, plugins, content with Storyblok space.\n \n COMMANDS\n components - sync components\n roles - sync roles\n datasources - sync datasources\n plugins - sync plugins\n content - sync content (stories, assets) - ! right now destructive, it will move content from 1 space to another, completelly overwriting it\n \n FLAGS\n --all - Sync all components, roles, datasources [components, roles, datasources]\n --presets - Pass it, if u want to sync also with presets (will take longer) [components only]\n \n --yes - Skip ask for confirmation (dangerous, but useful in CI/CD) [content only]\n --from - Space ID from which you want to sync content [content only]\n --to - Space ID to which you want to sync content [content only]\n --syncDirection [fromSpaceToFile|fromFileToSpace|fromSpaceToSpace|fromAWStoSpace] \n - Sync direction (from, to) [content only]\n \n EXAMPLES\n $ sb-mig sync components --all\n $ sb-mig sync components --all --presets\n $ sb-mig sync components accordion accordion-item\n $ sb-mig sync components accordion accordion-item --presets\n \n $ sb-mig sync roles --all\n \n $ sb-mig sync datasources --all\n \n $ sb-mig sync plugins my-awesome-plugin - (you have to be in catalog which has ./dist/export.js file with compiled plugin)\n \n $ sb-mig sync content --all --from 12345 --to 12345\n $ sb-mig sync content --stories --from 12345 --to 12345\n $ sb-mig sync content --assets --from 12345 --to 12345\n";
3
3
  export declare const copyDescription = "\n Usage\n $ sb-mig copy\n \n Description\n Copy stuff\n \n COMMANDS\n ?\n \n FLAGS\n ?\n \n EXAMPLES\n $ sb-mig copy ?\n";
4
- export declare const migrateDescription = "\n Usage\n $ sb-mig migrate [content] [space separated file names] or --all --from [spaceId] --to [spaceId] --migration [migration-config-filename]\n \n Description\n Migrate content from space to space, or from file to space. It's potentially dangerous command, so it will ask for confirmation.\n Use with care.\n \n COMMANDS\n content - migrate content \n \n FLAGS\n --from - Space ID from which you want to migrate / or file name if passed '--migrate-from file'\n --to - Space ID to which you want to migrate\n --migrate-from - Migrate from (space, file) default: space\n --migration - File name of migration file (without extension)\n --yes - Skip ask for confirmation (dangerous, but useful in CI/CD) \n \n EXAMPLES\n $ sb-mig migrate content --all --from 12345 --to 12345 --migration file-with-migration\n $ sb-mig migrate content --all --migrate-from file --from file-with-stories --to 12345 --migration file-with-migration\n $ sb-mig migrate content my-component-1 my-component-2 --from 12345 --to 12345 --migration file-with-migration\n $ sb-mig migrate content my-component-1 my-component-2 --migrate-from file --from file-with-stories --to 12345 --migration file-with-migration \n";
4
+ export declare const migrateDescription = "\n Usage\n $ sb-mig migrate [content] [space separated file names] or --all --from [spaceId] --to [spaceId] --migration [migration-config-filename]\n \n Description\n Migrate content from space to space, or from file to space. It's potentially dangerous command, so it will ask for confirmation.\n Use with care.\n \n COMMANDS\n content - migrate content \n \n FLAGS\n --from - Space ID from which you want to migrate / or file name if passed '--migrate-from file'\n --to - Space ID to which you want to migrate\n --migrate-from - Migrate from (space, file) default: space\n --migration - File name of migration file (without extension)\n --withSlug - Filter stories by full slug (can be repeated)\n --startsWith - Filter stories by starts_with prefix\n --yes - Skip ask for confirmation (dangerous, but useful in CI/CD) \n \n EXAMPLES\n $ sb-mig migrate content --all --from 12345 --to 12345 --migration file-with-migration\n $ sb-mig migrate content --all --from 12345 --to 12345 --migration file-with-migration --withSlug blog/home --withSlug docs/getting-started\n $ sb-mig migrate content --all --from 12345 --to 12345 --migration file-with-migration --startsWith blog/\n $ sb-mig migrate content --all --migrate-from file --from file-with-stories --to 12345 --migration file-with-migration\n $ sb-mig migrate content my-component-1 my-component-2 --from 12345 --to 12345 --migration file-with-migration\n $ sb-mig migrate content my-component-1 my-component-2 --migrate-from file --from file-with-stories --to 12345 --migration file-with-migration \n";
5
5
  export declare const revertDescription = "\n Usage\n $ sb-mig revert [content] --migration\n \n Description\n Revert content migration\n \n COMMANDS\n content - revert content migration \n \n FLAGS\n --migration - ???\n --yes - Skip ask for confirmation (dangerous, but useful in CI/CD) \n \n EXAMPLES\n $ sb-mig revert content --migration \n";
6
6
  export declare const discoverDescription = "\n Usage\n $ sb-mig discover [components] --all --write\n \n Description\n Discover all component and write to file or stdout\n \n COMMANDS\n components - discover components\n \n FLAGS\n --all - Discover all components\n --write - Write to file \n \n EXAMPLES\n $ sb-mig discover components --all\n $ sb-mig discover components --all -- write\n";
7
7
  export declare const migrationsDescription = "\n Usage\n $ sb-mig migrations recognize\n \n Description\n Recognize migrations you need to apply\n \n COMMANDS\n recognize - recognize migrations\n \n FLAGS \n \n EXAMPLES\n $ sb-mig migrations recognize\n\n";
@@ -86,10 +86,14 @@ export const migrateDescription = `
86
86
  --to - Space ID to which you want to migrate
87
87
  --migrate-from - Migrate from (space, file) default: space
88
88
  --migration - File name of migration file (without extension)
89
+ --withSlug - Filter stories by full slug (can be repeated)
90
+ --startsWith - Filter stories by starts_with prefix
89
91
  --yes - Skip ask for confirmation (dangerous, but useful in CI/CD)
90
92
 
91
93
  EXAMPLES
92
94
  $ sb-mig migrate content --all --from 12345 --to 12345 --migration file-with-migration
95
+ $ sb-mig migrate content --all --from 12345 --to 12345 --migration file-with-migration --withSlug blog/home --withSlug docs/getting-started
96
+ $ sb-mig migrate content --all --from 12345 --to 12345 --migration file-with-migration --startsWith blog/
93
97
  $ sb-mig migrate content --all --migrate-from file --from file-with-stories --to 12345 --migration file-with-migration
94
98
  $ sb-mig migrate content my-component-1 my-component-2 --from 12345 --to 12345 --migration file-with-migration
95
99
  $ sb-mig migrate content my-component-1 my-component-2 --migrate-from file --from file-with-stories --to 12345 --migration file-with-migration
@@ -1,10 +1,11 @@
1
1
  import { managementApi } from "../../api/managementApi.js";
2
2
  import { backupStories } from "../../api/stories/backup.js";
3
3
  import storyblokConfig from "../../config/config.js";
4
- import { createAndSaveToFile } from "../../utils/files.js";
4
+ import { createAndSaveToFile, getPackageJson } from "../../utils/files.js";
5
5
  import Logger from "../../utils/logger.js";
6
- import { extractFields, getPackageJson, isItFactory, unpackOne, } from "../../utils/main.js";
6
+ import { extractFields } from "../../utils/object-utils.js";
7
7
  import { apiConfig } from "../api-config.js";
8
+ import { isItFactory, unpackOne } from "../utils/cli-utils.js";
8
9
  const BACKUP_COMMANDS = {
9
10
  components: "components",
10
11
  stories: "stories",
@@ -276,7 +277,10 @@ export const backup = async (props) => {
276
277
  filename: `${component.name}.presets.sb`,
277
278
  res: { allPresets: res, ...metadata },
278
279
  folder: storyblokConfig.presetsBackupDirectory,
279
- }, { ...apiConfig, sbmigWorkingDirectory: "." });
280
+ }, {
281
+ ...apiConfig,
282
+ sbmigWorkingDirectory: ".",
283
+ });
280
284
  }
281
285
  })
282
286
  .catch((err) => {
@@ -1,8 +1,8 @@
1
1
  import { managementApi } from "../../api/managementApi.js";
2
2
  import { createTree, traverseAndCreate } from "../../api/stories/tree.js";
3
3
  import Logger from "../../utils/logger.js";
4
- import { getSourceSpace, getTargetSpace, getWhat, getWhere, } from "../../utils/others.js";
5
4
  import { apiConfig } from "../api-config.js";
5
+ import { getSourceSpace, getTargetSpace, getWhat, getWhere, } from "../utils/cli-utils.js";
6
6
  const COPY_COMMANDS = {
7
7
  stories: "stories",
8
8
  };
@@ -19,7 +19,7 @@ const decideStrategy = async (args) => {
19
19
  const { what, sourceSpace } = args;
20
20
  // Check if path ends with /* for recursive folder strategy
21
21
  if (what.endsWith("/*")) {
22
- const folderPath = what.slice(0, -2); // Remove /* from the end
22
+ const folderPath = what.slice(0, -2); // Remove /* from the endcurso
23
23
  const entryStory = await managementApi.stories.getStoryBySlug(folderPath, {
24
24
  ...apiConfig,
25
25
  spaceId: sourceSpace,
@@ -3,10 +3,9 @@ import { managementApi } from "../../api/managementApi.js";
3
3
  import { backupStories } from "../../api/stories/backup.js";
4
4
  import { createAndSaveToFile } from "../../utils/files.js";
5
5
  import Logger from "../../utils/logger.js";
6
- import { isItFactory, unpackElements } from "../../utils/main.js";
7
- import { getFrom, getTo } from "../../utils/others.js";
8
6
  import { apiConfig } from "../api-config.js";
9
7
  import { askForConfirmation } from "../helpers.js";
8
+ import { isItFactory, unpackElements, getFrom, getTo, } from "../utils/cli-utils.js";
10
9
  const MIGRATE_COMMANDS = {
11
10
  content: "content",
12
11
  presets: "presets",
@@ -24,6 +23,9 @@ export const migrate = async (props) => {
24
23
  "pageId",
25
24
  "migration",
26
25
  "yes",
26
+ "withSlug",
27
+ "startsWith",
28
+ "dryRun",
27
29
  ]);
28
30
  Logger.warning(`This feature is in BETA. Use it at your own risk. The API might change in the future. (Probably in a standard Prisma like migration way)`);
29
31
  switch (command) {
@@ -32,6 +34,13 @@ export const migrate = async (props) => {
32
34
  const from = getFrom(flags, apiConfig);
33
35
  const to = getTo(flags, apiConfig);
34
36
  const migrationConfig = flags["migration"];
37
+ const withSlugFlag = flags["withSlug"];
38
+ const withSlug = Array.isArray(withSlugFlag)
39
+ ? withSlugFlag
40
+ : withSlugFlag
41
+ ? [withSlugFlag]
42
+ : undefined;
43
+ const startsWith = flags["startsWith"] || undefined;
35
44
  if (isIt("empty")) {
36
45
  const componentsToMigrate = unpackElements(input) || [""];
37
46
  const migrateFrom = "space";
@@ -50,6 +59,7 @@ export const migrate = async (props) => {
50
59
  migrateFrom,
51
60
  componentsToMigrate,
52
61
  migrationConfig,
62
+ filters: { withSlug, startsWith },
53
63
  }, apiConfig);
54
64
  }, () => {
55
65
  Logger.warning("Migration not started, exiting the program...");
@@ -66,6 +76,7 @@ export const migrate = async (props) => {
66
76
  to,
67
77
  migrateFrom,
68
78
  migrationConfig,
79
+ filters: { withSlug, startsWith },
69
80
  }, apiConfig);
70
81
  }, () => {
71
82
  Logger.warning("Migration not started, exiting the program...");
@@ -1,8 +1,8 @@
1
1
  import path from "path";
2
- import { readFile } from "../../utils/files.js";
2
+ import { readFile, getFileContentWithRequire, getFilesContentWithRequire, } from "../../utils/files.js";
3
3
  import Logger from "../../utils/logger.js";
4
- import { getFileContentWithRequire, getFilesContentWithRequire, isItFactory, } from "../../utils/main.js";
5
4
  import { preselectMigrations } from "../../utils/migrations.js";
5
+ import { isItFactory } from "../utils/cli-utils.js";
6
6
  import { discoverVersionMapping, LOOKUP_TYPE, SCOPE, } from "../utils/discover.js";
7
7
  const MIGRATIONS_COMMANDS = {
8
8
  recognize: "recognize",
@@ -1,8 +1,8 @@
1
1
  import { managementApi } from "../../api/managementApi.js";
2
2
  import { removeAllComponents, removeSpecifiedComponents, } from "../../api/migrate.js";
3
3
  import Logger from "../../utils/logger.js";
4
- import { unpackElements } from "../../utils/main.js";
5
4
  import { apiConfig } from "../api-config.js";
5
+ import { unpackElements } from "../utils/cli-utils.js";
6
6
  const REMOVE_COMMANDS = {
7
7
  story: "story",
8
8
  components: "components",
@@ -1,9 +1,9 @@
1
1
  import { managementApi } from "../../api/managementApi.js";
2
+ import { getFilesContentWithRequire } from "../../utils/files.js";
2
3
  import Logger from "../../utils/logger.js";
3
- import { getFilesContentWithRequire, isItFactory } from "../../utils/main.js";
4
- import { getFrom, getTo } from "../../utils/others.js";
5
4
  import { apiConfig } from "../api-config.js";
6
5
  import { askForConfirmation } from "../helpers.js";
6
+ import { isItFactory, getFrom, getTo } from "../utils/cli-utils.js";
7
7
  import { discoverStories, LOOKUP_TYPE, SCOPE } from "../utils/discover.js";
8
8
  const REVERT_COMMANDS = {
9
9
  content: "content",
@@ -2,12 +2,11 @@ import { managementApi } from "../../api/managementApi.js";
2
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
- import { isItFactory, unpackElements } from "../../utils/main.js";
6
- import { getFrom, getTo } from "../../utils/others.js";
7
5
  import { apiConfig } from "../api-config.js";
8
6
  import { syncAllDatasources, syncProvidedDatasources, } from "../datasources/sync.js";
9
7
  import { askForConfirmation } from "../helpers.js";
10
8
  import { syncAllRoles, syncProvidedRoles } from "../roles/sync.js";
9
+ import { getFrom, getTo, isItFactory, unpackElements, } from "../utils/cli-utils.js";
11
10
  const SYNC_COMMANDS = {
12
11
  content: "content",
13
12
  components: "components",
package/dist/cli/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  #! /usr/bin/env node
2
2
  import meow from "meow";
3
- import { pipe, prop } from "../utils/main.js";
4
3
  import { backupDescription, debugDescription, mainDescription, syncDescription, removeDescription, initDescription, discoverDescription, migrateDescription, revertDescription, migrationsDescription, copyDescription, } from "./cli-descriptions.js";
5
4
  import { backup } from "./commands/backup.js";
6
5
  import { copyCommand } from "./commands/copy.js";
@@ -13,6 +12,7 @@ import { remove } from "./commands/remove.js";
13
12
  import { revert } from "./commands/revert.js";
14
13
  import { sync } from "./commands/sync.js";
15
14
  import { testCommand } from "./commands/test.js";
15
+ import { pipe, prop } from "./utils/cli-utils.js";
16
16
  const app = () => ({
17
17
  cli: meow(mainDescription, {
18
18
  importMeta: import.meta,
@@ -54,6 +54,13 @@ app.migrate = () => ({
54
54
  default: "space",
55
55
  isRequired: true,
56
56
  },
57
+ withSlug: {
58
+ type: "string",
59
+ isMultiple: true,
60
+ },
61
+ startsWith: {
62
+ type: "string",
63
+ },
57
64
  },
58
65
  }),
59
66
  action: (cli) => {
@@ -0,0 +1,69 @@
1
+ /**
2
+ * CLI-specific utility functions for building and parsing CLI commands
3
+ */
4
+ import type { RequestBaseConfig } from "../../api/utils/request.js";
5
+ /**
6
+ * Property accessor - curried function to get a property from an object
7
+ * @example prop('name')({ name: 'hero' }) // => 'hero'
8
+ */
9
+ export declare const prop: (k: any) => (o: any) => any;
10
+ /**
11
+ * Pipe functions left to right (function composition)
12
+ * @example pipe(addOne, double)(5) // => 12
13
+ */
14
+ export declare const pipe: (...fns: any[]) => (x: any) => any;
15
+ /**
16
+ * Extract elements after the first two from CLI input array
17
+ * Used for parsing component names from commands like: sync components hero card
18
+ * @example unpackElements(['sync', 'components', 'hero', 'card']) // => ['hero', 'card']
19
+ */
20
+ export declare const unpackElements: (input: string[]) => string[];
21
+ /**
22
+ * Extract the third element from CLI input array
23
+ * Used for parsing single component name from commands
24
+ * @example unpackOne(['sync', 'components', 'hero']) // => 'hero'
25
+ */
26
+ export declare const unpackOne: (input: string[]) => string | undefined;
27
+ /**
28
+ * Factory for creating flag matchers
29
+ * Used to determine which CLI action to take based on provided flags
30
+ *
31
+ * @param flags - The flags object from CLI parser
32
+ * @param rules - Object mapping action names to required flag combinations
33
+ * @param whitelist - Flags to ignore when matching (e.g., 'from', 'to')
34
+ * @returns A function that checks if a given action type matches the flags
35
+ *
36
+ * @example
37
+ * const rules = { all: ['all'], allWithPresets: ['all', 'presets'] };
38
+ * const isIt = isItFactory({ all: true, presets: true }, rules, []);
39
+ * isIt('allWithPresets') // => true
40
+ */
41
+ export declare const isItFactory: <T>(flags: any, rules: any, whitelist: string[]) => (type: T) => boolean;
42
+ /**
43
+ * Extract 'from' space ID from flags, falling back to config spaceId
44
+ */
45
+ export declare const getFrom: (flags: any, config: RequestBaseConfig) => string;
46
+ /**
47
+ * Extract 'to' space ID from flags, falling back to config spaceId
48
+ */
49
+ export declare const getTo: (flags: any, config: RequestBaseConfig) => string;
50
+ /**
51
+ * Extract 'sourceSpace' from flags, falling back to config spaceId
52
+ */
53
+ export declare const getSourceSpace: (flags: any, config: RequestBaseConfig) => string;
54
+ /**
55
+ * Extract 'targetSpace' from flags, falling back to config spaceId
56
+ */
57
+ export declare const getTargetSpace: (flags: any, config: RequestBaseConfig) => string;
58
+ /**
59
+ * Extract 'what' flag, defaulting to 'all'
60
+ */
61
+ export declare const getWhat: (flags: any) => string;
62
+ /**
63
+ * Extract 'where' flag, defaulting to 'all'
64
+ */
65
+ export declare const getWhere: (flags: any) => string;
66
+ /**
67
+ * Extract 'recursive' flag, defaulting to false
68
+ */
69
+ export declare const getRecursive: (flags: any) => boolean;
@@ -0,0 +1,100 @@
1
+ /**
2
+ * CLI-specific utility functions for building and parsing CLI commands
3
+ */
4
+ /**
5
+ * Property accessor - curried function to get a property from an object
6
+ * @example prop('name')({ name: 'hero' }) // => 'hero'
7
+ */
8
+ export const prop = (k) => (o) => o[k];
9
+ /**
10
+ * Pipe functions left to right (function composition)
11
+ * @example pipe(addOne, double)(5) // => 12
12
+ */
13
+ export const pipe = (...fns) => (x) => [...fns].reduce((acc, f) => f(acc), x);
14
+ /**
15
+ * Extract elements after the first two from CLI input array
16
+ * Used for parsing component names from commands like: sync components hero card
17
+ * @example unpackElements(['sync', 'components', 'hero', 'card']) // => ['hero', 'card']
18
+ */
19
+ export const unpackElements = (input) => {
20
+ const [_1, _2, ...elementsForUse] = input;
21
+ return elementsForUse;
22
+ };
23
+ /**
24
+ * Extract the third element from CLI input array
25
+ * Used for parsing single component name from commands
26
+ * @example unpackOne(['sync', 'components', 'hero']) // => 'hero'
27
+ */
28
+ export const unpackOne = (input) => {
29
+ const [_1, _2, elementForUse] = input;
30
+ return elementForUse;
31
+ };
32
+ /**
33
+ * Factory for creating flag matchers
34
+ * Used to determine which CLI action to take based on provided flags
35
+ *
36
+ * @param flags - The flags object from CLI parser
37
+ * @param rules - Object mapping action names to required flag combinations
38
+ * @param whitelist - Flags to ignore when matching (e.g., 'from', 'to')
39
+ * @returns A function that checks if a given action type matches the flags
40
+ *
41
+ * @example
42
+ * const rules = { all: ['all'], allWithPresets: ['all', 'presets'] };
43
+ * const isIt = isItFactory({ all: true, presets: true }, rules, []);
44
+ * isIt('allWithPresets') // => true
45
+ */
46
+ export const isItFactory = (flags, rules, whitelist) => {
47
+ return (type) => {
48
+ const rulesCopy = [...rules[type]];
49
+ const flagsKeys = Object.keys(flags);
50
+ const temp = flagsKeys.map((flag) => {
51
+ if (whitelist.includes(flag)) {
52
+ return true;
53
+ }
54
+ if (rulesCopy.includes(flag)) {
55
+ rulesCopy.splice(rulesCopy.indexOf(flag), 1);
56
+ return true;
57
+ }
58
+ else {
59
+ return false;
60
+ }
61
+ });
62
+ if (rulesCopy.length > 0) {
63
+ return false;
64
+ }
65
+ else {
66
+ return temp.every((el) => el === true);
67
+ }
68
+ };
69
+ };
70
+ // ============================================================================
71
+ // CLI Flag Extractors
72
+ // ============================================================================
73
+ /**
74
+ * Extract 'from' space ID from flags, falling back to config spaceId
75
+ */
76
+ export const getFrom = (flags, config) => (flags["from"] ? flags["from"] : config.spaceId).toString();
77
+ /**
78
+ * Extract 'to' space ID from flags, falling back to config spaceId
79
+ */
80
+ export const getTo = (flags, config) => (flags["to"] ? flags["to"] : config.spaceId).toString();
81
+ /**
82
+ * Extract 'sourceSpace' from flags, falling back to config spaceId
83
+ */
84
+ export const getSourceSpace = (flags, config) => (flags["sourceSpace"] ? flags["sourceSpace"] : config.spaceId).toString();
85
+ /**
86
+ * Extract 'targetSpace' from flags, falling back to config spaceId
87
+ */
88
+ export const getTargetSpace = (flags, config) => (flags["targetSpace"] ? flags["targetSpace"] : config.spaceId).toString();
89
+ /**
90
+ * Extract 'what' flag, defaulting to 'all'
91
+ */
92
+ export const getWhat = (flags) => (flags["what"] ? flags["what"] : "all").toString();
93
+ /**
94
+ * Extract 'where' flag, defaulting to 'all'
95
+ */
96
+ export const getWhere = (flags) => (flags["where"] ? flags["where"] : "all").toString();
97
+ /**
98
+ * Extract 'recursive' flag, defaulting to false
99
+ */
100
+ export const getRecursive = (flags) => flags["recursive"] ? flags["recursive"] : false;
@@ -1,3 +1,4 @@
1
+ import { type CompareResult, type OneFileElement } from "../../utils/path-utils.js";
1
2
  export declare enum SCOPE {
2
3
  local = "local",
3
4
  external = "external",
@@ -25,23 +26,9 @@ interface DiscoverManyByPackageNameRequest {
25
26
  packageNames: string[];
26
27
  scope: SCOPE;
27
28
  }
28
- interface CompareRequest {
29
- local: string[];
30
- external: string[];
31
- }
32
- export interface OneFileElement {
33
- name: string;
34
- p: string;
35
- }
36
- export interface CompareResult {
37
- local: OneFileElement[];
38
- external: OneFileElement[];
39
- }
40
29
  type DiscoverResult = string[];
41
- export declare const normalizeDiscover: ({ segments }: {
42
- segments: string[];
43
- }) => string | undefined;
44
- export declare const compare: (request: CompareRequest) => CompareResult;
30
+ export type { CompareResult, OneFileElement };
31
+ export { normalizeDiscover, compare, filesPattern, } from "../../utils/path-utils.js";
45
32
  export declare const discoverManyByPackageName: (request: DiscoverManyByPackageNameRequest) => DiscoverResult;
46
33
  export declare const discoverOneByPackageName: (request: DiscoverOneByPackageNameRequest) => DiscoverResult;
47
34
  export declare const discoverMany: (request: DiscoverManyRequest) => Promise<DiscoverResult>;
@@ -50,11 +37,6 @@ export declare const discoverStories: (request: DiscoverManyRequest) => Discover
50
37
  export declare const discoverMigrationConfig: (request: DiscoverManyRequest) => DiscoverResult;
51
38
  export declare const discoverVersionMapping: (request: DiscoverManyRequest) => DiscoverResult;
52
39
  export declare const discoverDatasources: (request: DiscoverRequest) => Promise<DiscoverResult>;
53
- export declare const filesPattern: ({ mainDirectory, componentDirectories, ext, }: {
54
- mainDirectory: string;
55
- componentDirectories: string[];
56
- ext: string;
57
- }) => string;
58
40
  export declare const discover: (request: DiscoverRequest) => Promise<DiscoverResult>;
59
41
  export declare const discoverResolvers: (request: DiscoverRequest) => Promise<DiscoverResult>;
60
42
  export declare const discoverRoles: (request: DiscoverRequest) => Promise<DiscoverResult>;
@@ -63,4 +45,3 @@ export declare const discoverAllComponents: () => Promise<{
63
45
  local: OneFileElement[];
64
46
  external: OneFileElement[];
65
47
  }>;
66
- export {};
@@ -5,7 +5,8 @@ import path from "path";
5
5
  import glob from "glob";
6
6
  import storyblokConfig, { SCHEMA } from "../../config/config.js";
7
7
  import { buildOnTheFly } from "../../rollup/build-on-the-fly.js";
8
- import { getFileContentWithRequire } from "../../utils/main.js";
8
+ import { getFileContentWithRequire } from "../../utils/files.js";
9
+ import { normalizeDiscover, filesPattern, compare, } from "../../utils/path-utils.js";
9
10
  export var SCOPE;
10
11
  (function (SCOPE) {
11
12
  SCOPE["local"] = "local";
@@ -18,51 +19,8 @@ export var LOOKUP_TYPE;
18
19
  LOOKUP_TYPE["packagName"] = "packageName";
19
20
  LOOKUP_TYPE["fileName"] = "fileName";
20
21
  })(LOOKUP_TYPE || (LOOKUP_TYPE = {}));
21
- // problem with glob sync is, that when there is only one folder to search for
22
- // we have to omit { } and when a lot, we have to use {folder1, folder2}
23
- // so this function will normalize it based on amount of folders provided
24
- export const normalizeDiscover = ({ segments }) => {
25
- if (segments.length === 0) {
26
- return "";
27
- }
28
- if (segments.length === 1) {
29
- return segments[0];
30
- }
31
- return `{${segments.join(",")}}`;
32
- };
33
- export const compare = (request) => {
34
- const { local, external } = request;
35
- const splittedLocal = local.map((p) => {
36
- return {
37
- name: p.split(path.sep)[p.split(path.sep).length - 1],
38
- p,
39
- };
40
- });
41
- const splittedExternal = external
42
- .map((p) => {
43
- return {
44
- name: p.split(path.sep)[p.split(path.sep).length - 1],
45
- p,
46
- };
47
- })
48
- .filter((file) => {
49
- // 1. check if the file has node_modules > 1
50
- const nodeModulesCount = (file.p.match(/node_modules/g) || [])
51
- .length;
52
- return nodeModulesCount <= 1;
53
- });
54
- // we only want to modify external array, because we want sometimes remove stuff which are already on local (overwrite node_modules ones)
55
- const result = {
56
- local: splittedLocal,
57
- external: splittedExternal.filter((externalComponent) => {
58
- if (splittedLocal.find((localComponent) => externalComponent.name === localComponent.name)) {
59
- return false;
60
- }
61
- return true;
62
- }),
63
- };
64
- return result;
65
- };
22
+ // Re-export functions for backwards compatibility
23
+ export { normalizeDiscover, compare, filesPattern, } from "../../utils/path-utils.js";
66
24
  export const discoverManyByPackageName = (request) => {
67
25
  const rootDirectory = "./";
68
26
  const directory = path.resolve(process.cwd(), rootDirectory);
@@ -464,11 +422,6 @@ export const discoverDatasources = async (request) => {
464
422
  }
465
423
  return listOfFiles;
466
424
  };
467
- export const filesPattern = ({ mainDirectory, componentDirectories, ext, }) => {
468
- return componentDirectories.length === 1
469
- ? path.join(`${mainDirectory}`, `${componentDirectories[0]}`, "**", `[^_]*.${ext}`)
470
- : path.join(`${mainDirectory}`, `{${componentDirectories.join(",")}}`, "**", `[^_]*.${ext}`);
471
- };
472
425
  export const discover = async (request) => {
473
426
  const rootDirectory = ".";
474
427
  const directory = path.resolve(process.cwd(), rootDirectory);
@@ -1,43 +1,6 @@
1
- import type { SchemaGlobalResolvers, SimpleResolver } from "../api/utils/resolvers.types.js";
2
- import type StoryblokClient from "storyblok-js-client";
1
+ import type { IStoryblokConfig } from "./config.types.js";
3
2
  import { SCHEMA } from "./helper.js";
4
- type SchemaType = (typeof SCHEMA)[keyof typeof SCHEMA];
5
3
  export { SCHEMA };
6
- export interface IStoryblokConfig {
7
- storyblokComponentsLocalDirectory: string;
8
- sbmigWorkingDirectory: string;
9
- presetsBackupDirectory: string;
10
- storiesBackupDirectory: string;
11
- componentsDirectories: string[];
12
- awsBucketData: {
13
- bucketName: string;
14
- s3Url: `s3://${string}`;
15
- httpUrl: `https://${string}`;
16
- };
17
- metadataSelection: Record<string, any>;
18
- contentHubOriginUrl: string;
19
- contentHubAuthorizationToken: string;
20
- schemaFileExt: "sb.cjs" | "sb.js";
21
- datasourceExt: string;
22
- rolesExt: string;
23
- storiesExt: string;
24
- migrationConfigExt: string;
25
- storyblokApiUrl: string;
26
- storyblokDeliveryApiUrl: string;
27
- storyblokGraphqlApiUrl: string;
28
- oauthToken: string;
29
- openaiToken: string;
30
- spaceId: string;
31
- accessToken: string;
32
- boilerplateSpaceId: string;
33
- schemaType: SchemaType;
34
- flushCache: boolean;
35
- cacheDir: string;
36
- debug: boolean;
37
- rateLimit: number;
38
- sbApi?: () => StoryblokClient;
39
- resolvers?: SimpleResolver[];
40
- advancedResolvers?: SchemaGlobalResolvers;
41
- }
4
+ export type { IStoryblokConfig };
42
5
  declare const _default: IStoryblokConfig;
43
6
  export default _default;
@@ -0,0 +1,40 @@
1
+ import type { SCHEMA } from "./constants.js";
2
+ import type { SchemaGlobalResolvers, SimpleResolver } from "../api/utils/resolvers.types.js";
3
+ import type StoryblokClient from "storyblok-js-client";
4
+ export type SchemaType = (typeof SCHEMA)[keyof typeof SCHEMA];
5
+ export interface IStoryblokConfig {
6
+ storyblokComponentsLocalDirectory: string;
7
+ sbmigWorkingDirectory: string;
8
+ presetsBackupDirectory: string;
9
+ storiesBackupDirectory: string;
10
+ componentsDirectories: string[];
11
+ awsBucketData: {
12
+ bucketName: string;
13
+ s3Url: `s3://${string}`;
14
+ httpUrl: `https://${string}`;
15
+ };
16
+ metadataSelection: Record<string, any>;
17
+ contentHubOriginUrl: string;
18
+ contentHubAuthorizationToken: string;
19
+ schemaFileExt: "sb.cjs" | "sb.js";
20
+ datasourceExt: string;
21
+ rolesExt: string;
22
+ storiesExt: string;
23
+ migrationConfigExt: string;
24
+ storyblokApiUrl: string;
25
+ storyblokDeliveryApiUrl: string;
26
+ storyblokGraphqlApiUrl: string;
27
+ oauthToken: string;
28
+ openaiToken: string;
29
+ spaceId: string;
30
+ accessToken: string;
31
+ boilerplateSpaceId: string;
32
+ schemaType: SchemaType;
33
+ flushCache: boolean;
34
+ cacheDir: string;
35
+ debug: boolean;
36
+ rateLimit: number;
37
+ sbApi?: () => StoryblokClient;
38
+ resolvers?: SimpleResolver[];
39
+ advancedResolvers?: SchemaGlobalResolvers;
40
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1,2 @@
1
- import type { IStoryblokConfig } from "./config.js";
1
+ import type { IStoryblokConfig } from "./config.types.js";
2
2
  export declare const defaultConfig: (pkg: any, path: string, env: any) => IStoryblokConfig;
@@ -35,7 +35,7 @@ export const defaultConfig = (pkg, path, env) => {
35
35
  // : "sb.stories.cjs",
36
36
  storiesExt: "sb.stories.json",
37
37
  storyblokApiUrl: env["NEXT_PUBLIC_STORYBLOK_MANAGEMENT_API_URL"] ||
38
- "https://mapi.storyblok.com/v1",
38
+ "https://mapi.storyblok.com/v1", // should be mapi.storyblok.com ?
39
39
  storyblokDeliveryApiUrl: env["NEXT_PUBLIC_STORYBLOK_DELIVERY_API_URL"] ||
40
40
  "https://api.storyblok.com/v2",
41
41
  storyblokGraphqlApiUrl: env["NEXT_PUBLIC_STORYBLOK_GRAPHQL_API_URL"] ||
@@ -46,7 +46,7 @@ export const defaultConfig = (pkg, path, env) => {
46
46
  accessToken: env["GATSBY_STORYBLOK_ACCESS_TOKEN"] ||
47
47
  env["NEXT_PUBLIC_STORYBLOK_ACCESS_TOKEN"] ||
48
48
  "",
49
- boilerplateSpaceId: "172677",
49
+ boilerplateSpaceId: "172677", // this is id of Content seed for nextjs boilerplate space
50
50
  schemaType: SCHEMA.JS,
51
51
  flushCache: true,
52
52
  cacheDir: ".next/cache",