From 274e271d3d19760182d085ad45cdab327f80f2ba Mon Sep 17 00:00:00 2001 From: Zongqi Chen Date: Mon, 9 Dec 2024 11:09:41 +0100 Subject: [PATCH] add prettier and recommend it --- .vscode/.settings.json | 9 ++++++++ .vscode/extensions.json | 5 +++++ lib/defaults.js | 2 +- lib/extendOrdWithCustom.js | 2 +- lib/index.js | 6 ++--- lib/plugin.js | 46 +++++++++++++++++++------------------- lib/templates.js | 2 +- 7 files changed, 43 insertions(+), 29 deletions(-) create mode 100644 .vscode/.settings.json create mode 100644 .vscode/extensions.json diff --git a/.vscode/.settings.json b/.vscode/.settings.json new file mode 100644 index 0000000..6c62a95 --- /dev/null +++ b/.vscode/.settings.json @@ -0,0 +1,9 @@ +{ + "editor.defaultFormatter": "rvest.vs-code-prettier-eslint", + "editor.formatOnType": false, + "editor.formatOnPaste": true, + "editor.formatOnSave": true, + "editor.formatOnSaveMode": "file", + "files.autoSave": "onFocusChange", + "vs-code-prettier-eslint.prettierLast": false +} \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..7bb4c6f --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "rvest.vs-code-prettier-eslint" + ] +} \ No newline at end of file diff --git a/lib/defaults.js b/lib/defaults.js index 25cd939..7b585eb 100644 --- a/lib/defaults.js +++ b/lib/defaults.js @@ -1,7 +1,7 @@ const { OPEN_RESOURCE_DISCOVERY_VERSION } = require("./constants"); const regexWithRemoval = (name) => { - return name?.replace(/[^a-zA-Z0-9]/g, ""); + return name?.replace(/[^a-zA-Z0-9]/g, ""); }; const nameWithDot = (name) => { diff --git a/lib/extendOrdWithCustom.js b/lib/extendOrdWithCustom.js index 3d07528..25677f8 100644 --- a/lib/extendOrdWithCustom.js +++ b/lib/extendOrdWithCustom.js @@ -50,7 +50,7 @@ function compareAndHandleCustomORDContentWithExistingContent(ordContent, customO function getCustomORDContent(appConfig) { if (!appConfig.env?.customOrdContentFile) return; const pathToCustomORDContent = path.join(cds.root, appConfig.env?.customOrdContentFile); - if (fs.existsSync(pathToCustomORDContent)) { + if (fs.existsSync(pathToCustomORDContent)) { Logger.error('Custom ORD content file not found at', pathToCustomORDContent); return require(pathToCustomORDContent); } diff --git a/lib/index.js b/lib/index.js index a0b6e5e..9f082de 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,5 +1,5 @@ module.exports = { - ord: require("./ord.js"), - getMetadata: require("./metaData.js"), - defaults: require("./defaults.js"), + ord: require("./ord.js"), + getMetadata: require("./metaData.js"), + defaults: require("./defaults.js"), }; diff --git a/lib/plugin.js b/lib/plugin.js index b2028e4..e279c78 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -4,30 +4,30 @@ const { ord, getMetadata, defaults } = require("./"); cds.on("bootstrap", (app) => { - app.use("/.well-known/open-resource-discovery", async (req, res) => { - if (req.url === "/") { - res.status(200).send(defaults.baseTemplate); - } else { - try { - const { contentType, response } = await getMetadata(req.url); - res.status(200).contentType(contentType).send(response); - } catch (error) { - Logger.error(error, 'Error while generating metadata'); - res.status(500).send(error.message); - } - } - }); + app.use("/.well-known/open-resource-discovery", async (req, res) => { + if (req.url === "/") { + res.status(200).send(defaults.baseTemplate); + } else { + try { + const { contentType, response } = await getMetadata(req.url); + res.status(200).contentType(contentType).send(response); + } catch (error) { + Logger.error(error, 'Error while generating metadata'); + res.status(500).send(error.message); + } + } + }); - app.get("/open-resource-discovery/v1/documents/1", async (req, res) => { - try { - const csn = await cds.load(cds.env.folders.srv); - const data = ord(csn); - return res.status(200).send(data); - } catch (error) { - Logger.error(error, 'Error while creating ORD document'); - return res.status(500).send(error.message); - } - }); + app.get("/open-resource-discovery/v1/documents/1", async (req, res) => { + try { + const csn = await cds.load(cds.env.folders.srv); + const data = ord(csn); + return res.status(200).send(data); + } catch (error) { + Logger.error(error, 'Error while creating ORD document'); + return res.status(500).send(error.message); + } + }); }); module.exports = cds.server; diff --git a/lib/templates.js b/lib/templates.js index 675f39e..da95796 100644 --- a/lib/templates.js +++ b/lib/templates.js @@ -177,7 +177,7 @@ const createAPIResourceTemplate = (serviceName, serviceDefinition, appConfig, pa supported: "no", }, // conditionally setting the entityTypeMappings field based on odmEntities in appConfig - ...(appConfig.odmEntities?.length > 0 && { entityTypeMappings: [{entityTypeTargets: appConfig.odmEntities}] }), + ...(appConfig.odmEntities?.length > 0 && { entityTypeMappings: [{ entityTypeTargets: appConfig.odmEntities }] }), ...ordExtensions, };