Skip to content

Commit 73785b3

Browse files
committed
[FEAT] Add support for docusaurus builds
1 parent bdd934d commit 73785b3

2 files changed

Lines changed: 44 additions & 8 deletions

File tree

server/buildserver.go

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,28 @@ func updateBranch(cloneURL, branch string, silent bool) {
4444
}
4545
}
4646

47-
// Run the retype build command
48-
cmd := exec.Command("retype", "build")
49-
cmd.Dir = repoBranchPath
47+
// Check if this is a docusaurus build
48+
isDocusaurus := false
49+
if _, err := os.Stat(fmt.Sprintf("%s/docusaurus.config.ts", repoBranchPath)); err == nil {
50+
isDocusaurus = true
51+
}
52+
53+
// Set up the command
54+
var cmd *exec.Cmd
55+
if isDocusaurus {
56+
// Install dependencies
57+
cmd = exec.Command("npm", "install")
58+
cmd.Dir = repoBranchPath
59+
_ = cmd.Run()
60+
61+
// Run the actual build
62+
cmd = exec.Command("npm", "run", "build")
63+
cmd.Dir = repoBranchPath
64+
} else {
65+
// It's a Retype site. Run that instead
66+
cmd = exec.Command("retype", "build")
67+
cmd.Dir = repoBranchPath
68+
}
5069

5170
// Set up logging for the command output
5271
var out, stderr bytes.Buffer
@@ -55,7 +74,7 @@ func updateBranch(cloneURL, branch string, silent bool) {
5574

5675
if err := cmd.Run(); err != nil {
5776
// Log the error and output (both stdout and stderr)
58-
logMessage("Retype build failed for branch %s: %v", branch, err)
77+
logMessage("Build failed for branch %s: %v", branch, err)
5978
logMessage("Stdout: %s", out.String())
6079
logMessage("Stderr: %s", stderr.String())
6180

@@ -75,7 +94,15 @@ func updateBranch(cloneURL, branch string, silent bool) {
7594
// Remove old HTML folder, and copy the new one
7695
os.RemoveAll(htmlBranchPath)
7796
os.MkdirAll(htmlBranchPath, os.ModePerm)
78-
exec.Command("cp", "-r", fmt.Sprintf("%s/.retype/.", repoBranchPath), htmlBranchPath).Run()
97+
98+
// Copy the output files
99+
var copyCmd *exec.Cmd
100+
if isDocusaurus {
101+
copyCmd = exec.Command("cp", "-r", fmt.Sprintf("%s/build/.", repoBranchPath), htmlBranchPath)
102+
} else {
103+
copyCmd = exec.Command("cp", "-r", fmt.Sprintf("%s/.retype/.", repoBranchPath), htmlBranchPath)
104+
}
105+
_ = copyCmd.Run()
79106

80107
// Send final notification to discord
81108
logMessage("Successfully built and updated branch: %s", branch)
@@ -85,7 +112,7 @@ func updateBranch(cloneURL, branch string, silent bool) {
85112
}
86113
}
87114

88-
// Branch was deleted, so we delete the output folder
115+
// The Branch was deleted, so we delete the output folder
89116
func deleteBranch(branch string) {
90117
htmlBranchPath := fmt.Sprintf("%s/%s", htmlPath, branch)
91118

@@ -139,7 +166,7 @@ func initializeBranches() {
139166
return
140167
}
141168

142-
// For each branch, check if it exists in the html folder. If not, update it
169+
// For each branch, check if it exists in the HTML folder. If not, update it
143170
for _, branch := range branches {
144171
if !branchFolderExists(branch) {
145172
logMessage("Found missing branch: %s. Building...", branch)

server/logging.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,18 @@ func sendDiscordMessage(branch string, message string, state string, color int,
1414
return
1515
}
1616

17+
icon := "⚡️"
18+
if color == red {
19+
icon = "💀"
20+
} else if color == orange {
21+
icon = "🗑️"
22+
} else if color == green {
23+
icon = "🎉"
24+
}
25+
1726
// Set up the embed details for the body
1827
currentTime := time.Now()
19-
description := fmt.Sprintf("⚡️Docktainer: %s \r\n\r\nBranch: %s\r\nURL: %s", message, branch, fmt.Sprintf("https://%s.%s", branch, baseUrl))
28+
description := fmt.Sprintf("%s Docktainer: %s %s\r\n\r\nBranch: %s\r\nURL: %s", icon, message, icon, branch, fmt.Sprintf("https://%s.%s", branch, baseUrl))
2029

2130
if errorLog != "" {
2231
description += fmt.Sprintf("\r\n\r\nBuild Output:\r\n%s", errorLog)

0 commit comments

Comments
 (0)