This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
/
seed.ts
executable file
·67 lines (60 loc) · 1.53 KB
/
seed.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { Command, flags } from "@oclif/command"
import Listr from "listr"
import mongoose, { Mongoose } from "mongoose"
import { generate, init, loadModels, populate, createDocsFromData } from "../tasks"
import { CacheFile, log, Options } from "../utils"
import chalk from "chalk"
export type SmartMapType = {
pathToEntry: string
pathToRef: string
onModel: string
id: string
timestamp: number
}
export type ListrContext = {
config: Options
models: string[]
mongoose: Mongoose
cache?: CacheFile
smartMap: SmartMapType
}
export default class Seed extends Command {
static description = "describe the command here"
static examples = [`$ gooseberry seed`, `$ gooseberry seed [collection]`]
static flags = {
help: flags.help({ char: "h" }),
verbose: flags.boolean({ char: "v", default: false })
}
async run() {
log(`Seeding all collections`)
const { flags } = this.parse(Seed)
await new Listr<ListrContext>(
[
{
title: "Initializing",
task: init
},
{
title: "Loading models",
task: loadModels
},
{
title: "Transforming Seed Data",
task: generate
},
{
title: "Populating Smart References",
task: populate
},
{
title: `Feeding ${chalk.green("Gooseberries")} to Mongoose`,
task: createDocsFromData
}
],
{
renderer: flags.verbose ? "verbose" : "default"
}
).run()
await mongoose.disconnect()
}
}