Permalink
Browse files

gettemplate last step

  • Loading branch information...
1 parent 16ed8b7 commit 0fd4512d088b5725c8e43773bf2cec5df0c391fb wouterm committed Feb 26, 2012
Showing with 30 additions and 3 deletions.
  1. +28 −1 lib/wercker.js
  2. +2 −2 wercker
View
@@ -109,7 +109,34 @@ Wercker.prototype.template = function(environment) {
function(config, next){
var client = new Client();
client.getTemplates(config.projectName, process.platform, self.token, next);
- }],
+ },
+ function(result, next){
+ var i, template, targetFullFileName;
+ var gitHookDirectory = path.resolve('./.git/hooks');
+ var projectDirectory = path.resolve('./');
+
+ console.log('');
+
+ for(i = 0; i < result.result.length; i++){
+ template = result.result[i];
+
+ if(template .templateType === 'hook'){
+ targetFullFileName = path.join(gitHookDirectory, template.fileName);
+ }
+ else if(template .templateType === 'project'){
+ targetFullFileName = path.join(projectDirectory, template.fileName);
+ }
+ if(path.existsSync(targetFullFileName)){
+ console.log(util.format('Ignoring %s because file already exists.', template.fileName));
+ }
+ else{
+ fs.writeFileSync(targetFullFileName, template.content);
+ console.log(util.format('%s created.', template.fileName));
+
+ }
+
+ }
+ }],
function(error, result){
if(error){
console.log(error);
View
@@ -17,15 +17,15 @@ program
.command('create [env]')
.description('create a wercker project')
.action(function(env) {
- console.log('Creating Wercker project with ' + env + ' environment');
+ console.log('Creating Wercker project with ' + env + ' environment.');
wercker.create(env);
});
program
.command('template')
.description('installs the template for this project type')
.action(function(env) {
- console.log('Retrieving the template files');
+ console.log('Retrieving the template files.');
wercker.template();
});

0 comments on commit 0fd4512

Please sign in to comment.