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