diff --git a/core/index.js b/core/index.js index 6c14417b..a17533c2 100644 --- a/core/index.js +++ b/core/index.js @@ -84,7 +84,7 @@ async function core(options) { const linksShorthand = data[name].releases[`v${versionSemver.version}`].files.links; // since we're going to be writing this a lot for assignments, it's nice to have shorthand for readability - for(const filename of Object.keys(availableShorthand)) { + for (const filename of Object.keys(availableShorthand)) { const id = data[name].releases[`v${versionSemver.version}`].files.available[ filename @@ -100,7 +100,7 @@ async function core(options) { files: parsedFile.files, architecture: parsedFile.architecture, }); - }; + } // # LTS // ## define the release-line specific support objec`t diff --git a/ranges/index.js b/ranges/index.js index 4bc9a476..c412b939 100644 --- a/ranges/index.js +++ b/ranges/index.js @@ -1,5 +1,5 @@ -const nodevu = require('@nodevu/core') -const aliases = require('@nodevu/aliases') +const nodevu = require('@nodevu/core'); +const aliases = require('@nodevu/aliases'); // building out the model of what we want to see. not totally necessary, // but helps reduce the amount of logic that's needed to achieve it dynamically. @@ -10,14 +10,14 @@ const defaultRangesObject = { newestLts: undefined, newestSecurity: undefined, newest: undefined, - oldest: undefined + oldest: undefined, }, current: { versions: [], oldestSecurity: undefined, newestSecurity: undefined, newest: undefined, - oldest: undefined + oldest: undefined, }, 'lts/latest': { versions: [], @@ -26,7 +26,7 @@ const defaultRangesObject = { newestLts: undefined, newestSecurity: undefined, newest: undefined, - oldest: undefined + oldest: undefined, }, 'lts/active': { versions: [], @@ -35,7 +35,7 @@ const defaultRangesObject = { newestLts: undefined, newestSecurity: undefined, newest: undefined, - oldest: undefined + oldest: undefined, }, 'lts/maintenance': { versions: [], @@ -44,14 +44,14 @@ const defaultRangesObject = { newestLts: undefined, newestSecurity: undefined, newest: undefined, - oldest: undefined + oldest: undefined, }, eol: { versions: [], newest: undefined, - oldest: undefined - } -} + oldest: undefined, + }, +}; // describing this early so it doesn't need to be commented everywhere: // filter can accept an array or a string. Each object's building phase @@ -62,96 +62,158 @@ const defaultRangesObject = { // If you figure one out, or there's one in the future, please feel free // to submit a PR to update this code. -async function generateRanges (filter) { - let localFilter = filter +async function generateRanges(filter) { + let localFilter = filter; if (typeof localFilter === 'string') { // check to make sure that the filter is valid. if it's not, yeet. if (!aliases.includes(localFilter)) { - throw new Error(`Unknown value passed as a filter. The passed value: '${localFilter}'.`) + throw new Error( + `Unknown value passed as a filter. The passed value: '${localFilter}'.`, + ); } } else if (Array.isArray(localFilter) === true) { // check to make sure that the filter is valid. if it's not, yeet. - if (!localFilter.every(alias => aliases.includes(alias))) { - throw new Error(`At least one of the values passed as a filter is unknown. The passed value(s): '${localFilter.join('\', \'')}'`) + if (!localFilter.every((alias) => aliases.includes(alias))) { + throw new Error( + `At least one of the values passed as a filter is unknown. The passed value(s): '${localFilter.join( + "', '", + )}'`, + ); } } else if (localFilter) { - throw new Error(`Unknown value passed as a filter. The passed value: '${localFilter}', with a type of '${typeof localFilter}'. Make sure you are passing a string (or an Array of strings) with valid value(s).`) + throw new Error( + `Unknown value passed as a filter. The passed value: '${localFilter}', with a type of '${typeof localFilter}'. Make sure you are passing a string (or an Array of strings) with valid value(s).`, + ); } else { - localFilter = 'all' + localFilter = 'all'; } // set up the data from @nodevu/core - const data = await nodevu() + const data = await nodevu(); // deep clone the default object so we don't modify it. // // modifying the default object has some super wonky side effects // on subsequent calls to this function that we don't want. - const ranges = JSON.parse(JSON.stringify(defaultRangesObject)) + const ranges = JSON.parse(JSON.stringify(defaultRangesObject)); for (const line in data) { for (const key in data[line].releases) { // define `all` data if (localFilter === 'all' || localFilter.includes('all')) { - ranges.all.versions.push(key) // put every release into the all array + ranges.all.versions.push(key); // put every release into the all array - if (data[line].releases[key].lts.isLts === true && ranges.all.newestLts === undefined) { - ranges.all.newestLts = `${key}` // if there's no entries yet and this iteration is an LTS release, push it into the array + if ( + data[line].releases[key].lts.isLts === true && + ranges.all.newestLts === undefined + ) { + ranges.all.newestLts = `${key}`; // if there's no entries yet and this iteration is an LTS release, push it into the array } - if (data[line].releases[key].security.isSecurity === true && ranges.all.newestSecurity === undefined) { - ranges.all.newestSecurity = `${key}` // if there's no entries yet and this iteration is an LTS release, push it into the array + if ( + data[line].releases[key].security.isSecurity === true && + ranges.all.newestSecurity === undefined + ) { + ranges.all.newestSecurity = `${key}`; // if there's no entries yet and this iteration is an LTS release, push it into the array } } // define 'current' data - if (localFilter === 'current' || localFilter === 'all' || localFilter.includes('current') || localFilter.includes('all')) { + if ( + localFilter === 'current' || + localFilter === 'all' || + localFilter.includes('current') || + localFilter.includes('all') + ) { if (data[line].support?.phases.current === 'start') { - ranges.current.versions.push(key) // add current iteration to the versions array if the phase is `start` which means it'll be current. + ranges.current.versions.push(key); // add current iteration to the versions array if the phase is `start` which means it'll be current. - if (ranges.current.oldestSecurity === undefined && ranges.current.newestSecurity === undefined) { - ranges.current.oldestSecurity = `${data[line].security.oldest}` - ranges.current.newestSecurity = `${data[line].security.newest}` + if ( + ranges.current.oldestSecurity === undefined && + ranges.current.newestSecurity === undefined + ) { + ranges.current.oldestSecurity = `${data[line].security.oldest}`; + ranges.current.newestSecurity = `${data[line].security.newest}`; } } } // define 'lts/latest' data - if (localFilter === 'lts/latest' || localFilter === 'lts/active' || localFilter === 'all' || localFilter.includes('lts/latest') || localFilter.includes('lts/active') || localFilter.includes('all')) { - if (data[line].support?.phases.current === 'lts' && data[line].releases[key].lts.isLts) { + if ( + localFilter === 'lts/latest' || + localFilter === 'lts/active' || + localFilter === 'all' || + localFilter.includes('lts/latest') || + localFilter.includes('lts/active') || + localFilter.includes('all') + ) { + if ( + data[line].support?.phases.current === 'lts' && + data[line].releases[key].lts.isLts + ) { // TODO: do we want to include all versions in the release line, even prior to it being minted LTS? - ranges['lts/latest'].versions.push(key) + ranges['lts/latest'].versions.push(key); - if (ranges['lts/latest'].oldestSecurity === undefined) { // only checking if this one is undefined, since everything else _should_ be undefined if this one is. saves some processing power. - ranges['lts/latest'].oldestSecurity = `${data[line].security.oldest}` - ranges['lts/latest'].newestSecurity = `${data[line].security.newest}` - ranges['lts/latest'].oldestLts = `${data[line].support.lts.oldest}` - ranges['lts/latest'].newestLts = `${data[line].support.lts.newest}` + if (ranges['lts/latest'].oldestSecurity === undefined) { + // only checking if this one is undefined, since everything else _should_ be undefined if this one is. saves some processing power. + ranges['lts/latest'].oldestSecurity = + `${data[line].security.oldest}`; + ranges['lts/latest'].newestSecurity = + `${data[line].security.newest}`; + ranges['lts/latest'].oldestLts = `${data[line].support.lts.oldest}`; + ranges['lts/latest'].newestLts = `${data[line].support.lts.newest}`; } } } // define 'lts/maintenance' data - if (localFilter === 'lts/maintenance' || localFilter === 'lts/active' || localFilter === 'all' || localFilter.includes('lts/maintenance') || localFilter.includes('lts/active') || localFilter.includes('all')) { - if (data[line].support?.phases.current === 'maintenance' && data[line].releases[key].lts.isLts) { - ranges['lts/maintenance'].versions.push(key) + if ( + localFilter === 'lts/maintenance' || + localFilter === 'lts/active' || + localFilter === 'all' || + localFilter.includes('lts/maintenance') || + localFilter.includes('lts/active') || + localFilter.includes('all') + ) { + if ( + data[line].support?.phases.current === 'maintenance' && + data[line].releases[key].lts.isLts + ) { + ranges['lts/maintenance'].versions.push(key); - if (ranges['lts/maintenance'].newestSecurity === undefined && ranges['lts/maintenance'].newestLts === undefined) { - ranges['lts/maintenance'].newestSecurity = `${data[line].security.newest}` - ranges['lts/maintenance'].newestLts = `${data[line].support.lts.newest}` + if ( + ranges['lts/maintenance'].newestSecurity === undefined && + ranges['lts/maintenance'].newestLts === undefined + ) { + ranges['lts/maintenance'].newestSecurity = + `${data[line].security.newest}`; + ranges['lts/maintenance'].newestLts = + `${data[line].support.lts.newest}`; } - if (ranges['lts/maintenance'].oldestSecurity !== `${data[line].security.oldest}` || ranges['lts/maintenance'].oldestLts !== `${data[line].support.lts.oldest}`) { - ranges['lts/maintenance'].oldestSecurity = `${data[line].security.oldest}` - ranges['lts/maintenance'].oldestLts = `${data[line].support.lts.oldest}` + if ( + ranges['lts/maintenance'].oldestSecurity !== + `${data[line].security.oldest}` || + ranges['lts/maintenance'].oldestLts !== + `${data[line].support.lts.oldest}` + ) { + ranges['lts/maintenance'].oldestSecurity = + `${data[line].security.oldest}`; + ranges['lts/maintenance'].oldestLts = + `${data[line].support.lts.oldest}`; } } } // define 'eol' data - if (localFilter === 'eol' || localFilter === 'all' || localFilter.includes('eol') || localFilter.includes('all')) { + if ( + localFilter === 'eol' || + localFilter === 'all' || + localFilter.includes('eol') || + localFilter.includes('all') + ) { if (data[line].support?.phases.current === 'end') { - ranges.eol.versions.push(key) + ranges.eol.versions.push(key); } } } @@ -161,39 +223,48 @@ async function generateRanges (filter) { // // doesn't need to be in the loops, since it's basically just a union // of lts/latest and lts/maintenance - if (localFilter === 'lts/active' || localFilter === 'all' || localFilter.includes('lts/active') || localFilter.includes('all')) { - ranges['lts/active'].versions = ranges['lts/latest'].versions.concat(ranges['lts/maintenance'].versions) - ranges['lts/active'].oldestLts = ranges['lts/maintenance'].oldestLts // the maintenance LTS is the older LTS - ranges['lts/active'].newestLts = ranges['lts/latest'].newestLts // the latest LTS is the newer LTS - ranges['lts/active'].oldestSecurity = ranges['lts/maintenance'].oldestSecurity // the maintenance security is the older security - ranges['lts/active'].newestSecurity = ranges['lts/latest'].newestSecurity // the latest security is the newer security + if ( + localFilter === 'lts/active' || + localFilter === 'all' || + localFilter.includes('lts/active') || + localFilter.includes('all') + ) { + ranges['lts/active'].versions = ranges['lts/latest'].versions.concat( + ranges['lts/maintenance'].versions, + ); + ranges['lts/active'].oldestLts = ranges['lts/maintenance'].oldestLts; // the maintenance LTS is the older LTS + ranges['lts/active'].newestLts = ranges['lts/latest'].newestLts; // the latest LTS is the newer LTS + ranges['lts/active'].oldestSecurity = + ranges['lts/maintenance'].oldestSecurity; // the maintenance security is the older security + ranges['lts/active'].newestSecurity = ranges['lts/latest'].newestSecurity; // the latest security is the newer security } // some quick maths for dynamically defining newest and oldest, regardless of what ranges we have. for (const alias in ranges) { - ranges[alias].newest = ranges[alias].versions[0] // set the newest version to the first version in the array - ranges[alias].oldest = ranges[alias].versions[ranges[alias].versions.length - 1] // set the oldest version to the last version in the array + ranges[alias].newest = ranges[alias].versions[0]; // set the newest version to the first version in the array + ranges[alias].oldest = + ranges[alias].versions[ranges[alias].versions.length - 1]; // set the oldest version to the last version in the array } // delete what we don't need for (const property in ranges) { if (ranges[property].versions.length === 0) { - delete ranges[property] + delete ranges[property]; } } // make sure we remove any unrequested remnants from lts/active construction if (Array.isArray(localFilter) && localFilter.includes('lts/active')) { if (!localFilter.includes('lts/latest')) { - ranges['lts/latest'] = undefined + ranges['lts/latest'] = undefined; } if (!localFilter.includes('lts/maintenance')) { - ranges['lts/maintenance'] = undefined + ranges['lts/maintenance'] = undefined; } } - return ranges + return ranges; } -module.exports = generateRanges \ No newline at end of file +module.exports = generateRanges;