This repository was archived by the owner on Mar 26, 2018. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathindex.js
83 lines (71 loc) · 2.2 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'use strict';
var path = require('path');
var chalk = require('chalk');
var util = require('util');
var ScriptBase = require('../script-base.js');
var angularUtils = require('../util.js');
var Generator = module.exports = function Generator() {
ScriptBase.apply(this, arguments);
this.option('uri', {
desc: 'Allow a custom uri for routing',
type: String,
required: false
});
var coffee = this.env.options.coffee;
var typescript = this.env.options.typescript;
var bower = require(path.join(process.cwd(), 'bower.json'));
var match = require('fs').readFileSync(path.join(
this.env.options.appPath,
'scripts/app.' + (coffee ? 'coffee' : typescript ? 'ts': 'js')
), 'utf-8').match(/\.when/);
if (
bower.dependencies['angular-route'] ||
bower.devDependencies['angular-route'] ||
match !== null
) {
this.foundWhenForRoute = true;
}
};
util.inherits(Generator, ScriptBase);
Generator.prototype.rewriteAppJs = function () {
var coffee = this.env.options.coffee;
if (!this.foundWhenForRoute) {
this.on('end', function () {
this.log(chalk.yellow(
'\nangular-route is not installed. Skipping adding the route to ' +
'scripts/app.' + (coffee ? 'coffee' : 'js')
));
});
return;
}
this.uri = this.name;
if (this.options.uri) {
this.uri = this.options.uri;
}
var typescript = this.env.options.typescript;
var config = {
file: path.join(
this.env.options.appPath,
'scripts/app.' + (coffee ? 'coffee' : typescript ? 'ts': 'js')
),
needle: '.otherwise',
splicable: [
" templateUrl: 'views/" + this.name.toLowerCase() + ".html'" + (coffee ? "" : "," ),
" controller: '" + this.classedName + "Ctrl'" + (coffee ? "" : ","),
" controllerAs: '" + this.cameledName + "'"
]
};
if (coffee) {
config.splicable.unshift(".when '/" + this.uri + "',");
}
else {
config.splicable.unshift(".when('/" + this.uri + "', {");
config.splicable.push("})");
}
angularUtils.rewriteFile(config);
};
Generator.prototype.install = function install() {
var args = [this.name];
this.composeWith('angular:controller', {args: args});
this.composeWith('angular:view', {args: args});
};