1 |
|
2 |
|
3 | 'use strict';
|
4 |
|
5 | var fs = require('fs'),
|
6 | path = require('path'),
|
7 | vm = require('vm'),
|
8 | code = {
|
9 | min: fs.readFileSync(path.join(__dirname, '..',
|
10 | 'node_modules', 'yui', 'yui-nodejs', 'yui-nodejs-min.js'), 'utf8'),
|
11 | raw: fs.readFileSync(path.join(__dirname, '..',
|
12 | 'node_modules', 'yui', 'yui-nodejs', 'yui-nodejs.js'), 'utf8'),
|
13 | debug: fs.readFileSync(path.join(__dirname, '..',
|
14 | 'node_modules', 'yui', 'yui-nodejs', 'yui-nodejs-debug.js'), 'utf8')
|
15 | };
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | exports.getYUI = function (filter) {
|
34 | var sandbox = {
|
35 | console: console,
|
36 | process: process,
|
37 | require: require,
|
38 | module: module,
|
39 | setTimeout: setTimeout,
|
40 | setInterval: setInterval,
|
41 | clearTimeout: clearTimeout,
|
42 | clearInterval: clearInterval,
|
43 | JSON: JSON,
|
44 | __filename: __filename,
|
45 | __dirname: path.join(__dirname, '..', 'node_modules', 'yui', 'yui-nodejs'),
|
46 | exports: {}
|
47 | },
|
48 | globalFunction = Function;
|
49 |
|
50 | filter = (filter && code.hasOwnProperty(filter)) ? filter : 'raw';
|
51 | vm.runInNewContext(code[filter], sandbox, 'build/yui-new/yui-new.js');
|
52 |
|
53 |
|
54 |
|
55 | sandbox.exports.YUI.applyConfig({
|
56 | global: globalFunction('return this')()
|
57 | });
|
58 | return sandbox.exports.YUI;
|
59 | }; |
\ | No newline at end of file |