var fs = require('fs');
var path = require('path');
var gulp = require('gulp');
var gutil = require('gulp-util');
var del = require('del');
var NwBuilder = require('nw-builder');

gulp.task('sync', function() {
  var package = JSON.parse(fs.readFileSync('package.json', 'utf8'));
  var srcPackage = JSON.parse(fs.readFileSync('src/package.json', 'utf8'));
  srcPackage.name = package.name;
  srcPackage.version = package.version;
  srcPackage.description = package.description;
  srcPackage.repository = package.repository;
  srcPackage.homepage = package.homepage;
  try {
    fs.writeFileSync('src/package.json', JSON.stringify(srcPackage, null, "  ") + "\n", 'utf8');
  } catch(e) {
    console.error("Failed to sync package.json");
  }
});

gulp.task('clean:build', function(cb) {
  del(['build'], cb);
});

var nw = function(cb, platforms) {
  var nw = new NwBuilder({
    files: 'src/**',
    version: '0.12.1',
    platforms: platforms,
    build: 'build',
    cacheDir: 'cache',
    macCredits: 'Credits.html',
    macIcns: 'src/images/jikkyo.icns',
    macZip: false,
    winIco: 'src/images/jikkyo.ico',
    winZip: false
  });
  nw.on('log', function(msg) {
    gutil.log('node-webkit-builder', msg);
  });
  nw.build().then(function() {
    platforms.forEach(function(platform) {
      var targets =
          platform === "win" ? ["win32", "win64"] :
          platform === "osx" ? ["osx32", "osx64"] :
          platform === "linux" ? ["linux32", "linux64"] : [platform];

      switch (platform) {
        case "win":
        case "win32":
        case "win64":
          var jikkyo_ct = fs.readFileSync(path.join(__dirname, "attachment", "jikkyo_ct.cmd"));
          targets.forEach(function(target) {
            fs.writeFileSync(path.join(__dirname, "build", "jikkyo", target, "jikkyo_ct.cmd"), jikkyo_ct);
          });
          break;
      }

      var readme = fs.readFileSync(path.join(__dirname, "README.md"));
      targets.forEach(function(target) {
        fs.writeFileSync(path.join(__dirname, "build", "jikkyo", target, "README.md"), readme);
      });
    });
    cb();
  });
};

gulp.task('nw:release', ['clean', 'sync'], function(cb) {
  nw(cb, ['win', 'osx', 'linux']);
});

gulp.task('nw:win32', function(cb) {
  nw(cb, ['win32']);
});

gulp.task('nw:win64', function(cb) {
  nw(cb, ['win64']);
});

gulp.task('nw:osx32', function(cb) {
  nw(cb, ['osx32']);
});

gulp.task('nw:osx64', function(cb) {
  nw(cb, ['osx64']);
});

gulp.task('nw:linux', function(cb) {
  nw(cb, ['linux']);
});

gulp.task('clean', ['clean:build']);
gulp.task('release', ['clean', 'nw:release']);
gulp.task('default', ['build']);

@@ -1490,14 +1490,10 @@
     
-switch
+if
  (pl
@@ -1502,75 +1502,33 @@
 form
-) %7B%0A        case %22win%22:%0A        case %22win32%22:%0A        case %22win64%22:
+.indexOf(%22win%22) !== -1) %7B
 %0A   
@@ -1528,26 +1528,24 @@
 ) %7B%0A        
-  
 var jikkyo_c
@@ -1614,26 +1614,24 @@
 _ct.cmd%22));%0A
-  
         targ
@@ -1667,26 +1667,24 @@
 %7B%0A          
-  
 fs.writeFile
@@ -1778,31 +1778,12 @@
     
- 
- 
 %7D);%0A
-          break;%0A
     
@@ -2005,24 +2005,24 @@
     %7D);%0A
-
     %7D);%0A
     cb()
@@ -2009,24 +2009,25 @@
 %7D);%0A    %7D);%0A
+%0A
     cb();%0A  

Refactor gulpfile.js