func mod() string {
	f, err := os.Open("go.mod")
	if err == nil {
		reader := bufio.NewReader(f)
		line, _, _ := reader.ReadLine()
		return strings.Replace(string(line), "module ", "", 1)
	}
	return ""
}
mod returns module name
package main
import (
	"bufio"
	"fmt"
	"os"
	"path"
	"path/filepath"
	"strings"
	"text/template"
	"github.com/magefile/mage/mg"
	"github.com/magefile/mage/sh"
)
var Default = Build
var (
	binPath   = path.Join("bin")
	buildPath = path.Join(binPath, "nodejs-portable.exe")
	buildEnv  = map[string]string{
		"GO111MODULE": "on",
		"GOOS":        "windows",
		"GOARCH":      "386",
		"CGO_ENABLED": "0",
	}
)
func Build() error {
	mg.Deps(Clean)
	mg.Deps(Generate)
	var args []string
	args = append(args, "build", "-o", buildPath, "-v")
	args = append(args, "-ldflags", flags())
	fmt.Println("⚙️ Go build...")
	if err := sh.RunWith(buildEnv, mg.GoCmd(), args...); err != nil {
		return err
	}
	return nil
}
func Clean() error {
	if err := createDir(binPath); err != nil {
		return err
	}
	if err := cleanDir(binPath); err != nil {
		return err
	}
	return nil
}
func Download() error {
	fmt.Println("⚙️ Go mod download...")
	if err := sh.RunWith(buildEnv, mg.GoCmd(), "mod", "download"); err != nil {
		return err
	}
	return nil
}
func Generate() error {
	mg.Deps(Download)
	mg.Deps(appConf)
	mg.Deps(versionInfo)
	fmt.Println("⚙️ Go generate...")
	if err := sh.RunV(mg.GoCmd(), "generate", "-v"); err != nil {
		return err
	}
	return nil
}
func flags() string {
	tag := tag()
	mod := mod()
	return fmt.Sprintf(`-s -w -X "main.version=%s" -X "main.module=%s"`, tag, mod)
}