コード例 #1
0
ファイル: main.go プロジェクト: RichardLitt/gx
func LoadPackageFile(path string) (*gx.Package, error) {
	var pkg gx.Package
	err := gx.LoadPackageFile(&pkg, path)
	if err != nil {
		return nil, err
	}
	return &pkg, nil
}
コード例 #2
0
ファイル: main.go プロジェクト: whyrusleeping/gx-go
func reqCheckHook(pkgpath string) error {
	var npkg Package
	pkgfile := filepath.Join(pkgpath, gx.PkgFileName)
	err := gx.LoadPackageFile(&npkg, pkgfile)
	if err != nil {
		return err
	}

	if npkg.Gx.GoVersion != "" {
		out, err := exec.Command("go", "version").CombinedOutput()
		if err != nil {
			return fmt.Errorf("no go compiler installed")
		}

		parts := strings.Split(string(out), " ")
		if len(parts) < 4 {
			return fmt.Errorf("unrecognized output from go compiler")
		}
		if parts[2] == "devel" {
			Log("warning: using unknown development version of go, proceed with caution")
			return nil
		}

		havevers := parts[2][2:]

		reqvers := npkg.Gx.GoVersion

		badreq, err := versionComp(havevers, reqvers)
		if err != nil {
			return err
		}
		if badreq {
			return fmt.Errorf("package '%s' requires at least go version %s, you have %s installed.", npkg.Name, reqvers, havevers)
		}

		gxgocompvers := runtime.Version()
		if strings.HasPrefix(gxgocompvers, "devel") {
			return nil
		}
		if strings.HasPrefix(gxgocompvers, "go") {
			badreq, err := versionComp(gxgocompvers[2:], reqvers)
			if err != nil {
				return err
			}
			if badreq {
				return fmt.Errorf("package '%s' requires at least go version %s.\nhowever, your gx-go binary was compiled with %s.\nPlease update gx-go (or recompile with your current go compiler)", npkg.Name, reqvers, gxgocompvers)
			}
		} else {
			Log("gx-go was compiled with an unrecognized version of go. (%s)", gxgocompvers)
			Log("If you encounter any strange issues during its usage, try rebuilding gx-go with go %s or higher", reqvers)
		}
	}
	return nil
}
コード例 #3
0
ファイル: main.go プロジェクト: whyrusleeping/gx-go
			return err
		}

		pkgdir := filepath.Join(gpath, "src", pkgpath)

		cmd := exec.Command("gx", "install")
		cmd.Dir = pkgdir
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr

		if err := cmd.Run(); err != nil {
			return err
		}

		var pkg Package
		if err := gx.LoadPackageFile(&pkg, filepath.Join(pkgdir, "package.json")); err != nil {
			return err
		}

		depsdir := filepath.Join(pkgdir, vendorDir)
		rwmapping := make(map[string]string)
		if err := buildRewriteMapping(&pkg, depsdir, rwmapping, false); err != nil {
			return err
		}

		if err := doRewrite(&pkg, pkgdir, rwmapping); err != nil {
			return err
		}

		return nil
	},
コード例 #4
0
ファイル: main.go プロジェクト: RichardLitt/gx
	Action: func(c *cli.Context) {
		if !c.Args().Present() {
			Fatal("must specify at least a query")
		}

		vendir := filepath.Join(cwd, vendorDir)

		var cfg map[string]interface{}
		if len(c.Args()) == 2 {
			ref := c.Args()[0]
			err := gx.LocalPackageByName(vendir, ref, &cfg)
			if err != nil {
				Fatal(err)
			}
		} else {
			err := gx.LoadPackageFile(&cfg, PkgFileName)
			if err != nil {
				Fatal(err)
			}
		}

		queryStr := c.Args()[len(c.Args())-1]
		var query []string
		for _, s := range strings.Split(queryStr, ".") {
			if s != "" {
				query = append(query, s)
			}
		}

		cur := cfg
		var val interface{} = cur