Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve command incompatibility issue on Windows #86

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/wp2hugo/internal/hugogenerator/hugo_gen_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"path"
"strings"
"time"
"runtime"

"github.com/ashishb/wp2hugo/src/wp2hugo/internal/hugogenerator/hugopage"
"github.com/ashishb/wp2hugo/src/wp2hugo/internal/nginxgenerator"
Expand Down Expand Up @@ -164,17 +165,18 @@
return nil, fmt.Errorf("hugo not found, install it from https://gohugo.io/: %s", err)
}

// Create output directory
os.MkdirAll(outputDirPath, 0700)

Check failure on line 169 in src/wp2hugo/internal/hugogenerator/hugo_gen_setup.go

View workflow job for this annotation

GitHub Actions / lintGo (1.23)

Error return value of `os.MkdirAll` is not checked (errcheck)

commands := []string{
"git version",
"hugo version",
fmt.Sprintf("mkdir -p %s", outputDirPath),
// Use YAML file as it is easier to edit it afterward than TOML
fmt.Sprintf("cd %s && hugo new site %s --format yaml", outputDirPath, siteName),
fmt.Sprintf("cd %s && git clone https://github.com/adityatelange/hugo-PaperMod themes/PaperMod --depth=1",
path.Join(outputDirPath, siteName)),
fmt.Sprintf("cd %s && rm -rf themes/PaperMod/.git themes/PaperMod/.github", path.Join(outputDirPath, siteName)),
// Set theme to PaperMod
fmt.Sprintf(`echo "theme: 'PaperMod'">> %s/hugo.yaml`, path.Join(outputDirPath, siteName)),
fmt.Sprintf(`echo theme: 'PaperMod'>> %s/hugo.yaml`, path.Join(outputDirPath, siteName)),
// Verify that the site is set up correctly
fmt.Sprintf("cd %s && hugo", path.Join(outputDirPath, siteName)),
}
Expand All @@ -184,7 +186,16 @@
Int("totalSteps", len(commands)).
Str("cmd", command).
Msg("Running Hugo setup command")
output, err := exec.Command("bash", "-c", command).Output()
var (
output []byte
err error
)
if runtime.GOOS == "windows" {
output, err = exec.Command("cmd", "/C", command).Output()
} else {
// mac & Linux
output, err = exec.Command("bash", "-c", command).Output()
}
if err != nil {
log.Error().
Err(err).
Expand All @@ -196,6 +207,10 @@
log.Debug().Msgf("Hugo setup output: %s", output)
}

// Delete .git directory
os.RemoveAll(path.Join(outputDirPath, siteName, "themes/PaperMod/.git"))
os.RemoveAll(path.Join(outputDirPath, siteName, "themes/PaperMod/.github"))

siteDir := path.Join(outputDirPath, siteName)
log.Info().
Str("location", siteDir).
Expand Down
Loading