Skip to content

Commit

Permalink
๐Ÿ› Fix: merge link.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashu11-A committed Apr 10, 2024
1 parent 9ce06af commit b3c5601
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface LinkData {

async function start() {
const links: LinkData[] = []
let linkData = JSON.parse(readFileSync('api/links.json', 'utf8')) as LinkData[]

for (const { repository, branch } of repos) {
const array = repository.split('/')
Expand All @@ -40,7 +41,6 @@ async function start() {
}

const repoData = (await axios.get(`https://api.github.com/repos/${repository}`)).data
const linkData = JSON.parse(readFileSync('api/links.json', 'utf8')) as LinkData[]

if (repoData.updated_at === linkData.find((element) => element.author === array[0])?.updated_at) {
console.log('Repositorio sem alteraรงรตes');
Expand All @@ -58,7 +58,7 @@ async function start() {
author: array[0],
link: `https://raw.githubusercontent.com/Ashu11-A/Eggs-Tracker/main/api/${array[0]}.min.json`,
eggs: eggs.length,
updated_at: repoData.updated_at
updated_at: repoData?.updated_at
})
} else {
console.log(`Download do Repositorio ${repoName} nรฃo foi realizado!`)
Expand All @@ -72,7 +72,18 @@ async function start() {
})
}

writeFile('api/links.json', JSON.stringify(links, null, 2), {}, ((err) => {
// Sistema de mesclagem
for (const link of links) {
const index = linkData.findIndex((element) => element.author === link.author)
if (index !== -1) {
linkData[index] = link
continue
}

linkData.push(link)
}

writeFile('api/links.json', JSON.stringify(linkData, null, 2), {}, ((err) => {
if (err) console.log('Ocorreu um erro ao salvar os Dados:', err)
}))
}
Expand Down

0 comments on commit b3c5601

Please sign in to comment.