-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored list.listProjects() to listTemplates()
- Loading branch information
Johannes Kissel
committed
Aug 27, 2014
1 parent
5f0846c
commit bdb67f6
Showing
19 changed files
with
95 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,38 @@ | ||
'use strict'; | ||
|
||
var fs = require('fs'), | ||
glob = require('glob'), | ||
_ = require('underscore'), | ||
text = require('./util/text'), | ||
templ = require('./template'); | ||
|
||
/** | ||
* Looks at the given folder and returns all valid project templates. | ||
* The following are valid templates: | ||
* | ||
* | ||
* folder/projects/myProject | ||
* |s | ||
* -- config.yml | ||
* | ||
* | ||
* folder/projects/java/myProject | ||
* | | ||
* -- config.yml | ||
* | ||
* | ||
* @param folder (string) an absolute or relative file path to a folder containing project templates | ||
* @returns [string] a list of template names | ||
*/ | ||
function listProjects(folder) { | ||
var results = []; | ||
|
||
var projectFolders = glob.sync('/projects/*', { root: folder }); | ||
|
||
_.forEach(projectFolders, function(folder) { | ||
var languageName = text.getMostNestedFolder(folder); | ||
if (templ.isValidProjectTemplate(folder)) { | ||
var desc = templ.readDescription(folder); | ||
results.push(languageName + ': ' + desc); | ||
} else { | ||
var templates = glob.sync('/*', {root: folder }); | ||
|
||
_.forEach(templates, function(template) { | ||
var templateName = text.getMostNestedFolder(template); | ||
if (templ.isValidProjectTemplate(template)) { | ||
var templateId = languageName + '/' + templateName, | ||
desc = templ.readDescription(template); | ||
results.push(templateId + ': ' + desc); | ||
} | ||
}); | ||
function listTemplates(folder) { | ||
var files = fs.readdirSync(folder), | ||
results = []; | ||
|
||
files.forEach(function (file) { | ||
var path = folder + '/' + file; | ||
|
||
if (templ.isValidProjectTemplate(path)) { | ||
results.push(file + ': ' + templ.readDescription(path)); | ||
} | ||
}); | ||
|
||
return results; | ||
} | ||
|
||
exports.listProjects = listProjects; | ||
exports.listTemplates = listTemplates; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
var sut = require('../../lib/list'), | ||
exampleFolder = process.cwd() + '/spec/testdata'; | ||
expect = require('chai').expect; | ||
|
||
describe('listProjects', function() { | ||
describe('when given a folder without any templates', function() { | ||
it('should return an empty list', function() { | ||
sut.listProjects('/tmp').should.be.empty; | ||
describe('listTemplates', function() { | ||
describe('when no folder given', function() { | ||
it('should throw', function() { | ||
expect(function() { sut.listTemplates(process.cwd() + '/no-folder'); }).to.throw(Error); | ||
}); | ||
}); | ||
|
||
describe('when given a folder with valid templates', function() { | ||
it('should return a list of the names of the project templates', function() { | ||
var result = sut.listProjects(exampleFolder); | ||
result.length.should.equal(2); | ||
result[0].should.equal('python/fabric: Create a Fabric project.'); | ||
result[1].should.equal('sample_project: Create a sample project.'); | ||
var result = sut.listTemplates(process.cwd() + '/spec/testdata/'); | ||
expect(result.length).to.equal(3); | ||
expect(result.indexOf('python-fabric: Create a Fabric project.')).to.not.equal(-1); | ||
}); | ||
}); | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,38 @@ | ||
var sut = require('../../lib/template'), | ||
exampleFolder = process.cwd() + '/spec/testdata/'; | ||
|
||
describe('isValidProjectTemplate', function() { | ||
describe('when given a valid project folder', function() { | ||
it('should return true', function() { | ||
sut.isValidProjectTemplate(exampleFolder + '/projects/python/fabric').should.be.true; | ||
}); | ||
}); | ||
|
||
describe('when given an invalid project folder', function() { | ||
it('should return false for container folders', function() { | ||
sut.isValidProjectTemplate(exampleFolder + '/projects/python').should.be.false; | ||
}); | ||
|
||
it('should return false for invalid folders', function() { | ||
sut.isValidProjectTemplate(exampleFolder + '/projects/invalid').should.be.false; | ||
sut.isValidProjectTemplate(exampleFolder + '/projects').should.be.false; | ||
}); | ||
}); | ||
}); | ||
// describe('isValidProjectTemplate', function() { | ||
// describe('when given a valid project folder', function() { | ||
// it('should return true', function() { | ||
// sut.isValidProjectTemplate(exampleFolder + '/projects/python/fabric').should.be.true; | ||
// }); | ||
// }); | ||
|
||
describe('readDescription()', function() { | ||
it('should output the description from the config file', function() { | ||
sut.readDescription(exampleFolder + '/projects/python/fabric').should.equal('Create a Fabric project.'); | ||
}); | ||
}); | ||
// describe('when given an invalid project folder', function() { | ||
// it('should return false for container folders', function() { | ||
// sut.isValidProjectTemplate(exampleFolder + '/projects/python').should.be.false; | ||
// }); | ||
|
||
describe('readConfigFile()', function() { | ||
it('should read the config file and return the content as an object', function() { | ||
var config = sut.readConfigFile(exampleFolder + '/projects/python/fabric'); | ||
config.should.be.ok; | ||
config.description.should.equal('Create a Fabric project.'); | ||
config.partials[0].should.equal('general/readme'); | ||
config.partials[1].should.equal('python/config'); | ||
config.defaults.name.should.equal('test-project'); | ||
}); | ||
}); | ||
// it('should return false for invalid folders', function() { | ||
// sut.isValidProjectTemplate(exampleFolder + '/projects/invalid').should.be.false; | ||
// sut.isValidProjectTemplate(exampleFolder + '/projects').should.be.false; | ||
// }); | ||
// }); | ||
// }); | ||
|
||
// describe('readDescription()', function() { | ||
// it('should output the description from the config file', function() { | ||
// sut.readDescription(exampleFolder + '/projects/python/fabric').should.equal('Create a Fabric project.'); | ||
// }); | ||
// }); | ||
|
||
// describe('readConfigFile()', function() { | ||
// it('should read the config file and return the content as an object', function() { | ||
// var config = sut.readConfigFile(exampleFolder + '/projects/python/fabric'); | ||
// config.should.be.ok; | ||
// config.description.should.equal('Create a Fabric project.'); | ||
// config.partials[0].should.equal('general/readme'); | ||
// config.partials[1].should.equal('python/config'); | ||
// config.defaults.name.should.equal('test-project'); | ||
// }); | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
var sut = require('../../../lib/util/text'); | ||
|
||
describe('getMostNestedFolder', function() { | ||
describe('when given a relative path', function() { | ||
it('should simply return the input', function() { | ||
sut.getMostNestedFolder('example').should.equal('example'); | ||
}); | ||
}); | ||
describe('when given an absolute path', function() { | ||
it('should return the last part of the path', function() { | ||
sut.getMostNestedFolder('/etc/init.d/myFolder').should.equal('myFolder'); | ||
}); | ||
it('should work with single folder paths', function() { | ||
sut.getMostNestedFolder('/etc').should.equal('etc'); | ||
}); | ||
it('should return an empty string if the last character is a slash', function() { | ||
sut.getMostNestedFolder('/etc/').should.equal(''); | ||
}); | ||
it('should work with windows style slashes', function() { | ||
sut.getMostNestedFolder('c:\\temp\\myFolder').should.equal('myFolder'); | ||
}); | ||
}); | ||
}) | ||
// describe('getMostNestedFolder', function() { | ||
// describe('when given a relative path', function() { | ||
// it('should simply return the input', function() { | ||
// sut.getMostNestedFolder('example').should.equal('example'); | ||
// }); | ||
// }); | ||
|
||
// describe('when given an absolute path', function() { | ||
// it('should return the last part of the path', function() { | ||
// sut.getMostNestedFolder('/etc/init.d/myFolder').should.equal('myFolder'); | ||
// }); | ||
|
||
// it('should work with single folder paths', function() { | ||
// sut.getMostNestedFolder('/etc').should.equal('etc'); | ||
// }); | ||
|
||
// it('should return an empty string if the last character is a slash', function() { | ||
// sut.getMostNestedFolder('/etc/').should.equal(''); | ||
// }); | ||
|
||
// it('should work with windows style slashes', function() { | ||
// sut.getMostNestedFolder('c:\\temp\\myFolder').should.equal('myFolder'); | ||
// }); | ||
// }); | ||
// }) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
description: Create a sample project. | ||
|
||
variables: | ||
- name |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.