forked from contentful/contentful-migration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path22-transform-entries-to-type.js
36 lines (32 loc) · 1 KB
/
22-transform-entries-to-type.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const MurmurHash3 = require('imurmurhash');
// Basic example: create new content type.
module.exports = function (migration) {
// please run 01-angry-dog first, add some entries
// create new content type
const copycat = migration.createContentType('copycat').name('copy of dog').description('super friendly copy dog');
// add field
copycat.createField('woofs', {
name: 'woof woof woof',
type: 'Symbol',
required: true
});
// add entry title
copycat.displayField('woofs');
migration.transformEntriesToType({
sourceContentType: 'dog',
targetContentType: 'copycat',
from: ['woofs'],
shouldPublish: false,
updateReferences: true,
removeOldEntries: true,
identityKey: function (fields) {
const value = fields.woofs['en-US'].toString();
return MurmurHash3(value).result().toString();
},
transformEntryForLocale: function (fromFields, currentLocale) {
return {
woofs: `copy - ${fromFields.woofs[currentLocale]}`
};
}
});
};