-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
22 lines (16 loc) · 793 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const { replace } = require( '@automattic/vip-search-replace' );
const fs = require( 'fs' );
const config = require( './config' );
const filename = config.innerFile;
const lastDotIndex = filename.lastIndexOf('.');
const name = filename.substring(0, lastDotIndex);
const extension = filename.substring(lastDotIndex + 1);
const stringToReplace = config.string;
const newString = config.newString;
// Create a readable and writeable stream. Can be any stream: File, std, etc...
(async() => {
const readableStream = fs.createReadStream( filename );
const writeableStream = fs.createWriteStream( `${name}_replaced.${extension}`, { encoding: 'utf8' } );
const result = await replace( readableStream, [ stringToReplace, newString, ] );
result.pipe( writeableStream );
})()