-
Notifications
You must be signed in to change notification settings - Fork 9
/
web.go
68 lines (53 loc) · 1.82 KB
/
web.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package web
import (
"context"
"google.golang.org/protobuf/proto"
"namespacelabs.dev/foundation/internal/fnerrors"
"namespacelabs.dev/foundation/internal/frontend/cuefrontend/integration/nodejs"
"namespacelabs.dev/foundation/internal/frontend/fncue"
"namespacelabs.dev/foundation/internal/parsing"
"namespacelabs.dev/foundation/schema"
"namespacelabs.dev/foundation/std/pkggraph"
)
type Parser struct{}
func (i *Parser) Url() string { return "namespace.so/from-web" }
func (i *Parser) Shortcut() string { return "web" }
type cueIntegrationWeb struct {
DevPort int32 `json:"devPort"`
}
func (i *Parser) Parse(ctx context.Context, env *schema.Environment, pl parsing.EarlyPackageLoader, loc pkggraph.Location, v *fncue.CueV) (proto.Message, error) {
nodejsParser := &nodejs.Parser{}
rawNodejsBuild, err := nodejsParser.Parse(ctx, env, pl, loc, v)
if err != nil {
return nil, err
}
nodejsBuild, ok := rawNodejsBuild.(*schema.NodejsBuild)
if !ok {
return nil, fnerrors.InternalError("expected nodejs integration")
}
if nodejsBuild.Prod != nil {
nodejsBuild.Prod.InstallDeps = false
if nodejsBuild.Prod.BuildOutDir == "" {
nodejsBuild.Prod.BuildOutDir = "dist"
}
if nodejsBuild.Prod.BuildScript == "" {
return nil, fnerrors.NewWithLocation(loc, "The `build` script is required for prod web build")
}
}
var bits cueIntegrationWeb
if v != nil {
if err := v.Val.Decode(&bits); err != nil {
return nil, err
}
}
if bits.DevPort == 0 {
return nil, fnerrors.NewWithLocation(loc, "web integration requires `devPort`")
}
return &schema.WebIntegration{
Nodejs: nodejsBuild,
DevPort: bits.DevPort,
}, nil
}