Skip to content

Commit

Permalink
use github repos as templates
Browse files Browse the repository at this point in the history
  • Loading branch information
zeke committed Feb 8, 2014
1 parent cb21ee0 commit ac4b129
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 71 deletions.
55 changes: 27 additions & 28 deletions bin/harp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env node

var nodePath = require("path")
var program = require("commander")
var fse = require("fs-extra")
var pkg = require("../package.json")
var helpers = require("../lib/helpers")
var harp = require("../")
var nodePath = require("path")
var program = require("commander")
var fse = require("fs-extra")
var downloadRepo = require("download-github-repo")
var pkg = require("../package.json")
var helpers = require("../lib/helpers")
var harp = require("../")

var output = function(msg){
var v = pkg.version
Expand All @@ -23,39 +24,37 @@ program

program
.command("init [path]")
.usage("initializes a new Harp project in the current directory.\n Use the init command if it’s your first time using Harp and you want to create a new project.")
.usage("initializes a new Harp project in the current directory.\n See available templates at https://github.com/harp-templates")
.option("-t, --template <github-username/repo>", "use a github repo as a template", "harp-templates/default")
.description("Initialize a new Harp project in current directory")
.action(function(path, program){
var projectPath = nodePath.resolve(process.cwd(), path || "")
var boilerplatePath = nodePath.resolve(__dirname, "..", "lib", "sample")
var template = program.template

var done = function(err){
console.log("Initialized project at", projectPath)
}
// Assume `harp-templates` github org if template doesn't contain a slash
template.match(/\//) || (template = "harp-templates/"+template)

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.")

if(contents.length !== 0){
console.log("Sorry,", projectPath, "must be empty.")
return
}
var count = 0

console.log("Downloading template: https://github.com/"+template)

downloadRepo(template, projectPath, function(err) {
if(err) {
console.error("Template not found:", "https://github.com/"+template)
} else {
console.log("Initialized project at", projectPath)
}
})

})
})
})
Expand Down
2 changes: 0 additions & 2 deletions lib/sample/404.jade

This file was deleted.

6 changes: 0 additions & 6 deletions lib/sample/_layout.jade

This file was deleted.

2 changes: 0 additions & 2 deletions lib/sample/index.jade

This file was deleted.

19 changes: 0 additions & 19 deletions lib/sample/main.less

This file was deleted.

68 changes: 54 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,58 @@
"description": "Static web server with built in preprocessing",
"author": "Brock Whitten <[email protected]>",
"contributors": [
{ "name": "Brock Whitten", "email": "[email protected]" },
{ "name": "Rob Ellis", "email": "[email protected]" },
{ "name": "Jorge Pedret", "email": "[email protected]" },
{ "name": "Michael Brooks", "email": "[email protected]" },
{ "name": "Tommy-Carlos Williams", "email": "[email protected]" },
{ "name": "Darryl Pogue", "email": "[email protected]" },
{ "name": "Boris Mann", "email": "[email protected]" },
{ "name": "Kenneth Ormandy", "email": "[email protected]" },
{ "name": "Keith Yao", "email": "[email protected]" },
{ "name": "Eric Drechsel", "email": "[email protected]" },
{ "name": "Andrew Hobden", "email": "[email protected]" },
{ "name": "Max Melentiev", "email": "[email protected]" },
{ "name": "Remy Sharp", "email": "[email protected]" }
{
"name": "Brock Whitten",
"email": "[email protected]"
},
{
"name": "Rob Ellis",
"email": "[email protected]"
},
{
"name": "Jorge Pedret",
"email": "[email protected]"
},
{
"name": "Michael Brooks",
"email": "[email protected]"
},
{
"name": "Tommy-Carlos Williams",
"email": "[email protected]"
},
{
"name": "Darryl Pogue",
"email": "[email protected]"
},
{
"name": "Boris Mann",
"email": "[email protected]"
},
{
"name": "Kenneth Ormandy",
"email": "[email protected]"
},
{
"name": "Keith Yao",
"email": "[email protected]"
},
{
"name": "Eric Drechsel",
"email": "[email protected]"
},
{
"name": "Andrew Hobden",
"email": "[email protected]"
},
{
"name": "Max Melentiev",
"email": "[email protected]"
},
{
"name": "Remy Sharp",
"email": "[email protected]"
}
],
"homepage": "http://harpjs.com",
"bugs": "http://github.com/sintaxi/harp/issues",
Expand All @@ -31,7 +70,8 @@
"connect": "2.9.0",
"fs-extra": "0.6.4",
"async": "0.2.9",
"mime": "1.2.11"
"mime": "1.2.11",
"download-github-repo": "0.0.1"
},
"devDependencies": {
"mocha": "1.8.1",
Expand Down

0 comments on commit ac4b129

Please sign in to comment.