Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions tools/cli/extract-changelog-section.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* eslint-disable */

const fs = require('fs');
const path = require('path');

const CHANGELOG_PATH = path.resolve(__dirname, '../../packages/teams-js/CHANGELOG.md');

/**
* Returns the changelog body for a specific version (the content between the
* `## <version>` header and the next `## ` header). If no version is provided,
* the full changelog is returned.
*
* @param {string} [version] semver string, e.g. "2.53.1"
* @param {string} [changelogPath] override path to CHANGELOG.md (used in tests)
* @returns {string} the trimmed changelog section, or the full changelog
*/
function extractChangelogSection(version, changelogPath = CHANGELOG_PATH) {
if (!fs.existsSync(changelogPath)) {
throw new Error(`Changelog was not found at ${changelogPath}`);
}
const fullChangelog = fs.readFileSync(changelogPath, 'utf8');
if (!version) {
return fullChangelog;
}
// Split on level-2 headers, keeping the headers as delimiters so the array
// alternates between header and body entries.
const parts = fullChangelog.split(/(^## .*$)/m);
const index = parts.findIndex((part) => part.trim() === `## ${version}`);
if (index === -1) {
throw new Error(`Matching version ${version} in changelog was not found`);
}
return parts[index + 1] ? parts[index + 1].trim() : '';
}

module.exports = { extractChangelogSection, CHANGELOG_PATH };

if (require.main === module) {
const version = process.argv[2];
try {
process.stdout.write(extractChangelogSection(version));
} catch (e) {
console.error(e.message || e);
process.exit(1);
}
}
2 changes: 1 addition & 1 deletion tools/cli/preRelease.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const updateVersionAndIntegrity = async (absolutePath, version, integrityHash) =
}
const readme = fs.readFileSync(absolutePath, 'utf8');
const result = readme
.replace(/integrity=\".*?\"/, `integrity="${integrityHash}"`)
.replace(/integrity=".*?"/g, `integrity="${integrityHash}"`)
.replace(
/res\.cdn\.office.net\/teams-js\/.*\/js\/MicrosoftTeams\.min\.js/g,
`res.cdn.office.net/teams-js/${version}/js/MicrosoftTeams.min.js`,
Expand Down
25 changes: 2 additions & 23 deletions tools/cli/readChangelog.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,12 @@
/* eslint-disable */

const fs = require('fs');
const path = require('path');

const readChangeLog = version => {
const relativePathToChangelog = '../../packages/teams-js/CHANGELOG.md';
const absolutePathToChangelog = path.resolve(__dirname, relativePathToChangelog);
if (!fs.existsSync(absolutePathToChangelog)) {
throw `ERROR: ${absolutePathToChangelog} was not found.`;
}
const fullChangelog = fs.readFileSync(absolutePathToChangelog, 'utf8');
if (!version) {
return fullChangelog;
} else {
const result = fullChangelog.split(/(## .*\d)/);
const index = result.findIndex(substr => substr.startsWith(`## ${version}`));
if (index !== -1) {
const log = result[index + 1];
return log;
}
throw new Error('Matching version in changelog was not found');
}
};
const { extractChangelogSection } = require('./extract-changelog-section');

(async () => {
const args = process.argv.slice(2);
const version = args[0];
try {
const section = readChangeLog(version);
const section = extractChangelogSection(version);
console.log(section);
} catch (e) {
console.log('Something went wrong!');
Expand Down
Loading