Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/fp 1499 core-styles demo - fix css import paths #39

4 changes: 1 addition & 3 deletions libs/core-styles/src/.postcssrc.base.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
plugins:
postcss-import:
path:
- 'src/lib'
postcss-import: {}

postcss-extend: {}

Expand Down
37 changes: 35 additions & 2 deletions libs/core-styles/src/bin/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ function config(customConfigFiles = [], cssVersion) {
});
const mergedJson = merge(...configObjects);

// Update version property
const updatedJson = updateVersion(mergedJson, cssVersion);
// Update properties
let updatedJson = updateVersion(mergedJson, cssVersion);
updatedJson = resolveImportFromPaths(updatedJson);
const configYaml = yaml.dump(updatedJson);

// Write final config file
Expand All @@ -55,6 +56,38 @@ function updateVersion(config, version) {
return config;
}

/**
* Update the value for the CSS version in given config data
* @param {object} config - The config data in which to update the version
* @return {object} - Updated config
*/
function resolveImportFromPaths(config) {
let paths = config['plugins']['postcss-env-function']['importFrom'];
paths = typeof paths === 'string' ? [paths] : paths;
let newPaths = [];

console.log(`Resolving 'importFrom' paths`);

if (paths) {
paths.forEach((path) => {
let newPath;
try {
newPath = require.resolve(path);
} catch {
newPath = path;
} finally {
newPaths.push(newPath);
}
});
} else {
newPaths = paths;
}

config['plugins']['postcss-env-function']['importFrom'] = newPaths;

return config;
}

/**
* Get JSON from YAML config file
* @param {string} filePath - YAML config file
Expand Down
4 changes: 2 additions & 2 deletions libs/core-styles/src/lib/_tests.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
2. Review `taccsite_cms/static/site_cms/css/build/_test.css` */
/* NOTE: This file is not intended to be imported */

@import url("_tests/postcss-extend.css");
@import url("_tests/postcss-preset-env.css");
@import url("./_tests/postcss-extend.css");
@import url("./_tests/postcss-preset-env.css");