Last active
August 29, 2015 14:05
-
-
Save huang-x-h/873fc1d6284354547f84 to your computer and use it in GitHub Desktop.
convert template file to variable string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'), | |
Buffer = require('buffer').Buffer; | |
fs.readFile('base.tpl', function(err, data) { | |
if (err) return; | |
var srcArray = data.toString().split('\r\n'), | |
destArray = []; | |
srcArray.forEach(function(content) { | |
destArray.push(content.replace(/(\t*).*/, function(match, $1, offset, string) { | |
return $1 + '\'' + string.substr($1.length) + '\' +'; | |
})); | |
}); | |
var file = fs.createWriteStream('base.js'); | |
destArray.forEach(function(content) { | |
file.write(content + '\r\n'); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment