Skip to content

Commit

Permalink
add prettier and recommend it
Browse files Browse the repository at this point in the history
  • Loading branch information
zongqichen committed Dec 9, 2024
1 parent a2931c5 commit 274e271
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 29 deletions.
9 changes: 9 additions & 0 deletions .vscode/.settings.json
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"rvest.vs-code-prettier-eslint"
]
}
2 changes: 1 addition & 1 deletion lib/defaults.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/extendOrdWithCustom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -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"),
};
46 changes: 23 additions & 23 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion lib/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down

0 comments on commit 274e271

Please sign in to comment.