Brave-Detection-Blocker-Chr.../scripts/create-release.js

63 lines
1.9 KiB
JavaScript
Raw Normal View History

2022-11-01 00:58:19 +00:00
const archiver = require('archiver')
const fs = require('fs')
const { spawn } = require('child_process')
2022-03-27 11:43:26 +00:00
async function ghRelease(changes) {
2022-11-01 00:58:19 +00:00
const pkg = JSON.parse(fs.readFileSync('package.json'))
const archive = archiver('zip', { zlib: { level: 9 } })
const dirPipes = ['_locales/', 'images/']
const filePipes = ['manifest.json', 'block-script.js', 'popup.html', 'popup.js', 'content-script.js', 'LICENSE', 'README.md', 'PRIVACY_POLICY.md']
const outputPath = `releases/${pkg.version}.zip`
const outputZip = fs.createWriteStream(outputPath)
await new Promise((resolve, reject) => {
let arch = archive
dirPipes.forEach((dir) => {
arch = arch.directory(dir)
})
filePipes.forEach((file) => {
arch = arch.file(file, { name: file })
})
arch.on('error', (err) => reject(err)).pipe(outputZip)
outputZip.on('close', () => resolve())
arch.finalize()
})
const changeLogPath = `releases/${pkg.version}.changelog.md`
fs.writeFileSync(
changeLogPath,
`# ${pkg.version} \n
2022-03-27 11:43:26 +00:00
${changes.reduce((acc, change) => {
2022-11-01 00:58:19 +00:00
return acc + `- ${change}\n`
}, '')}`,
)
console.log(
await new Promise((resolve) => {
const p = spawn('gh', ['release', 'create', `v${pkg.version}`, `./${outputPath}`, '-F', `./${changeLogPath}`], {
shell: true,
})
let result = ''
p.stdout.on('data', (data) => (result += data.toString()))
p.stderr.on('data', (data) => (result += data.toString()))
p.on('close', () => {
resolve(result)
})
}),
)
2022-03-27 11:43:26 +00:00
}
(async () => {
2022-11-01 00:58:19 +00:00
if (!process.argv[2]) {
console.log('No changes provided')
return
}
const changes = process.argv[2].split(',')
await ghRelease(changes)
console.log('Release created', changes)
})()