Skip to content

Commit

Permalink
fix script
Browse files Browse the repository at this point in the history
  • Loading branch information
slavaleleka committed Jun 29, 2023
1 parent 97e7764 commit f988a53
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions scripts/check-sources-updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ const COMMENT_MARKER = '//';
const FUNCTION_MARKER = 'function ';
const NAME_MARKER_START = "name: '";
const NAME_MARKER_END = "',";
const ALIASES_MARKER = 'aliases: ';
const ALIASES_MARKER_START = 'aliases: [';
const ALIASES_MARKER_END = '],';

/**
* Make request to UBO repo(master), parses and returns the list of UBO scriptlets
Expand All @@ -164,14 +165,17 @@ async function getCurrentUBOScriptlets() {

chunks.forEach((chunk) => {
let name;
let aliases;
const aliases = [];

const functionDefinitionIndex = chunk.indexOf(FUNCTION_MARKER) || chunk.length;
const scriptletObjectText = chunk.slice(0, functionDefinitionIndex).trim();

let areAliasesStarted = false;

const textLines = scriptletObjectText.split(EOL);
for (let i = 0; i < textLines.length; i += 1) {
const line = textLines[i].trim();

if (line.startsWith(COMMENT_MARKER)) {
continue;
}
Expand All @@ -181,19 +185,24 @@ async function getCurrentUBOScriptlets() {
continue;
}
// parse the aliases
if (line.startsWith(ALIASES_MARKER)) {
const aliasesStr = line
.slice(ALIASES_MARKER.length)
// prepare the string for JSON.parse
.replace(/'/g, '"')
.replace(/,?$/, '')
// remove comments
// e.g. "[ 'rnt.js', 'sed.js' /* to be removed */ ]"
.replace(/\/\*[\s|\w]+?\*\//, '');
aliases = JSON.parse(aliasesStr);
// 'name' string goes first and 'aliases' string goes after it
// so if aliases are parsed, no need to continue lines iterating
break;
if (line.startsWith(ALIASES_MARKER_START)) {
// now aliases array is set as multiline list
// so the flag is needed for correct parsing of following lines
areAliasesStarted = true;
continue;
}
if (areAliasesStarted) {
if (line === ALIASES_MARKER_END) {
areAliasesStarted = false;
// 'name' string goes first and 'aliases' string goes after it
// so if aliases are parsed, no need to continue lines iterating
break;
}
const alias = line
.replace(/,?$/g, '')
.replace(/'/g, '')
aliases.push(alias);
continue;
}
}

Expand All @@ -202,7 +211,7 @@ async function getCurrentUBOScriptlets() {
}

let namesStr = name;
if (aliases) {
if (aliases.length > 0) {
namesStr += ` (${aliases.join(', ')})`;
}
names.push(namesStr);
Expand Down

0 comments on commit f988a53

Please sign in to comment.