-
Notifications
You must be signed in to change notification settings - Fork 6
/
parse_schema.go
49 lines (43 loc) · 1.12 KB
/
parse_schema.go
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
package cmd
import (
"fmt"
"os"
"time"
"github.com/lolopinto/ent/internal/codegen"
"github.com/lolopinto/ent/internal/schema"
"github.com/lolopinto/ent/internal/schema/base"
"github.com/lolopinto/ent/internal/schema/input"
)
func parseSchemaImpl(cfg *codegen.Config) (*schema.Schema, error) {
// assume we're running from base of directory
path, err := os.Getwd()
if err != nil {
return nil, err
}
inputSchema, err := input.ParseSchemaFromTSDir(path, false)
if err != nil {
return nil, err
}
// need a codepath here...
// instead of lang, we want Options
// lang, pathToRoot, allowUserInput
return schema.ParseFromInputSchema(cfg, inputSchema, base.TypeScript)
}
func parseSchemaFromConfig(cfg *codegen.Config) (*schema.Schema, error) {
if !rootInfo.debug {
return parseSchemaImpl(cfg)
}
t1 := time.Now()
s, err := parseSchemaImpl(cfg)
t2 := time.Now()
diff := t2.Sub(t1)
fmt.Println("parse schema took", diff)
return s, err
}
func parseSchemaNoConfig() (*schema.Schema, error) {
cfg, err := codegen.NewConfig("src/schema", "")
if err != nil {
return nil, err
}
return parseSchemaFromConfig(cfg)
}