// These URL paths will be transformed to CN mirrors.
var mirrors = {
  "//developers.google.com"     : "developers.google.cn",
  "//firebase.google.com"       : "firebase.google.cn",
  "//developer.android.com"     : "developer.android.google.cn",
  "//source.android.com"        : "source.android.google.cn",
  "//www.tensorflow.org"        : "tensorflow.google.cn",
  "//angular.io"                : "angular.cn",
  "//translate.google.com"      : "translate.google.cn",
  "//careers.google.com"        : "careers.google.cn",
  "//golang.org"                : "golang.google.cn",
  "//sum.golang.org"            : "sum.golang.google.cn"
}

// These URL paths are not available on CN mirrors, therefore won't be transformed.
var skiplist = [
  "//careers.google.com/jobs"
]

function redirectRules() {
  let res = []
  let id = 1
  for (var index in skiplist) {
    var url = skiplist[index]
    res.push({
      "id": id++,
      "action": {
        "type": "allow"
      },
      "condition": {
        "urlFilter": url,
        "excludedResourceTypes": ["other"],
        "isUrlFilterCaseSensitive": false
      }
    })
  }
  for (let key in mirrors) {
    res.push({
      "id": id++,
      "action": {
        "type": "redirect",
        "redirect": {
          "transform": {
            "host": mirrors[key]
          }
        }
      },
      "condition": {
        "urlFilter": key,
        "excludedResourceTypes": ["other"],
        "isUrlFilterCaseSensitive": false
      }
    })
  }
  return res
}

// Export rules to 'rules.json' (node.js is required)
var fs = require('fs')
fs.writeFile('rules.json', JSON.stringify(redirectRules()), err => {
  if (err) {
    console.error(err)
	return
  } else {
    console.log('rules.json created.')
  }
})

// Generate 'google_cn_devsites.zip' (module 'archiever' is required)
var archiver = require('archiver')
var archive = archiver('zip')
var os = fs.createWriteStream('google_cn_devsites.zip')

os.on('close', function() {
    console.log('google_cn_devsites.zip created.')
})

archive.on('error', function(err){
    console.error(err)
	return
})

archive.pipe(os)

// Files in zip: bg.js, manifest.json, rules.json, off.png, on.png
archive
  .append(fs.createReadStream('bg.js'), {name: 'bg.js'})
  .append(fs.createReadStream('manifest.json'), {name: 'manifest.json'})
  .append(fs.createReadStream('rules.json'), {name: 'rules.json'})
  .append(fs.createReadStream('off.png'), {name: 'off.png'})
  .append(fs.createReadStream('on.png'), {name: 'on.png'})
  .finalize()

@@ -1761,774 +1761,4 @@
 %0A%7D)%0A
-%0A// Generate 'google_cn_devsites.zip' (module 'archiever' is required)%0Avar archiver = require('archiver')%0Avar archive = archiver('zip')%0Avar os = fs.createWriteStream('google_cn_devsites.zip')%0A%0Aos.on('close', function() %7B%0A    console.log('google_cn_devsites.zip created.')%0A%7D)%0A%0Aarchive.on('error', function(err)%7B%0A    console.error(err)%0A%09return%0A%7D)%0A%0Aarchive.pipe(os)%0A%0A// Files in zip: bg.js, manifest.json, rules.json, off.png, on.png%0Aarchive%0A  .append(fs.createReadStream('bg.js'), %7Bname: 'bg.js'%7D)%0A  .append(fs.createReadStream('manifest.json'), %7Bname: 'manifest.json'%7D)%0A  .append(fs.createReadStream('rules.json'), %7Bname: 'rules.json'%7D)%0A  .append(fs.createReadStream('off.png'), %7Bname: 'off.png'%7D)%0A  .append(fs.createReadStream('on.png'), %7Bname: 'on.png'%7D)%0A  .finalize()%0A

Remove zip generation logic, which is already in the CLI build rules