Exemplo n.º 1
0
// ArchiveZip 打包资源
func (c *Change) ArchiveZip(pubpath string) string {
	util.CheckOrCreateDir(pubpath + "/" + c.name)
	temppath, delpath := c.moveToTemp(pubpath)
	zippath := pubpath + "/" + c.name + "/" + c.chname + ".zip"
	util.ArchiveZip(zippath, temppath)
	// 删除临时目录
	_ = os.RemoveAll(delpath)
	return c.chname + ".zip"
}
Exemplo n.º 2
0
// MoveToTemp 移动到临时目录
func (c *Change) moveToTemp(pubpath string) (string, string) {
	temppath := pubpath + "/" + c.name + "_temp/" + c.chname
	util.CheckOrCreateDir(temppath)

	// 获取变化的文件
	files := c.vtar.CompareFilter(&c.vsrc)
	for _, name := range files {
		src := c.vtar.Path + "/" + name

		dst := temppath + "/" + name
		util.CopyFile(src, dst)
	}
	delpath := pubpath + "/" + c.name + "_temp"
	return temppath, delpath
}
Exemplo n.º 3
0
// Publish 发布资源
func (c *Channel) Publish(host, engine string) {
	if len(c.versions) <= 1 {
		fmt.Println("没有要发布的资源")
		return
	}
	channelpath := c.pubpath + "/" + c.name
	util.CheckOrCreateDir(channelpath)

	// 设置源版本
	vsrc := c.versions[0]

	mf := manifest.NewManifest()
	// 基本设置
	mf.SetURL(host + "/" + c.name)
	mf.SetVersion(vsrc.Name)
	mf.SetEngineVersion(engine)

	// 变化从 1 索引开始,0 对比 1
	for i := 1; i < len(c.versions); i++ {
		// 目标版本
		vtar := c.versions[i]
		chg := NewChange(c.name, vsrc, vtar)
		zipfile := chg.ArchiveZip(c.pubpath)

		mf.AddGroupVersion(vtar.Name)
		md5, _ := util.GetFileMD5(channelpath + "/" + zipfile)
		mf.AddAsset(zipfile, md5)

		vsrc = vtar
	}

	path := c.pubpath + "/" + c.name + "/"
	con, _ := mf.MarshalMini()
	_ = ioutil.WriteFile(path+"version.manifest", con, 0644)
	// fmt.Println(string(con))
	con, _ = mf.Marshal()
	_ = ioutil.WriteFile(path+"project.manifest", con, 0644)
}