Skip to content

Commit

Permalink
revamed the init call
Browse files Browse the repository at this point in the history
  • Loading branch information
sintaxi committed Jul 18, 2013
1 parent 3e96aac commit f43d21f
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions bin/harp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var program = require('commander')
var pkg = require('../package.json')
var harp = require('../')
var fse = require("fs-extra")
var helpers = require("../lib/helpers")

var output = function(msg){
var v = pkg.version
Expand Down Expand Up @@ -45,32 +46,39 @@ program
.command('init [path]')
.description('initialize new harp application in current directory')
.action(function(path, program){
var projectPath = nodePath.resolve(path || process.cwd())
var projectPath = nodePath.resolve(process.cwd(), path)
var boilerplatePath = nodePath.resolve(__dirname, "..", "test", "apps", "basic")

var done = function(err){
console.log('initialized project at', projectPath)
}

if(path){
var src = nodePath.resolve(__dirname, "../test/apps/basic")
var dest = nodePath.join(projectPath)
fse.copy(src, dest, done)
}else{
var src = nodePath.resolve(__dirname, "../test/apps/basic/public")
var dest = nodePath.join(projectPath, "public")

var readmeSrc = nodePath.join(__dirname, "../test/apps/basic/README.md")
var readmeDest = nodePath.join(projectPath, "README.md")

var harpJsonSrc = nodePath.join(__dirname, "../test/apps/basic/harp.json")
var harpJsonDest = nodePath.join(projectPath, "harp.json")
fse.mkdirp(projectPath, function(err){
if(err) return err

fse.readdir(projectPath, function(err, contents){
if(err) return err
if(contents.length == 0){
fse.readdir(boilerplatePath, function(err, contents){
if(err) return err
var total = contents.length
var count = 0
contents.forEach(function(i){
var fromPath = nodePath.resolve(boilerplatePath, i)
var toPath = nodePath.resolve(projectPath, i)
fse.copy(fromPath, toPath, function(err){
count++
if(count == total) done()
})
})
})
}else{
console.log("Sorry,", projectPath, " must be empty.")
}
var count = 0

fse.copy(src, dest, function(err){
fse.copy(readmeSrc, readmeDest, function(err){
fse.copy(harpJsonSrc, harpJsonDest, done)
})
})
}
})

})

Expand All @@ -79,7 +87,7 @@ program
.option('-p, --port <port>', 'specify port to listen on')
.description('start harp server')
.action(function(path, program){
var projectPath = nodePath.resolve(path || process.cwd())
var projectPath = nodePath.resolve(process.cwd(), path)
var port = program.port || 9966
harp.server(projectPath, { port: port }, function(){
output("Your server is listening at http://localhost:" + port + "...")
Expand All @@ -91,7 +99,7 @@ program
.option('-p, --port <port>', 'specify port to listen on')
.description('start harp server to host directory of harp apps')
.action(function(path, program){
var projectPath = nodePath.resolve(path || process.cwd())
var projectPath = nodePath.resolve(process.cwd(), path)
var port = program.port || 9966
harp.multihost(projectPath, { port: port }, function(){
if(port == "80"){
Expand Down

0 comments on commit f43d21f

Please sign in to comment.