Commit 2422248a authored by Fred Chasen's avatar Fred Chasen

Create folders if they don't exist when outputting

parent 29400f2e
......@@ -35,5 +35,6 @@ test/temp
# compiled es5 code
# lib
samples
test/output/*
samples/
!test/samples
test/output
......@@ -81,8 +81,7 @@ if (program.hyphenate) {
hyphenator = new Hyphenator(program.hyphenate);
hyphenator.process(relativePath, tmpPath, hyphenateOptions);
console.log("Hyphenated for",
typeof(program.hyphenate) === "string" ? program.hyphenate : "en-us");
console.log("Hyphenated for", typeof(program.hyphenate) === "string" ? program.hyphenate : "en-us");
if (program.debug && tmpPath) {
console.log("Hyphenated file at:", tmpPath);
......
......@@ -22,6 +22,10 @@ var _debug2 = _interopRequireDefault(_debug);
var _package = require('../package.json');
var _mkdirp = require('mkdirp');
var _mkdirp2 = _interopRequireDefault(_mkdirp);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var log = (0, _debug2.default)(_package.name + ':renderer');
......@@ -192,6 +196,7 @@ Renderer.prototype.convert = function (inputPath, settings) {
};
Renderer.prototype.output = function (stream, outputPath) {
_mkdirp2.default.sync(_path2.default.dirname(outputPath));
stream.pipe(_fs2.default.createWriteStream(outputPath));
};
......
......@@ -3,6 +3,7 @@ import fs from 'fs';
import path from 'path';
import debug from 'debug';
import { name as pkgName } from '../package.json';
import mkdirp from 'mkdirp';
const log = debug(`${pkgName}:renderer`);
......@@ -176,6 +177,7 @@ Renderer.prototype.convert = function(inputPath, settings) {
}
Renderer.prototype.output = function (stream, outputPath) {
mkdirp.sync(path.dirname(outputPath));
stream.pipe(fs.createWriteStream(outputPath));
};
......
......@@ -104,20 +104,19 @@ describe('CLI', function() {
it('should Hyphenate when giving the --hyphenate option', function(done) {
var cli = spawn(path, ["./test/samples/wood/index.html", "--hyphenate"])
var dataStr = "";
cli.stdout.on('data', function(data) {
var dataStr = data.toString();
console.log(dataStr);
assert.equal(dataStr, "Hyphenated for en-us\n");
dataStr += data.toString();
});
cli.on('close', function(code){
assert(dataStr.indexOf("Hyphenated for en-us\n") > -1, "Was Hyphenated");
assert.equal(code, 0);
done();
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment