Skip to content

Commit

Permalink
feat(index): expose config file
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-ciniawsky committed Dec 5, 2016
1 parent 8f7cebe commit c643172
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

'use strict'

var resolve = require('path').resolve

var config = require('cosmiconfig')
var assign = require('object-assign')

Expand All @@ -12,6 +14,7 @@ var loadPlugins = require('./lib/plugins')
/**
* @author Michael Ciniawsky (@michael-ciniawsky) <michael.ciniawsky@gmail.com>
* @description Autoload Plugins for PostCSS
* @license MIT
*
* @module postcss-load-plugins
* @version 1.0.0
Expand All @@ -29,25 +32,27 @@ var loadPlugins = require('./lib/plugins')
* @return {Array} config PostCSS Plugins
*/
module.exports = function pluginsrc (ctx, path, options) {
var defaults = { cwd: process.cwd(), env: process.env.NODE_ENV }
ctx = assign({ cwd: process.cwd(), env: process.env.NODE_ENV }, ctx)

path = path ? resolve(path) : process.cwd()

ctx = assign(defaults, ctx)
path = path || process.cwd()
options = options || {}
options = assign({}, options)

if (ctx.env === undefined) {
process.env.NODE_ENV = 'development'
}

var file

return config('postcss', options)
.load(path)
.then(function (result) {
if (result === undefined) {
console.log(
'PostCSS Plugins could not be loaded. Please check your PostCSS Config.'
)
console.log('PostCSS Plugins could not be loaded.' + path)
}

file = result ? result.filepath : ''

return result ? result.config : {}
})
.then(function (plugins) {
Expand All @@ -62,7 +67,10 @@ module.exports = function pluginsrc (ctx, path, options) {
plugins.plugins = []
}

return loadPlugins(plugins)
return {
plugins: loadPlugins(plugins),
file: file
}
})
.catch(function (err) {
console.log(err)
Expand Down

0 comments on commit c643172

Please sign in to comment.