Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
add priority of models
Browse files Browse the repository at this point in the history
  • Loading branch information
hennessyevan committed Sep 13, 2019
1 parent de232b6 commit ff4ef07
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@
"/oclif.manifest.json"
],
"homepage": "https://github.com/hennessyevan/gooseberry",
"keywords": [
"oclif"
],
"gooseberry": {
"modelDir": "./demo/models",
"mongoURI": "mongodb://localhost:27017/test",
"dataDir": "./demo/data",
"dropDatabase": true
"dropDatabase": true,
"top": [
"User"
]
},
"license": "MIT",
"main": "lib/index.js",
Expand Down
18 changes: 17 additions & 1 deletion src/tasks/createDocsFromData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,23 @@ import { ListrContext } from "../commands/seed"

export async function createDocsFromData(ctx: ListrContext, task: ListrTaskWrapper) {
if (ctx.cache) {
const creationPromises = Object.entries(ctx.cache).map(async ([modelName, { data }]) => {
let order = Object.keys(ctx.cache)
if (ctx.config.top) {
order.sort((a, b) => {
if (ctx.config.top!.includes(a)) {
if (ctx.config.top!.includes(b)) {
if (ctx.config.top!.indexOf(a) < ctx.config.top!.indexOf(b)) {
return -1
}
return 1
}
return -1
}
return 1
})
}
const creationPromises = order.map(async modelName => {
const { data } = ctx.cache![modelName]
const model = mongoose.model(modelName)
task.output = modelName

Expand Down
1 change: 1 addition & 0 deletions src/utils/parseOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type Options = {
modelDir: string
mongoURI: string
dataDir: string
top?: string[]
dropDatabase?: boolean
}

Expand Down

0 comments on commit ff4ef07

Please sign in to comment.