renovate/tools/distro-json-generate.mjs
Gabriel-Ladzaretti 786fd6ac94
feat(versioning/ubuntu): Support for Ubuntu codenames (#14601)
* feat(versioning/ubuntu): Support for Ubuntu codenames

initial commit

* feat(versioning/ubuntu): Support for Ubuntu codenames

exported hardcoded data into JSON

* feat(versioning/ubuntu): Support for Ubuntu codenames

exported hardcoded data into JSON

* feat(versioning/ubuntu): Support for Ubuntu codenames

lint fix for DataFile

* feat(versioning/ubuntu): Support for Ubuntu codenames

fix for kebabCase

* feat(versioning/ubuntu): Support for Ubuntu codenames

JSON data file

* feat(versioning/ubuntu): Support for Ubuntu codenames

tests added

* feat(versioning/ubuntu): Support for Ubuntu codenames

added default branch in getCodenameByVersion function

* feat(versioning/ubuntu): Support for Ubuntu codenames

added the cmd to generate the data file

* feat(versioning/ubuntu): Support for Ubuntu codenames

CR changes

* feat(versioning/ubuntu): Support for Ubuntu codenames

CR changes

* feat(versioning/ubuntu): Support for Ubuntu codenames

CR changes

* feat(versioning/ubuntu): Support for Ubuntu codenames

documentation added.
added test cases.

* feat(versioning/ubuntu): Support for Ubuntu codenames

documentation added.
added test cases.

* feat(versioning/ubuntu): Support for Ubuntu codenames

documentation added.
added test cases.

* feat(versioning/ubuntu): Support for Ubuntu codenames

documentation added.
added test cases.

* feat(versioning/ubuntu): Support for Ubuntu codenames

documentation added.
added test cases.

* feat(versioning/ubuntu): Support for Ubuntu codenames

documentation cr

* feat(versioning/ubuntu): Support for Ubuntu codenames

documentation cr

* feat(versioning/ubuntu): Support for Ubuntu codenames

documentation cr

* feat(versioning/ubuntu): Support for Ubuntu codenames

added sh script

* feat(versioning/ubuntu): Support for Ubuntu codenames

added mjs script

* feat(versioning/ubuntu): Support for Ubuntu codenames

mjs script updated

* feat(versioning/ubuntu): Support for Ubuntu codenames

mjs script updated

* feat(versioning/ubuntu): Support for Ubuntu codenames

mjs script updated

* feat(versioning/ubuntu): Support for Ubuntu codenames

mjs script updated

* feat(versioning/ubuntu): Support for Ubuntu codenames

mjs script regex modification

* feat(versioning/ubuntu): Support for Ubuntu codenames

initial commit

* feat(versioning/ubuntu): Support for Ubuntu codenames

exported hardcoded data into JSON

* feat(versioning/ubuntu): Support for Ubuntu codenames

exported hardcoded data into JSON

* feat(versioning/ubuntu): Support for Ubuntu codenames

lint fix for DataFile

* feat(versioning/ubuntu): Support for Ubuntu codenames

fix for kebabCase

* feat(versioning/ubuntu): Support for Ubuntu codenames

JSON data file

* feat(versioning/ubuntu): Support for Ubuntu codenames

tests added

* feat(versioning/ubuntu): Support for Ubuntu codenames

added default branch in getCodenameByVersion function

* feat(versioning/ubuntu): Support for Ubuntu codenames

added the cmd to generate the data file

* feat(versioning/ubuntu): Support for Ubuntu codenames

CR changes

* feat(versioning/ubuntu): Support for Ubuntu codenames

CR changes

* feat(versioning/ubuntu): Support for Ubuntu codenames

CR changes

* feat(versioning/ubuntu): Support for Ubuntu codenames

documentation added.
added test cases.

* feat(versioning/ubuntu): Support for Ubuntu codenames

documentation added.
added test cases.

* feat(versioning/ubuntu): Support for Ubuntu codenames

documentation added.
added test cases.

* feat(versioning/ubuntu): Support for Ubuntu codenames

documentation added.
added test cases.

* feat(versioning/ubuntu): Support for Ubuntu codenames

documentation added.
added test cases.

* feat(versioning/ubuntu): Support for Ubuntu codenames

documentation cr

* feat(versioning/ubuntu): Support for Ubuntu codenames

documentation cr

* feat(versioning/ubuntu): Support for Ubuntu codenames

documentation cr

* feat(versioning/ubuntu): Support for Ubuntu codenames

added sh script

* feat(versioning/ubuntu): Support for Ubuntu codenames

added mjs script

* feat(versioning/ubuntu): Support for Ubuntu codenames

mjs script updated

* feat(versioning/ubuntu): Support for Ubuntu codenames

mjs script updated

* feat(versioning/ubuntu): Support for Ubuntu codenames

mjs script updated

* feat(versioning/ubuntu): Support for Ubuntu codenames

mjs script updated

* feat(versioning/ubuntu): Support for Ubuntu codenames

mjs script regex modification

* feat(versioning/ubuntu): Support for Ubuntu codenames

debian distro json

* feat(versioning/ubuntu): Support for Ubuntu codenames

removed debian distro json

* Update tools/distro-json-generate.mjs

* feat(versioning/ubuntu): Support for Ubuntu codenames

added package.json script entry

* feat(versioning/ubuntu): Support for Ubuntu codenames

added package.json script entry

* feat(versioning/ubuntu): Support for Ubuntu codenames

added package.json script entry

Co-authored-by: Rhys Arkins <rhys@arkins.net>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2022-03-24 10:54:21 +00:00

73 lines
1.6 KiB
JavaScript

import fs from 'fs-extra';
import shell from 'shelljs';
shell.echo(`Verifying required packages...`);
if (!shell.which(`distro-info`)) {
shell.echo('This script requires distro-info, exiting...');
shell.exit(2);
}
if (!shell.which(`sed`)) {
shell.echo('This script requires sed, exiting...');
shell.exit(2);
}
shell.echo(`OK`);
const ubuntuDistroInfo = shell.exec(
`ubuntu-distro-info --all -f | sed -r 's/Ubuntu|"|LTS |Debian //g; s/([0-9]+.[0-9]+) /\\1 /; s/.*/\\L&/; s/( [a-z]*) [a-z]*/\\1/g; s/^[ \\t]*//'`,
{ silent: true }
);
/**
* @param {string} str
* @returns {{}}
*/
function objectify(str) {
let obj = {};
for (const line of str.split(/\r?\n/)) {
let [ver, codename] = line.split(' ');
// eslint-disable-next-line
// @ts-ignore
obj[ver] = codename;
}
return obj;
}
/**
* @param {string} file
* @param {string} newData
*/
async function updateJsonFile(file, newData) {
let oldData;
try {
oldData = fs.existsSync(file) ? await fs.readFile(file, 'utf8') : null;
// Eliminate formatting
oldData = oldData?.replace(/\s/g, '') ?? null;
} catch (e) {
shell.echo(e.toString());
shell.exit(1);
}
const parsedData = JSON.stringify(objectify(newData), undefined, 2);
if (oldData === parsedData) {
shell.echo(`${file} is up to date.`);
return;
}
try {
shell.echo(`Updating ${file}`);
await fs.writeFile(file, parsedData);
} catch (e) {
shell.echo(e.toString());
shell.exit(1);
}
}
// eslint-disable-next-line @typescript-eslint/no-floating-promises
updateJsonFile(`../data/ubuntu-distro-info.json`, ubuntuDistroInfo.toString());