All files / packages/design-system/scripts/release-notes index.js

0% Statements 0/26
0% Branches 0/12
0% Functions 0/5
0% Lines 0/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86                                                                                                                                                                           
const fs = require('fs');
 
const {
  getReleaseDate,
  logStatus,
  COMMENT_BEST_PRACTICES,
  NEW_LINE,
  NEW_LINE_DOUBLE,
  RELEASE_NOTES_FILENAME
} = require('./helpers.js');
const model = require('./model.js');
const { notes: notesLegacy } = require('./legacy.js');
const { TYPE_GENERAL } = require('./general.js');
const { TYPE_TOKENS } = require('./tokens.js');
 
/**
 * compileReleaseNotes
 * @returns {string} - content for the complete compiled release notes
 */
function compileReleaseNotes() {
  const versions = model.getVersions();
 
  const getNotesPerVersion = version => {
    // write a new type subhead into the stream when changing types
    const writeTypeSubHead = block => {
      if (
        (block.name || block.type === TYPE_TOKENS) &&
        block.type !== writeTypeSubHead.curType
      ) {
        writeTypeSubHead.curType = block.type;
        return `## ${writeTypeSubHead.curType}`;
      } else {
        return '';
      }
    };
 
    const perComponentNotes = model
      .getBlocks()
      .filter(block => block.version === version)
      .map(block => {
        return [
          writeTypeSubHead(block),
          block.component
            ? `### [${block.name}](https://www.lightningdesignsystem.com${block.urlPath}${block.component})`
            : '',
          block.versionNotes.join(NEW_LINE)
        ].join(NEW_LINE);
      });
 
    return perComponentNotes;
  };
 
  const getReleaseHead = version => {
    const generalNotes = model
      .getBlocks()
      .find(block => block.version === version && block.type === TYPE_GENERAL);
 
    const releaseDate =
      (generalNotes && generalNotes.versionDate) || getReleaseDate();
    return `## Release ${version} - ${releaseDate}`;
  };
 
  const perVersionNotes = versions.map(version =>
    [getReleaseHead(version), ...getNotesPerVersion(version)].join(
      NEW_LINE_DOUBLE
    )
  );
 
  return [COMMENT_BEST_PRACTICES, ...perVersionNotes, notesLegacy]
    .join(NEW_LINE_DOUBLE) // compile all the release notes parts
    .replace(/\n{3,}/g, NEW_LINE_DOUBLE); // clean up extra line breaks in compiled release notes
}
 
/**
 * output - writes the releasenotes file
 */
function output() {
  // write to release notes file
  fs.writeFile(RELEASE_NOTES_FILENAME, compileReleaseNotes(), err => {
    if (err) throw err;
    logStatus(`${RELEASE_NOTES_FILENAME} saved!`);
  });
}
 
output();