Skip to content

Commit

Permalink
feat(index): function support, jsdoc, cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-ciniawsky committed Oct 12, 2016
1 parent 9671219 commit a78c580
Showing 1 changed file with 52 additions and 14 deletions.
66 changes: 52 additions & 14 deletions index.js
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)
})
}

0 comments on commit a78c580

Please sign in to comment.