<commit_before>#!/usr/bin/env node

/* eslint-disable quotes */
const fs = require('fs');
const crypto = require('crypto');

/**
 * return a fixed length random string from array
 * @param array
 * @param len
 * @returns {string}
 */
function random(array, len) {
  const size = array.length;
  const randomIndexes = crypto.randomBytes(len).toJSON().data;
  return randomIndexes.map((char) => array[char % size]).join('');
}

const key = random('<KEY>', 16);

const clientJs = `module.exports = {
  // local hostname or ip address
  // For client, act as a Socks5/Socks4/HTTP server.
  // For server, act as a blinksocks server.
  host: "localhost",
  // local port to be listen on
  port: 1080,
  // a list of blinksocks/shadowsocks server(client side only)
  servers: [
    {
      // allow to use this server or not
      enabled: true,
      // the transport layer, "tcp" or "udp"
      transport: "tcp",
      // server host name or ip address
      host: "example.com",
      // server port
      port: 4321,
      // a secret key for encryption/description
      key: "${key}",
      // presets to process data stream
      // DO NOT modify the first preset if you don't know what it is.
      // Take care the order of those presets, read the docs before changing them.
      presets: [
        {
          // preset name
          name: "ss-base",
          // preset parameters
          params: {}
        },
        {
          name: "ss-aead-cipher",
          params: {
            method: "aes-256-gcm",
            info: "ss-subkey"
          }
        }
      ]
    }
  ],
  // an ip list of DNS server
  dns: [],
  // DNS cache expiration time in seconds
  dns_expire: 3600,
  // close inactive connection after timeout seconds
  timeout: 600,
  // collect performance statistics
  profile: false,
  // hot-reload when this file changed
  watch: true,
  // log at the level, "error", "warn", "info", "verbose", "debug" or "silly"
  log_level: "info"
};
`;

const serverJs = `module.exports = {
  // local hostname or ip address
  // For client, act as a Socks5/Socks4/HTTP server.
  // For server, act as a blinksocks server.
  host: "0.0.0.0",
  // local port to be listen on
  port: 4321,
  // the transport layer, "tcp" or "udp"
  transport: "tcp",
  // a secret key for encryption/description
  key: "${key}",
  // presets to process data stream
  // DO NOT modify the first preset if you don't know what it is.
  // Take care the order of those presets, read the docs before changing them.
  presets: [
    {
      // preset name
      name: "ss-base",
      // preset parameters
      params: {}
    },
    {
      name: "ss-aead-cipher",
      params: {
        method: "aes-256-gcm",
        info: "ss-subkey"
      }
    }
  ],
  // an ip list of DNS server
  dns: [],
  // DNS cache expiration time in seconds
  dns_expire: 3600,
  // redirect data to here once preset fail to process(server side only)
  // Should be formed with "host:port".
  redirect: "",
  // close inactive connection after timeout seconds
  timeout: 600,
  // collect performance statistics
  profile: false,
  // hot-reload when this file changed
  watch: true,
  // log at the level, "error", "warn", "info", "verbose", "debug" or "silly"
  log_level: "info"
};
`;

fs.writeFileSync('blinksocks.client.js', clientJs);
fs.writeFileSync('blinksocks.server.js', serverJs);<commit_msg>bin: generate .json instead of .js and remove all comments in cli-init.js<commit_after>#!/usr/bin/env node

/* eslint-disable quotes */
const fs = require('fs');
const crypto = require('crypto');

/**
 * return a fixed length random string from array
 * @param array
 * @param len
 * @returns {string}
 */
function random(array, len) {
  const size = array.length;
  const randomIndexes = crypto.randomBytes(len).toJSON().data;
  return randomIndexes.map((char) => array[char % size]).join('');
}

const key = random('<KEY>', 16);

const clientJs = `{
  "host": "localhost",
  "port": 1080,
  "servers": [
    {
      "enabled": true,
      "transport": "tcp",
      "host": "example.com",
      "port": 4321,
      "key": "${key}",
      "presets": [
        {
          "name": "ss-base",
          "params": {}
        },
        {
          "name": "ss-aead-cipher",
          "params": {
            "method": "aes-256-gcm",
            "info": "ss-subkey"
          }
        }
      ]
    }
  ],
  "dns": [],
  "dns_expire": 3600,
  "timeout": 600,
  "profile": false,
  "watch": false,
  "log_level": "info"
}`;

const serverJs = `{
  "host": "0.0.0.0",
  "port": 4321,
  "transport": "tcp",
  "key": "${key}",
  "presets": [
    {
      "name": "ss-base",
      "params": {}
    },
    {
      "name": "ss-aead-cipher",
      "params": {
        "method": "aes-256-gcm",
        "info": "ss-subkey"
      }
    }
  ],
  "dns": [],
  "dns_expire": 3600,
  "redirect": "",
  "timeout": 600,
  "profile": false,
  "watch": false,
  "log_level": "info"
}`;

fs.writeFileSync('blinksocks.client.json', clientJs);
fs.writeFileSync('blinksocks.server.json', serverJs);

console.log('> Generated blinksocks.client.json and blinksocks.server.json');
console.log('> For explanation to each option, please refer to docs/config/README.md');
{'fraction_non_alphanumeric': 0.15399348783757902, 'fraction_numerical': 0.015322735108216816, 'mean_word_length': 2.3931124106562702, 'pattern_counts': {'":': 39, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1404405', 'n_tokens_mistral': 1780, 'n_tokens_neox': 1705, 'n_words': 515}