distutil

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2022 License: MIT Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

func CopyDirFiltered(srcDir, dstDir string, fileInclPattern *regexp.Regexp) error

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

func CopyFile(src, dst string) error

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 Must

func Must(err error)

Must panics if error.

func MustCopyDirFiltered

func MustCopyDirFiltered(srcDir, dstDir string, fileInclPattern *regexp.Regexp)

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

func MustEnvExec(env2 []string, name string, arg ...string) string

MustEnvExec is like MustExec but also sets specific environment variables.

func MustExec

func MustExec(name string, arg ...string) string

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

func WasmExecJsPath() (string, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL