Skip to content

Commit

Permalink
refactor bumpyaml
Browse files Browse the repository at this point in the history
  • Loading branch information
joemaller committed Jan 10, 2022
1 parent 625e89d commit 06908a7
Showing 1 changed file with 23 additions and 28 deletions.
51 changes: 23 additions & 28 deletions app/lib/bump-yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,28 @@ module.exports = function (data, version, config) {
let prefixData = {};
let hasVersion = false;

try {
if (config.prefixes.length > 0) {
prefixData = bumpPlainText(data, version, config);
hasVersion = !!prefixData?.data;
}

/** @type {object} */
const yamlObj = YAML.parse(prefixData.data || data);

// TODO: Does this also need to check for Arrays and Strings?
if (yamlObj === null) {
throw "YAML.parse() returned null";
}

const yamlData = YAML.parseDocument(prefixData?.data || data, config.yaml);
const oldVersion = yamlData.get("version");

if (!hasVersion) {
yamlData.set("version", version);
}

return {
oldVersion: oldVersion,
data: yamlData.toString(config.yaml),
};
} catch (err) {
// console.log("bumpYAML Error:", err, data);
throw err;
if (config.prefixes.length > 0) {
prefixData = bumpPlainText(data, version, config);
hasVersion = !!prefixData?.data;
}

/** @type {object} */
const yamlObj = YAML.parse(prefixData.data || data);

// TODO: Does this also need to check for Arrays and Strings?
if (yamlObj === null) {
throw "YAML.parse() returned null";
}

const yamlData = YAML.parseDocument(prefixData?.data || data, config.yaml);
const oldVersion = yamlData.get("version");

if (!hasVersion) {
yamlData.set("version", version);
}

return {
oldVersion: oldVersion,
data: yamlData.toString(config.yaml),
};
};

0 comments on commit 06908a7

Please sign in to comment.