Mercurial > psgxs
annotate modules.js @ 58:b98e545a94f7 default tip
Always use children instead of tags. Might break something.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Tue, 13 Sep 2011 00:54:55 +0200 |
parents | addbf6bbfaa8 |
children |
rev | line source |
---|---|
43
023f767662d3
Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
41
diff
changeset
|
1 /* |
023f767662d3
Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
41
diff
changeset
|
2 * Copyright (C) 2010 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
023f767662d3
Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
41
diff
changeset
|
3 * |
023f767662d3
Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
41
diff
changeset
|
4 * This file is part of PSĜS, a PubSub server written in JavaScript. |
023f767662d3
Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
41
diff
changeset
|
5 * |
023f767662d3
Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
41
diff
changeset
|
6 * PSĜS is free software: you can redistribute it and/or modify |
023f767662d3
Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
41
diff
changeset
|
7 * it under the terms of the GNU Affero General Public License as |
023f767662d3
Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
41
diff
changeset
|
8 * published by the Free Software Foundation, either version 3 of the |
023f767662d3
Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
41
diff
changeset
|
9 * License. |
023f767662d3
Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
41
diff
changeset
|
10 * |
023f767662d3
Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
41
diff
changeset
|
11 * PSĜS is distributed in the hope that it will be useful, |
023f767662d3
Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
41
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
023f767662d3
Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
41
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
023f767662d3
Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
41
diff
changeset
|
14 * GNU Affero General Public License for more details. |
023f767662d3
Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
41
diff
changeset
|
15 * |
023f767662d3
Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
41
diff
changeset
|
16 * You should have received a copy of the GNU Affero General Public License |
023f767662d3
Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
41
diff
changeset
|
17 * along with PSĜS. If not, see <http://www.gnu.org/licenses/>. |
023f767662d3
Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
41
diff
changeset
|
18 */ |
023f767662d3
Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
41
diff
changeset
|
19 |
023f767662d3
Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
41
diff
changeset
|
20 'use strict'; |
023f767662d3
Fix compatibility with strict mode of node 0.4 and some files without licence header.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
41
diff
changeset
|
21 |
24
b80ab94da447
Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
22 var modules = exports; |
b80ab94da447
Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
23 |
41
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
24 var fs = require('fs'); |
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
25 var dir = require('./configuration').pluginsDir; |
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
26 var files = fs.readdirSync(dir); |
24
b80ab94da447
Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
27 var regex = /^mod_.*\.js/; |
b80ab94da447
Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
28 |
41
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
29 var Script = process.binding('evals').Script; |
47
0d3f18bb1d36
Remove usage of fdsq.js in modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
43
diff
changeset
|
30 var fdsq = require('./fdsq'); |
57
addbf6bbfaa8
Various fixes for the migration to ltx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
56
diff
changeset
|
31 |
41
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
32 var sandbox = { |
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
33 process: process, |
57
addbf6bbfaa8
Various fixes for the migration to ltx.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
56
diff
changeset
|
34 console: console, |
41
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
35 config: require('./configuration'), |
56
99bd1d1ac071
Migration to node-xmpp, done!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
47
diff
changeset
|
36 Element: require('ltx').Element, |
99bd1d1ac071
Migration to node-xmpp, done!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
47
diff
changeset
|
37 uuid: require('uuid'), |
41
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
38 errors: require('./errors'), |
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
39 forms: require('./forms'), |
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
40 makeError: require('./errors').makeError, |
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
41 notifs: require('./notifs'), |
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
42 NS: require('./namespaces'), |
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
43 require: require, |
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
44 storage: require('./storage'), |
47
0d3f18bb1d36
Remove usage of fdsq.js in modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
43
diff
changeset
|
45 JID: { |
0d3f18bb1d36
Remove usage of fdsq.js in modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
43
diff
changeset
|
46 toBare: fdsq.toBare, |
0d3f18bb1d36
Remove usage of fdsq.js in modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
43
diff
changeset
|
47 toResource: fdsq.toResource |
0d3f18bb1d36
Remove usage of fdsq.js in modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
43
diff
changeset
|
48 }, |
41
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
49 exports: {} |
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
50 }; |
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
51 |
24
b80ab94da447
Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
52 for (var i in files) { |
b80ab94da447
Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
53 var file = files[i]; |
b80ab94da447
Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
54 if (!regex.test(file)) |
b80ab94da447
Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
55 continue; |
b80ab94da447
Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
56 |
41
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
57 fs.readFile(dir + '/' + file, function(err, data) { |
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
58 if (err) { |
56
99bd1d1ac071
Migration to node-xmpp, done!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
47
diff
changeset
|
59 console.log('Erreur de chargement de module.'); |
41
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
60 return; |
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
61 } |
30
b2faacfefb90
Rewrite of the module manager; fix of some modules; fix of the directory backend.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
24
diff
changeset
|
62 |
56
99bd1d1ac071
Migration to node-xmpp, done!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
47
diff
changeset
|
63 Script.runInNewContext(data, sandbox, dir + '/' + file); |
41
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
64 var module = sandbox.exports; |
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
65 sandbox.exports = {}; |
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
66 |
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
67 for (var j in module) { |
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
68 if (typeof modules[j] != 'undefined') |
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
69 console.log('WARNING: module '+j+' already loaded.'); |
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
70 |
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
71 modules[j] = module[j]; |
56
99bd1d1ac071
Migration to node-xmpp, done!
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
47
diff
changeset
|
72 console.log('Module '+j+' loaded!'); |
41
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
73 } |
bc717575e66a
Much better handling of modules.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
30
diff
changeset
|
74 }); |
24
b80ab94da447
Add new modules files.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
75 } |