Skip to content

Commit

Permalink
fix(cf-deploy-config-writer): refactor hasUI5CliV3 to project-access …
Browse files Browse the repository at this point in the history
…for common reuse (#2313)

Co-authored-by: Austin Devine <[email protected]>
  • Loading branch information
longieirl and devinea authored Sep 3, 2024
1 parent 7f9f409 commit d962ce1
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 19 deletions.
6 changes: 6 additions & 0 deletions .changeset/dull-points-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@sap-ux/odata-service-writer': patch
'@sap-ux/project-access': patch
---

Move hasUI5CliV3 to project-access for common re-use
17 changes: 1 addition & 16 deletions packages/odata-service-writer/src/updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { t } from './i18n';
import type { OdataService, CdsAnnotationsInfo, EdmxAnnotationsInfo } from './types';
import semVer from 'semver';
import prettifyXml from 'prettify-xml';
import { getMinimumUI5Version, type Manifest } from '@sap-ux/project-access';
import { getMinimumUI5Version, type Manifest, hasUI5CliV3 } from '@sap-ux/project-access';

/**
* Internal function that updates the manifest.json based on the given service configuration.
Expand Down Expand Up @@ -152,18 +152,3 @@ export function updatePackageJson(path: string, fs: Editor, addMockServer: boole
}
fs.writeJSON(path, packageJson);
}

/**
* Check if dev dependencies contains @ui5/cli version greater than 2.
*
* @param devDependencies dev dependencies from package.json
* @returns boolean
*/
export function hasUI5CliV3(devDependencies: any): boolean {
let isV3 = false;
const ui5CliSemver = semVer.coerce(devDependencies['@ui5/cli']);
if (ui5CliSemver && semVer.gte(ui5CliSemver, '3.0.0')) {
isV3 = true;
}
return isV3;
}
3 changes: 2 additions & 1 deletion packages/project-access/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export {
toReferenceUri,
filterDataSourcesByType,
updatePackageScript,
findCapProjectRoot
findCapProjectRoot,
hasUI5CliV3
} from './project';
export * from './types';
export * from './library';
2 changes: 1 addition & 1 deletion packages/project-access/src/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ export {
export { getWebappPath, readUi5Yaml } from './ui5-config';
export { getMtaPath } from './mta';
export { createApplicationAccess, createProjectAccess } from './access';
export { updatePackageScript } from './script';
export { updatePackageScript, hasUI5CliV3 } from './script';
export { getSpecification, getSpecificationPath, refreshSpecificationDistTags } from './specification';
16 changes: 16 additions & 0 deletions packages/project-access/src/project/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FileName } from '../constants';
import type { Package } from '../types';
import type { Editor } from 'mem-fs-editor';
import { readJSON, updatePackageJSON } from '../file';
import semVer from 'semver';

/**
* Updates the package.json with a new script.
Expand All @@ -26,3 +27,18 @@ export async function updatePackageScript(
packageJson.scripts[scriptName] = script;
await updatePackageJSON(filePath, packageJson, fs);
}

/**
* Check if dev dependencies contains @ui5/cli version greater than 2.
*
* @param devDependencies dev dependencies from package.json
* @returns boolean
*/
export function hasUI5CliV3(devDependencies: any): boolean {
let isV3 = false;
const ui5CliSemver = semVer.coerce(devDependencies['@ui5/cli']);
if (ui5CliSemver && semVer.gte(ui5CliSemver, '3.0.0')) {
isV3 = true;
}
return isV3;
}
8 changes: 7 additions & 1 deletion packages/project-access/test/project/script.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { join } from 'path';
import { create as createStorage } from 'mem-fs';
import { create } from 'mem-fs-editor';
import { FileName, updatePackageScript } from '../../src';
import { FileName, updatePackageScript, hasUI5CliV3 } from '../../src';

describe('Test updatePackageScript()', () => {
const sampleRoot = join(__dirname, '../test-data/json/package');
Expand All @@ -25,4 +25,10 @@ describe('Test updatePackageScript()', () => {
}
`);
});

test('hasUI5CliV3', async () => {
expect(hasUI5CliV3({ '@ui5/cli': '3.0.0' })).toBe(true);
expect(hasUI5CliV3({})).toBe(false);
expect(hasUI5CliV3({ '@ui5/cli': '2.0.0' })).toBe(false);
});
});

0 comments on commit d962ce1

Please sign in to comment.