-
Notifications
You must be signed in to change notification settings - Fork 104
/
init.go
55 lines (44 loc) · 1.44 KB
/
init.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
package rillv1
import (
"context"
"fmt"
"strings"
"github.com/rilldata/rill/runtime/drivers"
)
// IsInit returns true if a Rill project exists in the repo
func IsInit(ctx context.Context, repo drivers.RepoStore, instanceID string) bool {
_, err := ParseRillYAML(ctx, repo, instanceID)
return err == nil
}
// InitEmpty initializes an empty project
func InitEmpty(ctx context.Context, repo drivers.RepoStore, instanceID, title string) error {
mockUsersInfo := "# These are example mock users to test your security policies.\n# For more information, see the documentation: https://docs.rilldata.com/manage/security"
mockUsers := "mock_users:\n- email: john@yourcompany.com\n- email: jane@partnercompany.com"
rillYAML := fmt.Sprintf("compiler: %s\n\ntitle: %q\n\n%s\n\n%s", Version, title, mockUsersInfo, mockUsers)
err := repo.Put(ctx, "rill.yaml", strings.NewReader(rillYAML))
if err != nil {
return err
}
gitignore, _ := repo.Get(ctx, ".gitignore")
if gitignore != "" {
gitignore += "\n"
}
gitignore += ".DS_Store\n\n# Rill\n.env\ntmp\n"
err = repo.Put(ctx, ".gitignore", strings.NewReader(gitignore))
if err != nil {
return err
}
err = repo.Put(ctx, "sources/.gitkeep", strings.NewReader(""))
if err != nil {
return err
}
err = repo.Put(ctx, "models/.gitkeep", strings.NewReader(""))
if err != nil {
return err
}
err = repo.Put(ctx, "dashboards/.gitkeep", strings.NewReader(""))
if err != nil {
return err
}
return nil
}