File: cli_helpers.go

package info (click to toggle)
golang-github-evanw-esbuild 0.25.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,184 kB
  • sloc: javascript: 28,602; makefile: 856; sh: 17
file content (64 lines) | stat: -rw-r--r-- 1,479 bytes parent folder | download | duplicates (2)
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
// This package contains internal CLI-related code that must be shared with
// other internal code outside of the CLI package.

package cli_helpers

import (
	"fmt"

	"github.com/evanw/esbuild/pkg/api"
)

type ErrorWithNote struct {
	Text string
	Note string
}

func MakeErrorWithNote(text string, note string) *ErrorWithNote {
	return &ErrorWithNote{
		Text: text,
		Note: note,
	}
}

func ParseLoader(text string) (api.Loader, *ErrorWithNote) {
	switch text {
	case "base64":
		return api.LoaderBase64, nil
	case "binary":
		return api.LoaderBinary, nil
	case "copy":
		return api.LoaderCopy, nil
	case "css":
		return api.LoaderCSS, nil
	case "dataurl":
		return api.LoaderDataURL, nil
	case "default":
		return api.LoaderDefault, nil
	case "empty":
		return api.LoaderEmpty, nil
	case "file":
		return api.LoaderFile, nil
	case "global-css":
		return api.LoaderGlobalCSS, nil
	case "js":
		return api.LoaderJS, nil
	case "json":
		return api.LoaderJSON, nil
	case "jsx":
		return api.LoaderJSX, nil
	case "local-css":
		return api.LoaderLocalCSS, nil
	case "text":
		return api.LoaderText, nil
	case "ts":
		return api.LoaderTS, nil
	case "tsx":
		return api.LoaderTSX, nil
	default:
		return api.LoaderNone, MakeErrorWithNote(
			fmt.Sprintf("Invalid loader value: %q", text),
			"Valid values are \"base64\", \"binary\", \"copy\", \"css\", \"dataurl\", \"empty\", \"file\", \"global-css\", \"js\", \"json\", \"jsx\", \"local-css\", \"text\", \"ts\", or \"tsx\".",
		)
	}
}