Permalink
Browse files

Throw error instead of overwriting an existing controller or view.

  • Loading branch information...
1 parent 9c960a0 commit 691e0f6600938d094d50043df3d394a1b833e72a @thatismatt committed Jun 7, 2010
Showing with 11 additions and 6 deletions.
  1. +11 −6 lib/josi/tasks/create.js
@@ -82,9 +82,12 @@ var createController = function(appName, controllerName) {
if (!utilities.fileOrDirectoryExists(controllersDir)) {
fs.mkdirSync(controllersDir, 0777);
}
- // todo: don't overwrite controller with the same name
+ var filename = appName + '/controllers/' + controllerName + '.js';
+ if (utilities.fileOrDirectoryExists(filename)) {
+ throw new Error('ERROR: Controller already exists');
+ }
// todo: if appname is '.' create a different index action
- fs.writeFileSync(appName + '/controllers/' + controllerName + '.js',
+ fs.writeFileSync(filename,
[ 'var view = require(\'josi/actionresults\').view;',
'',
'this.index = function() {',
@@ -107,10 +110,12 @@ var createView = function(appName, controllerName, viewName) {
if (!utilities.fileOrDirectoryExists(viewsDir)) {
fs.mkdirSync(viewsDir, 0777);
}
- // todo: don't overwrite view with the same name
- fs.writeFileSync(appName + '/views/' + controllerName + '/' + viewName + '.html',
- [
- '<p>App name: <b><%= name %></b></p>',
+ var filename = appName + '/views/' + controllerName + '/' + viewName + '.html';
+ if (utilities.fileOrDirectoryExists(filename)) {
+ throw new Error('ERROR: View already exists');
+ }
+ fs.writeFileSync(filename,
+ [ '<p>App name: <b><%= name %></b></p>',
'<p><%= description %></p>'
].join('\r\n')
);

0 comments on commit 691e0f6

Please sign in to comment.