Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

docs/public/rules/*.json


# environment variables
.env
Expand Down
3 changes: 3 additions & 0 deletions pathfinder-rules/gen-script/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/shivasurya/pathfinder-rules/gen-script

go 1.22.0
Empty file.
83 changes: 83 additions & 0 deletions pathfinder-rules/gen-script/main.go
Original file line number Diff line number Diff line change
@@ -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
}