Skip to content

Commit

Permalink
Build Resources File CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuyk committed Jul 9, 2020
1 parent 4228116 commit de4107e
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 5 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build-resources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ jobs:
node-version: 13
# Runs a set of commands using the runners shell
- name: Create a file.
run: |
echo "test" > test.txt
ls
run: npm install
- name: Build Files
run: npm run build
- name: Commit files
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add .
git commit -m "Add changes" -a
git add ./dist
git commit -m "Updated Resource List" -a
- name: Push changes
uses: ad-m/github-push-action@master
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
103 changes: 103 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "altv-hub",
"version": "0.0.1",
"description": "alt:V Hub is a reference point to post your resources for other users to explore.\r Simply create a pull request with a folder for your github username and a json file with your resource information.",
"main": "src/index.js",
"scripts": {
"build": "node ./src/index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/altmp/altv-hub.git"
},
"author": "stuyk",
"license": "ISC",
"bugs": {
"url": "https://github.com/altmp/altv-hub/issues"
},
"homepage": "https://github.com/altmp/altv-hub#readme",
"dependencies": {
"glob": "^7.1.6",
"node-fetch": "^2.6.0",
"walk": "^2.3.14"
}
}
44 changes: 44 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const fetch = require("node-fetch");
const fs = require("fs");
const path = require("path");
const walk = require("walk");
const files = [];

const walker = walk.walk("resources", { followLinks: false });

walker.on("file", (root, stat, next) => {
files.push({
author: root.replace("resources\\", ""),
filePath: path.join(root, stat.name),
});
next();
});

walker.on("end", async () => {
const finalizedFiles = [];

for (let i = 0; i < files.length; i++) {
let fileData = JSON.parse(fs.readFileSync(files[i].filePath).toString());
fileData.author = files[i].author;

const repoPath = fileData.url.replace("https://github.com/", "");
const response = await fetch(`https://api.github.com/repos/${repoPath}`);
const repoDataString = await response.text();
const repoData = JSON.parse(repoDataString);

fileData.updated = repoData.updated_at;
fileData.creation = repoData.created_at;
fileData.pushed = repoData.pushed_at;
fileData.stars = repoData.stargazers_count;
finalizedFiles.push(fileData);
}

if (!fs.existsSync(path.join(__dirname, "../", "/dist"))) {
fs.mkdirSync(path.join(__dirname, "../", "/dist"));
}

fs.writeFileSync(
path.join(__dirname, "../", "/dist/resources.json"),
JSON.stringify(finalizedFiles)
);
});

0 comments on commit de4107e

Please sign in to comment.