all files / commanders/server/ index.js

23.33% Statements 7/30
0% Branches 0/6
25% Functions 1/4
23.33% Lines 7/30
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72                                                                                                                                 
 
 
exports.name = 'server';
exports.usage = '[command] [options]';
exports.desc = 'tools for the dev server';
 
exports.register = function (commander) {
  commander
    .action(function (...args) {
 
      /* eslint-disable  */    
      const tpl = require('chameleon-templates');
      const inquirer = require('inquirer');
      const fse = require('fs-extra');
      /* eslint-disable  */  
 
      // 不能删除
      var options = args.pop(); // eslint-disable-line  
      var cmd = args.shift();
      if (cmd) {
        handlerCmd(cmd);
      } else {
        let questions = [{
          type: 'list',
          name: 'type',
          message: 'Which do you want to do?',
          choices: [
            'init',
            'open'
          ]
        }]
        inquirer.prompt(questions).then(answers => {
          handlerCmd(answers.type)
        })
      }
 
      function handlerCmd(cmd) {
        switch (cmd) {
          case 'open':
            cml.utils.open(cml.utils.getDevServerPath());
            break;
          case 'init':
            fse.copySync(tpl.serverTpl, cml.utils.getDevServerPath());
            cml.log.notice(`already init php server to ${cml.utils.getDevServerPath()}`)
            cml.log.notice(`you can use 'chameleon server open' to open the server workspace`)
            break;
          case 'clean':
            fse.emptyDirSync(cml.utils.getDevServerPath());
            cml.log.notice(`clean success!`)
            break;
          default:
            break;
 
        }
      }
    })
  commander.on('--help', function() {
    var cmd = `
  Commands:
    open   open the php server directory
    init   initialize the php server framework
    clean  clean server files
  Examples:
    cml server open
    cml server init
    cml server clean
    `
    console.log(cmd)
  })
 
}