postcss-cli
Advanced tools
Comparing version 2.3.1 to 2.3.2
2.3.2 / 2015-10-27 | ||
================== | ||
* auto-configure postcss-import support | ||
* add support for watching multiple entry points | ||
2.3.1 / 2015-10-25 | ||
@@ -3,0 +9,0 @@ ================== |
44
index.js
@@ -72,2 +72,14 @@ var globby = require("globby"); | ||
// support for postcss-import | ||
if (argv.use.indexOf("postcss-import") !== -1) { | ||
var importConfig = argv["postcss-import"] || {}; | ||
argv["postcss-import"] = importConfig; | ||
// auto-configure watch update hook | ||
if(!importConfig.onImport) { | ||
importConfig.onImport = function(sources) { | ||
global.watchCSS(sources, this.from); | ||
}; | ||
} | ||
} | ||
var inputFiles = globby.sync(argv._); | ||
@@ -121,6 +133,16 @@ if (!inputFiles.length) { | ||
if (argv.watch) { | ||
var watchedFiles = inputFiles; | ||
global.watchCSS = fsWatcher(inputFiles); | ||
} | ||
async.forEach(inputFiles, compile, onError); | ||
function fsWatcher(entryPoints) { | ||
var watchedFiles = entryPoints; | ||
var index = {}; // source files by entry point | ||
var watcher = require('chokidar').watch(watchedFiles); | ||
watcher.on('change', function() { // TODO: support for "add", "unlink" etc.? | ||
async.forEach(inputFiles, compile, function(err) { | ||
// recompile if any watched file is modified | ||
// TODO: only recompile relevant entry point | ||
watcher.on('change', function() { | ||
async.forEach(entryPoints, compile, function(err) { | ||
return onError.call(this, err, true); | ||
@@ -130,9 +152,17 @@ }); | ||
global.watchCSS = function(files) { | ||
return function updateWatchedFiles(files, entryPoint) { | ||
// update source files for current entry point | ||
entryPoint = entryPoint || null; | ||
index[entryPoint] = files; | ||
// aggregate source files across entry points | ||
var entryPoints = Object.keys(index); | ||
var sources = entryPoints.reduce(function(files, entryPoint) { | ||
return files.concat(index[entryPoint]); | ||
}, []); | ||
// update watch list | ||
watcher.unwatch(watchedFiles); | ||
watcher.add(files); | ||
watchedFiles = files; | ||
watcher.add(sources); | ||
watchedFiles = sources; | ||
}; | ||
} | ||
async.forEach(inputFiles, compile, onError); | ||
@@ -139,0 +169,0 @@ function compile(input, fn) { |
{ | ||
"name": "postcss-cli", | ||
"version": "2.3.1", | ||
"version": "2.3.2", | ||
"description": "CLI for postcss", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -57,5 +57,4 @@ [![Build Status](https://img.shields.io/travis/code42day/postcss-cli.svg)](http://travis-ci.org/code42day/postcss-cli) | ||
When inlining CSS imports (e.g. with [postcss-import]), add an update handler | ||
to your JavaScript configuration file to ensure referenced modules are taken | ||
into account: | ||
When inlining CSS imports, add an update handler to your JavaScript | ||
configuration file to ensure referenced modules are taken into account: | ||
@@ -66,3 +65,3 @@ ```js | ||
onImport: function(sources) { | ||
global.watchCSS(sources); | ||
global.watchCSS(sources, this.from); | ||
} | ||
@@ -73,2 +72,4 @@ } | ||
For [postcss-import], this handler is added automatically. | ||
#### `--config|-c` | ||
@@ -75,0 +76,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14115
209
155