From fcf4393680191584677872c686f26bfff01e4f37 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Thu, 6 Feb 2014 17:49:14 -0800 Subject: chore(build): Update closure i18n integration Use git repo as source and use q-io instead of q-fs --- i18n/src/closureSlurper.js | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'i18n/src') diff --git a/i18n/src/closureSlurper.js b/i18n/src/closureSlurper.js index 9f236cf2..02a1d9ef 100755 --- a/i18n/src/closureSlurper.js +++ b/i18n/src/closureSlurper.js @@ -2,7 +2,7 @@ 'use strict'; var Q = require('q'), - qfs = require('q-fs'), + qfs = require('q-io/fs'), converter = require('./converter.js'), util = require('./util.js'), closureI18nExtractor = require('./closureI18nExtractor.js'), @@ -47,24 +47,40 @@ function extractPlurals() { function writeLocaleFiles() { console.log('Final stage: Writing angular locale files to directory: %j', NG_LOCALE_DIR); - var writePromises = []; + var result = Q.defer(); var localeIds = Object.keys(localeInfo); var num_files = 0; - localeIds.forEach(function(localeID) { + + console.log('Generated %j locale files.', localeIds.length); + loop(); + return result.promise; + + // Need to use a loop and not write the files in parallel, + // as otherwise we will get the error EMFILE, which means + // we have too many open files. + function loop() { + var nextPromise; + if (localeIds.length) { + nextPromise = process(localeIds.pop()) || Q.when(); + nextPromise.then(loop, result.reject); + } else { + result.resolve(num_files); + } + } + + function process(localeID) { var content = closureI18nExtractor.outputLocale(localeInfo, localeID); if (!content) return; var correctedLocaleId = closureI18nExtractor.correctedLocaleId(localeID); var filename = NG_LOCALE_DIR + 'angular-locale_' + correctedLocaleId + '.js' - writePromises.push( - qfs.write(filename, content) - .then(function () { - console.log('Wrote ' + filename); - ++num_files; - })); console.log('Writing ' + filename); - }); - console.log('Generated %j locale files.', localeIds.length); - return Q.all(writePromises).then(function() { return num_files }); + return qfs.write(filename, content) + .then(function () { + console.log('Wrote ' + filename); + ++num_files; + }); + } + } /** -- cgit v1.2.3