11const path = require ( 'path' ) ;
22const fs = require ( 'fs' ) ;
33
4+ /**
5+ * Retrieves the name of the brand package from the given directory.
6+ *
7+ * @param {string } dir - The directory path containing the package.json file.
8+ * @return {string } The name of the brand package, or an empty string if not found.
9+ */
10+ function getBrandPackageName ( dir ) {
11+ const appDependencies = JSON . parse ( fs . readFileSync ( path . resolve ( dir , 'package.json' ) , 'utf-8' ) ) . dependencies ;
12+ return Object . keys ( appDependencies ) . find ( ( key ) => key . match ( / @ ( o p e n ) ? e d x \/ b r a n d / ) ) || '' ;
13+ }
14+
415/**
516 * Attempts to extract the Paragon version from the `node_modules` of
617 * the consuming application.
@@ -9,7 +20,7 @@ const fs = require('fs');
920 * @returns {string } Paragon dependency version of the consuming application
1021 */
1122function getParagonVersion ( dir , { isBrandOverride = false } = { } ) {
12- const npmPackageName = isBrandOverride ? '@openedx/brand' : '@openedx/paragon' ;
23+ const npmPackageName = isBrandOverride ? getBrandPackageName ( dir ) : '@openedx/paragon' ;
1324 const pathToPackageJson = `${ dir } /node_modules/${ npmPackageName } /package.json` ;
1425 if ( ! fs . existsSync ( pathToPackageJson ) ) {
1526 return undefined ;
@@ -44,7 +55,7 @@ function getParagonVersion(dir, { isBrandOverride = false } = {}) {
4455 * @returns {ParagonThemeCss }
4556 */
4657function getParagonThemeCss ( dir , { isBrandOverride = false } = { } ) {
47- const npmPackageName = isBrandOverride ? '@openedx/brand' : '@openedx/paragon' ;
58+ const npmPackageName = isBrandOverride ? getBrandPackageName ( dir ) : '@openedx/paragon' ;
4859 const pathToParagonThemeOutput = path . resolve ( dir , 'node_modules' , npmPackageName , 'dist' , 'theme-urls.json' ) ;
4960
5061 if ( ! fs . existsSync ( pathToParagonThemeOutput ) ) {
0 commit comments