Skip to content

Commit 5b4af7e

Browse files
victhevenotyuliy
authored and
yuliy
committed
use path options (#144)
* use path options * remove console logs * rename function * feedback * change key searching for
1 parent 005f574 commit 5b4af7e

File tree

5 files changed

+2932
-2904
lines changed

5 files changed

+2932
-2904
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ The `claycli.config.js` file currently supports the following arguments:
668668
* `babelTargets` (_Object_): the value of this property is passed to the [Babel `targets` option](https://babeljs.io/docs/en/babel-preset-env#targets) to describe the environments your compiled scripts support
669669
* `autoprefixerOptions` (_Object_): an Object which is [passed directly to `autoprefixer`](https://www.npmjs.com/package/autoprefixer#options) for style and Kiln plugin compilation
670670
* `customTasks` (_Array_): an Array of Gulp tasks to execute with the `clay compile custom-tasks` command.
671-
671+
* `postcssImportPaths` (_Array_): list of paths in which to look for nested CSS file imports to be used by the `styles` compilation command. If no value is specified in the congif, the CSS compiler will default to `['./styleguides']`.
672672
#### Example
673673

674674
```js

lib/cmd/compile/styles.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ function compile(options = {}) {
116116
}))
117117
.pipe(rename(renameFile))
118118
.pipe(postcss([
119-
cssImport(),
119+
cssImport({
120+
path: helpers.getConfigFileValue('postcssImportPaths') || ['./styleguides']
121+
}),
120122
autoprefixer(helpers.getConfigFileOrBrowsersList('autoprefixerOptions')),
121123
mixins(),
122124
// Simple vars must come before `nested` so that string interpolation of variables occurs before

lib/compilation-helpers.js

+12
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,17 @@ function getConfigFileOrBrowsersList(key) {
170170
return configFileValue ? configFileValue : module.exports.browserslist;
171171
}
172172

173+
/**
174+
* Given an key, grab the value from the config file
175+
*
176+
* @param {String} key
177+
* @returns {Object|String}
178+
*/
179+
function getConfigFileValue(key) {
180+
return configFile.getConfigValue(key);
181+
}
182+
183+
173184
module.exports.time = time;
174185
module.exports.debouncedWatcher = _.debounce(watcher, 200);
175186
module.exports.bucket = bucket;
@@ -180,6 +191,7 @@ module.exports.transformPath = transformPath;
180191
module.exports.browserslist = { browsers: ['> 3%', 'not and_uc > 0'] }; // used by styles, and vueify, and babel/preset-env
181192
module.exports.determinePostCSSPlugins = determinePostCSSPlugins;
182193
module.exports.getConfigFileOrBrowsersList = getConfigFileOrBrowsersList;
194+
module.exports.getConfigFileValue = getConfigFileValue;
183195

184196
// for testing
185197
module.exports.watcher = watcher;

lib/compilation-helpers.test.js

+14
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,18 @@ describe('compilation helpers', () => {
179179
expect(fn('foo')).toEqual(lib.browserslist);
180180
});
181181
});
182+
183+
describe('getConfigFileValue', () => {
184+
const fn = lib.getConfigFileValue;
185+
186+
it('returns a value from the config if one is found', () => {
187+
configFile.getConfigValue.mockReturnValue({});
188+
expect(fn('foo')).toEqual({});
189+
});
190+
191+
it('returns undefined if no value is found in the config file', () => {
192+
configFile.getConfigValue.mockReturnValue(undefined);
193+
expect(fn('foo')).toEqual(undefined);
194+
});
195+
});
182196
});

0 commit comments

Comments
 (0)