1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-09 08:45:55 +02:00
joplin/Tools/release-cli.js

103 lines
2.6 KiB
JavaScript
Raw Normal View History

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) {
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
'-',
// 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);
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}`;
await execCommand('git pull');
2019-05-13 01:42:16 +02:00
await execCommand('touch app/main.js');
await execCommand('npm run build');
2020-03-07 03:00:11 +02:00
// await execCommand('cp package.json build/');
2019-05-13 01:42:16 +02:00
await execCommand('cp ../README.md build/');
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
const newChangelog = await insertChangelog(newTag, changelog);
2019-05-13 01:42:16 +02:00
await fs.writeFile(changelogPath, newChangelog);
2019-05-13 01:42:16 +02:00
const defaultEditor = await execCommand('echo $EDITOR');
2019-05-13 01:42:16 +02:00
const finalCmds = [
'git pull',
'git add -A',
2019-09-19 23:51:18 +02:00
`git commit -m "CLI ${newVersion}"`,
`git tag "cli-${newVersion}"`,
'git push',
'git push --tags',
];
2019-05-13 01:42:16 +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}"`);
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);
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);
});