forked from yeoman/generator-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript-base.js
More file actions
106 lines (87 loc) · 3.3 KB
/
Copy pathscript-base.js
File metadata and controls
106 lines (87 loc) · 3.3 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
'use strict';
var util = require('util');
var path = require('path');
var yeoman = require('yeoman-generator');
var angularUtils = require('./util.js');
var AngularAppNamedBase = require('./angular-app-named-base');
var Generator = module.exports = function Generator() {
AngularAppNamedBase.apply(this, arguments);
this.cameledName = this._.camelize(this.name);
this.classedName = this._.classify(this.name);
if (this._.str.include(this.name, '/')) {
//clean the name for all slashes and only take the name to the right of the last slash
var cleanedName = this._.strRightBack(this.name, '/');
this.cameledName = this._.camelize(cleanedName);
//Make the cameledName classified.
this.cameledName = this._.classify(this.cameledName);
this.classedName = angularUtils.replaceSlashesWithDots(this.name);
}
this.env.options.coffee = this.options.coffee;
if (typeof this.env.options.minsafe === 'undefined') {
this.option('minsafe');
this.env.options.minsafe = this.options.minsafe;
}
var sourceRoot = '/templates/javascript';
this.scriptSuffix = '.js';
if (this.env.options.coffee) {
sourceRoot = '/templates/coffeescript';
this.scriptSuffix = '.coffee';
}
if (this.env.options.minsafe) {
sourceRoot += '-min';
}
this.fileNameSuffix = '';
this.sourceRoot(path.join(__dirname, sourceRoot));
};
util.inherits(Generator, AngularAppNamedBase);
Generator.prototype.appTemplate = function (src, dest) {
yeoman.generators.Base.prototype.template.apply(this, [
src + this.scriptSuffix,
path.join(this.appPath, this.scriptsPath, dest + this.fileNameSuffix) + this.scriptSuffix
]);
};
Generator.prototype.testTemplate = function (src, dest) {
yeoman.generators.Base.prototype.template.apply(this, [
src + this.scriptSuffix,
path.join(this.appScriptsTestPath, dest + this.fileNameSuffix) + this.scriptSuffix
]);
};
Generator.prototype.htmlTemplate = function (src, dest) {
yeoman.generators.Base.prototype.template.apply(this, [
src,
path.join(this.appPath, this.viewsPath, dest)
]);
};
Generator.prototype.addScriptToIndex = function (script) {
if (typeof this.env.options.coffee === 'undefined') {
this.option('coffee');
// attempt to detect if user is using CS or not
// if cml arg provided, use that; else look for the existence of cs
if (!this.options.coffee &&
this.expandFiles(path.join(this.appPath, this.scriptsPath, '/**/*.coffee'), {}).length > 0) {
this.options.coffee = true;
}
this.env.options.coffee = this.options.coffee;
}
try {
var fullPath = path.join(this.appPath, 'index.html');
angularUtils.rewriteFile({
file: fullPath,
needle: '<!-- endbuild -->',
splicable: [
//replace backslash with slash...
'<script src="' + this.scriptsPath + '/' + script.replace(/\\/g, '/') + this.scriptSuffix + '"></script>'
]
});
} catch (e) {
console.log('\nUnable to find '.yellow + fullPath + '. Reference to '.yellow + script + '.js ' + 'not added.\n'.yellow);
}
};
Generator.prototype.generateSourceAndTest = function (appTemplate, testTemplate, targetDirectory, skipAdd) {
var dir = path.join(targetDirectory, this.name);
this.appTemplate(appTemplate, dir);
this.testTemplate(testTemplate, dir);
if (!skipAdd) {
this.addScriptToIndex(dir);
}
};