UNPKG

kef-kit-buffet

Version:

buffet kit

72 lines (67 loc) 2.29 kB
'use strict'; const fs = require('fs'); const debug = require('debug')('buffet'); const chalk = require('chalk'); module.exports = function (Kit, def) { // 定义环境变量 return { description: 'buffet调试', options: { entryPage: { alias: 't', description: '页面筛选,例如 -t=index,选择只编译 index 页面' }, https: { description: '本地启动 https 服务器', default: false }, }, handler: function* (args, kwargs) { let abcOptions = def.lookupABCJson(); let builder = abcOptions.builder; def.log.verbose(abcOptions); // todo checkport // 初始值 传递环境变量 todo remove 用参数传递 process.env.BUILD_ENV_TARGET = ''; process.env.BUILD_DEBUG = 'dev'; process.env.NODE_ENV = 'dev'; process.env.BUILD_DEBUG_IP = false; process.env.BUILD_DEBUG_PORT = kwargs.port; process.env.BUILD_STYLE_EXTENSION = process.env.BUILD_STYLE_EXTENSION || '.less'; // 如果用户有指定再赋值 if (kwargs.entryPage) { process.env.BUILD_ENV_TARGET = kwargs.entryPage; } /* * opts: * - base: 基准目录(默认:process.cwd()) * - port: 服务器端口 * - ip: 服务器 ip 地址 * - host: 服务器 host 地址 * - tmpDir: 服务器临时目录 * 其他调用 def.kit.reflect.start 时传递的参数都会合并到 opts 对象中 */ let refletParams = { builderReflect: builder + '/reflect.js', port: kwargs.port, openUrl: kwargs.openUrl, livereload: !kwargs.noLivereload, customLivereload: true, notShowOpenTip: true, ip: '127.0.0.1', https: kwargs.https, }; let localip = yield def.util.localip(); // 调用 def server let protocol = kwargs.https ? 'https' : 'http'; const url = `${protocol}://127.0.0.1:${kwargs.port}`; const exUrl = `${protocol}://${localip}:${kwargs.port}`; console.log(''); console.log('buffet serer at:'); console.log(' '+chalk.cyan(url)); console.log(' ' + chalk.cyan(exUrl)); console.log(''); yield def.kit.reflect.start(refletParams); } }; };