This repository has been archived by the owner on Sep 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 204
/
requirejs-wrapper-template.js
executable file
·78 lines (67 loc) · 1.84 KB
/
requirejs-wrapper-template.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
/* Setup file run before spec files to setup the context (and RequireJS
* specifically) to execute the spec file.
*
* Defined by caller:
* - Jasmine predefines
* - require (Node require)
* - __dirname, __filename
* - baseUrl (Relative path to the directory containing this file)
* - csPath (Path to require-cs module)
*
* See requirejs-runner source for full invocation details.
*/
var define,
requirejsOrig = require('requirejs'),
ostring = Object.prototype.toString,
path = require('path'),
isArray = function(it){
return ostring.call(it) === '[object Array]';
},
isFunction = function(it){
return ostring.call(it) === '[object Function]';
},
requirejs = function(deps, callback){
var retVal;
if(!isArray(deps) && typeof deps !== 'string'){
if(isArray(callback)){
retVal = requirejsOrig(deps, callback, arguments[2]);
} else {
retVal = requirejsOrig(deps, [], callback);
}
} else {
retVal = requirejsOrig(deps, callback);
}
return retVal;
};
requirejsOrig.config({
baseUrl: baseUrl,
nodeRequire: require,
paths: {
cs: csPath
}
});
for(var key in requirejsOrig) {
requirejs[key] = requirejsOrig[key];
}
requirejs.config = function(config){
var alteredConfig = {};
for(var key in config) {
alteredConfig[key] = config[key];
}
if(alteredConfig.baseUrl){
var base = baseUrl.replace(/\\/g, '/'),
splitUrl = alteredConfig.baseUrl.replace(/\\/g, '/').split('/'),
index = 0;
for(; index < splitUrl.length; index++){
if(splitUrl[index] === '..'){
base = path.dirname(base);
} else {
base += '/' + splitUrl[index];
}
}
alteredConfig.baseUrl = base;
}
return requirejsOrig.config(alteredConfig);
};
require = requirejs;
define = requirejs.define;