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 vendor path to be ignored #312

Open
wants to merge 4 commits into
base: release-v0.13.0
Choose a base branch
from
Open
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
20 changes: 16 additions & 4 deletions bin/harp
Original file line number Diff line number Diff line change
@@ -105,11 +105,12 @@ program
})

program
.command("compile [projectPath] [outputPath]")
.command("compile [projectPath] [vendorPath] [outputPath]")
.option("-o, --output <path>", "Specify the output directory for compiled assets (relative to project path)")
.option("-v, --vendor <path>", "Specify a vendor directory to be ignored (copied without compiling to output folder, relative to project public path)")
.usage("compile your project files to static assets (HTML, JS and CSS). \n Use this command if you want to host your application without using the Harp web server.")
.description("Compile project to static assets (HTML, JS and CSS)")
.action(function(projectPath, outputPath, program){
.action(function(projectPath, vendorPath, outputPath, program){

if(!program){
program = outputPath
@@ -121,7 +122,7 @@ program
/**
* We deal with output path 3 different ways
*
* 1. second argument (relative to directory called in)
* 1. third argument (relative to directory called in)
* 2. `--output` argument (relative to project root)
* 3. implicitly projectPath + "/www"
*
@@ -133,7 +134,18 @@ program
outputPath = nodePath.resolve(projectPath, (program.output || "www"))
}

harp.compile(projectPath, outputPath, function(errors, output){
/**
* We deal with vendor path 3 different ways
*
* 1. second argument (relative to directory called in)
* 2. `--vendor` argument (relative to project root)
* 3. implicitly publicPath + "/vendor"
*
*/

var setup = helpers.setup(projectPath, "production")

harp.compile(projectPath, vendorPath, outputPath, function(errors, output){
if(errors) {
console.log(JSON.stringify(errors, null, 2))
process.exit(1)
21 changes: 15 additions & 6 deletions lib/helpers.js
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@ exports.mimeType = function(source){
*
*/

var walk = function(dir, done) {
var walk = function(dir, options, done) {
var results = []

fs.readdir(dir, function(err, list) {
@@ -80,10 +80,14 @@ var walk = function(dir, done) {
file = path.resolve(dir, file)
fs.stat(file, function(err, stat) {
if (stat && stat.isDirectory()) {
walk(file, function(err, res) {
results = results.concat(res)
if (file !== options.ignore) {
walk(file, options, function(err, res) {
results = results.concat(res)
if (!--pending) done(null, results)
})
} else {
if (!--pending) done(null, results)
})
}
} else {
results.push(file)
if (!--pending) done(null, results)
@@ -102,8 +106,13 @@ var walk = function(dir, done) {
*
*/

exports.ls = function(dir, callback) {
walk(dir, function(err, results){
exports.ls = function(dir, options, callback) {
if(!callback){
callback = options
options = {}
}

walk(dir, options, function(err, results){
var files = []
results.map(function(file){ files.push(path.relative(dir, file)) })
callback(null, files)
26 changes: 18 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -142,7 +142,7 @@ exports.pkg = pkg
*
*/

exports.compile = function(projectPath, outputPath, callback){
exports.compile = function(projectPath, vendorPath, outputPath, callback){

/**
* Both projectPath and outputPath are optional
@@ -157,6 +157,12 @@ exports.compile = function(projectPath, outputPath, callback){
outputPath = "www"
}

if(!vendorPath){
vendorPath = "vendor"
}

vendorDir = vendorPath


/**
* Setup all the paths and collect all the data
@@ -165,7 +171,8 @@ exports.compile = function(projectPath, outputPath, callback){
try{
outputPath = path.resolve(projectPath, outputPath)
var setup = helpers.setup(projectPath, "production")
var terra = terraform.root(setup.publicPath, setup.config.globals)
var terra = terraform.root(setup.publicPath, setup.config.globals)
vendorPath = path.resolve(projectPath, path.join(setup.publicPath, vendorPath))
}catch(err){
return callback(err)
}
@@ -227,21 +234,24 @@ exports.compile = function(projectPath, outputPath, callback){
}

/**
* Scan dir, Compile Less and Jade, Copy the others
* Scan dir, Compile Less and Jade, Copy the others.
* Do not compile vendor folder but copy it directly.
*/

helpers.prime(outputPath, { ignore: projectPath }, function(err){
helpers.prime(outputPath, { ignore: projectPath }, function(err){
if(err) console.log(err)

helpers.ls(setup.publicPath, function(err, results){
helpers.ls(setup.publicPath, { ignore: vendorPath }, function(err, results){
async.eachLimit(results, 72, compileFile, function(err){
if(err){
callback(err)
}else{
async.eachLimit(results, 72, copyFile, function(err){
setup.config['harp_version'] = pkg.version
delete setup.config.globals
callback(null, setup.config)
fs.copy(vendorPath, path.join(outputPath, vendorDir), function(err){
setup.config['harp_version'] = pkg.version
delete setup.config.globals
callback(null, setup.config)
})
})
}
})