From 00f539eeb26d2507a5576f0f95a004f04b78464c Mon Sep 17 00:00:00 2001 From: Daijiro Wachi Date: Fri, 8 Apr 2016 10:43:49 +0200 Subject: [PATCH 1/2] npm install --save mkdirp --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 4d1d3fd..ce0ffc5 100644 --- a/package.json +++ b/package.json @@ -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", @@ -33,4 +34,4 @@ "postcss-import": "^7.1.0", "postcss-url": "^4.0.0" } -} \ No newline at end of file +} From 0a7aa7e2a2d835d36fe5f4fdae6c5477c47f8821 Mon Sep 17 00:00:00 2001 From: Daijiro Wachi Date: Fri, 8 Apr 2016 12:00:18 +0200 Subject: [PATCH 2/2] Support mkdirp to create dest path if it doesn't exists --- Makefile | 4 ++++ index.js | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 871ead1..aaa3d55 100644 --- a/Makefile +++ b/Makefile @@ -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 $@ diff --git a/index.js b/index.js index f865c85..597ce7c 100644 --- a/index.js +++ b/index.js @@ -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() {}; @@ -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); + } + }); }