const tokens = require('./tokens.json') const sponsors = require('@jamesives/github-sponsors-readme-action') const fs = require('fs') const packageJson = require('./package.json') let configuration = { token: tokens.github, file: './readme.md', marker: 'sponsors', template: '{name}', } const sponsorsGenerate = async () => { const sponsorsReturn = await (await (sponsors.getSponsors(configuration))).data.viewer const count = sponsorsReturn.sponsorshipsAsMaintainer.totalCount const sponsorsList = sponsorsReturn.sponsorshipsAsMaintainer.nodes let sentence = ``; if (count >= 1) { sentence = `

Thanks to the sponsors:

` } else if (count > 10) { sentence = `

Thanks to the ${count} sponsors:

` } // open the readme const readme = fs.readFileSync(configuration.file, 'utf8') // replace the sponsors marker with the new list const newReadme = readme.replace( new RegExp(`[\\s\\S]*`), `\n${sentence}
\n

${sponsorsList.map(sponsor => { return configuration.template .replace(/\{name\}/gi, sponsor.sponsorEntity.name) .replace(/\{avatar\}/gi, `https://avatars.githubusercontent.com/${sponsor.sponsorEntity.login}`) .replace(/\{url\}/gi, sponsor.sponsorEntity.url) }).join('\n')}\n

` ) // write the new readme fs.writeFileSync(configuration.file, newReadme) // add to current commit by runnning shell command const { exec } = require('child_process') const e = exec('git add readme.md') e.stdout.on('data', (data) => { console.log(data) }) e.stderr.on('data', (data) => { console.error(data) }) console.log(`Sponsors updated!`) } function changelog() { // get the changes from last commit message const { execSync } = require('child_process') let commitMessage = execSync('git log -1 --pretty=%B').toString() if(!commitMessage.startsWith('[release]')) { console.log('Not a release commit, skipping changelog update') return } const version = packageJson.version commitMessage = commitMessage.replace('[release]', 'Version') // open changelog.md const changelog = fs.readFileSync('./changelog.md', 'utf8') // add the new changes to the top of the changelog const newChangelog = `## ${commitMessage}\n\n${changelog}` // write the new changelog fs.writeFileSync('./changelog.md', newChangelog) // add to current commit by runnning shell command const { exec } = require('child_process') const e = exec('git add changelog.md') e.stdout.on('data', (data) => { console.log(data) }) e.stderr.on('data', (data) => { console.error(data) }) } sponsorsGenerate() // changelog();