forked from sveltejs/community-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: adds script to update number of stars and last updated for resou…
…rces.
- Loading branch information
1 parent
e94cbbf
commit aeedc17
Showing
4 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/node_modules | ||
__sapper__ | ||
.backup | ||
.netlify | ||
.netlify | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters