From ac4b1293061200756f5374616aa7c6a56662b40a Mon Sep 17 00:00:00 2001 From: zeke Date: Fri, 7 Feb 2014 21:00:16 -0800 Subject: [PATCH] use github repos as templates --- bin/harp | 55 ++++++++++++++++----------------- lib/sample/404.jade | 2 -- lib/sample/_layout.jade | 6 ---- lib/sample/index.jade | 2 -- lib/sample/main.less | 19 ------------ package.json | 68 ++++++++++++++++++++++++++++++++--------- 6 files changed, 81 insertions(+), 71 deletions(-) delete mode 100644 lib/sample/404.jade delete mode 100644 lib/sample/_layout.jade delete mode 100644 lib/sample/index.jade delete mode 100644 lib/sample/main.less diff --git a/bin/harp b/bin/harp index 253aeac5..e0354b4a 100755 --- a/bin/harp +++ b/bin/harp @@ -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 @@ -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 ", "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) + } + }) + }) }) }) diff --git a/lib/sample/404.jade b/lib/sample/404.jade deleted file mode 100644 index 137c1676..00000000 --- a/lib/sample/404.jade +++ /dev/null @@ -1,2 +0,0 @@ -h1 404 -h3 Whoops. Looks like what you're looking for can't be found. :( diff --git a/lib/sample/_layout.jade b/lib/sample/_layout.jade deleted file mode 100644 index dd2d77b2..00000000 --- a/lib/sample/_layout.jade +++ /dev/null @@ -1,6 +0,0 @@ -doctype -html - head - link(rel="stylesheet", href="/main.css") - body - != yield diff --git a/lib/sample/index.jade b/lib/sample/index.jade deleted file mode 100644 index 3380ff50..00000000 --- a/lib/sample/index.jade +++ /dev/null @@ -1,2 +0,0 @@ -h1 Welcome to Harp. -h3 This is yours to own. Enjoy. diff --git a/lib/sample/main.less b/lib/sample/main.less deleted file mode 100644 index a0762eca..00000000 --- a/lib/sample/main.less +++ /dev/null @@ -1,19 +0,0 @@ -body{ - font-family: "Helvetica"; - text-align: center; - padding: 50px 20px 0; - background: #f4f4f7; - color: #444; - margin: 0; -} - -h1{ - font-size: 65px; - line-height: 1.2em; - border-bottom: #CCC solid 1px; - padding: 20px 0; -} - -h3{ - font-weight: 300; -} \ No newline at end of file diff --git a/package.json b/package.json index 4c80ff23..19c1f906 100644 --- a/package.json +++ b/package.json @@ -4,19 +4,58 @@ "description": "Static web server with built in preprocessing", "author": "Brock Whitten ", "contributors": [ - { "name": "Brock Whitten", "email": "brock@chloi.io" }, - { "name": "Rob Ellis", "email": "rob@chloi.io" }, - { "name": "Jorge Pedret", "email": "jorge@chloi.io" }, - { "name": "Michael Brooks", "email": "michael@michaelbrooks.ca" }, - { "name": "Tommy-Carlos Williams", "email": "tommy@devgeeks.org" }, - { "name": "Darryl Pogue", "email": "darryl@dpogue.ca" }, - { "name": "Boris Mann", "email": "boris@bmannconsulting.com" }, - { "name": "Kenneth Ormandy", "email": "kenneth@chloi.io" }, - { "name": "Keith Yao", "email": "i@yaofur.com" }, - { "name": "Eric Drechsel", "email": "eric@pdxhub.org" }, - { "name": "Andrew Hobden", "email": "andrew@hoverbear.org" }, - { "name": "Max Melentiev", "email": "printercu@gmail.com" }, - { "name": "Remy Sharp", "email": "remy@remysharp.com" } + { + "name": "Brock Whitten", + "email": "brock@chloi.io" + }, + { + "name": "Rob Ellis", + "email": "rob@chloi.io" + }, + { + "name": "Jorge Pedret", + "email": "jorge@chloi.io" + }, + { + "name": "Michael Brooks", + "email": "michael@michaelbrooks.ca" + }, + { + "name": "Tommy-Carlos Williams", + "email": "tommy@devgeeks.org" + }, + { + "name": "Darryl Pogue", + "email": "darryl@dpogue.ca" + }, + { + "name": "Boris Mann", + "email": "boris@bmannconsulting.com" + }, + { + "name": "Kenneth Ormandy", + "email": "kenneth@chloi.io" + }, + { + "name": "Keith Yao", + "email": "i@yaofur.com" + }, + { + "name": "Eric Drechsel", + "email": "eric@pdxhub.org" + }, + { + "name": "Andrew Hobden", + "email": "andrew@hoverbear.org" + }, + { + "name": "Max Melentiev", + "email": "printercu@gmail.com" + }, + { + "name": "Remy Sharp", + "email": "remy@remysharp.com" + } ], "homepage": "http://harpjs.com", "bugs": "http://github.com/sintaxi/harp/issues", @@ -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",