Skip to content

Commit

Permalink
Fail nicely when create task called without specifying the name of th…
Browse files Browse the repository at this point in the history
…e app to create.
  • Loading branch information
thatismatt committed Jun 7, 2010
1 parent d11128e commit f4962e3
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/josi/tasks/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ this.task = {
name: 'create',
doc: 'create a new josi app',
execute: function(opts) {
if (!opts.name) {
sys.puts('ERROR: When creating a josi app you must specify its name.');
return;
}
var appName = opts.name;
if (utilities.fileOrDirectoryExists(appName)) {
sys.puts('Can\'t create a new josi app with the name "' + appName + '",' +
Expand All @@ -22,8 +26,7 @@ this.task = {
var createApp = function(appName) {
fs.mkdirSync(appName, 0777);
fs.writeFileSync(appName + '/app.js',
[
'this.init = function() {',
[ 'this.init = function() {',
' this.router.add(',
' // this route matches: /<controller>/<action>/<id>',
' /^\\/(?:(\\w+)\\/?)?(?:(\\w+)\\/?)?(?:([0-9]+)\\/?)?$/,',
Expand All @@ -35,8 +38,7 @@ var createApp = function(appName) {
createController(appName, 'home');
fs.mkdirSync(appName + '/views', 0777);
fs.writeFileSync(appName + '/views/master.html',
[
'<html>',
[ '<html>',
' <head><title><%= title %></title></head>',
' <body>',
' <h1><%= title %></h1>',
Expand All @@ -54,13 +56,13 @@ var createController = function(appName, controllerName) {
fs.mkdirSync(controllersDir, 0777);
}
fs.writeFileSync(appName + '/controllers/' + controllerName + '.js',
[
'var view = require(\'josi/actionresults\').view;',
[ 'var view = require(\'josi/actionresults\').view;',
'',
'this.index = function() {',
' return view({',
' title: \'' + appName + ' - a <a href="http://thatismatt.github.com/josi/">josi</a> app\',',
' name: \'' + appName + '\'',
' title: \'' + appName + ' - a josi app\',',
' name: \'' + appName + '\',',
' description: \'' + appName + ' is a <a href="http://thatismatt.github.com/josi/">josi</a> app\'',
' });',
'};', ''
].join('\r\n')
Expand All @@ -78,7 +80,8 @@ var createView = function(appName, controllerName, viewName) {
}
fs.writeFileSync(appName + '/views/' + controllerName + '/' + viewName + '.html',
[
'<p>App name: <b><%= name %></b></p>', ''
'<p>App name: <b><%= name %></b></p>',
'<p><%= description %></p>'
].join('\r\n')
);
};

0 comments on commit f4962e3

Please sign in to comment.