UNPKG

kef-kit-buffet

Version:

buffet kit

132 lines (114 loc) 3.44 kB
'use strict'; const debug = require('debug')('buffet'); const path = require('path'); const chalk = require('chalk'); const fs = require('fs'); const initCmd = require('./lib/init'); const addCmd = require('./lib/add'); const devCmd = require('./lib/dev'); const buildCmd = require('./lib/build'); const testCmd = require('./lib/test'); var HOME = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE; var NICK_PATH = path.join(HOME, '.or', 'nick'); module.exports = function(def) { let Kit = {}; // let user = {}; // hooks. Kit.hooks = { before: function*(cmd, args, opts) { // 在正式执行命令前的前置操作 // throw new Error('msg'); // 抛出异常,将不再执行相关命令,包括 after hook 也不会执行 // return false; // 返回 false,将不再执行相关命令,继续执行 after hook // return true; // 返回 true,继续执行相关命令,包括 after hook }, after: function*(cmd, args, opts) { // 可以执行一些命令清理工作 } }; // 项目初始化JSON定义 Kit.init = initCmd(Kit, def); // 添加页面的命令 Kit.add = addCmd(Kit, def); // 编译调试代码 Kit.dev = devCmd(Kit, def); // def build [--options] // 除非有非常特殊的自定义逻辑,一般不建议自己实现,底层 core 已有统一实现 Kit.build = buildCmd(Kit, def); // def test [type] [--options] // Kit.test = { // description: '对命令描述', // options: {}, // action: function*(type, opts) {} // }; // def publish // 除非有非常特殊的自定义逻辑,一般不建议自己实现,底层 core 已有统一实现 /* Kit.publish = { 'description': '对命令描述', '__force__': true, // 强制自定义 publish 命令 'action': function* (opts) { } }; */ return Kit; }; // { // options: { // app: { // alias: 'app', // description: 'buffet 项目 app 页面项目初始化', // canChoose: true // }, // act: { // alias: 'act', // description: '活动模板项目初始化', // canChoose: true // } // }, // action: function*(opts) { // /* // * opts: 选项 map // * = .test // */ // // debug('writeFileSync abc.json'); // // fs.writeFileSync( // // path.join(process.cwd(), './abc.json'), // // '{'type': 'buffet'}' // // ); // debug('init'); // let type = 'app'; // if (opts.act) { // type = 'act'; // } // yield def.kit.yo.run({ // generator: '@ali/generator-buffet:' + type, // argv: ['--user', JSON.stringify(user)] // }); // } // }; // { // description: '对命令描述,可选,不提供使用默认文案', // options: {}, // arguments: { // type: { // choices: { // // 有了 choices 后,用户执行 def add 将会自动展示列表选择 // c: '添加组件', // -> def add c // p: '添加页面' // -> def add p // }, // description: '对参数描述,不提供就默认' // }, // names: { // description: '对参数描述,不提供就默认' // } // }, // action: function*(type, names, opts) { // /* // * type: 类型(choices 中提供的 key) // * = c // * = p // * names: 名称(一个数组) // * opts: 选项 map // */ // } // };