Skip to content

Commit 17a31ef

Browse files
committed
chore(gen): revert modular project structure
Reverted until more fleshed out. Revert "feat(gen): generate a more modular project stucture" This reverts commit 84d2e4e. Conflicts: view/index.js
1 parent c5625ef commit 17a31ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+129
-146
lines changed

app/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ var Generator = module.exports = function Generator(args, options) {
6161
coffee: this.options.coffee,
6262
travis: true,
6363
'skip-install': this.options['skip-install']
64-
}
64+
}
6565
}
6666
});
6767

@@ -162,7 +162,7 @@ Generator.prototype.bootstrapFiles = function bootstrapFiles() {
162162
});
163163
};
164164

165-
Generator.prototype.bootstrapJs = function bootstrapJs() {
165+
Generator.prototype.bootstrapJS = function bootstrapJS() {
166166
if (!this.bootstrap) {
167167
return; // Skip if disabled.
168168
}

constant/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
var path = require('path');
33
var util = require('util');
44
var ScriptBase = require('../script-base.js');
5+
var angularUtils = require('../util.js');
56

67

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

1516
Generator.prototype.createServiceFiles = function createServiceFiles() {
16-
this.appTemplate('service/constant');
17-
this.testTemplate('spec/service');
17+
this.appTemplate('service/constant', 'scripts/services/' + this.name);
18+
this.testTemplate('spec/service', 'services/' + this.name);
19+
this.addScriptToIndex('services/' + this.name);
1820
};

controller/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function Generator() {
1919
util.inherits(Generator, ScriptBase);
2020

2121
Generator.prototype.createControllerFiles = function createControllerFiles() {
22-
this.appTemplate('controller');
23-
this.testTemplate('spec/controller');
22+
this.appTemplate('controller', 'scripts/controllers/' + this.name);
23+
this.testTemplate('spec/controller', 'controllers/' + this.name);
24+
this.addScriptToIndex('controllers/' + this.name);
2425
};

decorator/index.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Generator.prototype.askForOverwrite = function askForOverwrite() {
1414
var cb = this.async();
1515

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

2929
cb();
3030
}.bind(this));
31-
} else {
31+
}
32+
else{
3233
cb();
34+
return;
3335
}
3436
};
3537

@@ -40,18 +42,19 @@ Generator.prototype.askForNewName = function askForNewName() {
4042
cb();
4143
return;
4244
}
45+
else {
46+
var prompts = [];
47+
prompts.push({
48+
name: 'decoratorName',
49+
message: 'Alternative name for the decorator'
50+
});
4351

44-
var prompts = [];
45-
prompts.push({
46-
name: 'decoratorName',
47-
message: 'Alternative name for the decorator'
48-
});
49-
50-
this.prompt(prompts, function (props) {
51-
this.fileName = props.decoratorName;
52+
this.prompt(prompts, function (props) {
53+
this.fileName = props.decoratorName;
5254

53-
cb();
54-
}.bind(this));
55+
cb();
56+
}.bind(this));
57+
}
5558
};
5659

5760
Generator.prototype.createDecoratorFiles = function createDecoratorFiles() {
@@ -60,5 +63,5 @@ Generator.prototype.createDecoratorFiles = function createDecoratorFiles() {
6063
};
6164

6265
function buildRelativePath(fileName){
63-
return 'decorators/' + fileName + 'Decorator';
66+
return 'decorators/' + fileName + "Decorator";
6467
}

directive/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ function Generator() {
1414
util.inherits(Generator, ScriptBase);
1515

1616
Generator.prototype.createDirectiveFiles = function createDirectiveFiles() {
17-
this.appTemplate('directive');
18-
this.testTemplate('spec/directive');
17+
this.appTemplate('directive', 'scripts/directives/' + this.name);
18+
this.testTemplate('spec/directive', 'directives/' + this.name);
19+
this.addScriptToIndex('directives/' + this.name);
1920
};

factory/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ function Generator() {
1414
util.inherits(Generator, ScriptBase);
1515

1616
Generator.prototype.createServiceFiles = function createServiceFiles() {
17-
this.appTemplate('service/factory');
18-
this.testTemplate('spec/service');
17+
this.appTemplate('service/factory', 'scripts/services/' + this.name);
18+
this.testTemplate('spec/service', 'services/' + this.name);
19+
this.addScriptToIndex('services/' + this.name);
1920
};

provider/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ function Generator() {
1414
util.inherits(Generator, ScriptBase);
1515

1616
Generator.prototype.createServiceFiles = function createServiceFiles() {
17-
this.appTemplate('service/provider');
18-
this.testTemplate('spec/service');
17+
this.appTemplate('service/provider', 'scripts/services/' + this.name);
18+
this.testTemplate('spec/service', 'services/' + this.name);
19+
this.addScriptToIndex('services/' + this.name);
1920
};

route/index.js

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,27 @@ function Generator() {
1515
util.inherits(Generator, ScriptBase);
1616

1717
Generator.prototype.rewriteAppJs = function () {
18-
var htmlTemplatePath = this.name + '.html',
19-
splicable,
20-
filePath = path.join(this.env.options.appPath, 'scripts/app.');
21-
22-
if (htmlTemplatePath.indexOf('/') === -1) {
23-
htmlTemplatePath = 'views/' + htmlTemplatePath;
24-
}
25-
2618
if (this.env.options.coffee) {
27-
splicable = [
28-
'.when \'/' + this.name + '\',',
29-
' templateUrl: \'' + htmlTemplatePath + '\',',
30-
' controller: \'' + this._.classify(this.name) + 'Ctrl\''
31-
];
32-
filePath += 'coffee';
33-
} else {
34-
splicable = [
35-
'.when(\'/' + this.name + '\', {',
36-
' templateUrl: \'' + htmlTemplatePath + '\',',
37-
' controller: \'' + this._.classify(this.name) + 'Ctrl\'',
38-
'})'
39-
];
40-
filePath += 'js';
19+
angularUtils.rewriteFile({
20+
file: path.join(this.env.options.appPath, 'scripts/app.coffee'),
21+
needle: '.otherwise',
22+
splicable: [
23+
'.when \'/' + this.name + '\',',
24+
' templateUrl: \'views/' + this.name + '.html\',',
25+
' controller: \'' + this._.classify(this.name) + 'Ctrl\''
26+
]
27+
});
28+
}
29+
else {
30+
angularUtils.rewriteFile({
31+
file: path.join(this.env.options.appPath, 'scripts/app.js'),
32+
needle: '.otherwise',
33+
splicable: [
34+
'.when(\'/' + this.name + '\', {',
35+
' templateUrl: \'views/' + this.name + '.html\',',
36+
' controller: \'' + this._.classify(this.name) + 'Ctrl\'',
37+
'})'
38+
]
39+
});
4140
}
42-
43-
angularUtils.rewriteFile({
44-
file: filePath,
45-
needle: '.otherwise',
46-
splicable: splicable
47-
});
4841
};

script-base.js

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -60,64 +60,43 @@ function Generator() {
6060
}
6161

6262
this.sourceRoot(path.join(__dirname, sourceRoot));
63-
64-
this.moduleName = this._.camelize(this.appname) + 'App';
65-
66-
this.namespace = [];
67-
if (this.name.indexOf('/') !== -1) {
68-
this.namespace = this.name.split('/');
69-
this.name = this.namespace.pop();
70-
71-
this.moduleName += '.' + this.namespace.join('.'); // add to parent ?
72-
}
73-
7463
}
7564

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

78-
Generator.prototype._dest = function (src) {
79-
if (src.indexOf('spec/') === 0) {
80-
src = src.substr(5);
81-
} else if (src.indexOf('service/') === 0) {
82-
src = src.substr(8);
83-
}
84-
return path.join((this.namespace.join('/') || src), this.name);
85-
};
86-
87-
Generator.prototype.appTemplate = function (src) {
67+
Generator.prototype.appTemplate = function (src, dest) {
8868
yeoman.generators.Base.prototype.template.apply(this, [
8969
src + this.scriptSuffix,
90-
path.join(this.env.options.appPath, this._dest(src)) + this.scriptSuffix
70+
path.join(this.env.options.appPath, dest) + this.scriptSuffix
9171
]);
92-
this.addScriptToIndex(src);
9372
};
9473

95-
Generator.prototype.testTemplate = function (src) {
74+
Generator.prototype.testTemplate = function (src, dest) {
9675
yeoman.generators.Base.prototype.template.apply(this, [
9776
src + this.scriptSuffix,
98-
path.join(this.env.options.testPath, this._dest(src)) + this.scriptSuffix
77+
path.join(this.env.options.testPath, dest) + this.scriptSuffix
9978
]);
10079
};
10180

102-
Generator.prototype.htmlTemplate = function (src) {
81+
Generator.prototype.htmlTemplate = function (src, dest) {
10382
yeoman.generators.Base.prototype.template.apply(this, [
10483
src,
105-
path.join(this.env.options.appPath, this._dest(src))
84+
path.join(this.env.options.appPath, dest)
10685
]);
10786
};
10887

109-
Generator.prototype.addScriptToIndex = function (src) {
88+
Generator.prototype.addScriptToIndex = function (script) {
11089
try {
11190
var appPath = this.env.options.appPath;
11291
var fullPath = path.join(appPath, 'index.html');
11392
angularUtils.rewriteFile({
11493
file: fullPath,
11594
needle: '<!-- endbuild -->',
11695
splicable: [
117-
'<script src="' + this._dest(src) + '.js"></script>'
96+
'<script src="scripts/' + script + '.js"></script>'
11897
]
11998
});
12099
} catch (e) {
121-
console.log('\nUnable to find '.yellow + fullPath + '. Reference to '.yellow + this._dest(src) + '.js ' + 'not added.\n'.yellow);
100+
console.log('\nUnable to find '.yellow + fullPath + '. Reference to '.yellow + script + '.js ' + 'not added.\n'.yellow);
122101
}
123102
};

service/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ function Generator() {
1414
util.inherits(Generator, ScriptBase);
1515

1616
Generator.prototype.createServiceFiles = function createServiceFiles() {
17-
this.appTemplate('service/service');
18-
this.testTemplate('spec/service');
17+
this.appTemplate('service/service', 'scripts/services/' + this.name);
18+
this.testTemplate('spec/service', 'services/' + this.name);
19+
this.addScriptToIndex('services/' + this.name);
1920
};

0 commit comments

Comments
 (0)