Commit | Line | Data |
---|---|---|
8eb39b80 D |
1 | var fs = require('fs'),\r |
2 | uglyfyJS = require('uglify-js'),\r | |
f9ff7686 | 3 | _ = require('lodash'),\r |
8eb39b80 | 4 | config = require('./../../../server/configuration.js');\r |
23533845 D |
5 | \r |
6 | var FILE_ENCODING = 'utf-8',\r | |
7 | EOL = '\n';\r | |
8 | \r | |
9 | \r | |
9df70c63 D |
10 | function concat(src) {\r |
11 | var file_list = src;\r | |
23533845 | 12 | var out = file_list.map(function(file_path){\r |
9df70c63 | 13 | return fs.readFileSync(file_path, FILE_ENCODING) + '\n\n';\r |
23533845 D |
14 | });\r |
15 | \r | |
9df70c63 | 16 | return out.join(EOL);\r |
23533845 D |
17 | }\r |
18 | \r | |
8eb39b80 D |
19 | \r |
20 | \r | |
21 | config.loadConfig();\r | |
22 | \r | |
23 | \r | |
24 | \r | |
25 | \r | |
26 | \r | |
27 | /**\r | |
eaaf73b0 | 28 | * Build the _kiwi.js files\r |
8eb39b80 D |
29 | */\r |
30 | \r | |
9df70c63 D |
31 | var src = concat([\r |
32 | __dirname + '/app.js',\r | |
33 | __dirname + '/model_application.js',\r | |
34 | __dirname + '/model_gateway.js',\r | |
ce13508b | 35 | __dirname + '/model_network.js',\r |
9df70c63 D |
36 | __dirname + '/model_member.js',\r |
37 | __dirname + '/model_memberlist.js',\r | |
f2bb5380 | 38 | __dirname + 'dev/model_newconnection.js',\r |
9df70c63 D |
39 | __dirname + '/model_panel.js',\r |
40 | __dirname + '/model_panellist.js',\r | |
8fcd0453 | 41 | __dirname + '/model_networkpanellist.js',\r |
b9c64fcd | 42 | __dirname + '/model_query.js',\r |
9df70c63 D |
43 | __dirname + '/model_channel.js',\r |
44 | __dirname + '/model_server.js',\r | |
19cc6364 | 45 | __dirname + '/model_applet.js',\r |
890a9b91 | 46 | __dirname + '/model_pluginmanager.js',\r |
5bed0536 | 47 | __dirname + '/model_datastore.js',\r |
19cc6364 D |
48 | \r |
49 | __dirname + '/applet_settings.js',\r | |
721ad945 | 50 | __dirname + '/applet_nickserv.js',\r |
51ae0eb8 | 51 | __dirname + '/applet_chanlist.js',\r |
22373da6 | 52 | __dirname + '/applet_scripteditor.js',\r |
9df70c63 D |
53 | \r |
54 | __dirname + '/utils.js',\r | |
55 | __dirname + '/view.js'\r | |
56 | ]);\r | |
57 | \r | |
58 | \r | |
eaaf73b0 | 59 | src = '(function (global, undefined) {\n\n' + src + '\n\n})(window);';\r |
9df70c63 D |
60 | \r |
61 | \r | |
62 | fs.writeFileSync(__dirname + '/../kiwi.js', src, FILE_ENCODING);\r | |
63 | \r | |
64 | \r | |
65 | src = uglyfyJS.parser.parse(src);\r | |
66 | src = uglyfyJS.uglify.ast_mangle(src);\r | |
67 | src = uglyfyJS.uglify.ast_squeeze(src);\r | |
68 | fs.writeFileSync(__dirname + '/../kiwi.min.js', uglyfyJS.uglify.gen_code(src), FILE_ENCODING);\r | |
23533845 D |
69 | \r |
70 | \r | |
71 | \r | |
72 | \r | |
8eb39b80 D |
73 | console.log('kiwi.js and kiwi.min.js built');\r |
74 | \r | |
75 | \r | |
76 | \r | |
77 | \r | |
78 | \r | |
79 | \r | |
80 | \r | |
81 | \r | |
82 | \r | |
83 | \r | |
84 | /**\r | |
85 | * Build the index.html file\r | |
86 | */\r | |
87 | \r | |
88 | var index_src = fs.readFileSync(__dirname + '/index.html.tmpl', FILE_ENCODING);\r | |
89 | var vars = {\r | |
0a8a61ad | 90 | base_path: config.get().http_base_path || '/kiwi',\r |
93e84f75 | 91 | cache_buster: Math.ceil(Math.random() * 9000).toString(),\r |
76391784 D |
92 | server_settings: {},\r |
93 | client_plugins: []\r | |
8eb39b80 D |
94 | };\r |
95 | \r | |
2eec3842 | 96 | // Any restricted server mode set?\r |
93e84f75 | 97 | if (config.get().restrict_server) {\r |
76391784 | 98 | vars.server_settings = {\r |
93e84f75 D |
99 | connection: {\r |
100 | server: config.get().restrict_server,\r | |
101 | port: config.get().restrict_server_port || 6667,\r | |
102 | ssl: config.get().restrict_server_ssl,\r | |
103 | channel: config.get().restrict_server_channel,\r | |
104 | nick: config.get().restrict_server_nick,\r | |
105 | allow_change: false\r | |
106 | }\r | |
76391784 D |
107 | };\r |
108 | }\r | |
109 | \r | |
110 | // Any client default settings?\r | |
111 | if (config.get().client) {\r | |
112 | vars.server_settings.client = config.get().client;\r | |
93e84f75 D |
113 | }\r |
114 | \r | |
2eec3842 D |
115 | // Any client plugins?\r |
116 | if (config.get().client_plugins && config.get().client_plugins.length > 0) {\r | |
76391784 | 117 | vars.client_plugins = config.get().client_plugins;\r |
2eec3842 D |
118 | }\r |
119 | \r | |
8eb39b80 | 120 | _.each(vars, function(value, key) {\r |
76391784 | 121 | if (typeof value === 'object') value = JSON.stringify(value);\r |
8eb39b80 D |
122 | index_src = index_src.replace(new RegExp('<%' + key + '%>', 'g'), value);\r |
123 | });\r | |
124 | \r | |
125 | fs.writeFileSync(__dirname + '/../../index.html', index_src, FILE_ENCODING);\r | |
126 | \r | |
127 | \r | |
128 | console.log('index.html built'); |