Documentation ¶
Overview ¶
Package distutil has some useful functions for building your Vugu application's distribution
Rather than introducing third party build tools. Authors of Vugu-based applications are encouraged to build their distribution files (output which is run on the production server) using a simple .go file which can be "go run"ed. This package makes some common tasks simpler:
Copying a directory of static files from one location to another. The destination directory can safely be a child of the source directory. Files which are up to date are not re-copied, for speed.
// by default uses DefaultFileInclPattern, matches common static file extensions distutil.MustCopyDirFiltered(fromDir, toDir, nil)
You can also provide your own pattern to say which files to copy:
distutil.MustCopyDirFiltered(fromDir, toDir, regexp.MustCompile(`[.](css|js|map|jpg|png|wasm)$`)
File the wasm_exec.js file included with your Go distribution and copy that:
distutil.MustCopyFile(distutil.MustWasmExecJsPath(), filepath.Join(toDir, "wasm_exec.js"))
Run a command and automatically include $GOPATH/bin (defaults to $HOME/go/bin) to $PATH. This makes it easy to ensure tools installed by "go get" are available during "go generate". (The output of the command is returned as a string, panics on error.)
fmt.Print(distutil.MustExec("go", "generate", "."))
Executing a command while overriding certain environment variables is also easy:
fmt.Print(distutil.MustEnvExec( []string{"GOOS=js", "GOARCH=wasm"}, "go", "build", "-o", filepath.Join(outDir, "main.wasm"), "."))
Index ¶
- Variables
- func CopyDirFiltered(srcDir, dstDir string, fileInclPattern *regexp.Regexp) error
- func CopyFile(src, dst string) error
- func Must(err error)
- func MustCopyDirFiltered(srcDir, dstDir string, fileInclPattern *regexp.Regexp)
- func MustCopyFile(src, dst string)
- func MustEnvExec(env2 []string, name string, arg ...string) string
- func MustExec(name string, arg ...string) string
- func MustWasmExecJsPath() string
- func WasmExecJsPath() (string, error)
Constants ¶
This section is empty.
Variables ¶
var DefaultFileInclPattern = regexp.MustCompile(`[.](css|js|html|map|jpg|jpeg|png|gif|svg|eot|ttf|otf|woff|woff2|wasm)$`)
DefaultFileInclPattern is a sensible default set of "static" files. This might be updated from time to time to include new types of assets used on the web. Extensions which are used for server executables, server configuration files, or files with an empty extension will not be added here.
Functions ¶
func CopyDirFiltered ¶
CopyDirFiltered recursively copies from srcDir to dstDir that match fileInclPattern. fileInclPattern is only checked against the base name of the file, not its directory. If fileInclPattern is nil, DefaultFileInclPattern will be used. The dstDir is skipped if encountered when recursing into srcDir. Directories are only created in the output dir if there's a file there. dstDir must already exist. For individual file copies, CopyFile() is used, which means files with the same name, modification time and size are assumed to be up to date and the function returns immediately. Conversely when the copy succeeds the modification time is set to that of the source.
func CopyFile ¶
CopyFile copies src to dest. Will not copy directories. Symlinks will have their contents copied. Files with the same name, modification time and size are assumed to be up to date and the function returns immediately. Conversely when the copy succeeds the modification time is set to that of the source.
func MustCopyDirFiltered ¶
MustCopyDirFiltered is like CopyDirFiltered but panics on error.
func MustCopyFile ¶
func MustCopyFile(src, dst string)
MustCopyFile is like CopyFile but panics on error.
func MustEnvExec ¶
MustEnvExec is like MustExec but also sets specific environment variables.
func MustExec ¶
MustExec wraps exec.Command(...).CombinedOutput() with certain differences. If `go env GOPATH`/bin exists it is added to the PATH environment variable. Upon error the output of the command and the error will be printed and it will panic. Upon success the output is returned as a string.
func MustWasmExecJsPath ¶
func MustWasmExecJsPath() string
MustWasmExecJsPath find wasm_exec.js in the local Go distribution and return it's path. Panic if not found.
func WasmExecJsPath ¶
WasmExecJsPath find wasm_exec.js in the local Go distribution and return it's path. Return error if not found.
Types ¶
This section is empty.