-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Contentful Entry Migration functions #3
base: master
Are you sure you want to change the base?
Conversation
5a38ca1
to
22cf6a1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Just one small comment. This project is shaping up, looking much better. Thanks for the contributions 🙌
seedEntries () { | ||
const entries = fs.readdirSync(this.entriesPath).map((f) => | ||
require(`${this.entriesPath}/${f}`) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is repeated between the two methods, maybe pull into a common function?
const entries = fs.readdirSync(this.entriesPath).map((f) => | ||
require(`${this.entriesPath}/${f}`) | ||
) | ||
return Promise.all(flatten(entries).map((e) => this.createEntry(e))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could roll the flatten in as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For flatten do you mean add flatten
as part of the exported Client
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More like:
seedEntries () {
return Promise.all(getEntryStructures().map(this.createEntry.bind(this)))
}
getEntryStructures () {
const entries = fs.readdirSync(this.entriesPath).map((f) =>
require(`${this.entriesPath}/${f}`)
)
return flatten(entries)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see. I handled the readdirSync
a little differently. Incorporating both then, what do you think of:
getEntryStructures () {
return flatten(this.readDataFromPath(this.entriesPath))
}
readDataFromPath (path) {
return fs.readdirSync(path).map((file) => require(`${path}/${file}`))
}
migrateContentTypes () {
const models = this.readDataFromPath(this.modelsPath)
return Promise.all(models.map((m) => this.updateContentType(m)))
}
migrateEntries () {
return Promise.all(getEntryStructures().map((e) => this.updateEntry(e)))
}
seedEntries () {
return Promise.all(getEntryStructures().map((e) => this.createEntry(e)))
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, much cleaner and more DRY 🙌
Maybe just use a path.join
rather than the manual string concat in the readDataFromPath
method, otherwise this looks perfect
Hello! I notice this PR hasn't been touched for a while, any chance of it being completed in the near future? |
createEntry
andupdateEntry
functionsmigrateEntries
(usesupdateEntry
) andseedEntries
(usescreateEntry
) functions