Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
2.6.0 / 2016-08-30
==================

* Add log option
* Update postcss-import to v8.1.2 from v7.1.0
* Update globby to v4.1.0 from v3.0.1
* Update postcss-url to v5.1.2 from v4.0.0
* Update jshint to v2.9.2 from v2.6.3
* Update chokidar to v1.5.1 from v1.0.3
* Update yargs to v4.7.1 from v3.32.0
* Support es6 export
* Allow running without plugins
* Add test for --poll
* Add --poll flag

2.5.2 / 2016-04-18
==================

Expand Down
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ all: clean lint test
lint:
./node_modules/.bin/jshint *.js

TESTS = opts source-maps source-maps-file stdout stdin config config-all config-wildcard js-config js-config-all invalid warning
TESTS = opts source-maps source-maps-file stdout stdin config config-all config-wildcard js-config js-config-all invalid warning no-plugin


DIFF = diff -q
Expand Down Expand Up @@ -42,6 +42,17 @@ test-watch: test/import-*.css
kill `cat test/watch.pid` # FIXME: never reached on failure
rm test/watch.pid

test-watch-poll: test/import-*.css
echo '@import "import-foo.css";' > test/import-index.css
./bin/postcss -c test/config-watch.js -w --poll & echo $$! > test/watch.pid
sleep 1
$(DIFF) test/build/watch.css test/ref/watch-1.css
echo '@import "import-bar.css";' >> test/import-index.css
sleep 1
$(DIFF) test/build/watch.css test/ref/watch-2.css
kill `cat test/watch.pid` # FIXME: never reached on failure
rm test/watch.pid

test-local-plugins:
cd test; ../bin/postcss --use a-dummy-plugin --local-plugins -o build/local-plugins in.css

Expand Down Expand Up @@ -72,6 +83,9 @@ test/build/invalid.css: test/in-force-error.css
test/build/warning.css: test/in-warning.css
./bin/postcss --use ./test/dummy-plugin -o $@ $< && echo Warning is OK here....

test/build/no-plugin.css: test/no-plugin.css
./bin/postcss ./test/no-plugin.css -o $@ && echo It works without plugins

test/build/config.css: test/in.css
./bin/postcss -u postcss-url -c test/config.json -o $@ $<
$(DIFF) $@ $(subst build,ref,$@)
Expand Down
34 changes: 27 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ var argv = require("yargs")
.describe('s', 'Alternative input syntax parser')
.alias('p', 'parser')
.describe('p', 'Alternative CSS parser')
.option('poll', {
describe: 'Use polling to monitor for changes.',
default: false,
})
.alias('t', 'stringifier')
.describe('t', 'Alternative output stringifier')
.alias('l', 'log')
.describe('l', 'Log when file is written')
.alias('w', 'watch')
.describe('w', 'auto-recompile when detecting source changes')
.requiresArg(['u', 'c', 'i', 'o', 'd', 's', 'p', 't'])
Expand All @@ -40,14 +46,11 @@ var argv = require("yargs")
'postcss version',
require('./node_modules/postcss/package.json').version
].join(' ');
}, 'v')
})
.alias('v', 'version')
.help('h')
.alias('h', 'help')
.check(function(argv) {
if (!argv.use) {
throw 'Please specify at least one plugin name.';
}
if (argv._.length && argv.input) {
throw 'Both positional arguments and --input option used for `input file`: please only use one of them.';
}
Expand Down Expand Up @@ -100,8 +103,13 @@ var plugins = argv.use.map(function(name) {
if (local) {
var resolved = resolve.sync(name, {basedir: process.cwd()});
plugin = require(resolved);
} else {
} else if (name) {
plugin = require(name);
} else {
return null;
}
if (plugin.default && typeof plugin.default === 'function') {
plugin = plugin.default;
}
if (name in argv) {
plugin = plugin(argv[name]);
Expand Down Expand Up @@ -132,7 +140,7 @@ var path = require('path');
var readFile = require('read-file-stdin');
var path = require('path');
var postcss = require('postcss');
var processor = postcss(plugins);
var processor = plugins[0] ? postcss(plugins) : postcss();
var mkdirp = require('mkdirp');

// hook for dynamically updating the list of watched files
Expand All @@ -146,8 +154,16 @@ async.forEach(inputFiles, compile, onError);
function fsWatcher(entryPoints) {
var watchedFiles = entryPoints;
var index = {}; // source files by entry point
var opts = {};

var watcher = require('chokidar').watch(watchedFiles);
if (argv.poll) {
opts.usePolling = true;
}
if (typeof argv.poll === 'number') {
opts.interval = argv.poll;
}

var watcher = require('chokidar').watch(watchedFiles, opts);
// recompile if any watched file is modified
// TODO: only recompile relevant entry point
watcher.on('change', function() {
Expand Down Expand Up @@ -255,6 +271,10 @@ function writeFile(name, content, fn) {
fn(err);
} else {
fs.writeFile(name, content, fn);

if (argv.log) {
console.log('Generated file: ' + name);
}
}
});
}
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
"author": "Damian Krzeminski <pirxpilot@code42day.com>",
"license": "MIT",
"dependencies": {
"globby": "^3.0.1",
"globby": "^4.1.0",
"mkdirp": "^0.5.1",
"neo-async": "^1.0.0",
"postcss": "^5.0.0",
"read-file-stdin": "^0.2.0",
"resolve": "^1.1.6",
"yargs": "^3.32.0"
"yargs": "^4.7.1"
},
"optionalDependencies": {
"chokidar": "^1.0.3"
"chokidar": "^1.5.1"
},
"devDependencies": {
"jshint": "^2.6.3",
"postcss-import": "^7.1.0",
"postcss-url": "^4.0.0"
"jshint": "^2.9.2",
"postcss-import": "^8.1.2",
"postcss-url": "^5.1.2"
}
}
3 changes: 3 additions & 0 deletions test/no-plugin.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
margin: 0;
}