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