Skip to content

Commit

Permalink
wip: adds script to update number of stars and last updated for resou…
Browse files Browse the repository at this point in the history
…rces.
  • Loading branch information
kevmodrome committed Oct 11, 2019
1 parent e94cbbf commit aeedc17
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/node_modules
__sapper__
.backup
.netlify
.netlify
.env
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
"dependencies": {
"@ssgjs/source-yaml": "^0.0.3",
"@sveltejs/site-kit": "^1.1.4",
"dotenv": "^8.1.0",
"fuse.js": "^3.4.5",
"js-yaml": "^3.13.1",
"node-fetch": "^2.6.0",
"ssg": "^0.0.38",
"yaml": "^1.7.1"
},
"scripts": {
"start": "ssg dev",
"build": "ssg export"
"build": "ssg export",
"update": "node scripts/updateResources.js"
}
}
64 changes: 64 additions & 0 deletions scripts/updateResources.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Used to fetch and update number of stars on each resource.
require("dotenv").config();
const fs = require("fs");
const yaml = require("js-yaml");
const fetch = require("node-fetch");

async function getStars() {
try {
const resources = yaml.safeLoad(
fs.readFileSync("data/resources.yml", "utf8")
);

const updatedResources = await Promise.all(
resources.resources.map(async res => {
// if (hasGitHubUrl) {
let result = await fetch(
`https://api.github.com/repos/jasonrudolph/keyboard?client_id=${process.env.GITHUB_CLIENT_ID}&client_secret=${process.env.GITHUB_CLIENT_SECRET}`
);

result = await result.json();

return {
...res,
stars: result.watchers,
last_updated: result.updated_at
};
// } else {
// return res;
// }
})
);

const finishedYaml = {
...resources,
resources: updatedResources
};

fs.writeFile("data/resources.yml", yaml.safeDump(finishedYaml), err => {
if (err) {
console.log(err);
}
});
} catch (e) {
console.log(e);
}
}

getStars();

// const url = "https://api.github.com/repos/";

// async function main() {
// const starships = [];

// const res = await fetch(base, opts);
// const list = await res.json();

// fs.writeFileSync(
// `../src/routes/_starships.js`,
// `export default ${JSON.stringify(list)};`
// );
// }

// main();
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,11 @@ debug@^4.1.0:
dependencies:
ms "^2.1.1"

dotenv@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.1.0.tgz#d811e178652bfb8a1e593c6dd704ec7e90d85ea2"
integrity sha512-GUE3gqcDCaMltj2++g6bRQ5rBJWtkWTmqmD0fo1RnnMuUqHNCt2oTPeDnS9n6fKYvlhn7AeBkb38lymBtWBQdA==

end-of-stream@^1.1.0:
version "1.4.4"
resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.4.tgz#5ae64a5f45057baf3626ec14da0ca5e4b2431eb0"
Expand Down Expand Up @@ -758,6 +763,11 @@ no-case@^2.2.0:
dependencies:
lower-case "^1.1.1"

node-fetch@^2.6.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd"
integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==

node-modules-regexp@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/node-modules-regexp/-/node-modules-regexp-1.0.0.tgz#8d9dbe28964a4ac5712e9131642107c71e90ec40"
Expand Down

0 comments on commit aeedc17

Please sign in to comment.