Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F10361381
core.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
core.js
View Options
var
path
=
require
(
"path"
);
var
http
=
require
(
"http"
);
var
ModuleManager
=
require
(
"./module/module-manager.js"
);
var
ConfigManager
=
require
(
"./config/config-manager.js"
);
function
SealiousCore
(
path_to_package_json
,
mode
,
layer_name
){
this
.
mode
=
mode
||
"local"
;
this
.
layer_name
=
layer_name
||
null
;
if
(
this
.
mode
==
"local"
){
this
.
dispatcher
=
require
(
"../lib/dispatchers/local/dispatcher-local.js"
);
}
else
{
this
.
dispatcher
=
require
(
"../lib/dispatchers/"
+
this
.
layer_name
+
"/dispatcher-"
+
this
.
layer_name
+
".js"
);
}
this
.
init
(
require
(
path_to_package_json
));
}
SealiousCore
.
prototype
=
new
function
(){
var
check_version
=
function
(
package_info
){
var
pkg
=
require
(
"../package.json"
)
var
pkg_split
=
pkg
.
version
.
split
(
"."
);
var
version
=
pkg_split
[
0
]
+
"."
+
pkg_split
[
1
];
var
url
=
"http://registry.npmjs.org/sealious/"
+
version
;
http
.
get
(
url
,
function
(
res
)
{
res
.
setEncoding
(
'utf8'
);
var
body
=
""
;
res
.
on
(
'data'
,
function
(
chunk
)
{
body
+=
chunk
.
toString
();
});
res
.
on
(
'end'
,
function
(){
var
sealious_npm
=
JSON
.
parse
(
body
);
var
sealious_npm_array
=
sealious_npm
.
version
.
split
(
"."
);
if
((
sealious_npm
.
version
!==
pkg
.
version
)
&&
(
parseInt
(
sealious_npm_array
[
2
])
>
parseInt
(
pkg_split
[
2
])
))
{
Sealious
.
Logger
.
warning
(
"Sealious@"
+
pkg
.
version
+
" - update available. Run `npm install sealious@"
+
sealious_npm
.
version
+
"` to update."
);
}
else
{
Sealious
.
Logger
.
info
(
"Sealious@"
+
pkg
.
version
+
" is up-to-date."
);
}
});
});
}
this
.
load_base_modules
=
function
(){
ModuleManager
.
add_module
(
require
.
resolve
(
"sealious-base-chips"
))
}
this
.
config
=
function
(
config_object
){
ConfigManager
.
set_config
(
config_object
);
}
this
.
config_from_file
=
function
(
path_to_file
){
this
.
config
(
require
(
path_to_file
));
}
this
.
init
=
function
(
package_info
){
//check_version(package_info);
this
.
load_base_modules
();
this
.
load_all_modules
(
package_info
);
}
this
.
load_all_modules
=
function
(
package_info
){
var
dependencies
=
package_info
.
dependencies
;
for
(
var
dependency_name
in
dependencies
){
try
{
var
dependency_path
=
require
.
resolve
(
dependency_name
);
}
catch
(
e
){
//in case the module is npm link-ed
var
dependency_path
=
require
.
resolve
(
path
.
resolve
(
module
.
parent
.
parent
.
filename
,
"../node_modules/"
+
dependency_name
));
}
var
dep_info
=
path
.
parse
(
dependency_path
);
if
(
dep_info
.
name
==
"sealious-module"
&&
dep_info
.
ext
==
".json"
){
ModuleManager
.
add_module
(
dependency_path
);
}
}
ModuleManager
.
initialize_all
(
this
.
dispatcher
);
}
var
which_chip_types_to_start_for_layer
=
{
db
:
[
"datastore"
],
biz
:
[
"field_type"
,
"resource_type"
,
"service"
],
web
:
[
"field_type"
,
"resource_type"
,
"channel"
]
}
function
decide_chip_types_to_start
(
mode
,
layer_name
){
if
(
mode
==
"local"
){
return
[
"field_type"
,
"resource_type"
,
"service"
,
"channel"
,
"datastore"
];
//}else if(!(layer_name)){
// throw new Sealious.Errors.ValidationError("Invalid layer name: " + layer_name); //~
}
else
{
return
which_chip_types_to_start_for_layer
[
layer_name
];
}
}
function
getDispatcher
(
mode
,
layer_name
){
if
(
mode
==
"local"
){
var
dispatcher_path
=
"./dispatchers/local/dispatcher-local.js"
;
}
else
{
var
dispatcher_path
=
"./dispatchers/"
+
layer_name
+
"/dispatcher-"
+
layer_name
+
".js"
;
}
return
require
(
dispatcher_path
);
}
this
.
start
=
function
(){
Sealious
.
Dispatcher
=
this
.
dispatcher
;
this
.
dispatcher
.
init
();
this
.
dispatcher
.
start
();
var
chip_types_to_start
=
decide_chip_types_to_start
(
this
.
mode
,
this
.
layer_name
);
return
ModuleManager
.
start
(
chip_types_to_start
);
}
}
module
.
exports
=
SealiousCore
;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 8, 13:06 (13 h, 6 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1034614
Default Alt Text
core.js (3 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment