build: enhance publish script

pull/29/head
sualko 2020-04-29 14:14:30 +02:00
parent a5402c5780
commit 92a06e3ff1
1 changed files with 24 additions and 12 deletions

View File

@ -89,7 +89,8 @@ async function generateChangelog() {
let issues = entry.issues.map(issue => { let issues = entry.issues.map(issue => {
return `[#${issue}](https://github.com/sualko/cloud_bbb/issues/${issue})`; return `[#${issue}](https://github.com/sualko/cloud_bbb/issues/${issue})`;
}).join(''); }).join('');
return `- ${issues} ${entry.description}\n`;
return `- ${issues}${issues.length > 0 ? ' ' : ''}${entry.description}\n`;
} }
sections.forEach(section => { sections.forEach(section => {
@ -123,6 +124,17 @@ async function generateChangelog() {
return changeLog; return changeLog;
} }
async function editChangeLog(changeLog) {
let answers = await inquirer.prompt([{
type: 'editor',
name: 'changeLog',
message: 'You have now the possibility to edit the change log',
default: changeLog,
}]);
return answers.changeLog;
}
function hasChangeLogEntry() { function hasChangeLogEntry() {
return new Promise(resolve => { return new Promise(resolve => {
fs.readFile(path.join(__dirname, '..', 'CHANGELOG.md'), function (err, data) { fs.readFile(path.join(__dirname, '..', 'CHANGELOG.md'), function (err, data) {
@ -234,9 +246,8 @@ async function createGithubRelease(changeLog) {
owner, owner,
repo, repo,
tag_name: tagName, tag_name: tagName,
name: tagName, name: `${package.name} ${tagName}`,
body: changeLog, body: changeLog.replace(/^## [^\n]+\n/, ''),
draft: true,
prerelease: !/^\d+\.\d+\.\d+$/.test(package.version), prerelease: !/^\d+\.\d+\.\d+$/.test(package.version),
}; };
@ -265,9 +276,7 @@ async function createGithubRelease(changeLog) {
return 'application/octet-stream'; return 'application/octet-stream';
} }
let assetUrls = []; let assetUrls = await Promise.all(files.map(async file => {
files.forEach(async file => {
const filename = path.basename(file); const filename = path.basename(file);
const uploadOptions = { const uploadOptions = {
owner, owner,
@ -276,7 +285,7 @@ async function createGithubRelease(changeLog) {
data: fs.createReadStream(file), data: fs.createReadStream(file),
headers: { headers: {
'content-type': getMimeType(filename), 'content-type': getMimeType(filename),
'content-length': fs.statSync(file)[size], 'content-length': fs.statSync(file)['size'],
}, },
name: filename, name: filename,
}; };
@ -285,8 +294,8 @@ async function createGithubRelease(changeLog) {
console.log(`Asset uploaded: ${assetResponse.data.name}`.verbose); console.log(`Asset uploaded: ${assetResponse.data.name}`.verbose);
assetUrls.push(assetResponse.data.browser_download_url); return assetResponse.data.browser_download_url;
}); }));
return assetUrls; return assetUrls;
} }
@ -362,10 +371,12 @@ async function run() {
await isMasterBranch(); await isMasterBranch();
console.log(`✔ this is the master branch`.green); console.log(`✔ this is the master branch`.green);
const changeLog = await generateChangelog(); let changeLog = await generateChangelog();
console.log(changeLog.verbose);
console.log(`✔ change log generated`.green); console.log(`✔ change log generated`.green);
changeLog = await editChangeLog(changeLog);
console.log(`✔ change log updated`.green);
console.log('Press any key to continue...'); console.log('Press any key to continue...');
await keypress(); await keypress();
@ -399,6 +410,7 @@ async function run() {
console.log(`✔ released on github`.green); console.log(`✔ released on github`.green);
const archiveAssetUrl = assetUrls.find(url => url.endsWith('.tar.gz')); const archiveAssetUrl = assetUrls.find(url => url.endsWith('.tar.gz'));
console.log(`Asset url for Nextcloud store: ${archiveAssetUrl}`.verbose);
await wantToContinue('Should I continue to upload the release to the app store?'); await wantToContinue('Should I continue to upload the release to the app store?');