-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathassets.js
66 lines (58 loc) · 1.56 KB
/
assets.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
'use strict';
//
// Required modules.
//
var fuse = require('fusing')
, async = require('async')
, path = require('path')
, fs = require('fs');
//
// Base path for assets.
//
var assets = path.join(__dirname, 'pagelets');
/**
* Create new collection of assets from a specific brand.
*
* @param {String} brand nodejitsu by default.
* @param {String} mode standalone || bigpipe, defaults to bigpipe.
* @api public
*/
function Assets(brand, mode) {
var readable = Assets.predefine(this, Assets.predefine.READABLE)
, enumerable = Assets.predefine(this, { configurable: false })
, self = this
, i = 0
, files;
/**
* Callback to emit optimized event after all Pagelets have been optimized.
*
* @param {Error} error
* @api private
*/
function next(error) {
if (error) return self.emit('error', error);
if (++i === files.length) self.emit('optimized');
}
//
// Default framework to use with reference to the path to core.styl.
//
readable('brand', brand = brand || 'nodejitsu');
//
// Load all assets of the branch.
//
(files = fs.readdirSync(assets)).forEach(function include(file) {
if ('.js' !== path.extname(file) || ~file.indexOf('pagelet')) return;
//
// Create getter for each pagelet in assets.
//
var Pagelet = require(path.join(assets, file));
enumerable(path.basename(file, '.js'), {
enumerable: true,
value: Pagelet.brand(self.brand, mode === 'standalone', next)
}, true);
});
}
//
// Expose the collection.
//
module.exports = fuse(Assets, require('events').EventEmitter);