diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 6bdbc339..9e382c8f 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,4 +1,4 @@ -name: Deploy to GitHub Pages +name: Deploy to Cloudflare Pages on: # Trigger the workflow every time you push to the `main` branch @@ -28,5 +28,9 @@ jobs: echo "PUBLIC_ANALYTICS_KEY=${{ secrets.POSTHOG_WEB_ANALYTICS }}" >> docs/.env cd docs npm install + cd ../pathfinder-rules/gen-script + go mod download + go run main.go + cd ../../docs npm run build npx wrangler pages deploy ./dist --project-name=codepathfinder --branch=main \ No newline at end of file diff --git a/.gitignore b/.gitignore index 32db93e1..8d826baa 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,8 @@ yarn-debug.log* yarn-error.log* pnpm-debug.log* +docs/public/rules/*.json + # environment variables .env diff --git a/pathfinder-rules/android/webview/WebViewJavaScriptEnabled.cql b/pathfinder-rules/android/WebViewJavaScriptEnabled.cql similarity index 100% rename from pathfinder-rules/android/webview/WebViewJavaScriptEnabled.cql rename to pathfinder-rules/android/WebViewJavaScriptEnabled.cql diff --git a/pathfinder-rules/android/webview/WebViewaddJavascriptInterface.cql b/pathfinder-rules/android/WebViewaddJavascriptInterface.cql similarity index 100% rename from pathfinder-rules/android/webview/WebViewaddJavascriptInterface.cql rename to pathfinder-rules/android/WebViewaddJavascriptInterface.cql diff --git a/pathfinder-rules/android/webview/WebViewsetAllowContentAccess.cql b/pathfinder-rules/android/WebViewsetAllowContentAccess.cql similarity index 100% rename from pathfinder-rules/android/webview/WebViewsetAllowContentAccess.cql rename to pathfinder-rules/android/WebViewsetAllowContentAccess.cql diff --git a/pathfinder-rules/android/webview/WebViewsetAllowFileAccess.cql b/pathfinder-rules/android/WebViewsetAllowFileAccess.cql similarity index 100% rename from pathfinder-rules/android/webview/WebViewsetAllowFileAccess.cql rename to pathfinder-rules/android/WebViewsetAllowFileAccess.cql diff --git a/pathfinder-rules/android/webview/WebViewsetAllowFileAccessFromFileURLs.cql b/pathfinder-rules/android/WebViewsetAllowFileAccessFromFileURLs.cql similarity index 100% rename from pathfinder-rules/android/webview/WebViewsetAllowFileAccessFromFileURLs.cql rename to pathfinder-rules/android/WebViewsetAllowFileAccessFromFileURLs.cql diff --git a/pathfinder-rules/gen-script/go.mod b/pathfinder-rules/gen-script/go.mod new file mode 100644 index 00000000..5bfd910e --- /dev/null +++ b/pathfinder-rules/gen-script/go.mod @@ -0,0 +1,3 @@ +module github.com/shivasurya/pathfinder-rules/gen-script + +go 1.22.0 diff --git a/pathfinder-rules/gen-script/go.sum b/pathfinder-rules/gen-script/go.sum new file mode 100644 index 00000000..e69de29b diff --git a/pathfinder-rules/gen-script/main.go b/pathfinder-rules/gen-script/main.go new file mode 100644 index 00000000..360bc64d --- /dev/null +++ b/pathfinder-rules/gen-script/main.go @@ -0,0 +1,83 @@ +package main + +import ( + "encoding/json" + "fmt" + "os" + "path/filepath" +) + +type CQLFileContent struct { + FileName string `json:"file_name"` + Content string `json:"content"` +} + +type CQLFiles struct { + Directory string `json:"ruleset"` + Files []CQLFileContent `json:"files"` +} + +func main() { + rootDir := "../../pathfinder-rules" // Set the root directory to start traversal + err := filepath.Walk(rootDir, processDirectory) + if err != nil { + fmt.Printf("Error walking the path %q: %v\n", rootDir, err) + } +} + +func processDirectory(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + + if info.IsDir() { + var cqlFiles []CQLFileContent + entries, err := os.ReadDir(path) + if err != nil { + return err + } + + for _, entry := range entries { + if filepath.Ext(entry.Name()) == ".cql" { + filePath := filepath.Join(path, entry.Name()) + content, err := os.ReadFile(filePath) + if err != nil { + return err + } + cqlFiles = append(cqlFiles, CQLFileContent{ + FileName: entry.Name(), + Content: string(content), + }) + } + } + + if len(cqlFiles) > 0 { + jsonData := CQLFiles{ + Directory: filepath.Base(path), + Files: cqlFiles, + } + + jsonFileName := filepath.Base(path) + ".json" + jsonFilePath := filepath.Join("..", "..", "docs", "public", "rules", jsonFileName) + + err := os.MkdirAll(filepath.Dir(jsonFilePath), 0755) + if err != nil { + return err + } + + jsonBytes, err := json.MarshalIndent(jsonData, "", " ") + if err != nil { + return err + } + + err = os.WriteFile(jsonFilePath, jsonBytes, 0644) + if err != nil { + return err + } + + fmt.Printf("Created JSON file at: %s\n", jsonFilePath) + } + } + + return nil +}