forked from revel/revel
/
build.go
76 lines (61 loc) · 1.95 KB
/
build.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
76
package main
import (
"fmt"
"github.com/robfig/revel"
"github.com/robfig/revel/harness"
"os"
"path"
"path/filepath"
)
var cmdBuild = &Command{
UsageLine: "build [import path] [target path]",
Short: "build a Revel application (e.g. for deployment)",
Long: `
Build the Revel web application named by the given import path.
This allows it to be deployed and run on a machine that lacks a Go installation.
WARNING: The target path will be completely deleted, if it already exists!
For example:
revel build github.com/robfig/revel/samples/chat /tmp/chat
`,
}
func init() {
cmdBuild.Run = buildApp
}
func buildApp(args []string) {
if len(args) != 2 {
fmt.Fprintf(os.Stderr, "%s\n%s", cmdBuild.UsageLine, cmdBuild.Long)
return
}
appImportPath, destPath := args[0], args[1]
if !revel.Initialized {
revel.Init("", appImportPath, "")
}
os.RemoveAll(destPath)
os.MkdirAll(destPath, 0777)
app, reverr := harness.Build()
panicOnError(reverr, "Failed to build")
// Included are:
// - run scripts
// - binary
// - revel
// - app
// Revel and the app are in a directory structure mirroring import path
srcPath := path.Join(destPath, "src")
tmpRevelPath := path.Join(srcPath, filepath.FromSlash(revel.REVEL_IMPORT_PATH))
mustCopyFile(path.Join(destPath, filepath.Base(app.BinaryPath)), app.BinaryPath)
mustCopyDir(path.Join(tmpRevelPath, "conf"), path.Join(revel.RevelPath, "conf"), nil)
mustCopyDir(path.Join(tmpRevelPath, "templates"), path.Join(revel.RevelPath, "templates"), nil)
mustCopyDir(path.Join(srcPath, filepath.FromSlash(appImportPath)), revel.BasePath, nil)
tmplData := map[string]interface{}{
"BinName": filepath.Base(app.BinaryPath),
"ImportPath": appImportPath,
}
mustRenderTemplate(
path.Join(destPath, "run.sh"),
path.Join(revel.RevelPath, "cmd", "package_run.sh.template"),
tmplData)
mustRenderTemplate(
path.Join(destPath, "run.bat"),
path.Join(revel.RevelPath, "cmd", "package_run.bat.template"),
tmplData)
}