in src/main.ts [532:582]
export function createXlfFiles(projectName: string, extensionName: string): ThroughStream {
let _xlf: XLF;
let header: BundledMetaDataHeader | undefined;
let data: BundledMetaDataFile | undefined;
function getXlf() {
if (!_xlf) {
_xlf = new XLF(projectName);
}
return _xlf;
}
return through(function (this: ThroughStream, file: File) {
if (!file.isBuffer()) {
this.emit('error', `File ${file.path} is not a buffer`);
return;
}
const buffer: Buffer = file.contents as Buffer;
const basename = path.basename(file.path);
if (basename === 'package.nls.json') {
const json: PackageJsonFormat = JSON.parse(buffer.toString('utf8'));
const keys = Object.keys(json);
const messages = keys.map((key) => {
const value = json[key];
return value === undefined ? `Unknown message for key: ${key}` : value;
});
getXlf().addFile('package', keys, messages);
} else if (basename === 'nls.metadata.json') {
data = JSON.parse(buffer.toString('utf8'));
} else if (basename === 'nls.metadata.header.json') {
header = JSON.parse(buffer.toString('utf8'));
} else {
this.emit('error', new Error(`${file.path} is not a valid nls or meta data file`));
return;
}
}, function (this: ThroughStream) {
if (header && data) {
const outDir = header.outDir;
for (const module in data) {
const fileContent: BundledMetaDataEntry = data[module];
// in the XLF files we only use forward slashes.
getXlf().addFile(`${outDir}/${module.replace(/\\/g, '/')}`, fileContent.keys, fileContent.messages);
}
}
if (_xlf) {
const xlfFile = new File({
path: path.join(projectName, extensionName + '.xlf'),
contents: new Buffer(_xlf.toString(), 'utf8')
});
this.queue(xlfFile);
}
this.queue(null);
});