All files / src/config schema.js

50% Statements 6/12
20% Branches 2/10
100% Functions 1/1
54.55% Lines 6/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 581x 1x 1x   1x                         19x                   19x                                                            
const buffer = require('crypto').randomBytes(60);
const token = buffer.toString('base64').replace(/\//g,'_').replace(/\+/g,'-');
const path = require('path');
 
module.exports = {
  __root: 'port',
  port: {
    default: 3000,
    type: Number
  },
  public: {
    default: 'public',
    type: [String, Boolean],
    file: true,
    find: (value, option) => {
      // console.log('Global:', value, Object.keys(option));
      // console.log(process.platform, value);
      Iif (/^win/.test(process.platform) && value === 'C:\\Users\\Public') {
        // return (arg.public || schema.public.default);
        // return path.normalize(path.join(process.cwd(), 'test'));
        value = option.arg.public || option.schema.default;
        console.log('LOG:', option.arg.public, option.schema.default);
 
        if (!value) return;
        const fullpath = path.isAbsolute(value) ? value : path.join(process.cwd(), value);
        return path.normalize(fullpath);
      }
      return value;
    }
  },
  env: {
    default: 'development',
    enum: ['production', 'test', 'development'],
    arg: false,
    env: 'NODE_ENV'
  },
  engine: {
    default: 'pug',
    type: [String, Object]
  },
  secret: {
    default: 'secret-' + token,
    type: String,
    arg: false
    // TODO: integrate this
    // if (options.secret === 'your-random-string-here') {
    //   throw new ServerError('/server/options/secret/example');
    // }
    //
    // if (/^secret-/.test(options.secret) && options.verbose) {
    //   console.log(new ServerError('/server/options/secret/generated'));
    // }
  },
  'x-powered-by': {
    default: false
  }
};