Skip to content

Commit

Permalink
feat: expose locally installed paragon theme css as global variable
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstankiewicz committed May 21, 2023
1 parent 0b1e43e commit 0aff13d
Show file tree
Hide file tree
Showing 7 changed files with 990 additions and 14 deletions.
2 changes: 1 addition & 1 deletion config/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = {
},
globals: {
newrelic: false,
PARAGON_VERSION: false,
PARAGON: false,
},
ignorePatterns: [
'module.config.js',
Expand Down
19 changes: 18 additions & 1 deletion config/data/getParagonVersion.js → config/data/paragonUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function getParagonVersion(dir, options = {}) {
const directDependencyVersion = dependencies && dependencies['@edx/paragon']?.version;
const peerDependencyVersion = peerDependencies && peerDependencies['@edx/paragon']?.version;
const resolvedVersion = packagesDependencyVersion || directDependencyVersion || peerDependencyVersion;

if (resolvedVersion) {
return resolvedVersion;
}
Expand All @@ -47,4 +48,20 @@ function getParagonVersion(dir, options = {}) {
return getParagonVersion(parentDir, options);
}

module.exports = getParagonVersion;
function getParagonThemeCssUrls(dir) {
const pathToCoreCss = `${dir}/node_modules/@edx/paragon/dist/core.min.css`;
const pathToThemeVariantLightCss = `${dir}/node_modules/@edx/paragon/dist/light.min.css`;
return {
core: fs.existsSync(pathToCoreCss) ? pathToCoreCss : undefined,
variants: {
light: fs.existsSync(pathToThemeVariantLightCss) ? pathToThemeVariantLightCss : undefined,
},
};
}

console.log(getParagonThemeCssUrls(process.cwd()));

module.exports = {
getParagonVersion,
getParagonThemeCssUrls,
};
4 changes: 1 addition & 3 deletions config/jest/setupTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ const fs = require('fs');
const dotenv = require('dotenv');
require('babel-polyfill');

const getParagonVersion = require('../data/getParagonVersion');

const testEnvFile = path.resolve(process.cwd(), '.env.test');

if (fs.existsSync(testEnvFile)) {
dotenv.config({ path: testEnvFile });
}

global.PARAGON_VERSION = JSON.stringify(getParagonVersion(path.resolve(process.cwd(), 'example')));
global.PARAGON_VERSION = '1.0.0';
17 changes: 15 additions & 2 deletions config/webpack.common.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const path = require('path');
const webpack = require('webpack');

const getParagonVersion = require('./data/getParagonVersion');
const {
getParagonVersion,
getParagonThemeCssUrls,
} = require('./data/paragonUtils');

const paragonThemeUrls = getParagonThemeCssUrls(process.cwd());

module.exports = {
entry: {
Expand All @@ -24,7 +29,15 @@ module.exports = {
},
plugins: [
new webpack.DefinePlugin({
PARAGON_VERSION: JSON.stringify(getParagonVersion(process.cwd())),
PARAGON: JSON.stringify({
VERSION: getParagonVersion(process.cwd()),
THEME_URLS: {
CORE: paragonThemeUrls.core,
VARIANTS: {
LIGHT: paragonThemeUrls.variants.light,
},
},
}),
}),
],
};
Loading

0 comments on commit 0aff13d

Please sign in to comment.