Copyright 2021 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
Package static builds static assets for the frontend and the worker.
package static

import (
	
	
	

	
)

type Config struct {
	StaticPath string
	Watch      bool
	Write      bool
	Bundle     bool
}
Build compiles TypeScript files into minified JavaScript files using github.com/evanw/esbuild. When run with watch=true sourcemaps are placed inline, the output is unminified, and changes to any TypeScript files will force a rebuild of the JavaScript output. This function is used in Server.staticHandler with watch=true when cmd/frontend is run in dev mode and in devtools/cmd/static/main.go with watch=false for building productionized assets.
func ( Config) (*api.BuildResult, error) {
	var  []string
	 := .StaticPath
	,  := ioutil.ReadDir()
	if  != nil {
		return nil, 
	}
	for ,  := range  {
		if strings.HasSuffix(.Name(), ".ts") && !strings.HasSuffix(.Name(), ".test.ts") {
			 = append(, +"/"+.Name())
		}
	}
	 := api.BuildOptions{
		EntryPoints: ,
		Outdir:      ,
		Write:       .Write,
		Bundle:      .Bundle,
	}
	if .Watch {
		.Sourcemap = api.SourceMapInline
		.Watch = &api.WatchMode{}
	} else {
		.MinifyIdentifiers = true
		.MinifySyntax = true
		.MinifyWhitespace = true
		.Sourcemap = api.SourceMapLinked
	}
	 := api.Build()
	if len(.Errors) > 0 {
		return nil, fmt.Errorf("error building static files: %v", .Errors)
	}
	if len(.Warnings) > 0 {
		return nil, fmt.Errorf("error building static files: %v", .Warnings)
	}
	return &, nil