Skip to content

Instantly share code, notes, and snippets.

@BraunreutherA
Created December 6, 2016 01:12
Show Gist options
  • Save BraunreutherA/af89e7483bd8d4150081fa0c553a4c8e to your computer and use it in GitHub Desktop.
Save BraunreutherA/af89e7483bd8d4150081fa0c553a4c8e to your computer and use it in GitHub Desktop.
Keystone.js custom fields
/**
* This little script copies the custom fields into the node modules directly into the keystone types.
* Afterwards it hooks into the keystone field types and registers the new model.
*
* ATTENTION if a model already exists it'll overwrite it.
* This way you can copy the fields and update them to your liking.
*/
var _ = require('lodash');
var shell = require('shelljs');
var path = require('path');
function customFields (keystone, fieldPath, nodeModulesPath, mapping) {
shell.cp('-R', `${fieldPath}/*`, path.join(nodeModulesPath, 'keystone', 'fields', 'types'));
_.assign(keystone.fieldTypes, mapping);
}
// customFields(
// keystone,
// path.join(__dirname, 'fields'),
// path.join(__dirname, 'node_modules'),
// { file: 'File' }
// );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment