EOL = '\n';\r
\r
\r
-function concat(src) {\r
- var file_list = src;\r
- var out = file_list.map(function(file_path){\r
- return fs.readFileSync(file_path, FILE_ENCODING) + '\n\n';\r
+function concat(file_list, callback) {\r
+ var num_files = file_list.length,\r
+ files = [],\r
+ loaded = 0,\r
+ error = false;\r
+\r
+ file_list.forEach(function (file_path, idx) {\r
+ if (error) {\r
+ return;\r
+ }\r
+ fs.readFile(file_path, { encoding: FILE_ENCODING }, function (err, data) {\r
+ if (error) {\r
+ return;\r
+ } else if (err) {\r
+ error = true;\r
+ return callback(err);\r
+ }\r
+ files[idx] = data + '\n\n';\r
+ if (++loaded === num_files) {\r
+ callback(null, files.join(EOL));\r
+ }\r
+ });\r
});\r
-\r
- return out.join(EOL);\r
}\r
\r
\r
/**\r
* Build the kiwi.js/kiwi.min.js files\r
*/\r
-var src = concat(source_files);\r
-src = '(function (global, undefined) {\n\n' + src + '\n\n})(window);';\r
-\r
-\r
-fs.writeFileSync(__dirname + '/../kiwi.js', src, FILE_ENCODING);\r
-\r
-// Uglify can take take an array of filenames to produce minified code\r
-// but it's not wraped in an IIFE and produces a slightly larger file\r
-//src = uglifyJS.minify(source_files);\r
-\r
-var ast = uglifyJS.parse(src, {filename: 'kiwi.js'});\r
-ast.figure_out_scope();\r
-ast = ast.transform(uglifyJS.Compressor({warnings: false}));\r
-ast.figure_out_scope();\r
-ast.compute_char_frequency();\r
-ast.mangle_names();\r
-src = ast.print_to_string();\r
-\r
-fs.writeFileSync(__dirname + '/../kiwi.min.js', src, FILE_ENCODING);\r
-\r
-\r
-\r
-\r
-console.log('kiwi.js and kiwi.min.js built');\r
+concat(source_files, function (err, src) {\r
+ if (!err) {\r
+ src = '(function (global, undefined) {\n\n' + src + '\n\n})(window);';\r
+\r
+ fs.writeFile(__dirname + '/../kiwi.js', src, { encoding: FILE_ENCODING }, function (err) {\r
+ if (!err) {\r
+ console.log('Built kiwi.js');\r
+ } else {\r
+ console.error('Error building kiwi.js:', err);\r
+ }\r
+ });\r
+\r
+ // Uglify can take take an array of filenames to produce minified code\r
+ // but it's not wraped in an IIFE and produces a slightly larger file\r
+ //src = uglifyJS.minify(source_files);\r
+\r
+ var ast = uglifyJS.parse(src, {filename: 'kiwi.js'});\r
+ ast.figure_out_scope();\r
+ ast = ast.transform(uglifyJS.Compressor({warnings: false}));\r
+ ast.figure_out_scope();\r
+ ast.compute_char_frequency();\r
+ ast.mangle_names();\r
+ src = ast.print_to_string();\r
+\r
+ fs.writeFile(__dirname + '/../kiwi.min.js', src, { encoding: FILE_ENCODING }, function (err) {\r
+ if (!err) {\r
+ console.log('Built kiwi.min.js');\r
+ } else {\r
+ console.error('Error building kiwi.min.js:', err);\r
+ }\r
+ });\r
+ } else {\r
+ console.error('Error building kiwi.js and kiwi.min.js:', err);\r
+ }\r
+});\r
\r
\r
\r
/**\r
* Convert translations from .po to .json\r
*/\r
-var translations = [];\r
-var translation_files = fs.readdirSync(__dirname + '/translations');\r
if (!fs.existsSync(__dirname + '/../locales')) {\r
fs.mkdirSync(__dirname + '/../locales');\r
}\r
-translation_files.forEach(function (file) {\r
- var locale = file.slice(0, -3),\r
- json = '',\r
- languages = JSON.parse(fs.readFileSync(__dirname + '/translations/translations.json'));\r
- if ((file.slice(-3) === '.po') && (locale !== 'template')) {\r
- json = po2json.parseSync(__dirname + '/translations/' + file);\r
- fs.writeFileSync(__dirname + '/../locales/' + locale + '.json', JSON.stringify(json));\r
- translations.push({tag: locale, language: languages[locale]});\r
- console.log('Built translation file %s', locale + '.json');\r
+fs.readdir(__dirname + '/translations', function (err, translation_files) {\r
+ if (!err) {\r
+ translation_files.forEach(function (file) {\r
+ var locale = file.slice(0, -3);\r
+\r
+ if ((file.slice(-3) === '.po') && (locale !== 'template')) {\r
+ po2json.parse(__dirname + '/translations/' + file, function (err, json) {\r
+ if (!err) {\r
+ fs.writeFile(__dirname + '/../locales/' + locale + '.json', JSON.stringify(json), function (err) {\r
+ if (!err) {\r
+ console.log('Built translation file %s.json', locale);\r
+ } else {\r
+ console.error('Error building translation file %s.json:', locale, err);\r
+ }\r
+ });\r
+ } else {\r
+ console.error('Error building translation file %s.json: ', locale, err);\r
+ }\r
+ });\r
+ }\r
+ });\r
+ } else {\r
+ console.error('Error building translation files:', err);\r
}\r
});\r
\r
\r
fs.writeFile(__dirname + '/../../index.html', index_src, { encoding: FILE_ENCODING }, function (err) {\r
if (!err) {\r
- console.log('index.html built');\r
+ console.log('Built index.html');\r
} else {\r
- console.log('Error building index.html');\r
+ console.error('Error building index.html');\r
}\r
});\r