Skip to content

Commit

Permalink
WIP eslint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomByte committed Feb 27, 2019
1 parent 6db75b3 commit 2489edd
Show file tree
Hide file tree
Showing 5 changed files with 1,738 additions and 1,713 deletions.
80 changes: 39 additions & 41 deletions lib/processors/jsdoc/create-api-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const fs = require("fs");
const path = require("path");

function process(versionInfoFile, unpackedTestresourcesRoot, targetFile, targetFileDeprecated, targetFileExperimental, targetFileSince) {

console.log("[INFO] creating API index files");
console.log("[INFO] sap-ui-version.json: " + versionInfoFile);
console.log("[INFO] unpacked test-resources: " + unpackedTestresourcesRoot);
Expand All @@ -21,7 +20,7 @@ function process(versionInfoFile, unpackedTestresourcesRoot, targetFile, targetF
console.log("[INFO]");

// Deprecated, Experimental and Since collections
let oListCollection = {
const oListCollection = {
deprecated: {
noVersion: {
apis: []
Expand All @@ -40,8 +39,8 @@ function process(versionInfoFile, unpackedTestresourcesRoot, targetFile, targetF
};

function readJSONFile(file) {
return new Promise(function (resolve, reject) {
fs.readFile(file, 'utf8', function (err, data) {
return new Promise(function(resolve, reject) {
fs.readFile(file, "utf8", function(err, data) {
if (err) {
reject(err);
} else {
Expand All @@ -64,7 +63,7 @@ function process(versionInfoFile, unpackedTestresourcesRoot, targetFile, targetF
}

function writeJSON(file, content) {
return new Promise(function(resolve,reject) {
return new Promise(function(resolve, reject) {
// Create dir if it does not exist
mkdirSync( path.dirname(file) );
fs.writeFile(file, JSON.stringify(content), "utf-8", function(err) {
Expand All @@ -83,14 +82,14 @@ function process(versionInfoFile, unpackedTestresourcesRoot, targetFile, targetF
* Returns a promise that resolves with an array of symbols.
*/
function createSymbolSummaryForLib(lib) {
let file = path.join(unpackedTestresourcesRoot, lib.replace(/\./g, "/"), "designtime/api.json");
const file = path.join(unpackedTestresourcesRoot, lib.replace(/\./g, "/"), "designtime/api.json");

return readJSONFile(file).then(function (apijson) {
return readJSONFile(file).then(function(apijson) {
if (!apijson.hasOwnProperty("symbols") || !Array.isArray(apijson.symbols)) {
// Ignore libraries with invalid api.json content like empty object or non-array "symbols" property.
return [];
}
return apijson.symbols.map(symbol => {
return apijson.symbols.map((symbol) => {
collectLists(symbol);
return {
name: symbol.name,
Expand All @@ -101,24 +100,25 @@ function process(versionInfoFile, unpackedTestresourcesRoot, targetFile, targetF
lib: lib
};
});
})
});
}

/*
* Collects Deprecated, Experimental and Since data from passed symbol
* including symbol itself, methods and events.
*/
function collectLists(oSymbol) {

function addData(oDataType, oEntityObject, sObjectType, sSymbolName) {
let sSince = oDataType !== "since" ? oEntityObject[oDataType].since : oEntityObject.since,
oData = {
control: sSymbolName,
text: oEntityObject[oDataType].text || oEntityObject.description,
type: sObjectType,
"static": !!oEntityObject.static,
visibility: oEntityObject.visibility
};
const sSince = oDataType !== "since" ? oEntityObject[oDataType].since : oEntityObject.since;


const oData = {
"control": sSymbolName,
"text": oEntityObject[oDataType].text || oEntityObject.description,
"type": sObjectType,
"static": !!oEntityObject.static,
"visibility": oEntityObject.visibility
};

// For class we skip entityName
if (sObjectType !== "class") {
Expand All @@ -127,7 +127,7 @@ function process(versionInfoFile, unpackedTestresourcesRoot, targetFile, targetF

if (sSince) {
// take only major and minor versions
let sVersion = sSince.split(".").slice(0, 2).join(".");
const sVersion = sSince.split(".").slice(0, 2).join(".");

oData.since = sSince;

Expand Down Expand Up @@ -158,7 +158,7 @@ function process(versionInfoFile, unpackedTestresourcesRoot, targetFile, targetF
}

// Methods
oSymbol.methods && oSymbol.methods.forEach(oMethod => {
oSymbol.methods && oSymbol.methods.forEach((oMethod) => {
if (oMethod.deprecated) {
addData("deprecated", oMethod, "methods", oSymbol.name);
}
Expand All @@ -173,7 +173,7 @@ function process(versionInfoFile, unpackedTestresourcesRoot, targetFile, targetF
});

// Events
oSymbol.events && oSymbol.events.forEach(oEvent => {
oSymbol.events && oSymbol.events.forEach((oEvent) => {
if (oEvent.deprecated) {
addData("deprecated", oEvent, "events", oSymbol.name);
}
Expand All @@ -186,30 +186,29 @@ function process(versionInfoFile, unpackedTestresourcesRoot, targetFile, targetF
addData("since", oEvent, "events", oSymbol.name);
}
});

}

function deepMerge(arrayOfArrays) {
return arrayOfArrays.reduce((array, items) => {
array.push.apply(array, items);
array.push(...items);
return array;
}, []);
}

function expandHierarchyInfo(symbols) {
let byName = new Map();
symbols.forEach(symbol => {
const byName = new Map();
symbols.forEach((symbol) => {
byName.set(symbol.name, symbol);
});
symbols.forEach(symbol => {
let parent = symbol.extends && byName.get(symbol.extends);
symbols.forEach((symbol) => {
const parent = symbol.extends && byName.get(symbol.extends);
if (parent) {
parent.extendedBy = parent.extendedBy ||  [];
parent.extendedBy.push(symbol.name);
}
if (symbol.implements) {
symbol.implements.forEach(intfName => {
let intf = byName.get(intfName);
symbol.implements.forEach((intfName) => {
const intf = byName.get(intfName);
if (intf) {
intf.implementedBy = intf.implementedBy ||  [];
intf.implementedBy.push(symbol.name);
Expand All @@ -223,14 +222,14 @@ function process(versionInfoFile, unpackedTestresourcesRoot, targetFile, targetF
function createOverallIndex() {
let version = "0.0.0";

var p = readJSONFile(versionInfoFile)
.then(versionInfo => {
const p = readJSONFile(versionInfoFile)
.then((versionInfo) => {
version = versionInfo.version;
return Promise.all(
versionInfo.libraries.map(
lib => createSymbolSummaryForLib(lib.name).catch(err => {
(lib) => createSymbolSummaryForLib(lib.name).catch((err) => {
// ignore 'file not found' errors as some libs don't have an api.json (themes, server libs)
if (err.code === 'ENOENT') {
if (err.code === "ENOENT") {
return [];
}
throw err;
Expand All @@ -240,12 +239,12 @@ function process(versionInfoFile, unpackedTestresourcesRoot, targetFile, targetF
})
.then(deepMerge)
.then(expandHierarchyInfo)
.then(symbols => {
let result = {
.then((symbols) => {
const result = {
"$schema-ref": "http://schemas.sap.com/sapui5/designtime/api.json/1.0",
version: version,
library: "*",
symbols: symbols
"version": version,
"library": "*",
"symbols": symbols
};
return writeJSON(targetFile, result);
})
Expand All @@ -255,16 +254,15 @@ function process(versionInfoFile, unpackedTestresourcesRoot, targetFile, targetF
writeJSON(targetFileExperimental, oListCollection.experimental),
writeJSON(targetFileSince, oListCollection.since)
]))
.catch(err => {
console.error("**** failed to create API index for libraries:", err)
.catch((err) => {
console.error("**** failed to create API index for libraries:", err);
throw err;
});

return p;
}

return createOverallIndex();

}

module.exports = process;
6 changes: 3 additions & 3 deletions lib/processors/jsdoc/dummy-child.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
console.log('child executing');
console.log("child executing");
setTimeout(function() {
console.log("child done");
//process.exit(0);
},20000);
// process.exit(0);
}, 20000);
Loading

0 comments on commit 2489edd

Please sign in to comment.