Skip to content

Commit

Permalink
fix: check in devDependencies for component
Browse files Browse the repository at this point in the history
  • Loading branch information
marianfoo committed Jul 9, 2024
1 parent 6cac638 commit 0ba887b
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ 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);
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;
Expand Down Expand Up @@ -53,21 +53,23 @@ module.exports = async function ({ log, workspace, taskUtil, options }) {
// Check if ui5-cc-spreadsheetimporter is present in dependencies
const packageJsonPath = path.join(cwd, "package.json");
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, "utf8"));
const hasSpreadsheetImporter = packageJson.dependencies && packageJson.dependencies["ui5-cc-spreadsheetimporter"];
// replace all "." with "_" from hasSpreadsheetImporter
const spreadsheetimporterversion = hasSpreadsheetImporter.replace(/\./g, "_");

const hasSpreadsheetImporter =
packageJson.dependencies?.["ui5-cc-spreadsheetimporter"] ||
packageJson.devDependencies?.["ui5-cc-spreadsheetimporter"];
if (!hasSpreadsheetImporter) {
isDebug && log.info("ui5-cc-spreadsheetimporter not found in dependencies. Skipping manifest change.");
return;
}
const spreadsheetImporterVersionPoint = hasSpreadsheetImporter;
// replace all "." with "_" from hasSpreadsheetImporter
const spreadsheetimporterversion = spreadsheetImporterVersionPoint.replace(/\./g, "_");

// Find the manifest.json for ui5-cc-spreadsheetimporter
const spreadsheetImportermanifestContent = await fs.readFile(nodeModuleSpreadsheetImporterManifestPath, "utf8");

// 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";
// if spreadsheetImporterVersionPoint less than "0.34.0", then use customControl and spreadsheetImporter
const useCustomControl = compareVersions(spreadsheetImporterVersionPoint, "0.34.0") < 0;
const pathSegment = useCustomControl ? "customControl/spreadsheetImporter" : "customcontrol/spreadsheetimporter";

const spreadsheetImporterManifestPath = `/resources/${taskUtil
.getProject()
Expand Down

0 comments on commit 0ba887b

Please sign in to comment.