1
1
const path = require ( 'path' ) ;
2
2
const fs = require ( 'fs' ) ;
3
3
4
+ /**
5
+ * Retrieves the name of the brand package from the dependencies in the application.
6
+ *
7
+ * @param {string } dir - The root path of the application.
8
+ * @returns {string | undefined } The name of the brand package, or undefined 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
+
4
15
/**
5
16
* Attempts to extract the Paragon version from the `node_modules` of
6
17
* the consuming application.
@@ -9,7 +20,7 @@ const fs = require('fs');
9
20
* @returns {string } Paragon dependency version of the consuming application
10
21
*/
11
22
function getParagonVersion ( dir , { isBrandOverride = false } = { } ) {
12
- const npmPackageName = isBrandOverride ? '@openedx/brand' : '@openedx/paragon' ;
23
+ const npmPackageName = isBrandOverride ? getBrandPackageName ( dir ) : '@openedx/paragon' ;
13
24
const pathToPackageJson = `${ dir } /node_modules/${ npmPackageName } /package.json` ;
14
25
if ( ! fs . existsSync ( pathToPackageJson ) ) {
15
26
return undefined ;
@@ -44,7 +55,7 @@ function getParagonVersion(dir, { isBrandOverride = false } = {}) {
44
55
* @returns {ParagonThemeCss }
45
56
*/
46
57
function getParagonThemeCss ( dir , { isBrandOverride = false } = { } ) {
47
- const npmPackageName = isBrandOverride ? '@openedx/brand' : '@openedx/paragon' ;
58
+ const npmPackageName = isBrandOverride ? getBrandPackageName ( dir ) : '@openedx/paragon' ;
48
59
const pathToParagonThemeOutput = path . resolve ( dir , 'node_modules' , npmPackageName , 'dist' , 'theme-urls.json' ) ;
49
60
50
61
if ( ! fs . existsSync ( pathToParagonThemeOutput ) ) {
0 commit comments