@greenberry/datocms-migration-utils
A collection of utils to help with the development of DatoCMS migration files.
yarn add @greenberry/datocms-migration-utils -D
Each field creator method need 3 arguments a working DatoCMS SiteClient , field options and the modelId you want to attach the field to.
await createFieldMethod ( client , options , modelId ) ;
Key
Type
Required
label
String
✅
apiKey
String
✅
hint
String
❌
localized
Boolean
❌
required
Boolean
❌
Key
Type
Required
label
String
✅
apiKey
String
✅
hint
String
❌
localized
Boolean
❌
required
Boolean
❌
presetColors
[#000]
❌
enableAlpha
Boolean
❌
Key
Type
Required
label
String
✅
apiKey
String
✅
hint
String
❌
localized
Boolean
❌
required
Boolean
❌
Key
Type
Required
label
String
✅
apiKey
String
✅
hint
String
❌
localized
Boolean
❌
required
Boolean
❌
dateRange
{min: 'ISO-8601', max: 'ISO-8601'}
❌
Key
Type
Required
label
String
✅
apiKey
String
✅
hint
String
❌
localized
Boolean
❌
required
Boolean
❌
dateRange
{min: 'ISO-8601', max: 'ISO-8601'}
❌
Key
Type
Required
label
String
✅
apiKey
String
✅
options
[String]
✅
defaultValue
String
❌
hint
String
❌
localized
Boolean
❌
required
Boolean
❌
Key
Type
Required
label
String
✅
apiKey
String
✅
hint
String
❌
localized
Boolean
❌
required
Boolean
❌
Key
Type
Required
label
String
✅
apiKey
String
✅
items
[ItemType ID]
✅
hint
String
❌
localized
Boolean
❌
required
Boolean
❌
unique
Boolean
❌
Key
Type
Required
label
String
✅
apiKey
String
✅
items
[ItemType ID]
✅
size
{ min: Number, max: Number }
❌
hint
String
❌
localized
Boolean
❌
required
Boolean
❌
Key
Type
Required
label
String
✅
apiKey
String
✅
blockIds
[ItemType ID]
✅
hint
String
❌
localized
Boolean
❌
required
Boolean
❌
Key
Type
Required
label
String
✅
apiKey
String
✅
hint
String
❌
localized
Boolean
❌
required
Boolean
❌
Key
Type
Required
label
String
✅
apiKey
String
✅
hint
String
❌
localized
Boolean
❌
Key
Type
Required
label
String
✅
apiKey
String
✅
hint
String
❌
localized
Boolean
❌
required
Boolean
❌
heading
Boolean
❌
Key
Type
Required
label
String
✅
apiKey
String
✅
titleField
Field
✅
prefix
String
❌
hint
String
❌
localized
Boolean
❌
required
Boolean
❌
Key
Type
Required
label
String
✅
apiKey
String
✅
hint
String
❌
localized
Boolean
❌
required
Boolean
❌
Key
Type
Required
label
String
✅
apiKey
String
✅
hint
String
❌
localized
Boolean
❌
required
Boolean
❌
toolbar
Array
❌
Key
Type
Required
label
String
✅
apiKey
String
✅
localized
Boolean
❌
hint
String
❌
blockIds
[ItemType ID]
✅
DatoCMS only accepts a specific format when filling colors. That is why we added a util to format hex values in a shape acceptable by DatoCMS.
const color = formatColor ( '#000000' ) ;
console . log ( color ) ;
// {
// red: 0,
// blue: 0,
// green: 0,
// alpha: 255,
// }
formatColor also accepts a second argument to specify the alpha of the color, this works in the same way as CSS opacity.
const color = formatColor ( '#000000' , 0.8 ) ;
console . log ( color ) ;
// {
// red: 0,
// blue: 0,
// green: 0,
// alpha: 204,
// }