Skip to content

Commit

Permalink
fix: allow processing edx and openedx brand scope
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoa committed Aug 4, 2024
1 parent c019cc9 commit 7c65744
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
15 changes: 13 additions & 2 deletions config/data/paragonUtils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
const path = require('path');
const fs = require('fs');

/**
* Retrieves the name of the brand package from the dependencies in the application.
*
* @param {string} dir - The root path of the application.
* @returns {string | undefined} The name of the brand package, or undefined if not found.
*/
function getBrandPackageName(dir) {
const appDependencies = JSON.parse(fs.readFileSync(path.resolve(dir, 'package.json'), 'utf-8')).dependencies;
return Object.keys(appDependencies).find((key) => key.match(/@(open)?edx\/brand/));
}

/**
* Attempts to extract the Paragon version from the `node_modules` of
* the consuming application.
Expand All @@ -9,7 +20,7 @@ const fs = require('fs');
* @returns {string} Paragon dependency version of the consuming application
*/
function getParagonVersion(dir, { isBrandOverride = false } = {}) {
const npmPackageName = isBrandOverride ? '@openedx/brand' : '@openedx/paragon';
const npmPackageName = isBrandOverride ? getBrandPackageName(dir) : '@openedx/paragon';
const pathToPackageJson = `${dir}/node_modules/${npmPackageName}/package.json`;
if (!fs.existsSync(pathToPackageJson)) {
return undefined;
Expand Down Expand Up @@ -44,7 +55,7 @@ function getParagonVersion(dir, { isBrandOverride = false } = {}) {
* @returns {ParagonThemeCss}
*/
function getParagonThemeCss(dir, { isBrandOverride = false } = {}) {
const npmPackageName = isBrandOverride ? '@openedx/brand' : '@openedx/paragon';
const npmPackageName = isBrandOverride ? getBrandPackageName(dir) : '@openedx/paragon';
const pathToParagonThemeOutput = path.resolve(dir, 'node_modules', npmPackageName, 'dist', 'theme-urls.json');

if (!fs.existsSync(pathToParagonThemeOutput)) {
Expand Down
4 changes: 2 additions & 2 deletions config/webpack.common.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ module.exports = {
/**
* The entry points for the brand theme CSS. Example: ```
* {
* "paragon.theme.core": "/path/to/node_modules/@openedx/brand/dist/core.min.css",
* "paragon.theme.variants.light": "/path/to/node_modules/@openedx/brand/dist/light.min.css"
* "paragon.theme.core": "/path/to/node_modules/@(open)edx/brand/dist/core.min.css",
* "paragon.theme.variants.light": "/path/to/node_modules/@(open)edx/brand/dist/light.min.css"
* }
*/
...getParagonEntryPoints(brandThemeCss),
Expand Down
2 changes: 1 addition & 1 deletion config/webpack.dev.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ module.exports = merge(commonConfig, {
test: /(.scss|.css)$/,
oneOf: [
{
resource: /(@openedx\/paragon|@openedx\/brand)/,
resource: /(@openedx\/paragon|@(open)?edx\/brand)/,
use: [
MiniCssExtractPlugin.loader,
...getStyleUseConfig(),
Expand Down

0 comments on commit 7c65744

Please sign in to comment.