This repository has been archived by the owner on Oct 30, 2018. It is now read-only.
/
store.js
92 lines (73 loc) · 2.45 KB
/
store.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
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* Copyright (c) 2011-2012, Yahoo! Inc. All rights reserved.
* Copyrights licensed under the New BSD License.
* See the accompanying LICENSE file for terms.
*/
/*jslint anon:true, sloppy:true, nomen:true*/
// ----------------------------------------------------------------------------
// Prerequisites
// ----------------------------------------------------------------------------
var libpath = require('path'),
YUIFactory = require('./yui-sandbox.js');
// ----------------------------------------------------------------------------
// Store
// ----------------------------------------------------------------------------
/**
* A factory object providing methods for creating and managing ResourceStore
* instances.
*/
var Store = {};
/**
* Creates a new server-side resource store instance and returns it.
* @method createStore
* @param {{root: string,
* context: Object,
* appConfig: Object,
* verbose: boolean}} options An object containing store options.
* @return Y.mojito.ResourceStore
*/
Store.createStore = function(options) {
var store,
YUI,
Y;
if (!options) {
options = {};
}
if (!options.root) {
options.root = process.cwd();
}
if (!options.context) {
options.context = {};
}
// Create a sandboxed YUI instance. This is necessary to avoid shared
// metadata with the main Mojito execution context and the execution context
// of the ResourceStore instance.
YUI = YUIFactory.getYUI();
// Configure the prerequisites and load the resource store impl code.
Y = YUI({
useSync: true,
modules: {
'mojito': {
fullpath: libpath.join(__dirname, 'app/autoload/mojito.common.js')
},
'mojito-util': {
fullpath: libpath.join(__dirname, 'app/autoload/util.common.js')
},
'mojito-resource-store': {
fullpath: libpath.join(__dirname, 'app/autoload/store.server.js')
}
}
});
Y.use('mojito-resource-store');
store = new Y.mojito.ResourceStore({
root: options.root,
context: options.context,
appConfig: options.appConfig
});
store.preload();
return store;
};
// ----------------------------------------------------------------------------
// EXPORT(S)
// ----------------------------------------------------------------------------
module.exports = Store;