Skip to content

Commit

Permalink
chore(gen): revert modular project structure
Browse files Browse the repository at this point in the history
Reverted until more fleshed out.

Revert "feat(gen): generate a more modular project stucture"

This reverts commit 84d2e4e.

Conflicts:
	view/index.js
  • Loading branch information
passy committed Aug 20, 2013
1 parent c5625ef commit 17a31ef
Show file tree
Hide file tree
Showing 63 changed files with 129 additions and 146 deletions.
4 changes: 2 additions & 2 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var Generator = module.exports = function Generator(args, options) {
coffee: this.options.coffee,
travis: true,
'skip-install': this.options['skip-install']
}
}
}
});

Expand Down Expand Up @@ -162,7 +162,7 @@ Generator.prototype.bootstrapFiles = function bootstrapFiles() {
});
};

Generator.prototype.bootstrapJs = function bootstrapJs() {
Generator.prototype.bootstrapJS = function bootstrapJS() {
if (!this.bootstrap) {
return; // Skip if disabled.
}
Expand Down
6 changes: 4 additions & 2 deletions constant/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
var path = require('path');
var util = require('util');
var ScriptBase = require('../script-base.js');
var angularUtils = require('../util.js');


module.exports = Generator;
Expand All @@ -13,6 +14,7 @@ function Generator() {
util.inherits(Generator, ScriptBase);

Generator.prototype.createServiceFiles = function createServiceFiles() {
this.appTemplate('service/constant');
this.testTemplate('spec/service');
this.appTemplate('service/constant', 'scripts/services/' + this.name);
this.testTemplate('spec/service', 'services/' + this.name);
this.addScriptToIndex('services/' + this.name);
};
5 changes: 3 additions & 2 deletions controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function Generator() {
util.inherits(Generator, ScriptBase);

Generator.prototype.createControllerFiles = function createControllerFiles() {
this.appTemplate('controller');
this.testTemplate('spec/controller');
this.appTemplate('controller', 'scripts/controllers/' + this.name);
this.testTemplate('spec/controller', 'controllers/' + this.name);
this.addScriptToIndex('controllers/' + this.name);
};
29 changes: 16 additions & 13 deletions decorator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Generator.prototype.askForOverwrite = function askForOverwrite() {
var cb = this.async();

// TODO: Any yeoman.util function to handle this?
var fileExists = fs.existsSync(this.env.cwd + '/app/scripts/' + buildRelativePath(this.fileName) + '.js');
var fileExists = fs.existsSync(this.env.cwd + '/app/scripts/' + buildRelativePath(this.fileName) + ".js");
if (fileExists) {
var prompts = [{
type: 'confirm',
Expand All @@ -28,8 +28,10 @@ Generator.prototype.askForOverwrite = function askForOverwrite() {

cb();
}.bind(this));
} else {
}
else{
cb();
return;
}
};

Expand All @@ -40,18 +42,19 @@ Generator.prototype.askForNewName = function askForNewName() {
cb();
return;
}
else {
var prompts = [];
prompts.push({
name: 'decoratorName',
message: 'Alternative name for the decorator'
});

var prompts = [];
prompts.push({
name: 'decoratorName',
message: 'Alternative name for the decorator'
});

this.prompt(prompts, function (props) {
this.fileName = props.decoratorName;
this.prompt(prompts, function (props) {
this.fileName = props.decoratorName;

cb();
}.bind(this));
cb();
}.bind(this));
}
};

Generator.prototype.createDecoratorFiles = function createDecoratorFiles() {
Expand All @@ -60,5 +63,5 @@ Generator.prototype.createDecoratorFiles = function createDecoratorFiles() {
};

function buildRelativePath(fileName){
return 'decorators/' + fileName + 'Decorator';
return 'decorators/' + fileName + "Decorator";
}
5 changes: 3 additions & 2 deletions directive/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function Generator() {
util.inherits(Generator, ScriptBase);

Generator.prototype.createDirectiveFiles = function createDirectiveFiles() {
this.appTemplate('directive');
this.testTemplate('spec/directive');
this.appTemplate('directive', 'scripts/directives/' + this.name);
this.testTemplate('spec/directive', 'directives/' + this.name);
this.addScriptToIndex('directives/' + this.name);
};
5 changes: 3 additions & 2 deletions factory/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function Generator() {
util.inherits(Generator, ScriptBase);

Generator.prototype.createServiceFiles = function createServiceFiles() {
this.appTemplate('service/factory');
this.testTemplate('spec/service');
this.appTemplate('service/factory', 'scripts/services/' + this.name);
this.testTemplate('spec/service', 'services/' + this.name);
this.addScriptToIndex('services/' + this.name);
};
5 changes: 3 additions & 2 deletions provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function Generator() {
util.inherits(Generator, ScriptBase);

Generator.prototype.createServiceFiles = function createServiceFiles() {
this.appTemplate('service/provider');
this.testTemplate('spec/service');
this.appTemplate('service/provider', 'scripts/services/' + this.name);
this.testTemplate('spec/service', 'services/' + this.name);
this.addScriptToIndex('services/' + this.name);
};
49 changes: 21 additions & 28 deletions route/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,27 @@ function Generator() {
util.inherits(Generator, ScriptBase);

Generator.prototype.rewriteAppJs = function () {
var htmlTemplatePath = this.name + '.html',
splicable,
filePath = path.join(this.env.options.appPath, 'scripts/app.');

if (htmlTemplatePath.indexOf('/') === -1) {
htmlTemplatePath = 'views/' + htmlTemplatePath;
}

if (this.env.options.coffee) {
splicable = [
'.when \'/' + this.name + '\',',
' templateUrl: \'' + htmlTemplatePath + '\',',
' controller: \'' + this._.classify(this.name) + 'Ctrl\''
];
filePath += 'coffee';
} else {
splicable = [
'.when(\'/' + this.name + '\', {',
' templateUrl: \'' + htmlTemplatePath + '\',',
' controller: \'' + this._.classify(this.name) + 'Ctrl\'',
'})'
];
filePath += 'js';
angularUtils.rewriteFile({
file: path.join(this.env.options.appPath, 'scripts/app.coffee'),
needle: '.otherwise',
splicable: [
'.when \'/' + this.name + '\',',
' templateUrl: \'views/' + this.name + '.html\',',
' controller: \'' + this._.classify(this.name) + 'Ctrl\''
]
});
}
else {
angularUtils.rewriteFile({
file: path.join(this.env.options.appPath, 'scripts/app.js'),
needle: '.otherwise',
splicable: [
'.when(\'/' + this.name + '\', {',
' templateUrl: \'views/' + this.name + '.html\',',
' controller: \'' + this._.classify(this.name) + 'Ctrl\'',
'})'
]
});
}

angularUtils.rewriteFile({
file: filePath,
needle: '.otherwise',
splicable: splicable
});
};
39 changes: 9 additions & 30 deletions script-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,64 +60,43 @@ function Generator() {
}

this.sourceRoot(path.join(__dirname, sourceRoot));

this.moduleName = this._.camelize(this.appname) + 'App';

this.namespace = [];
if (this.name.indexOf('/') !== -1) {
this.namespace = this.name.split('/');
this.name = this.namespace.pop();

this.moduleName += '.' + this.namespace.join('.'); // add to parent ?
}

}

util.inherits(Generator, yeoman.generators.NamedBase);

Generator.prototype._dest = function (src) {
if (src.indexOf('spec/') === 0) {
src = src.substr(5);
} else if (src.indexOf('service/') === 0) {
src = src.substr(8);
}
return path.join((this.namespace.join('/') || src), this.name);
};

Generator.prototype.appTemplate = function (src) {
Generator.prototype.appTemplate = function (src, dest) {
yeoman.generators.Base.prototype.template.apply(this, [
src + this.scriptSuffix,
path.join(this.env.options.appPath, this._dest(src)) + this.scriptSuffix
path.join(this.env.options.appPath, dest) + this.scriptSuffix
]);
this.addScriptToIndex(src);
};

Generator.prototype.testTemplate = function (src) {
Generator.prototype.testTemplate = function (src, dest) {
yeoman.generators.Base.prototype.template.apply(this, [
src + this.scriptSuffix,
path.join(this.env.options.testPath, this._dest(src)) + this.scriptSuffix
path.join(this.env.options.testPath, dest) + this.scriptSuffix
]);
};

Generator.prototype.htmlTemplate = function (src) {
Generator.prototype.htmlTemplate = function (src, dest) {
yeoman.generators.Base.prototype.template.apply(this, [
src,
path.join(this.env.options.appPath, this._dest(src))
path.join(this.env.options.appPath, dest)
]);
};

Generator.prototype.addScriptToIndex = function (src) {
Generator.prototype.addScriptToIndex = function (script) {
try {
var appPath = this.env.options.appPath;
var fullPath = path.join(appPath, 'index.html');
angularUtils.rewriteFile({
file: fullPath,
needle: '<!-- endbuild -->',
splicable: [
'<script src="' + this._dest(src) + '.js"></script>'
'<script src="scripts/' + script + '.js"></script>'
]
});
} catch (e) {
console.log('\nUnable to find '.yellow + fullPath + '. Reference to '.yellow + this._dest(src) + '.js ' + 'not added.\n'.yellow);
console.log('\nUnable to find '.yellow + fullPath + '. Reference to '.yellow + script + '.js ' + 'not added.\n'.yellow);
}
};
5 changes: 3 additions & 2 deletions service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function Generator() {
util.inherits(Generator, ScriptBase);

Generator.prototype.createServiceFiles = function createServiceFiles() {
this.appTemplate('service/service');
this.testTemplate('spec/service');
this.appTemplate('service/service', 'scripts/services/' + this.name);
this.testTemplate('spec/service', 'services/' + this.name);
this.addScriptToIndex('services/' + this.name);
};
2 changes: 1 addition & 1 deletion templates/coffeescript-min/app.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

angular.module('<%= moduleName %>', [])
angular.module('<%= _.camelize(appname) %>App', [])
.config ['$routeProvider', ($routeProvider) ->
$routeProvider
.when '/',
Expand Down
2 changes: 1 addition & 1 deletion templates/coffeescript-min/controller.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

angular.module('<%= moduleName %>')
angular.module('<%= _.camelize(appname) %>App')
.controller '<%= _.classify(name) %>Ctrl', ['$scope', ($scope) ->
$scope.awesomeThings = [
'HTML5 Boilerplate'
Expand Down
4 changes: 2 additions & 2 deletions templates/coffeescript-min/decorator.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

angular.module('<%= moduleName %>').config ['$provide', ($provide) ->
$provide.decorator '<%= _.camelize(name) %>', ($delegate) ->
angular.module("<%= _.camelize(appname) %>App").config ["$provide", ($provide) ->
$provide.decorator "<%= _.camelize(name) %>", ($delegate) ->
# decorate the $delegate
$delegate
]
2 changes: 1 addition & 1 deletion templates/coffeescript-min/directive.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

angular.module('<%= moduleName %>')
angular.module('<%= _.camelize(appname) %>App')
.directive '<%= _.camelize(name) %>', [->
template: '<div></div>'
restrict: 'E'
Expand Down
2 changes: 1 addition & 1 deletion templates/coffeescript-min/filter.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

angular.module('<%= moduleName %>')
angular.module('<%= _.camelize(appname) %>App')
.filter '<%= _.camelize(name) %>', [() ->
(input) ->
'<%= _.camelize(name) %> filter: ' + input
Expand Down
2 changes: 1 addition & 1 deletion templates/coffeescript-min/service/constant.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict'

angular.module('<%= moduleName %>')
angular.module('<%= _.camelize(appname) %>App')
.constant '<%= _.camelize(name) %>', 42
2 changes: 1 addition & 1 deletion templates/coffeescript-min/service/factory.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

angular.module('<%= moduleName %>')
angular.module('<%= _.camelize(appname) %>App')
.factory '<%= _.camelize(name) %>', [() ->
# Service logic
# ...
Expand Down
2 changes: 1 addition & 1 deletion templates/coffeescript-min/service/provider.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

angular.module('<%= moduleName %>')
angular.module('<%= _.camelize(appname) %>App')
.provider '<%= _.camelize(name) %>', [() ->

# Private variables
Expand Down
2 changes: 1 addition & 1 deletion templates/coffeescript-min/service/service.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

angular.module('<%= moduleName %>')
angular.module('<%= _.camelize(appname) %>App')
.service '<%= _.classify(name) %>', () ->
# AngularJS will instantiate a singleton by calling "new" on this function
2 changes: 1 addition & 1 deletion templates/coffeescript-min/service/value.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';

angular.module('<%= moduleName %>')
angular.module('<%= _.camelize(appname) %>App')
.value '<%= _.camelize(name) %>', 42
2 changes: 1 addition & 1 deletion templates/coffeescript-min/spec/controller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe 'Controller: <%= _.classify(name) %>Ctrl', () ->

# load the controller's module
beforeEach module '<%= moduleName %>'
beforeEach module '<%= _.camelize(appname) %>App'

<%= _.classify(name) %>Ctrl = {}
scope = {}
Expand Down
2 changes: 1 addition & 1 deletion templates/coffeescript-min/spec/directive.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe 'Directive: <%= _.camelize(name) %>', () ->

# load the directive's module
beforeEach module '<%= moduleName %>'
beforeEach module '<%= _.camelize(appname) %>App'

scope = {}

Expand Down
2 changes: 1 addition & 1 deletion templates/coffeescript-min/spec/filter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe 'Filter: <%= _.camelize(name) %>', () ->

# load the filter's module
beforeEach module '<%= moduleName %>'
beforeEach module '<%= _.camelize(appname) %>App'

# initialize a new instance of the filter before each test
<%= _.camelize(name) %> = {}
Expand Down
2 changes: 1 addition & 1 deletion templates/coffeescript-min/spec/service.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe 'Service: <%= _.camelize(name) %>', () ->

# load the service's module
beforeEach module '<%= moduleName %>'
beforeEach module '<%= _.camelize(appname) %>App'

# instantiate service
<%= _.camelize(name) %> = {}
Expand Down
2 changes: 1 addition & 1 deletion templates/coffeescript/app.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

angular.module('<%= moduleName %>', [])
angular.module('<%= _.camelize(appname) %>App', [])
.config ($routeProvider) ->
$routeProvider
.when '/',
Expand Down
Loading

0 comments on commit 17a31ef

Please sign in to comment.