2019-07-30 09:35:42 +02:00
|
|
|
const { execCommand } = require('./tool-utils.js');
|
2019-05-13 01:42:16 +02:00
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
const moment = require('moment');
|
|
|
|
|
|
|
|
const rootDir = path.dirname(__dirname);
|
2019-09-19 23:51:18 +02:00
|
|
|
const appDir = `${rootDir}/CliClient`;
|
|
|
|
const changelogPath = `${rootDir}/readme/changelog_cli.md`;
|
2019-05-13 01:42:16 +02:00
|
|
|
|
|
|
|
async function insertChangelog(tag, changelog) {
|
2019-05-14 00:18:44 +02:00
|
|
|
const currentText = await fs.readFile(changelogPath, 'UTF-8');
|
2019-05-13 01:42:16 +02:00
|
|
|
const lines = currentText.split('\n');
|
|
|
|
|
|
|
|
const beforeLines = [];
|
|
|
|
const afterLines = [];
|
|
|
|
|
|
|
|
for (const line of lines) {
|
|
|
|
if (afterLines.length) {
|
|
|
|
afterLines.push(line);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (line.indexOf('##') === 0) {
|
|
|
|
afterLines.push(line);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeLines.push(line);
|
|
|
|
}
|
|
|
|
|
|
|
|
const header = [
|
|
|
|
'##',
|
2019-09-19 23:51:18 +02:00
|
|
|
`[${tag}](https://github.com/laurent22/joplin/releases/tag/${tag})`,
|
2019-05-13 01:42:16 +02:00
|
|
|
'-',
|
2019-07-30 09:35:42 +02:00
|
|
|
// eslint-disable-next-line no-useless-escape
|
2019-09-19 23:51:18 +02:00
|
|
|
`${moment.utc().format('YYYY-MM-DD\THH:mm:ss')}Z`,
|
2019-05-13 01:42:16 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
let newLines = [];
|
|
|
|
newLines.push(header.join(' '));
|
|
|
|
newLines.push('');
|
|
|
|
newLines = newLines.concat(changelog.split('\n'));
|
|
|
|
newLines.push('');
|
|
|
|
|
|
|
|
const output = beforeLines.concat(newLines).concat(afterLines);
|
|
|
|
|
2019-05-14 00:18:44 +02:00
|
|
|
return output.join('\n');
|
2019-05-13 01:42:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Start with node Tools/release-cli.js --changelog-from cli-v1.0.126
|
|
|
|
// to specify from where the changelog should be created
|
|
|
|
async function main() {
|
|
|
|
process.chdir(appDir);
|
|
|
|
|
|
|
|
const newVersion = await execCommand('npm version patch');
|
2019-09-19 23:51:18 +02:00
|
|
|
console.info(`Building ${newVersion}...`);
|
|
|
|
const newTag = `cli-${newVersion}`;
|
2019-07-30 09:35:42 +02:00
|
|
|
|
2019-05-13 01:42:16 +02:00
|
|
|
await execCommand('touch app/main.js');
|
|
|
|
await execCommand('bash build.sh');
|
|
|
|
await execCommand('cp package.json build/');
|
|
|
|
await execCommand('cp ../README.md build/');
|
2019-07-30 09:35:42 +02:00
|
|
|
|
2019-09-19 23:51:18 +02:00
|
|
|
process.chdir(`${appDir}/build`);
|
2019-05-14 00:52:12 +02:00
|
|
|
|
2019-05-14 00:20:25 +02:00
|
|
|
await execCommand('npm publish');
|
2019-05-13 01:42:16 +02:00
|
|
|
|
2019-09-19 23:51:18 +02:00
|
|
|
const changelog = await execCommand(`node ${rootDir}/Tools/git-changelog ${newTag}`);
|
2019-05-13 01:42:16 +02:00
|
|
|
|
2019-05-14 00:18:44 +02:00
|
|
|
const newChangelog = await insertChangelog(newTag, changelog);
|
2019-05-13 01:42:16 +02:00
|
|
|
|
2019-05-14 00:18:44 +02:00
|
|
|
await fs.writeFile(changelogPath, newChangelog);
|
2019-05-13 01:42:16 +02:00
|
|
|
|
2019-05-14 00:18:44 +02:00
|
|
|
const defaultEditor = await execCommand('echo $EDITOR');
|
2019-05-13 01:42:16 +02:00
|
|
|
|
2019-05-14 00:18:44 +02:00
|
|
|
const finalCmds = [
|
2020-01-25 01:18:46 +02:00
|
|
|
'git pull',
|
2019-05-14 00:18:44 +02:00
|
|
|
'git add -A',
|
2019-09-19 23:51:18 +02:00
|
|
|
`git commit -m "CLI ${newVersion}"`,
|
|
|
|
`git tag "cli-${newVersion}"`,
|
2019-05-14 00:18:44 +02:00
|
|
|
'git push',
|
|
|
|
'git push --tags',
|
|
|
|
];
|
2019-05-13 01:42:16 +02:00
|
|
|
|
2019-05-14 00:18:44 +02:00
|
|
|
console.info('');
|
|
|
|
console.info('Verify that the changelog is correct:');
|
|
|
|
console.info('');
|
2019-09-19 23:51:18 +02:00
|
|
|
console.info(`${defaultEditor} "${changelogPath}"`);
|
2019-05-14 00:18:44 +02:00
|
|
|
console.info('');
|
|
|
|
console.info('Then run these commands:');
|
|
|
|
console.info('');
|
|
|
|
console.info(finalCmds.join(' && '));
|
2019-05-13 01:42:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
main().catch((error) => {
|
|
|
|
console.error('Fatal error');
|
|
|
|
console.error(error);
|
2019-05-14 00:18:44 +02:00
|
|
|
console.error('');
|
|
|
|
console.error('If the app cannot auto-detect the previous tag name, specify it using --changelog-from TAG_NAME');
|
2019-05-13 01:42:16 +02:00
|
|
|
process.exit(1);
|
2019-07-30 09:35:42 +02:00
|
|
|
});
|