storyblok-cli icon indicating copy to clipboard operation
storyblok-cli copied to clipboard

Add migration path option and find stories for renamed components

Open dylanschoenmakers opened this issue 10 months ago • 1 comments

Hi,

We are having a problem with renaming of stories where the contains_component query does not work for us. We solved it with this patch for now, is this a known issue?

Here is the diff that solved my problem:

diff --git a/node_modules/storyblok/src/cli.js b/node_modules/storyblok/src/cli.js
index 5b50343..a4adebd 100755
--- a/node_modules/storyblok/src/cli.js
+++ b/node_modules/storyblok/src/cli.js
@@ -383,12 +383,14 @@ program
   .option('--dryrun', 'Do not update the story content')
   .option('--publish <PUBLISH_OPTION>', 'Publish the content. It can be: all, published or published-with-changes')
   .option('--publish-languages <LANGUAGES>', 'Publish specific languages')
+  .option('--migration-path <MIGRATION_PATH>', 'Path to the migration file')
   .action(async (options) => {
     const field = options.field || ''
     const component = options.component || ''
     const isDryrun = !!options.dryrun
     const publish = options.publish || null
     const publishLanguages = options.publishLanguages || ''
+    const migrationPath = options.migrationPath || ''
 
     const space = program.space
     if (!space) {
@@ -418,7 +420,7 @@ program
         api,
         component,
         field,
-        { isDryrun, publish, publishLanguages }
+        { isDryrun, publish, publishLanguages, migrationPath }
       )
     } catch (e) {
       console.log(chalk.red('X') + ' An error ocurred when run the migration file: ' + e.message)
diff --git a/node_modules/storyblok/src/tasks/migrations/utils.js b/node_modules/storyblok/src/tasks/migrations/utils.js
index 3839f77..84755c9 100644
--- a/node_modules/storyblok/src/tasks/migrations/utils.js
+++ b/node_modules/storyblok/src/tasks/migrations/utils.js
@@ -1,5 +1,5 @@
 const onChange = require('on-change')
-const { isArray, isPlainObject, has, isEmpty, template, truncate } = require('lodash')
+const { isArray, isPlainObject, has, isEmpty, template, truncate, filter } = require('lodash')
 const fs = require('fs-extra')
 const chalk = require('chalk')
 
@@ -49,7 +49,11 @@ const getNameOfMigrationFile = (component, field) => {
 const getStoriesByComponent = async (api, componentName) => {
   try {
     const stories = await api.getStories({
-      contain_component: componentName
+      filter_query: {
+        component: {
+          like: componentName
+        }
+      }
     })
 
     return stories

This issue body was partially generated by patch-package.

dylanschoenmakers avatar Apr 23 '24 10:04 dylanschoenmakers