Permalink
Browse files

Updated repo, added search for themes and improved handling of errors

  • Loading branch information...
1 parent dcf8c7f commit 013bfd376978fe685fb66859bb2c18fcfa6243a6 @cliftonc committed Oct 23, 2011
Showing with 101 additions and 25 deletions.
  1. +9 −1 bin/calipso
  2. +18 −8 lib/cli/Download.js
  3. +6 −2 lib/cli/Modules.js
  4. +2 −2 lib/cli/RepoApi.js
  5. +60 −10 lib/cli/Themes.js
  6. +6 −2 scripts/templates/help.ejs
View
@@ -141,9 +141,17 @@ function isCalipso() {
* Runs by default from path where calipso runs via __dirname.
*/
function runScript(scriptLauncher) {
+
+ if(!nodepath.existsSync(path + '/scripts/'+ scriptLauncher.name)) {
+ scriptLauncher.name = 'help';
+ scriptLauncher.params = [];
+ }
+
var script = require(path + '/scripts/'+ scriptLauncher.name);
logo.print();
- script.execute(scriptLauncher.params,path);
+ script.execute(scriptLauncher.params, path);
+
+
}
/**
View
@@ -17,6 +17,7 @@ var rootpath = process.cwd() + '/',
calipso = require(path.join(rootpath, 'lib/calipso')),
api = require(path.join(rootpath, 'lib/cli/RepoApi')),
moduleCli = require(path.join(rootpath, 'lib/cli/Modules')),
+ themeCli = require(path.join(rootpath, 'lib/cli/Themes')),
exec = require('child_process').exec,
sys = require('sys'),
colors = require('colors'),
@@ -62,7 +63,7 @@ function download(type,fromUrl,toPath,cli,next) {
}
// Otherwise assume repo - append type
- fromUrl = "module/" + fromUrl;
+ fromUrl = type + "/" + fromUrl;
return downloadRepo(type, fromUrl, toPath, cli, localNext);
}
@@ -83,7 +84,7 @@ function downloadRepo(type,fromUrl,toPath,cli,next) {
var repoName = repoName.split('@')[0];
var tmpName = repoName.replace("/","-");
- constructRepoUrl(repoName,version,function(err,url) {
+ constructRepoUrl(repoName, version, function(err,url) {
if(!err && url) {
return downloadGithub(url, toPath, cli, next);
} else {
@@ -284,7 +285,7 @@ function constructRepoUrl(repoName, version, next) {
var name = repoName.split("/")[1];
var version = version || "master";
- repo.get({type:type,name:name,version:version},function(err,r) {
+ repo.get({type:type, name:name, version:version},function(err,r) {
if(err || !r) {
next(err);
} else {
@@ -305,11 +306,20 @@ function constructRepoUrl(repoName, version, next) {
}
} else {
if(r.length === 0) {
- console.log("\r\nNo entries found, searching the repository for something along the same lines ...".white.bold);
- moduleCli.findModule(["",name], true, function(err,data) {
- // Throw a blank error
- next(new Error("Please try again using one of the module names listed above, or perhaps this is the inspiration for you to build one? :)"));
- });
+ if(type === "module") {
+ console.log("\r\nNo entries found, searching the repository for a module along the same lines ...".white.bold);
+ moduleCli.findModule(["",name], true, function(err,data) {
+ // Throw a blank error
+ next(new Error("Please try again using one of the module names listed above, or perhaps this is the inspiration for you to build one? :)"));
+ });
+ } else {
+ console.log("\r\nNo entries found, searching the repository for a theme along the same lines ...".white.bold);
+ themeCli.findTheme(["",name], true, function(err,data) {
+ // Throw a blank error
+ next(new Error("Please try again using one of the theme names listed above, or perhaps this is the inspiration for you to build one? :)"));
+ });
+ }
+
} else {
next(new Error("There was an error locating that module, " + r.length.toString().red.bold + " entries returned".red));
}
View
@@ -79,6 +79,7 @@ function findModule(options, cli, next) {
var repo = new api();
repo.find('module', options, function(err, data) {
+ if(data.length > 0) {
console.log("");
data.forEach(function(module) {
var versionString = "";
@@ -87,14 +88,17 @@ function findModule(options, cli, next) {
});
var description = module.description.replace(searchRegex,search.yellow.bold);
var author = " - [Author] ".cyan + module.author.cyan.bold + "\r\n";
- console.log(module.name.white.bold + "\r\n" + description.white + "\r\n" + author + versionString.cyan);
+ console.log(module.name.white.bold + "\r\n" + description + "\r\n" + author + versionString.cyan);
});
console.log("");
console.log("To install a module, use: ".white + "\r\n");
console.log(" calipso modules download".cyan.bold + " ModuleName".green.bold + " [for latest version]".grey);
console.log(" calipso modules download".cyan.bold + " repo/project@version".green.bold + " [for specific version]".grey);
console.log("");
- next();
+ } else {
+ console.log("No modules found that matched your search.".white + "\r\n");
+ }
+ next();
});
}
View
@@ -41,7 +41,7 @@ Api.prototype.get = function(options, next) {
(options.version ? options.version : "master"));
console.log("");
- console.log("Asking repository for " + options.name.green.bold + "@".white + options.version.green.bold + " ...");
+ console.log("Asking repository for " + options.type.green.bold + "/" + options.name.green.bold + "@".white + options.version.green.bold + " ...");
// Simple get request
get(url, next);
@@ -62,7 +62,7 @@ Api.prototype.find = function(type, options, next) {
var url = this.url + path.join('find', type, searchString);
console.log("");
- console.log("Searching repository for " + searchString.green.bold + " ...");
+ console.log("Searching repository for " + type + " " + searchString.green.bold + " ...");
// Simple get request
get(url, next);
View
@@ -38,17 +38,13 @@ exports.themeRouter = function(path,options,cli,next) {
case 'uninstall':
uninstallTheme(options,cli,next);
break;
+ case 'find':
+ findTheme(options, cli, next);
+ break;
+
+ case 'install': // Default is github
case 'download': // Default is github
- var toPath = calipso.app.path + "/themes/downloaded/";
- var fromUrl = options[1];
- download('theme',fromUrl,toPath,cli,function(err,themeName,path) {
- if(err) {
- next(err);
- } else {
- console.log("Theme ".green + themeName + " was installed successfully.".green);
- next();
- }
- });
+ downloadTheme(options, cli, next);
break;
default:
@@ -57,6 +53,60 @@ exports.themeRouter = function(path,options,cli,next) {
}
+
+/**
+ *Find module
+ */
+
+function findTheme(options, cli, next) {
+
+ var search = options[1]; // Second parameter is our query
+ var searchRegex = new RegExp(search,"ig");
+ search = search.replace(/\*/g,"");
+
+ var repo = new api();
+ repo.find('theme', options, function(err, data) {
+ console.log("");
+ if(data.length > 0) {
+ data.forEach(function(module) {
+ var versionString = "";
+ module.versions.forEach(function(version) {
+ versionString += " - [" + version.version + "] : " + version.url + "\r\n"
+ });
+ var description = module.description.replace(searchRegex,search.yellow.bold);
+ var author = " - [Author] ".cyan + module.author.cyan.bold + "\r\n";
+ console.log(module.name.white.bold + "\r\n" + description + "\r\n" + author + versionString.cyan);
+ });
+ console.log("");
+ console.log("To install a theme, use: ".white + "\r\n");
+ console.log(" calipso themes download".cyan.bold + " ThemeName".green.bold + " [for latest version]".grey);
+ console.log(" calipso themes download".cyan.bold + " repo/project@version".green.bold + " [for specific version]".grey);
+ console.log("");
+ } else {
+ console.log("No modules found that matched your search.".white + "\r\n");
+ }
+ next();
+ });
+
+}
+exports.findTheme = findTheme;
+
+/**
+ * Try to download a module
+ */
+function downloadTheme(options, cli, next) {
+ var toPath = calipso.app.path + "/themes/downloaded/";
+ var fromUrl = options[1];
+ download('theme', fromUrl, toPath, cli, function(err, themeName, path) {
+ if(err) {
+ next(err);
+ } else {
+ console.log("Theme ".green + themeName + " was installed successfully.".green);
+ next();
+ }
+ });
+}
+
/**
* Show the list of currently installed modules - highlight those with issues / updates?
*/
@@ -4,22 +4,26 @@ Command format:
calipso : Show this help file.
calipso site <name> : Create site in folder.
-calipso install : Ensure valid installation.
+calipso install : Ensure valid site installation (via npm).
calipso cluster : Run as cluster.
calipso server : Run as a single server (use -p or --port to change port)
calipso modules list : List installed modules
+calipso modules install *url : Download (url: http://, gh: cliftonc/calipso-elastic, repo: elastic).
+calipso modules find *search : Search the repository.
+calipso modules download *url : Download (url: http://, gh: cliftonc/calipso-elastic, repo: elastic).
calipso modules reinstall *mod : Reinstall module dependencies
calipso modules uninstall *mod : Remove module (delete from disk)
calipso modules check : Check installation of all modules.
calipso modules enable *mod : Enable module.
calipso modules disable *mod : Disable module.
-calipso modules download *url : Download (url: http://, gh: cliftonc/calipso-elastic, repo: elastic).
calipso themes list : List installed themes.
calipso themes uninstall *theme : Remove theme (delete from disk)
+calipso themes install *url : Download (url: http://, gh: cliftonc/calipso-site-theme, repo: calipso-site).
calipso themes download *url : Download (url: http://, gh: cliftonc/calipso-site-theme, repo: calipso-site).
+calipso themes find *search : Search the repository.
calipso test : Run all tests.

0 comments on commit 013bfd3

Please sign in to comment.