()
| 65 | } |
| 66 | |
| 67 | func 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 { |
nothing calls this directly
no test coverage detected
searching dependent graphs…