Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support mkdirp to create dest path if it doesn't exists #16

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ test/build/js-config-all.css: test/in.css
./bin/postcss -c test/config-all.js
$(DIFF) $@ $(subst build,ref,$@)

test/build/mkdirp/in.css: test/in.css
./bin/postcss -u postcss-url -o $@ $<
$(DIFF) $@ $(subst build,ref,$@)

test/build:
mkdir -p $@

Expand Down
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,12 @@ if (mapOptions === 'file') {

var async = require('neo-async');
var fs = require('fs');
var path = require('path');
var readFile = require('read-file-stdin');
var path = require('path');
var postcss = require('postcss');
var processor = postcss(plugins);
var mkdirp = require('mkdirp');

// hook for dynamically updating the list of watched files
global.watchCSS = function() {};
Expand Down Expand Up @@ -247,5 +249,12 @@ function writeFile(name, content, fn) {
process.stdout.write(content);
return fn();
}
fs.writeFile(name, content, fn);

mkdirp(path.dirname(name), function (err) {
if (err) {
fn(err);
} else {
fs.writeFile(name, content, fn);
}
});
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"license": "MIT",
"dependencies": {
"globby": "^3.0.1",
"mkdirp": "^0.5.1",
"neo-async": "^1.0.0",
"postcss": "^5.0.0",
"read-file-stdin": "^0.2.0",
Expand All @@ -33,4 +34,4 @@
"postcss-import": "^7.1.0",
"postcss-url": "^4.0.0"
}
}
}