fix stream end with message

This commit is contained in:
Konstantin Vulsonov
2018-09-19 00:34:26 +03:00
parent 67062481b5
commit a9877dd899

View File

@@ -33,17 +33,19 @@ export class SvgIconset {
const ids = optimizedResponse.map(el => el.id); const ids = optimizedResponse.map(el => el.id);
Promise.all(optimizedResponse.map(el => el.optimized)) Promise.all(optimizedResponse.map(el => el.optimized))
.then(resFiles => { .then(resFiles => {
createWriteStream(join(process.cwd(), this.config.source, `${this.config.result}-iconset.svg`)) const resultFile = join(process.cwd(), this.config.source, `${this.config.result}-iconset.svg`);
createWriteStream(resultFile)
.once('open', function (this: WriteStream) { .once('open', function (this: WriteStream) {
try { try {
const data = resFiles.map(res => res.data.replace(/<svg /, `<svg id="${ids[idx]}" `)); const data = resFiles.map(res => res.data.replace(/<svg /, `<svg id="${ids[idx]}" `));
this.write(`<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">${data.join('')}</svg>`); this.write(`<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">${data.join('')}</svg>`);
idx++; idx++;
this.end();
} catch (err) { } catch (err) {
console.log('ERROR', err); console.log('ERROR', err);
} }
}) })
.on('close', () => console.log(`Succesfully written file ${this.config.result}-iconset.svg`)) .on('close', () => console.log(`Succesfully written file ${resultFile}`))
.on('error', () => console.error('Somethings wrong try again')); .on('error', () => console.error('Somethings wrong try again'));
}) })
.catch(console.error); .catch(console.error);