punch
Advanced tools
Comparing version 0.0.7-beta to 0.0.8-beta
var fs = require("fs"); | ||
var util = require("util"); | ||
var child_process = require('child_process'); | ||
var _ = require("underscore"); | ||
@@ -275,13 +276,11 @@ | ||
var output_path = config.output_path; | ||
var source_directory_path = source_file.split("/"); | ||
source_directory_path[0] = config.output_dir; | ||
var destination_path = source_directory_path.join("/"); | ||
// copy to output directory as it is | ||
fs.readFile(source_file, function (err, data) { | ||
var copy_command = "cp " + source_file + " " + destination_path; | ||
// copy the file to destination | ||
child_process.exec(copy_command, function(err, stdout, stderr) { | ||
if (err) throw err; | ||
var source_directory_path = source_file.split("/"); | ||
source_directory_path[0] = output_path; | ||
var output_content_path = source_directory_path.join("/"); | ||
fs.writeFile(output_content_path, data); | ||
}); | ||
@@ -288,0 +287,0 @@ }, |
@@ -5,3 +5,3 @@ { | ||
, "keywords": ["static", "sites", "mustache", "json", "markdown"] | ||
, "version": "0.0.7-beta" | ||
, "version": "0.0.8-beta" | ||
, "homepage": "https://github.com/laktek/punch" | ||
@@ -8,0 +8,0 @@ , "author": "Lakshan Perera <lakshan@web2media.net> (http://laktek.com)" |
var util = require("util"); | ||
var fs = require("fs"); | ||
var child_process = require("child_process"); | ||
var punch = require("../lib/punch.js"); | ||
@@ -194,39 +195,20 @@ | ||
it("throws an exception if source file doesn't exist", function(){ | ||
spyOn(fs, 'readFile').andCallFake(function(path, callback){ | ||
callback("File not found", null); | ||
}); | ||
it("throws an exception if an error occurrs", function(){ | ||
expect(function(){ punch.staticFileHandler("templates/not_exist.html", {"output_path": "public"}) }).toThrow(); | ||
}); | ||
it("copies source file to output path", function(){ | ||
var buf = new Buffer("sample content"); | ||
spyOn(fs, 'readFile').andCallFake(function(path, callback){ | ||
callback(null, buf); | ||
spyOn(child_process, "exec").andCallFake(function(cmd, callback){ | ||
callback("error"); | ||
}); | ||
spyOn(fs, 'writeFile') | ||
punch.staticFileHandler("templates/simple.html", {"output_path": "public"}); | ||
expect(fs.writeFile).toHaveBeenCalled(); | ||
expect(function(){ punch.staticFileHandler("templates/not_exist.html", {"output_dir": "public"}) }).toThrow(); | ||
}); | ||
it("preserves the directory structure", function(){ | ||
var buf = new Buffer("sample content"); | ||
spyOn(fs, 'readFile').andCallFake(function(path, callback){ | ||
callback(null, buf); | ||
it("issues the copy command with correct source and destination", function(){ | ||
spyOn(child_process, "exec").andCallFake(function(cmd, callback){ | ||
callback(); | ||
}); | ||
spyOn(fs, 'writeFile') | ||
punch.staticFileHandler("templates/sub/foo/static.html", {"output_dir": "public"}); | ||
punch.staticFileHandler("templates/foo/bar/simple.html", {"output_path": "public"}); | ||
expect(fs.writeFile.mostRecentCall.args[0]).toEqual("public/foo/bar/simple.html"); | ||
expect(child_process.exec.mostRecentCall.args[0]).toEqual("cp templates/sub/foo/static.html public/sub/foo/static.html"); | ||
}); | ||
@@ -233,0 +215,0 @@ |
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
27
39616
939
2