Created
December 20, 2015 14:55
-
-
Save windwp/621fcca92f1bb0f6b323 to your computer and use it in GitHub Desktop.
This file contains 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
gulp.task('watch:replace', function () { | |
return gulp.watch(['./app/scripts/controllers/*.ts', 'app/scripts/math/*.ts'], ['replacefile']); | |
}); | |
// noi' cac' file trong cung` 1 folder lai. de? cho dep. code :) | |
gulp.task('replacefile', function() { | |
var result = ''; | |
var header = ''; | |
var folders = { | |
'_Controller': 'app/scripts/controllers', | |
'_Math': 'app/scripts/math' | |
}; | |
_.forEach(folders, function(folder, name) { | |
var files = fs.readdirSync(folder); | |
_.forEach(files, function(file) { | |
if (file === 'header.txt') { | |
header = fs.readFileSync(folder + '/' + file); | |
} | |
if (fs.statSync(folder + '/' + file).isFile()&&file.indexOf('.ts')!==-1) { | |
var moduleText = fs.readFileSync(folder + '/' + file, 'utf8'); | |
var myregexp = /\/\/Start\/\/((?:[^])*)\/\/End\/\//; | |
var match = myregexp.exec(moduleText); | |
if (match !== null) { | |
result += match[1]; | |
} | |
} | |
}); | |
var moduleName = name.replace('_', ''); | |
var data = header + '\r\nexport module ' + moduleName + '{' + result + '\r\n}'; | |
fs.writeFileSync(folder + '/' + name.toLowerCase() + '.ts', data); | |
result = ''; | |
header = ''; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment