in src/main.ts [212:253]
export function bundleLanguageFiles(): ThroughStream {
interface MapValue {
base: string;
content: ExtensionLanguageBundle;
}
const bundles: Map<MapValue> = Object.create(null);
function getModuleKey(relativeFile: string): string {
return relativeFile.match(/(.*)\.nls\.(?:.*\.)?json/)![1].replace(/\\/g, '/');
}
return through(function (this: ThroughStream, file: File) {
const basename = path.basename(file.path);
const matches = basename.match(/.nls\.(?:(.*)\.)?json/);
if (!matches || !file.isBuffer()) {
// Not an nls file.
this.queue(file);
return;
}
const language = matches[1] ? matches[1] : 'en';
let bundle = bundles[language];
if (!bundle) {
bundle = {
base: file.base,
content: Object.create(null)
};
bundles[language] = bundle;
}
bundle.content[getModuleKey(file.relative)] = JSON.parse((file.contents as Buffer).toString('utf8'));
}, function () {
for (const language in bundles) {
const bundle = bundles[language];
const languageId = language === 'en' ? '' : `${language}.`;
const file = new File({
base: bundle.base,
path: path.join(bundle.base, `nls.bundle.${languageId}json`),
contents: new Buffer(JSON.stringify(bundle.content), 'utf8')
});
this.queue(file);
}
this.queue(null);
});
}