Replace pieces of your source using comment tags to identify the location.
/* configuration.js */
var myServer = /*host*/ '' /*/host*/;
var fs = require('fs');
var taggedReplace = require('tagged-replace');
var content = fs.readFileSync('./configuration.js');
console.log( taggedReplace( content, { host: '\'myhost.example.com\'' } ) );
/* console */
var myServer = /*host*/ 'myhost.example.com' /*/host*/;
taggedReplace(contents[, values[, options]])
contents
is the string which may contains some tags
values
is an object where each key is the name of a tag and its value will be replaced, as a string in the characters between the starting and ending tag.
options
is an object with overrides for the default parameters described below.
The beginning of the start tag. Defaults to '/*'.
The ending of the start tag. Defaults to '*/'.
The beginning of the end tag. Defaults to '/*/'.
The ending of the end tag. Defaults to '*/'.
Set to true
to keep the contents separated from the tags by a space. Defaults to true
.
The default options are:
defaultOptions = {
startPrefix: '/*',
startSuffix: '*/',
endPrefix: '/*/',
endSuffix: '*/',
space: true
};