From 351c74378cc1abafdbdc7ef82a65814e8dd5659c Mon Sep 17 00:00:00 2001 From: Kai Falkowski Date: Tue, 9 May 2017 09:31:11 +0200 Subject: [PATCH 1/3] add condition so an absolute path doesn't get joined with cwd --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 1dbe99c..d88c939 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,7 @@ module.exports = function(input, options, cb) { }, options); // Read input file - var inputFile = fs.readFileSync(path.join(process.cwd(), input)); + var inputFile = path.isAbsolute(input) ? fs.readFileSync(path.join(input)) : fs.readFileSync(path.join(process.cwd(), input)); // The divider for pages is four newlines var pages = inputFile.toString().replace(/(?:\r\n)/mg, "\n").split('\n\n\n\n'); @@ -55,9 +55,9 @@ module.exports = function(input, options, cb) { }); // Write file to disk - var templateFile = fs.readFileSync(path.join(process.cwd(), options.template)); + var templateFile = path.isAbsolute(options.template) ? fs.readFileSync(path.join(options.template)) : fs.readFileSync(path.join(process.cwd(), options.template)); var template = handlebars.compile(templateFile.toString(), { noEscape: true }); - var outputPath = path.join(process.cwd(), options.output); + var outputPath = path.isAbsolute(options.template) ? path.join(options.output) : path.join(process.cwd(), options.output); fs.writeFile(outputPath, template({ pages: pages }), cb); } From 6d3123bba45eae5abc400827cdeaa8da8ec8a4bb Mon Sep 17 00:00:00 2001 From: Kai Falkowski Date: Tue, 9 May 2017 09:40:54 +0200 Subject: [PATCH 2/3] create output directory if not present --- index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.js b/index.js index d88c939..86ea091 100644 --- a/index.js +++ b/index.js @@ -58,6 +58,11 @@ module.exports = function(input, options, cb) { var templateFile = path.isAbsolute(options.template) ? fs.readFileSync(path.join(options.template)) : fs.readFileSync(path.join(process.cwd(), options.template)); var template = handlebars.compile(templateFile.toString(), { noEscape: true }); var outputPath = path.isAbsolute(options.template) ? path.join(options.output) : path.join(process.cwd(), options.output); + var outputDir = path.dirname(outputPath); + + if(!fs.existsSync(outputDir)) { + fs.mkdirSync(outputDir); + } fs.writeFile(outputPath, template({ pages: pages }), cb); } From 4577fde7b6cf4180a3775325b8d0bf73b661010f Mon Sep 17 00:00:00 2001 From: SassNinja Date: Tue, 9 May 2017 12:42:06 +0200 Subject: [PATCH 3/3] update package version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d405055..c156e94 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "style-sherpa", - "version": "1.0.2", + "version": "1.1.0", "description": "A simple style guide generator.", "main": "index.js", "scripts": {