1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-14 18:27:44 +02:00
joplin/Tools/release-cli.js

109 lines
2.9 KiB
JavaScript
Raw Normal View History

2019-05-13 01:42:16 +02:00
const { execCommand, githubRelease, handleCommitHook, githubOauthToken } = require('./tool-utils.js');
const path = require('path');
const fs = require('fs-extra');
const moment = require('moment');
const rootDir = path.dirname(__dirname);
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 = [
'##',
'[' + tag + '](https://github.com/laurent22/joplin/releases/tag/' + tag + ')',
2019-05-13 01:42:16 +02:00
'-',
moment.utc().format('YYYY-MM-DD\THH:mm:ss') + 'Z',
];
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() {
const argv = require('yargs').argv;
process.chdir(appDir);
const packageJson = await fs.readFile('package.json', 'UTF-8');
const packageConf = JSON.parse(packageJson);
const previousVersion = 'v' + packageConf.version;
let changelogFrom = 'cli-' + previousVersion;
2019-05-13 01:42:16 +02:00
if (argv.changelogFrom) changelogFrom = argv.changelogFrom;
const newVersion = await execCommand('npm version patch');
console.info('Building ' + newVersion + '...');
const newTag = 'cli-' + newVersion;
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-05-14 00:52:12 +02:00
process.chdir(appDir + '/build');
2019-05-14 00:20:25 +02:00
await execCommand('npm publish');
2019-05-13 01:42:16 +02:00
const changelog = await execCommand('node ../Tools/git-changelog ' + changelogFrom);
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 add -A',
'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('');
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);
});