Skip to content

Commit

Permalink
fix: improve error handling if service not in manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
marianfoo committed Jul 3, 2024
1 parent 658460f commit 846bcc4
Showing 1 changed file with 35 additions and 19 deletions.
54 changes: 35 additions & 19 deletions lib/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ const fs = require("fs").promises;
* @param {object} parameters Parameters
* @param {module:@ui5/logger/Logger} parameters.log Logger instance
* @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files
* @param {module:@ui5/fs.AbstractReader} parameters.dependencies Reader or Collection to read dependency files
* @param {object} parameters.taskUtil Specification Version dependent interface to a
* [TaskUtil]{@link module:@ui5/builder.tasks.TaskUtil} instance
* @param {object} parameters.options Options
* @param {Array} parameters.options.files all file name patterns where replace should occur
* @param {Array} [parameters.options.strings] Array of objects containing placeholder and replacment text value
* @param {Array} parameters.options.debug Debug flag
* @param {Array} parameters.options.service Service name to be set in the manifest
* @returns {Promise<undefined>} Promise resolving with undefined once data has been written
*/
module.exports = async function ({ log, workspace, taskUtil, options }) {
Expand Down Expand Up @@ -72,23 +73,38 @@ module.exports = async function ({ log, workspace, taskUtil, options }) {
spreadsheetImporterManifest["sap.cloud"] = {};
}
// Read the manifest.json
const { projectNamespace } = options;
const ui5AppmanifestPath = `/resources/${projectNamespace}/manifest.json`;
isDebug && log.info(`Reading manifest from ${ui5AppmanifestPath}`);
const ui5AppManifestResource = await workspace.byPath(ui5AppmanifestPath);
const ui5AppManifestContent = await ui5AppManifestResource.getString();
const ui5AppManifest = JSON.parse(ui5AppManifestContent);
if(service !== ""){
spreadsheetImporterManifest["sap.cloud"].service = service;
} else {
spreadsheetImporterManifest["sap.cloud"].service = ui5AppManifest["sap.cloud"].service; // Or any other value you want to set
}
isDebug && log.info("Updated ui5-cc-spreadsheetimporter manifest with servicename:", spreadsheetImporterManifest["sap.cloud"].service);
try {
const { projectNamespace } = options;
const ui5AppmanifestPath = `/resources/${projectNamespace}/manifest.json`;
isDebug && log.info(`Reading manifest from ${ui5AppmanifestPath}`);

const ui5AppManifestResource = await workspace.byPath(ui5AppmanifestPath);
if (!ui5AppManifestResource) {
throw new Error(`Manifest not found at ${ui5AppmanifestPath}`);
}

const ui5AppManifestContent = await ui5AppManifestResource.getString();
const ui5AppManifest = JSON.parse(ui5AppManifestContent);

const manifestService = ui5AppManifest["sap.cloud"]?.service;
if (!manifestService && !service) {
isDebug && log.info("Service name not found in manifest.json and not provided in options. Skipping task.");
return;
}

// Write the updated manifest back to the workspace
spreadsheetImporterManifestResource.setString(JSON.stringify(spreadsheetImporterManifest, null, 2));
spreadsheetImporterManifest["sap.cloud"].service = service || manifestService;
isDebug && log.info("Updated ui5-cc-spreadsheetimporter manifest with service name:", spreadsheetImporterManifest["sap.cloud"].service);

// Write the updated manifest back to the workspace
const updatedManifestContent = JSON.stringify(spreadsheetImporterManifest, null, 2);
spreadsheetImporterManifestResource.setString(updatedManifestContent);
await workspace.write(spreadsheetImporterManifestResource);

isDebug && log.info("Successfully updated ui5-cc-spreadsheetimporter manifest at:", spreadsheetImporterManifestPath);
} catch (error) {
isDebug && log.error(`Error processing manifest.json: ${error.message}`);
return;
}

await workspace.write(spreadsheetImporterManifestResource);

isDebug && log.info("Successfully updated ui5-cc-spreadsheetimporter manifest to path:", spreadsheetImporterManifestPath);
};

0 comments on commit 846bcc4

Please sign in to comment.