Skip to content

Instantly share code, notes, and snippets.

@lokhmakov
Created October 21, 2018 10:41
Show Gist options
  • Save lokhmakov/256b58929d7b5562a7ae2f89ece29ded to your computer and use it in GitHub Desktop.
Save lokhmakov/256b58929d7b5562a7ae2f89ece29ded to your computer and use it in GitHub Desktop.
core/entity/api/generate/model.js
import { builders as b } from 'ast-types'
import generateRequire from './require'
import generateListAdd from './listAdd'
export default ({
name,
fields = [],
}) => {
const _typesDeclare = b.variableDeclaration(
'const',
[
b.variableDeclarator(
b.identifier('Types'),
b.identifier('keystone.Field.Types'),
)
]
)
const _listDeclare = b.variableDeclaration(
'const',
[
b.variableDeclarator(
b.identifier(name),
b.newExpression(
b.identifier('keystone.List'),
[
b.stringLiteral(name)
]
)
)
]
)
const _registerCall = b.expressionStatement(
b.callExpression(
b.identifier(`${ name }.register`),
[]
)
)
return b.program([
generateRequire({ name: `keystone`, from: `keystone`, }),
_typesDeclare,
_listDeclare,
generateListAdd({ name, fields }),
_registerCall,
])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment