/
template.go
49 lines (40 loc) · 1.32 KB
/
template.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 link
import (
"encoding/json"
"strings"
msg "github.com/aziontech/azion-cli/messages/init"
"github.com/aziontech/azion-cli/pkg/contracts"
"github.com/aziontech/azion-cli/utils"
)
func (cmd *LinkCmd) createTemplateAzion(info *LinkInfo) error {
err := cmd.Mkdir(info.PathWorkingDir+"/azion", 0755) // 0755 is the permission mode for the new directories
if err != nil {
return msg.ErrorFailedCreatingAzionDirectory
}
azionJson := &contracts.AzionApplicationOptions{
Name: info.Name,
Env: "production",
Preset: strings.ToLower(info.Preset),
Mode: strings.ToLower(info.Mode),
Prefix: "",
}
azionJson.Function.Name = "__DEFAULT__"
azionJson.Function.InstanceName = "__DEFAULT__"
azionJson.Function.File = "./out/worker.js"
azionJson.Function.Args = "./azion/args.json"
azionJson.Domain.Name = "__DEFAULT__"
azionJson.Application.Name = "__DEFAULT__"
azionJson.RtPurge.PurgeOnPublish = true
return cmd.createJsonFile(azionJson, info)
}
func (cmd *LinkCmd) createJsonFile(options *contracts.AzionApplicationOptions, info *LinkInfo) error {
data, err := json.MarshalIndent(options, "", " ")
if err != nil {
return msg.ErrorUnmarshalAzionFile
}
err = cmd.WriteFile(info.PathWorkingDir+"/azion/azion.json", data, 0644)
if err != nil {
return utils.ErrorInternalServerError
}
return nil
}