打包时包含源文件

pull/1/head
chai2010 2016-02-15 16:47:48 +08:00
parent e94fc341de
commit 79fe61e65c
1 changed files with 13 additions and 0 deletions

View File

@ -29,6 +29,9 @@ func main() {
// zip文件名
zipBaseName := fmt.Sprintf("gopl-zh-%s-%s", time.Now().Format("20060102"), gitVersion[:6])
// 导出Git
exportGitToZip("./_book/" + zipBaseName + ".source.zip")
os.Remove(zipBaseName + ".zip")
file, err := os.Create(zipBaseName + ".zip")
if err != nil {
@ -112,6 +115,16 @@ func getGitCommitVersion() (version string) {
return "master"
}
// 导出Git到Zip文件
func exportGitToZip(filename string) {
if !strings.HasSuffix(filename, ".zip") {
filename += ".zip"
}
if _, err := exec.Command(`git`, `archive`, `--format`, `zip`, `--output`, filename, `master`).CombinedOutput(); err != nil {
log.Fatal("cpFile: ", err)
}
}
func cpFile(dst, src string) {
err := os.MkdirAll(filepath.Dir(dst), 0666)
if err != nil && !os.IsExist(err) {