This repository has been archived by the owner on Apr 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
provider.go
75 lines (64 loc) · 1.45 KB
/
provider.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
69
70
71
72
73
74
75
package netlify
import (
_ "embed"
"os"
"path"
"github.com/devrel-blox/drb/hosting"
"github.com/pterm/pterm"
)
func init() {
vp := &NetlifyProvider{
internalName: "netlify",
internalDescription: "Netlify express api-only provider",
}
hosting.Register(vp.Name(), vp)
}
type NetlifyProvider struct {
internalName string
internalDescription string
}
func (p *NetlifyProvider) Name() string {
return p.internalName
}
func (p *NetlifyProvider) Description() string {
return p.internalDescription
}
func (p *NetlifyProvider) Install() error {
// make api directory
root, err := os.Getwd()
if err != nil {
return err
}
api := path.Join(root, "api")
err = os.MkdirAll(api, 0755)
if err != nil {
return err
}
// create index.js in api directory
index := path.Join(api, "index.mjs")
err = hosting.CreateFileWithContents(index, indexjs)
if err != nil {
return err
}
// create package.json
pkg := path.Join(root, "package.json")
err = hosting.CreateFileWithContents(pkg, packagejson)
if err != nil {
return err
}
// create netlify.toml
vc := path.Join(root, "netlify.toml")
err = hosting.CreateFileWithContents(vc, netlifyToml)
if err != nil {
return err
}
pterm.Info.Println("Netlify provider installed.")
pterm.Info.Println("Run `npm install` to install dependencies.")
return nil
}
//go:embed index.mjs
var indexjs string
//go:embed netlify.toml
var netlifyToml string
//go:embed package.json
var packagejson string