forked from yeoman/generator-backbone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript-base.js
59 lines (50 loc) · 1.7 KB
/
script-base.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
'use strict';
var path = require('path');
var util = require('util');
var yeoman = require('yeoman-generator');
var Generator = module.exports = function Generator() {
yeoman.generators.NamedBase.apply(this, arguments);
if (typeof this.env.options.appPath === 'undefined') {
try {
this.env.options.appPath = require(path.join(process.cwd(), 'bower.json')).appPath;
} catch (err) {}
this.env.options.appPath = this.env.options.appPath || 'app';
}
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.env.options.appPath, '/scripts/**/*.coffee'), {}).length > 0) {
this.options.coffee = true;
}
this.env.options.coffee = this.options.coffee;
}
};
util.inherits(Generator, yeoman.generators.NamedBase);
/*
* Check whether the App is a RequireJS app or not
*
* @return boolean
*/
Generator.prototype.isUsingRequireJS = function isUsingRequireJS() {
var ext = this.env.options.coffee ? '.coffee' : '.js';
var filepath = path.join(process.cwd(), 'app/scripts/main' + ext);
try {
return (/require\.config/).test(this.read(filepath));
} catch (e) {
return false;
}
};
Generator.prototype.getTemplateFramework = function getTemplateFramework() {
if (!(require('fs').existsSync(path.join(process.cwd(), 'Gruntfile.js')))) {
return 'lodash';
}
var ftest = (/templateFramework: '([^\']*)'/);
var match = ftest.exec(this.read(path.join(process.cwd(), 'Gruntfile.js')));
if (match) {
return match[1];
} else {
return 'lodash';
}
};