diff --git a/lib/unbuild.js b/lib/unbuild.js index 0e4a8e20..197fb723 100644 --- a/lib/unbuild.js +++ b/lib/unbuild.js @@ -19,6 +19,13 @@ var mk = function(path){ fs.mkdirSync(path); } +var rn = function(path, newPath){ + path = nodePath.join(dir, path) + newPath = nodePath.join(dir, newPath) + if(fs.existsSync(newPath)){ return } + fs.renameSync(path, newPath); +} + var between = function(text, start, end){ end = end || start; var s = text.indexOf(start); @@ -65,15 +72,19 @@ var undent = function(code, n){ var arg = process.argv[2] || 'gun'; + var g; if('gun' === arg){ - rm('./src'); + g = 'gun'; + rn('./src','./old_src'); mk('./src'); mk('./src/polyfill'); mk('./src/adapters'); } else { - rm('./'+arg); + g = arg; + rn('./'+arg,'./old_'+arg); mk('./'+arg); } + console.log("unbuild:", arg+'.js') var f = read(arg+'.js'); var code = next(f); @@ -81,7 +92,7 @@ var undent = function(code, n){ code = next("/* UNBUILD */"); - if('gun' === arg){ + if('gun' === g){ write('src/polyfill/unbuild.js', undent(code, 1)); arg = ''; } @@ -92,7 +103,20 @@ var undent = function(code, n){ var file = path(arg); if(!file){ return } code = code.replace(/\bUSE\(/g, 'require('); - write(file, undent(code)); + code = undent(code); + var rcode; + try{ rcode = read('old_'+file); } catch(e){} + // console.log(rcode); + if(rcode != code){ + console.log("unbuild:","update",file); + } + write(file, code); recurse(); }()); + if('gun' === g){ + rm('./old_src'); + }else{ + rm('./old_'+g); + } + }());