2021-11-08 18:45:29 +03:00
|
|
|
const fs = require('fs')
|
2021-05-05 13:58:14 +03:00
|
|
|
|
2021-11-08 18:45:29 +03:00
|
|
|
const inputPath = process.argv[2]
|
|
|
|
const outputPath = process.argv[3]
|
2021-05-05 13:58:14 +03:00
|
|
|
|
2021-11-08 18:45:29 +03:00
|
|
|
console.log('Extracting release notes from ' + inputPath + ' to ' + outputPath)
|
2021-05-05 13:58:14 +03:00
|
|
|
|
|
|
|
/** Returns the part of the text until the second top-level heading (exclusive)
|
|
|
|
* in Markdown formatting.
|
|
|
|
*/
|
|
|
|
function cutFirstSection(content) {
|
2021-11-08 18:45:29 +03:00
|
|
|
const nightlySectionRegex = /^# Enso Next$/gm
|
|
|
|
function findNightlySectionStart(text) {
|
|
|
|
return text.search(nightlySectionRegex)
|
|
|
|
}
|
|
|
|
const regularSectionRegex = /^# Enso .*? \(\d\d\d\d-\d\d-\d\d\)$/gm
|
|
|
|
function findFirstRegularSectionStart(text) {
|
|
|
|
return text.search(regularSectionRegex)
|
|
|
|
}
|
|
|
|
function findNewline(text) {
|
|
|
|
return text.indexOf('\n')
|
|
|
|
}
|
|
|
|
|
|
|
|
const firstHeading = findNightlySectionStart(content)
|
|
|
|
if (firstHeading < 0) {
|
|
|
|
throw 'Could not find the nightly section, matching ' + nightlySectionRegex
|
|
|
|
}
|
|
|
|
|
|
|
|
const restOffset = firstHeading + 2
|
|
|
|
const newLineOffset = findNewline(content.substring(restOffset))
|
|
|
|
if (newLineOffset < 0) {
|
|
|
|
throw 'No content after the section heading'
|
|
|
|
}
|
|
|
|
const restStart = restOffset + newLineOffset + 1
|
|
|
|
|
|
|
|
const rest = content.substring(restStart)
|
|
|
|
const secondHeading = findFirstRegularSectionStart(rest)
|
|
|
|
if (secondHeading < 0) {
|
|
|
|
throw 'Could not find the first released section, matching' + regularSectionRegex
|
|
|
|
}
|
|
|
|
|
|
|
|
const firstSectionContent = rest.substring(0, secondHeading)
|
|
|
|
return firstSectionContent
|
2021-05-05 13:58:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2021-11-08 18:45:29 +03:00
|
|
|
const content = fs.readFileSync(inputPath, { encoding: 'utf-8' })
|
|
|
|
const nightlyPart = cutFirstSection(content)
|
|
|
|
fs.writeFileSync(outputPath, nightlyPart)
|
2021-05-05 13:58:14 +03:00
|
|
|
|
2021-11-08 18:45:29 +03:00
|
|
|
console.log('Created ' + outputPath + ' with the following content:')
|
|
|
|
console.log(nightlyPart)
|
2021-05-05 13:58:14 +03:00
|
|
|
} catch (exc) {
|
2021-11-08 18:45:29 +03:00
|
|
|
console.error(exc)
|
|
|
|
process.exit(1)
|
2021-05-05 13:58:14 +03:00
|
|
|
}
|