2022-03-27 11:43:26 +00:00
|
|
|
const archiver = require('archiver');
|
|
|
|
const fs = require('fs');
|
|
|
|
const { spawn } = require('child_process');
|
2022-03-27 12:54:00 +00:00
|
|
|
const path = require('path');
|
2022-03-27 11:43:26 +00:00
|
|
|
|
|
|
|
async function ghRelease(changes) {
|
|
|
|
const package = 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/${package.version}.zip`;
|
|
|
|
const outputZip = fs.createWriteStream(outputPath);
|
|
|
|
|
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
let arch = archive;
|
|
|
|
dirPipes.forEach((dir) => {
|
2022-03-29 02:23:39 +00:00
|
|
|
arch = arch.directory(dir);
|
2022-03-27 11:43:26 +00:00
|
|
|
});
|
|
|
|
filePipes.forEach((file) => {
|
|
|
|
arch = arch.file(file, { name: file });
|
|
|
|
});
|
2022-03-27 12:54:00 +00:00
|
|
|
arch.on('error', (err) => reject(err)).pipe(outputZip);
|
2022-03-27 11:43:26 +00:00
|
|
|
|
2022-03-27 12:54:00 +00:00
|
|
|
outputZip.on('close', () => resolve());
|
2022-03-27 11:43:26 +00:00
|
|
|
arch.finalize();
|
|
|
|
});
|
|
|
|
|
2022-03-27 12:54:00 +00:00
|
|
|
const changeLogPath = `releases/${package.version}.changelog.md`;
|
2022-03-27 11:43:26 +00:00
|
|
|
|
|
|
|
fs.writeFileSync(
|
|
|
|
changeLogPath,
|
2022-03-27 12:54:00 +00:00
|
|
|
`# ${package.version} \n
|
2022-03-27 11:43:26 +00:00
|
|
|
${changes.reduce((acc, change) => {
|
|
|
|
return acc + `- ${change}\n`;
|
|
|
|
}, '')}`,
|
|
|
|
);
|
|
|
|
|
2022-03-27 12:54:00 +00:00
|
|
|
console.log(
|
|
|
|
await new Promise((resolve) => {
|
|
|
|
const p = spawn('gh', ['release', 'create', `v${package.version}`, `./${outputPath}`, '-F', `./${changeLogPath}`], {
|
|
|
|
shell: true,
|
|
|
|
});
|
|
|
|
// const p = spawn('pwd');
|
|
|
|
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 () => {
|
|
|
|
if (!process.argv[2]) {
|
|
|
|
console.log('No changes provided');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const changes = process.argv[2].split(',');
|
2022-03-27 12:54:00 +00:00
|
|
|
await ghRelease(changes);
|
2022-03-27 11:43:26 +00:00
|
|
|
console.log('Release created', changes);
|
|
|
|
})();
|