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 182100f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ frontend-platform:
dist: The sub-directory of the source code where it puts its build artifact. Often "dist".
*/
localModules: [
{ moduleName: '@openedx/brand', dir: '../src/brand-openedx' }, // replace with your brand checkout
{ moduleName: '@edx/brand', dir: '../src/brand-openedx' }, // replace with your brand checkout
{ moduleName: '@openedx/paragon/scss/core', dir: '../src/paragon', dist: 'scss/core' },
{ moduleName: '@openedx/paragon/icons', dir: '../src/paragon', dist: 'icons' },
{ moduleName: '@openedx/paragon', dir: '../src/paragon', dist: 'dist' },
Expand Down
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 given directory.
*
* @param {string} dir - The directory path containing the package.json file.
* @return {string} The name of the brand package, or an empty string 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 182100f

Please sign in to comment.