Skip to content

Commit

Permalink
fix(index): support node v0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-ciniawsky committed Oct 14, 2016
1 parent c440e6b commit e31fab3
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

'use strict'

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

const loadPlugins = require('./lib/plugins')
var loadPlugins = require('./lib/plugins')

/**
* @author Michael Ciniawsky (@michael-ciniawsky) <[email protected]>
Expand All @@ -16,6 +17,7 @@ const loadPlugins = require('./lib/plugins')
* @version 1.0.0
*
* @requires cosmiconfig
* @requires object-assign
* @requires ./lib/plugins.js
*
* @method pluginsrc
Expand All @@ -27,33 +29,41 @@ const loadPlugins = require('./lib/plugins')
* @return {Array} config PostCSS Plugins
*/
module.exports = function pluginsrc (ctx, path, options) {
const defaults = {
cwd: process.cwd(),
env: process.env.NODE_ENV
}
var defaults = { cwd: process.cwd(), env: process.env.NODE_ENV }

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

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

result = result === undefined ? { config: {} } : result
result = result.config

return result
})
.then((plugins) => {
.then(function (plugins) {
if (typeof plugins === 'function') {
plugins = plugins(ctx)
}
if (typeof result === 'object') {
plugins = Object.assign(plugins, ctx)
plugins = assign(plugins, ctx)
}

if (!plugins.plugins) {
plugins.plugins = []
}

return loadPlugins(plugins)
})
.catch((err) => {
.catch(function (err) {
console.log(err)
})
}

0 comments on commit e31fab3

Please sign in to comment.