Ejemplo n.º 1
0
func runProjectVersion(cmd *cobra.Command, args []string) {
	initProjectDir(args)
	version, err := settings.ReadVersion(projectDir)
	if err != nil {
		Quitf("%s\n", err)
	}
	fmt.Println(version)
}
Ejemplo n.º 2
0
func GetProjectInfo() (*ProjectInfo, error) {
	// Read the current version and name
	project := ""
	manifests := []Manifest{}
	mf, err := tryReadManifest(packageJsonFile)
	if err != nil {
		return nil, maskAny(err)
	}
	var oldVersion string
	if mf != nil {
		manifests = append(manifests, *mf)
		oldVersion = mf.Data[versionKey].(string)
		project = mf.Data[nameKey].(string)
	}
	if oldVersion == "" {
		// Read version from VERSION file
		oldVersion, err = settings.ReadVersion(".")
		if err != nil {
			return nil, maskAny(err)
		}
	}
	if oldVersion == "" {
		oldVersion = "0.0.1"
	}
	if project == "" {
		// Take current directory as name
		if dir, err := os.Getwd(); err != nil {
			return nil, maskAny(err)
		} else {
			project = path.Base(dir)
		}
	}

	// Read project settings (if any)
	image := project
	registry := ""
	namespace := ""
	noGrunt := false
	tagLatest := false
	tagMajorVersion := false
	tagMinorVersion := false
	gradleConfigFile := ""
	gitBranch := "master"
	var githubAssets []settings.GithubAsset
	settings, err := settings.Read(".")
	if err != nil {
		return nil, maskAny(err)
	}
	if settings != nil {
		if settings.Image != "" {
			image = settings.Image
		}
		if settings.Registry != "" {
			registry = settings.Registry
		}
		if settings.Namespace != "" {
			namespace = settings.Namespace
		}
		noGrunt = settings.NoGrunt
		tagLatest = settings.TagLatest
		tagMajorVersion = settings.TagMajorVersion
		tagMinorVersion = settings.TagMinorVersion
		gradleConfigFile = settings.GradleConfigFile
		if settings.GitBranch != "" {
			gitBranch = settings.GitBranch
		}
		githubAssets = settings.GithubAssets

		for _, path := range settings.ManifestFiles {
			mf, err := tryReadManifest(path)
			if err != nil {
				return nil, maskAny(err)
			} else if mf == nil {
				return nil, maskAny(fmt.Errorf("manifest '%s' not found", path))
			}
			manifests = append(manifests, *mf)
		}
	}

	result := &ProjectInfo{
		Name:             project,
		Image:            image,
		Registry:         registry,
		Namespace:        namespace,
		NoGrunt:          noGrunt,
		TagLatest:        tagLatest,
		TagMajorVersion:  tagMajorVersion,
		TagMinorVersion:  tagMinorVersion,
		GitBranch:        gitBranch,
		Version:          oldVersion,
		Manifests:        manifests,
		GradleConfigFile: gradleConfigFile,
		GithubAssets:     githubAssets,
	}
	result.Targets.CleanTarget = "clean"
	if settings != nil && settings.Targets.CleanTarget != "" {
		result.Targets.CleanTarget = settings.Targets.CleanTarget
	}
	result.Targets.ReleaseTarget = ""
	if settings != nil && settings.Targets.ReleaseTarget != "" {
		result.Targets.ReleaseTarget = settings.Targets.ReleaseTarget
	}

	return result, nil
}