fix: linux cp theme failed

This commit is contained in:
Young Xu 2023-02-19 00:05:43 +08:00
parent d769f4115d
commit e2c140706e
Signed by: xuthus5
GPG Key ID: A23CF9620CBB55F9
1 changed files with 31 additions and 20 deletions

View File

@ -73,29 +73,40 @@ func (o *Outter) createDir(fp string) error {
// sourceCopy 资源拷贝 将主题的资源拷贝到目标文件夹中
func (o *Outter) sourceCopy() {
var args []string
sourcePath := slash(fmt.Sprintf("./themes/%s/", o.Config.Theme))
destPath := slash("./dist/" + o.Config.SourceVersion + "/")
switch runtime.GOOS {
case "windows":
args = []string{"cmd.exe", "/C", "xcopy", "/e", "/y"}
// args = []string{"cmd.exe", "/C", "xcopy", "/e", "/y"}
default:
args = []string{"cp", "-r"}
}
themePath := slash(fmt.Sprintf("./themes/%s/", o.Config.Theme))
destPath := slash("./dist/" + o.Config.SourceVersion + "/")
cmd := exec.Command(args[0], append(args[1:], themePath+"css", slash(destPath+"css/"))...)
if err := cmd.Run(); err != nil {
sout(cmd.String())
sfault("copy theme css source failed: %v", err)
}
cmd = exec.Command(args[0], append(args[1:], themePath+"js", slash(destPath+"js/"))...)
if err := cmd.Run(); err != nil {
sout(cmd.String())
sfault("copy theme js source failed: %v", err)
}
cmd = exec.Command(args[0], append(args[1:], themePath+"images", slash(destPath+"images/"))...)
if err := cmd.Run(); err != nil {
sout(cmd.String())
sfault("copy theme images source failed: %v", err)
// mkdir
cssDir := fmt.Sprintf("%s/css", destPath)
jsDir := fmt.Sprintf("%s/js", destPath)
imagesDir := fmt.Sprintf("%s/images", destPath)
if err := mkdir(cssDir); err != nil {
sfault("mkdir css directory failed: %v", err)
}
if err := mkdir(jsDir); err != nil {
sfault("mkdir js directory failed: %v", err)
}
if err := mkdir(imagesDir); err != nil {
sfault("mkdir images directory failed: %v", err)
}
cmd := exec.Command("cp", "-r", sourcePath+"css", destPath)
if err := cmd.Run(); err != nil {
sout(cmd.String())
sfault("copy theme css source failed: %v", err)
}
cmd = exec.Command("cp", "-r", sourcePath+"js", destPath)
if err := cmd.Run(); err != nil {
sout(cmd.String())
sfault("copy theme js source failed: %v", err)
}
cmd = exec.Command("cp", "-r", sourcePath+"images", destPath)
if err := cmd.Run(); err != nil {
sout(cmd.String())
sfault("copy theme images source failed: %v", err)
}
}
}