Exemple #1
0
func (d *DefaultRenderer) copyStatic() error {
	theme := d.getTheme()
	out := d.getOutputDir()
	switch theme {
	case defaultTheme:
		info, _ := os.Stat(d.root)
		for _, f := range gh.AssetNames() {
			if filepath.Ext(f) == ".html" {
				continue
			}
			base := filepath.Join(out, filepath.Dir(f))
			os.MkdirAll(base, info.Mode())
			b, err := gh.Asset(f)
			if err != nil {
				return err
			}
			err = ioutil.WriteFile(filepath.Join(out, f), b, DefaultPerm)
			if err != nil {
				log.Println(err, base)
				return err
			}
		}
		return nil
	default:
		// we copy the static directory in the current theme directory
		staticDir := filepath.Join(d.root, ThemeDir, theme, StaticDir)
		if com.IsExist(staticDir) {
			err := com.CopyDir(staticDir, filepath.Join(d.root, OutputDir, StaticDir))
			if err != nil {
				return err
			}
		}

	}

	// if we have the static set on the config file we use it.
	if staticDirective, ok := d.config[StaticDir]; ok {
		switch staticDirective.(type) {
		case []interface{}:
			sd := staticDirective.([]interface{})
			for _, f := range sd {
				dir := f.(string)
				err := com.CopyDir(filepath.Join(d.root, dir), filepath.Join(out, dir))
				if err != nil {
					return err
				}
			}
		}
	}
	return nil
}
Exemple #2
0
func makeLink(srcPath, destPath string) error {
	// Check if Windows version is XP.
	if getWindowsVersion() >= 6 {
		cmd := exec.Command("cmd", "/c", "mklink", "/j", destPath, srcPath)
		return cmd.Run()
	}

	// XP.
	isWindowsXP = true
	// if both are ntfs file system
	if volumnType(srcPath) == "NTFS" && volumnType(destPath) == "NTFS" {
		// if has junction command installed
		file, err := exec.LookPath("junction")
		if err == nil {
			path, _ := filepath.Abs(file)
			if com.IsFile(path) {
				cmd := exec.Command("cmd", "/c", "junction", destPath, srcPath)
				return cmd.Run()
			}
		}
	}
	os.RemoveAll(destPath)

	return com.CopyDir(srcPath, destPath, func(filePath string) bool {
		return strings.Contains(filePath, doc.VENDOR)
	})
}
Exemple #3
0
func copyToGopath(srcPath, destPath string) {
	os.RemoveAll(destPath)
	err := com.CopyDir(srcPath, destPath)
	if err != nil {
		log.Error("download", "Fail to copy to GOPATH:")
		log.Fatal("", "\t"+err.Error())
	}
}
Exemple #4
0
func (e *Event) packTarget(srcPath, name, destDir string, target setting.Target) (err error) {
	binName := name
	if target.GOOS == "windows" {
		binName += ".exe"
	}

	if err = os.MkdirAll(destDir, os.ModePerm); err != nil {
		return err
	}

	targetPath := path.Join(destDir, name+"_"+e.targetString(target))
	log.Debug("Packing target to: %s", targetPath)

	if err = os.RemoveAll(targetPath); err != nil {
		return err
	}

	zipPath := targetPath + ".zip"
	packPath := path.Join(targetPath, name)
	if err = os.MkdirAll(packPath, os.ModePerm); err != nil {
		return err
	}

	if err = os.Rename(path.Join(srcPath, binName), path.Join(packPath, binName)); err != nil {
		return err
	}

	// Pack resources.
	for _, resName := range setting.Resources {
		resPath := path.Join(srcPath, resName)
		destPath := path.Join(packPath, resName)
		if com.IsDir(resPath) {
			err = com.CopyDir(resPath, destPath)
		} else {
			err = com.Copy(resPath, destPath)
		}
		if err != nil {
			return err
		}
	}

	if err = zip.PackTo(targetPath, zipPath); err != nil {
		return err
	}

	os.RemoveAll(targetPath)
	return nil
}
Exemple #5
0
func copyToGopath(srcPath, destPath string) {
	importPath := strings.TrimPrefix(destPath, installGopath+"/")
	if len(getVcsName(destPath)) > 0 {
		log.Warn("Package in GOPATH has version control: %s", importPath)
		return
	}

	os.RemoveAll(destPath)
	err := com.CopyDir(srcPath, destPath)
	if err != nil {
		log.Error("download", "Fail to copy to GOPATH:")
		log.Fatal("", "\t"+err.Error())
	}

	log.Log("Package copied to GOPATH: %s", importPath)
}
Exemple #6
0
func makeLink(srcPath, destPath string) error {
	srcPath = strings.Replace(srcPath, "/", "\\", -1)
	destPath = strings.Replace(destPath, "/", "\\", -1)

	// Check if Windows version is XP.
	if getWindowsVersion() >= 6 {
		_, stderr, err := com.ExecCmd("cmd", "/c", "mklink", "/j", destPath, srcPath)
		if err != nil {
			return errors.New(stderr)
		}
		return nil
	}

	// XP.
	setting.IsWindowsXP = true
	// if both are ntfs file system
	if volumnType(srcPath) == "NTFS" && volumnType(destPath) == "NTFS" {
		// if has junction command installed
		file, err := exec.LookPath("junction")
		if err == nil {
			path, _ := filepath.Abs(file)
			if com.IsFile(path) {
				_, stderr, err := com.ExecCmd("cmd", "/c", "junction", destPath, srcPath)
				if err != nil {
					return errors.New(stderr)
				}
				return nil
			}
		}
	}
	os.RemoveAll(destPath)

	return com.CopyDir(srcPath, destPath, func(filePath string) bool {
		return strings.Contains(filePath, setting.VENDOR)
	})
}
Exemple #7
0
func runBin(ctx *cli.Context) {
	setup(ctx)

	if len(ctx.Args()) == 0 {
		log.Error("bin", "Cannot start command:")
		log.Fatal("", "\tNo package specified")
	}

	installRepoPath = doc.HomeDir + "/repos"
	log.Log("Local repository path: %s", installRepoPath)

	// Check arguments.
	num := 1
	if ctx.Bool("dir") {
		num = 2
	}
	if len(ctx.Args()) != num {
		log.Error("bin", "Cannot start command:")
		log.Fatal("", "\tMissing indicated path to build binary")
	}

	// Check if given directory exists.
	if ctx.Bool("dir") && !com.IsDir(ctx.Args()[1]) {
		log.Error("bin", "Cannot start command:")
		log.Fatal("", "\tIndicated path does not exist or is not a directory")
	}

	// Parse package version.
	info := ctx.Args()[0]
	pkgPath := info
	node := doc.NewNode(pkgPath, pkgPath, doc.BRANCH, "", true)
	var err error
	if i := strings.Index(info, "@"); i > -1 {
		pkgPath = info[:i]
		node.ImportPath = pkgPath
		node.DownloadURL = pkgPath
		node.Type, node.Value = validPath(info[i+1:])
	}

	// Check package name.
	if !strings.Contains(pkgPath, "/") {
		pkgPath = doc.GetPkgFullPath(pkgPath)
	}

	// Get code.
	downloadPackages(ctx, []*doc.Node{node})

	// Check if previous steps were successful.
	repoPath := installRepoPath + "/" + pkgPath + versionSuffix(node.Value)
	if !com.IsDir(repoPath) {
		log.Error("bin", "Cannot continue command:")
		log.Fatal("", "\tPrevious steps weren't successful")
	}

	wd, err := os.Getwd()
	if err != nil {
		log.Error("bin", "Cannot get work directory:")
		log.Fatal("", "\t"+err.Error())
	}

	// Change to repository path.
	log.Log("Changing work directory to %s", repoPath)
	if err = os.Chdir(repoPath); err != nil {
		log.Error("bin", "Fail to change work directory:")
		log.Fatal("", "\t"+err.Error())
	}

	// Build application.
	buildBinary(ctx)
	defer func() {
		// Clean files.
		os.RemoveAll(path.Join(repoPath, doc.VENDOR))
	}()

	includes := make([]string, 0, 3)
	// Check if previous steps were successful.
	if com.IsFile(doc.GOPM_FILE_NAME) {
		log.Trace("Loading gopmfile...")
		gf := doc.NewGopmfile(".")

		var err error
		pkgName, err = gf.GetValue("target", "path")
		if err == nil {
			log.Log("Target name: %s", pkgName)
		}

		includes = strings.Split(gf.MustValue("res", "include"), "|")
	}

	if len(pkgName) == 0 {
		_, pkgName = filepath.Split(pkgPath)
	}

	// Because build command moved binary to root path.
	binName := path.Base(pkgName)
	if runtime.GOOS == "windows" {
		binName += ".exe"
	}
	if !com.IsFile(binName) {
		log.Error("bin", "Binary does not exist:")
		log.Error("", "\t"+binName)
		log.Fatal("", "\tPrevious steps weren't successful or the project does not contain main package")
	}

	// Move binary to given directory.
	movePath := wd
	if ctx.Bool("dir") {
		movePath = ctx.Args()[1]
	}

	if com.IsExist(movePath + "/" + binName) {
		if err = os.Remove(movePath + "/" + binName); err != nil {
			log.Warn("Cannot remove binary in work directory:")
			log.Warn("\t %s", err)
		}
	}

	if err = os.Rename(binName, movePath+"/"+binName); err != nil {
		log.Error("bin", "Fail to move binary:")
		log.Fatal("", "\t"+err.Error())
	}
	os.Chmod(movePath+"/"+binName, os.ModePerm)

	if len(includes) > 0 {
		log.Log("Copying resources to %s", movePath)
		for _, include := range includes {
			if com.IsDir(include) {
				if err = com.CopyDir(include, filepath.Join(movePath, include)); err != nil {
					log.Error("bin", "Fail to copy following resource:")
					log.Error("", "\t"+include)
				}
			}
		}
	}

	log.Log("Changing work directory back to %s", wd)
	os.Chdir(wd)

	log.Success("SUCC", "bin", "Command executed successfully!")
	fmt.Println("Binary has been built into: " + movePath)
}