export function createKeyValuePairFile()

in src/main.ts [268:305]


export function createKeyValuePairFile(commentSeparator: string | undefined = undefined): ThroughStream {
	return through(function (this: ThroughStream, file: File) {
		const basename = path.basename(file.relative);
		if (basename.length < NLS_METADATA_JSON.length || NLS_METADATA_JSON !== basename.substr(basename.length - NLS_METADATA_JSON.length)) {
			this.queue(file);
			return;
		}
		let kvpFile: File | undefined;
		const filename = file.relative.substr(0, file.relative.length - NLS_METADATA_JSON.length);
		if (file.isBuffer()) {
			const buffer: Buffer = file.contents as Buffer;
			const json = JSON.parse(buffer.toString('utf8'));
			if (JavaScriptMessageBundle.is(json)) {
				const resolvedBundle = json as JavaScriptMessageBundle;
				if (resolvedBundle.messages.length !== resolvedBundle.keys.length) {
					this.queue(file);
					return;
				}
				const kvpObject = bundle2keyValuePair(resolvedBundle, commentSeparator);
				kvpFile = new File({
					base: file.base,
					path: path.join(file.base, filename) + I18N_JSON,
					contents: new Buffer(JSON.stringify(kvpObject, null, '\t'), 'utf8')
				});
			} else {
				this.emit('error', `Not a valid JavaScript message bundle: ${file.relative}`);
				return;
			}
		} else {
			this.emit('error', `Failed to read JavaScript message bundle file: ${file.relative}`);
			return;
		}
		this.queue(file);
		if (kvpFile) {
			this.queue(kvpFile);
		}
	});
}