MCPcopy
hub / github.com/gopherjs/gopherjs / main

Function main

tool.go:67–593  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

65}
66
67func main() {
68 var (
69 options = &gbuild.Options{}
70 pkgObj string
71 tags string
72 )
73
74 flagVerbose := pflag.NewFlagSet("", 0)
75 flagVerbose.BoolVarP(&options.Verbose, "verbose", "v", false, "print the names of packages as they are compiled")
76 flagQuiet := pflag.NewFlagSet("", 0)
77 flagQuiet.BoolVarP(&options.Quiet, "quiet", "q", false, "suppress non-fatal warnings")
78
79 compilerFlags := pflag.NewFlagSet("", 0)
80 compilerFlags.BoolVarP(&options.Minify, "minify", "m", false, "minify generated code")
81 compilerFlags.BoolVar(&options.Color, "color", term.IsTerminal(int(os.Stderr.Fd())) && os.Getenv("TERM") != "dumb", "colored output")
82 compilerFlags.StringVar(&tags, "tags", "", "a list of build tags to consider satisfied during the build")
83 compilerFlags.BoolVar(&options.MapToLocalDisk, "localmap", false, "use local paths for sourcemap")
84 compilerFlags.BoolVarP(&options.NoCache, "no_cache", "a", false, "rebuild all packages from scratch")
85 compilerFlags.BoolVarP(&options.CreateMapFile, "source_map", "s", true, "enable generation of source maps")
86
87 flagWatch := pflag.NewFlagSet("", 0)
88 flagWatch.BoolVarP(&options.Watch, "watch", "w", false, "watch for changes to the source files")
89
90 cmdBuild := &cobra.Command{
91 Use: "build [packages]",
92 Short: "compile packages and dependencies",
93 }
94 cmdBuild.Flags().StringVarP(&pkgObj, "output", "o", "", "output file")
95 cmdBuild.Flags().AddFlagSet(flagVerbose)
96 cmdBuild.Flags().AddFlagSet(flagQuiet)
97 cmdBuild.Flags().AddFlagSet(compilerFlags)
98 cmdBuild.Flags().AddFlagSet(flagWatch)
99 cmdBuild.RunE = func(cmd *cobra.Command, args []string) error {
100 options.BuildTags = strings.Fields(tags)
101 for {
102 s, err := gbuild.NewSession(options)
103 if err != nil {
104 options.PrintError("%s\n", err)
105 return err
106 }
107
108 err = func() error {
109 // Handle "gopherjs build [files]" ad-hoc package mode.
110 if len(args) > 0 && (strings.HasSuffix(args[0], ".go") || strings.HasSuffix(args[0], incjs.Ext)) {
111 for _, arg := range args {
112 if !strings.HasSuffix(arg, ".go") && !strings.HasSuffix(arg, incjs.Ext) {
113 return fmt.Errorf("named files must be .go or %s files", incjs.Ext)
114 }
115 }
116 if pkgObj == "" {
117 basename := filepath.Base(args[0])
118 pkgObj = basename[:len(basename)-3] + ".js"
119 }
120 names := make([]string, len(args))
121 for i, name := range args {
122 name = filepath.ToSlash(name)
123 names[i] = name
124 if s.Watcher != nil {

Callers

nothing calls this directly

Calls 15

handleErrorFunction · 0.85
runNodeFunction · 0.85
runTestDirFunction · 0.85
RemoveMethod · 0.80
PrintfMethod · 0.80
AddMethod · 0.65
StringMethod · 0.65
ImportMethod · 0.45
NameMethod · 0.45
CloseMethod · 0.45
BoolMethod · 0.45
NewMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…