Last active
July 29, 2016 08:59
-
-
Save xx7y7xx/d94ef726e692f3c1a3c170251aec2a7d to your computer and use it in GitHub Desktop.
Make gulpfile.js (http://git.yonyou.com/sscplatform/ssc_webcomp/issues/98)
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
// input file `/tmp/xx3` is created by: | |
// | |
// ``` | |
// $ ls -d -1 $PWD/**/* | |
// ``` | |
var util = require('util'); | |
var lineReader = require('readline').createInterface({ | |
input: require('fs').createReadStream('/tmp/xx3') | |
}); | |
var l = function (msg) { | |
console.log(msg); | |
}; | |
// Check input file type | |
var typeOf = function (path) { | |
if (path.endsWith('.html')) { | |
return 'html'; | |
} else { | |
return 'js'; | |
} | |
}; | |
l('var config = {'); | |
l(' define: {'); | |
lineReader.on('line', function (line) { | |
var atom, moduleName, newLine, | |
ext = typeOf(line); | |
// integer/template | |
// ssc/integer/viewmodel | |
atom = line.replace("/home/chenyang/source/ssc_webcomp/comp/", "").replace('.' + ext, ''); | |
switch(ext) { | |
// Input: /home/chenyang/source/ssc_webcomp/comp/integer/template.html | |
case 'html': | |
// text!ssc/integer/template.html | |
moduleName = 'text!' + atom + '.' + ext; | |
break; | |
// Input: /home/chenyang/source/ssc_webcomp/comp/integer/viewmodel.js | |
case 'js': | |
moduleName = 'ssc/' + atom; | |
break; | |
default: | |
} | |
newLine = util.format(" '%s': '/'+path.project+'/'+path.version+'/%s/'+'%s.%s',", moduleName, ext, atom, ext); | |
// Output: '/iwebap/js/ref/refers_RefGrid.js':'/'+path.project+'/'+path.version+'/js/'+'RefTree/refers_RefGrid.js', | |
l(newLine); | |
}); | |
lineReader.on('close', function (line) { | |
l(' }'); | |
l('}'); | |
}); | |
/* | |
'/iwebap/trd/handlebars/handlebars-v4.0.5.js': '/'+path.project+'/'+path.version+'/js/lib/'+'handlebars/handlebars-v4.0.5.js', | |
'/iwebap/trd/handlebars/handlebars.runtime-v4.0.5.js': '/'+path.project+'/'+path.version+'/js/lib/'+'handlebars/handlebars.runtime-v4.0.5.js', | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
result: