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

Add config option to copy certain files instead of compiling them #442

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var terraform = require('terraform')
var async = require('async')
var connect = require('connect')
var mime = require('mime')
var minimatch = require('minimatch')
var helpers = require('./helpers')
var middleware = require('./middleware')
var pkg = require('../package.json')
Expand Down Expand Up @@ -185,13 +186,29 @@ exports.compile = function(projectPath, outputPath, callback){
})
}

var shouldCopy = function(file) {
var result = false
if(setup.config.copy && setup.config.copy.forEach) {
var patterns = setup.config.copy
patterns.forEach(function (pattern) {
if(minimatch(file, pattern, { matchBase: true })) {
result = true
}
})
}
return result
}

/**
* Compile and save file
*/

var compileFile = function(file, done){
process.nextTick(function () {
if(shouldCopy(file)) {
done()
return
}
terra.render(file, function(error, body){
if(error){
done(error)
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"fs-extra": "0.18.2",
"mime": "1.2.11",
"download-github-repo": "0.1.3",
"envy-json": "0.2.1"
"envy-json": "0.2.1",
"minimatch": "2.0.4"
},
"devDependencies": {
"mocha": "1.8.1",
Expand Down
5 changes: 5 additions & 0 deletions test/apps/bootstrap/harp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"copy": [
"vendor/**"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@import "variables.less";
@import "something.less";
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
color: @brand-info;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@brand-info: #5bc0de;
29 changes: 29 additions & 0 deletions test/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var should = require("should")
var request = require('request')
var path = require("path")
var fs = require("fs")
var exec = require("child_process").exec
var harp = require("../");

describe("bootstrap", function(){

describe("bootstrap in public directory", function(){
var projectPath = path.join(__dirname, "apps/bootstrap")
var outputPath = path.join(__dirname, "out/bootstrap")

it("should compile without errors", function(done){
harp.compile(projectPath, outputPath, function(error){
should.not.exist(error)
done()
})
})

after(function(done){
exec("rm -rf " + outputPath, function() {
done();
})
})

})

})