TypeError: migrationCreator is not a function

TypeError: migrationCreator is not a function

我正在尝试 createAsset 使用 content-management-api

我使用的JavaScript脚本是

./contentful/contentful-import.js

const contentful = require('contentful-management');

const client = contentful.createClient({
  accessToken:'AUTHTOKEN'
});

client
  .getSpace('SPACE')
  .then(space => {
    space.createAsset({
      fields: {
        title: {
          'en-US': 'Example 1'
        },
        description: {
          'en-US': 'Example Description'
        },
        file: {
          'en-US': {
            contentType: 'image/jpeg',
            fileName: 'example1.jpeg',
            upload:'https://example1.jpeg'
          }
        }
      }
    }),
    space.createAsset({
      fields: {
        title: {
          'en-US': 'Example 2'
        },
        description: {
          'en-US': 'Example Description'
        },
        file: {
          'en-US': {
            contentType: 'image/jpeg',
            fileName: 'example2.jpeg',
            upload:'https://example2.jpeg'
          }
        }
      }
    }),
    //... 700 other assets
  })
  .then(asset => asset.processForAllLocales())
  .then(asset => console.log(asset))
  .catch(console.error)

而我运行的CLI函数是

contentful space migration ./contentful/contentful-import.js

返回 TypeError: migrationCreator is not a function

的错误

我查看了 Contentful 文档的其他地方,但没有找到任何有用的信息。

我是在尝试正确上传资产还是做错了什么?

您编写的脚本是"normal"node.js脚本。

node contentful-import.js

会很好地完成这项工作。 contentful space migration 使用特定格式的特定脚本(他们必须导出 migrationCreator)。有效的迁移是:

module.exports = function (migration, context) {
  const dog = migration.createContentType('dog');
  const name = dog.createField('name');
  name.type('Symbol').required(true);
};

contentful-cli 在后台使用 contentful-migration。您会在那里找到更多文档。

我将立即为 CLI 文档打开一个 PR。 :)