-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(index): function support, jsdoc, cleanups
- Loading branch information
1 parent
9671219
commit a78c580
Showing
1 changed file
with
52 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,66 @@ | ||
// ------------------------------------ | ||
// #POSTCSS - LOAD CONFIG | ||
// #POSTCSS - LOAD CONFIG - INDEX | ||
// ------------------------------------ | ||
|
||
'use strict' | ||
|
||
var config = require('cosmiconfig') | ||
const config = require('cosmiconfig') | ||
|
||
var loadOptions = require('postcss-load-options/lib/loadOptions.js') | ||
var loadPlugins = require('postcss-load-plugins/lib/loadPlugins.js') | ||
const loadOptions = require('postcss-load-options/lib/options.js') | ||
const loadPlugins = require('postcss-load-plugins/lib/plugins.js') | ||
|
||
module.exports = function loadConfig (options) { | ||
return config('postcss') | ||
.catch(function (error) { | ||
console.log(error) | ||
}) | ||
/** | ||
* @author Michael Ciniawsky (@michael-ciniawsky) <michael.ciniawsky@gmail.com> | ||
* @description Autoload Config for PostCSS | ||
* | ||
* @module postcss-load-config | ||
* @version 1.0.0 | ||
* | ||
* @requires comsiconfig | ||
* @requires postcss-load-options | ||
* @requires postcss-load-plugins | ||
* | ||
* @method postcssrc | ||
* | ||
* @param {Object} ctx Context | ||
* @param {String} path Config Directory | ||
* @param {Object} options Config Options | ||
* | ||
* @return {Promise} config PostCSS Plugins, PostCSS Options | ||
*/ | ||
module.exports = function postcssrc (ctx, path, options) { | ||
const defaults = { | ||
cwd: process.cwd(), | ||
env: process.env.NODE_ENV | ||
} | ||
|
||
ctx = Object.assign(defaults, ctx) || defaults | ||
path = path || process.cwd() | ||
options = options || {} | ||
|
||
return config('postcss', options) | ||
.load(path) | ||
.then(function (result) { | ||
return result || {} | ||
result = result.config || {} | ||
return result | ||
}) | ||
.then(function (result) { | ||
var config = result.config || { plugins: [] } | ||
.then(function (config) { | ||
if (typeof config === 'function') { | ||
config = config(ctx) | ||
} else { | ||
config = Object.assign(config, ctx) | ||
} | ||
|
||
if (!config.plugins) { | ||
config.plugins = [] | ||
} | ||
|
||
return { | ||
plugins: loadPlugins(config, options), | ||
options: loadOptions(config, options) | ||
plugins: loadPlugins(config), | ||
options: loadOptions(config) | ||
} | ||
}) | ||
.catch(function (err) { | ||
console.log(err) | ||
}) | ||
} |