TypeError:migrationCreator不是函数

问题描述 投票:0回答:1

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

我正在使用的JavaScript脚本是

./content附录/content附录-import.就是

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文档中查看了其他内容,但我看不到任何有用的内容。

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

javascript contentful contentful-management
1个回答
1
投票

您编写的脚本是“普通”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);
};

内容丰富的cli在引擎盖下使用contentful-migration。你会在那里找到更多文档。

我将立即打开CLI文档的PR。 :)

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.