github.com/evanw/esbuild@v0.21.4/internal/cli_helpers/cli_helpers.go (about)

     1  // This package contains internal CLI-related code that must be shared with
     2  // other internal code outside of the CLI package.
     3  
     4  package cli_helpers
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"github.com/evanw/esbuild/pkg/api"
    10  )
    11  
    12  type ErrorWithNote struct {
    13  	Text string
    14  	Note string
    15  }
    16  
    17  func MakeErrorWithNote(text string, note string) *ErrorWithNote {
    18  	return &ErrorWithNote{
    19  		Text: text,
    20  		Note: note,
    21  	}
    22  }
    23  
    24  func ParseLoader(text string) (api.Loader, *ErrorWithNote) {
    25  	switch text {
    26  	case "base64":
    27  		return api.LoaderBase64, nil
    28  	case "binary":
    29  		return api.LoaderBinary, nil
    30  	case "copy":
    31  		return api.LoaderCopy, nil
    32  	case "css":
    33  		return api.LoaderCSS, nil
    34  	case "dataurl":
    35  		return api.LoaderDataURL, nil
    36  	case "default":
    37  		return api.LoaderDefault, nil
    38  	case "empty":
    39  		return api.LoaderEmpty, nil
    40  	case "file":
    41  		return api.LoaderFile, nil
    42  	case "global-css":
    43  		return api.LoaderGlobalCSS, nil
    44  	case "js":
    45  		return api.LoaderJS, nil
    46  	case "json":
    47  		return api.LoaderJSON, nil
    48  	case "jsx":
    49  		return api.LoaderJSX, nil
    50  	case "local-css":
    51  		return api.LoaderLocalCSS, nil
    52  	case "text":
    53  		return api.LoaderText, nil
    54  	case "ts":
    55  		return api.LoaderTS, nil
    56  	case "tsx":
    57  		return api.LoaderTSX, nil
    58  	default:
    59  		return api.LoaderNone, MakeErrorWithNote(
    60  			fmt.Sprintf("Invalid loader value: %q", text),
    61  			"Valid values are \"base64\", \"binary\", \"copy\", \"css\", \"dataurl\", \"empty\", \"file\", \"global-css\", \"js\", \"json\", \"jsx\", \"local-css\", \"text\", \"ts\", or \"tsx\".",
    62  		)
    63  	}
    64  }