UNPKG

@theo.gravity/changelog-version

Version:

Creates / updates a changelog with customizable options, including version / timestamp / CI support.

68 lines (50 loc) 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _fs = require("fs"); var _util = _interopRequireDefault(require("util")); var _path = require("path"); var _utils = require("../utils"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const writeFileAsync = _util.default.promisify(_fs.writeFile); const debug = require('debug')('base-stamper'); /** * Contains methods that are common to stampers. * A stamper is a class that modifies a changelog in some fashion. */ class BaseStamper { constructor(options = {}) { this.projectRoot = options.projectRoot || process.cwd(); this.changelogFile = options.changelogFile || 'CHANGELOG.md'; } /** * Writes the changelog with new data. * @param {string} data * @return {Promise<void>} * @protected */ async _writeChangelog(data) { const changelogFilePath = (0, _path.join)(this.projectRoot, this.changelogFile); try { await writeFileAsync(changelogFilePath, data); } catch (e) { debug(e); throw new Error(`Unable to write the changelog file at: ${changelogFilePath}`); } } /** * Gets the raw file data * @return {Promise<string>} Contents of the file * @protected */ async _readFileContents(file) { if (!file) { throw new Error('_getFileContents() requires the file name.'); } const filePath = (0, _path.join)(this.projectRoot, file); return (0, _utils.getFileContents)(filePath); } } exports.default = BaseStamper;