Skip to content

Commit

Permalink
Fix ESLint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomByte committed Mar 1, 2019
1 parent f7b68fe commit 399af06
Show file tree
Hide file tree
Showing 8 changed files with 2,051 additions and 1,954 deletions.
106 changes: 53 additions & 53 deletions lib/processors/jsdoc/create-api-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@
"use strict";
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);
console.log("[INFO] target file: " + targetFile);
console.log("[INFO] target file deprecated: " + targetFileDeprecated);
console.log("[INFO] target file experimental: " + targetFileExperimental);
console.log("[INFO] target file since: " + targetFileSince);
console.log("[INFO]");
const log = require("@ui5/logger").getLogger("builder:processors:jsdoc:");

function process(versionInfoFile, unpackedTestresourcesRoot, targetFile, targetFileDeprecated,
targetFileExperimental, targetFileSince) {
log.info("creating API index files");
log.info(" sap-ui-version.json: " + versionInfoFile);
log.info(" unpacked test-resources: " + unpackedTestresourcesRoot);
log.info(" target file: " + targetFile);
log.info(" target file deprecated: " + targetFileDeprecated);
log.info(" target file experimental: " + targetFileExperimental);
log.info(" target file since: " + targetFileSince);
log.info("");

// Deprecated, Experimental and Since collections
let oListCollection = {
const oListCollection = {
deprecated: {
noVersion: {
apis: []
Expand All @@ -40,8 +41,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 +65,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 +84,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 +102,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 +129,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 +160,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 +175,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,32 +188,31 @@ 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 = 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 = intf.implementedBy || [];
intf.implementedBy.push(symbol.name);
}
});
Expand All @@ -223,14 +224,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 +241,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 +256,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) => {
log.error("**** failed to create API index for libraries:", err);
throw err;
});

return p;
}

return createOverallIndex();

}

module.exports = process;
5 changes: 0 additions & 5 deletions lib/processors/jsdoc/dummy-child.js

This file was deleted.

3 changes: 2 additions & 1 deletion lib/processors/jsdoc/jsdocGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ async function buildJsdoc({sourcePath, configPath}) {
* @param {string} parameters.options.projectName Project name
* @param {string} parameters.options.version Project version
* @param {Array} [parameters.options.variants=["apijson"]] JSDoc variants to be built
* @param {boolean} [parameters.options.sdkBuild=true] Whether additional SDK specific api.json resources shall be generated
* @param {boolean} [parameters.options.sdkBuild=true] Whether additional SDK specific
* api.json resources shall be generated
* @returns {Promise<module:@ui5/fs.Resource[]>} Promise resolving with
*/
module.exports = async function({sourcePath, targetPath, tmpPath, options}) {
Expand Down
Loading

0 comments on commit 399af06

Please sign in to comment.