diff --git a/src/MariaDB.js b/src/MariaDB.js index bf40db31..4edc7f9c 100644 --- a/src/MariaDB.js +++ b/src/MariaDB.js @@ -11,7 +11,7 @@ function parsePage(url, cbSuccess) { for (let i = 0; i < elements.length; i++) { let element = elements[i]; let doc = { id: element.id }; - doc.name = element.childNodes[0].textContent; + doc.name = element.childNodes[0].textContent.trim(); try { // Parse ul > li element.nextSibling.nextSibling.childNodes.forEach(liChild => { diff --git a/src/MySQL.js b/src/MySQL.js index 61e49e8f..76de1ab8 100644 --- a/src/MySQL.js +++ b/src/MySQL.js @@ -16,7 +16,13 @@ function parsePage(url, cbSuccess) { } doc.id = element.parentElement.getElementsByTagName('a')[0].name; - + const regexCli = /([-]{2})([0-9a-z-_]+)/i; + doc.name = element.parentElement.getElementsByTagName('code')[0].textContent.trim(); + var cli = doc.name.match(regexCli); + if (cli) { + // cli format + doc.name = cli[2].replace(/-/g, '_'); //Try to clean format + } var tbody = element.getElementsByTagName('tbody')[0]; var trs = tbody.getElementsByTagName('tr'); @@ -29,7 +35,14 @@ function parsePage(url, cbSuccess) { doc.dynamic = value.textContent.toLowerCase().trim() === 'yes'; break; case 'system variable': - doc.name = value.textContent.toLowerCase().trim(); + var theName = value.textContent.toLowerCase().trim(); + if (doc.name !== undefined) { + if (doc.name.match(regexCli)) { + doc.name = theName; + } + } else { + doc.name = theName; + } break; case 'scope': doc.scope = value.textContent diff --git a/src/common.js b/src/common.js index 6a9d516b..2c6a8a26 100644 --- a/src/common.js +++ b/src/common.js @@ -6,29 +6,25 @@ const fs = require('fs'); * @param {function} arraySorter The sorter callback */ function sortObject(obj, arraySorter) { - if(typeof obj !== 'object') - return obj + if (typeof obj !== 'object') return obj; if (Array.isArray(obj)) { - if (arraySorter) { - obj.sort(arraySorter); - } - for (var i = 0; i < obj.length; i++) { - obj[i] = sortObject(obj[i], arraySorter); - } - return obj; + if (arraySorter) { + obj.sort(arraySorter); + } + for (var i = 0; i < obj.length; i++) { + obj[i] = sortObject(obj[i], arraySorter); + } + return obj; } var temp = {}; var keys = []; - for(var key in obj) - keys.push(key); + for (var key in obj) keys.push(key); keys.sort(); - for(var index in keys) - temp[keys[index]] = sortObject(obj[keys[index]], arraySorter); + for (var index in keys) temp[keys[index]] = sortObject(obj[keys[index]], arraySorter); return temp; } exports.writeJSON = function writeJSON(filename, data) { - - fs.writeFile(filename, JSON.stringify(sortObject(data), null, 2)+"\n", function(err) { + fs.writeFile(filename, JSON.stringify(sortObject(data), null, 2) + '\n', function(err) { if (err) { return console.log(err); } diff --git a/src/merge.php b/src/merge.php index e0df8415..3f78cb27 100644 --- a/src/merge.php +++ b/src/merge.php @@ -96,16 +96,17 @@ function fixRange(stdClass &$current, stdClass &$cache): void } foreach ($data as $doc) { - if (isset($doc->name)) { - if (isset($variables[$doc->name]) === false) { + $identifier = $doc->name; + if (isset($identifier)) { + if (isset($variables[$identifier]) === false) { if (isset($doc->ids) === false) { $doc->ids = array(); } - $variables[$doc->name] = $doc; - $kbEntry = new stdClass(); - $kbEntry->anchor = $doc->id; - $kbEntry->url = $fileData->url; - $doc->ids[] = $kbEntry; + $variables[$identifier] = $doc; + $kbEntry = new stdClass(); + $kbEntry->anchor = $doc->id; + $kbEntry->url = $fileData->url; + $doc->ids[] = $kbEntry; unset($doc->id); } else { if (isset($doc->ids) === false) { @@ -116,11 +117,11 @@ function fixRange(stdClass &$current, stdClass &$cache): void $kbEntry->url = $fileData->url; $doc->ids[] = $kbEntry; unset($doc->id); - //echo $doc->name." duplicate ! in ".str_replace($dataDir, "", $file).PHP_EOL; + //echo $identifier." duplicate ! in ".str_replace($dataDir, "", $file).PHP_EOL; $newData = new stdClass(); foreach ((array) $doc as $key => $val) { - if (isset($variables[$doc->name]->$key)) { - $cacheValue = $variables[$doc->name]->$key; + if (isset($variables[$identifier]->$key)) { + $cacheValue = $variables[$identifier]->$key; $docValue = $doc->$key; if (( strtoupper(json_encode($cacheValue)) === strtoupper(json_encode($docValue))) && ( json_encode($cacheValue) !== json_encode($docValue)) @@ -308,7 +309,7 @@ function fixRange(stdClass &$current, stdClass &$cache): void $cache = $cacheValue; fixRange($current, $cache); } else { - echo '[ERROR] conflict '.$key.' + '.$doc->name.' - '.json_encode($cacheValue).' - '.json_encode($docValue).PHP_EOL; + echo '[ERROR] conflict '.$key.' + '.$identifier.' - '.json_encode($cacheValue).' - '.json_encode($docValue).PHP_EOL; } } else { $newData->$key = $val; @@ -318,7 +319,7 @@ function fixRange(stdClass &$current, stdClass &$cache): void } } //print_r($newData); - $variables[$doc->name] = $newData; + $variables[$identifier] = $newData; } } }