Skip to content

Commit

Permalink
feat: support spreadsheet importer for version below 0.34.0
Browse files Browse the repository at this point in the history
  • Loading branch information
marianfoo committed Jul 5, 2024
1 parent a4b8033 commit e1223b4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
12 changes: 12 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"printWidth": 120,
"tabWidth": 2,
"useTabs": true,
"semi": true,
"singleQuote": false,
"quoteProps": "as-needed",
"trailingComma": "none",
"bracketSpacing": true,
"arrowParens": "always",
"endOfLine": "lf"
}
38 changes: 32 additions & 6 deletions lib/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
const path = require("path");
const fs = require("fs").promises;

function compareVersions(v1, v2) {
const parts1 = v1.split("_").map(Number);
const parts2 = v2.split("_").map(Number);

for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
const part1 = parts1[i] || 0;
const part2 = parts2[i] || 0;

if (part1 > part2) return 1;
if (part1 < part2) return -1;
}

return 0;
}

/**
* Task to replace strings from files
*
Expand Down Expand Up @@ -49,14 +64,22 @@ module.exports = async function ({ log, workspace, taskUtil, options }) {

// Find the manifest.json for ui5-cc-spreadsheetimporter
const spreadsheetImportermanifestContent = await fs.readFile(nodeModuleSpreadsheetImporterManifestPath, "utf8");
const spreadsheetImporterManifestPath = `/resources/${taskUtil.getProject().getNamespace()}/thirdparty/customcontrol/spreadsheetimporter/v${spreadsheetimporterversion}/manifest.json`;

// if spreadsheetimporterversion less than 0_34_0, then use customControl and spreadsheetImporter
const useCustomControl = compareVersions(spreadsheetimporterversion, "0_34_0") < 0;
const pathSegment = useCustomControl ? "customControl/spreadsheetImporter" : "customControl/spreadsheetimporter";

const spreadsheetImporterManifestPath = `/resources/${taskUtil
.getProject()
.getNamespace()}/thirdparty/${pathSegment}/v${spreadsheetimporterversion}/manifest.json`;
const spreadsheetImporterManifestResource = createResource({
path: spreadsheetImporterManifestPath,
string: spreadsheetImportermanifestContent
});

if (!spreadsheetImportermanifestContent) {
isDebug && log.info("Couldn't find manifest.json for ui5-cc-spreadsheetimporter. It might not be in the build workspace.");
isDebug &&
log.info("Couldn't find manifest.json for ui5-cc-spreadsheetimporter. It might not be in the build workspace.");
return;
}

Expand Down Expand Up @@ -93,18 +116,21 @@ module.exports = async function ({ log, workspace, taskUtil, options }) {
}

spreadsheetImporterManifest["sap.cloud"].service = service || manifestService;
isDebug && log.info("Updated ui5-cc-spreadsheetimporter manifest with service name:", spreadsheetImporterManifest["sap.cloud"].service);
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);
isDebug &&
log.info("Successfully updated ui5-cc-spreadsheetimporter manifest at:", spreadsheetImporterManifestPath);
} catch (error) {
isDebug && log.error(`Error processing manifest.json: ${error.message}`);
return;
}


};

0 comments on commit e1223b4

Please sign in to comment.