diff --git a/.github/workflows/raw-api.yml b/.github/workflows/raw-api.yml new file mode 100644 index 0000000..e65c71c --- /dev/null +++ b/.github/workflows/raw-api.yml @@ -0,0 +1,32 @@ +name: Raw API + +on: + push: + branches: [main] + paths: + - "domains/*" + - ".github/workflows/raw-api.yml" + - "scripts/raw-api.js" + +jobs: + update: + name: Update + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Node + uses: actions/setup-node@v2 + with: + node-version: 16 + + - name: Run Script + run: | + git config --global user.email "will@is-a-good.dev" + git config --global user.name "is-a-good-dev-BOT" + node scripts/raw-api.js + git add utils/raw.json + git commit -m "Update Raw API" + git push diff --git a/scripts/raw-api.js b/scripts/raw-api.js new file mode 100644 index 0000000..464747f --- /dev/null +++ b/scripts/raw-api.js @@ -0,0 +1,45 @@ +const fs = require("fs"); +const path = require("path"); + +const directoryPath = path.join(__dirname, "../sub-logs"); + +let combinedArray = []; + +fs.readdir(directoryPath, function (err, files) { + if(err) throw err; + + function removeValue(value, index, arr) { + if(value === "reserved") { + arr.splice(index, 1); + return true; + } + + return false; + } + + files.filter(removeValue); + + files.forEach(function (file) { + const filePath = path.join(directoryPath, file); + + fs.readFile(filePath, "utf8", (err, data) => { + if(err) throw err; + + const dataArray = [JSON.parse(data)]; + + for(const item of dataArray) { + delete item.owner.email; + + item.domain = path.parse(file).name + ".is-a-good.dev"; + } + + combinedArray = combinedArray.concat(dataArray); + + if(combinedArray.length === files.length) { + fs.writeFile("utils/raw.json", JSON.stringify(combinedArray), (err) => { + if(err) throw err; + }) + } + }) + }) +}) diff --git a/utils/raw.json b/utils/raw.json new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/utils/raw.json @@ -0,0 +1 @@ +