From aa6dbaacdfff60163acb3f9136eb2745cb8c1782 Mon Sep 17 00:00:00 2001 From: muniz <1160007652@qq.com> Date: Mon, 30 Nov 2020 16:00:21 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(create|cli):=20=E5=8E=BB=E9=99=A4?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=91=BD=E4=BB=A4=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E5=BC=80=E5=8F=91create=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit affects: @muniz/cli, @muniz/muniz-plugin-create cli 主控制器,删除 执行插件默认命令的功能 create 插件增加PC、H5、Extensions、Plugin模版入口 create增加lib处理库 create删除ink开发方式 --- .../@muniz/cli/dist/configs/locales/en-US.js | 2 + .../@muniz/cli/dist/configs/locales/zh-CN.js | 2 + packages/@muniz/cli/dist/configs/system.json | 11 +- .../dist/core/middleWare/helpCommand/index.js | 10 +- .../dist/core/middleWare/isCommand/index.js | 17 +- .../dist/core/middleWare/mergeArgv/index.js | 22 +- .../dist/core/middleWare/runCommand/index.js | 22 +- .../@muniz/cli/src/configs/locales/en-US.js | 2 + .../@muniz/cli/src/configs/locales/zh-CN.js | 2 + .../src/core/middleWare/helpCommand/index.js | 10 +- .../src/core/middleWare/isCommand/index.js | 14 +- .../src/core/middleWare/mergeArgv/index.js | 17 +- .../src/core/middleWare/runCommand/index.js | 15 +- .../dist/command/Create/index.js | 206 ------------------ .../dist/command/Update/index.js | 57 ----- .../dist/configs/commandHelp.json | 2 +- .../@muniz/muniz-plugin-create/dist/index.js | 6 +- .../@muniz/muniz-plugin-create/package.json | 7 +- .../src/command/Create/index.js | 185 ---------------- .../src/command/Extension/index.js | 38 ++++ .../src/command/H5/index.js | 38 ++++ .../src/command/Pc/index.js | 38 ++++ .../src/command/Plugin/index.js | 38 ++++ .../src/command/Update/index.js | 45 ---- .../@muniz/muniz-plugin-create/src/index.js | 4 +- .../src/lib/pkgManger/index.js | 7 + .../src/lib/project/index.js | 6 + .../src/lib/prompts/index.js | 11 + .../src/lib/render/index.js | 4 + 29 files changed, 275 insertions(+), 563 deletions(-) delete mode 100644 packages/@muniz/muniz-plugin-create/dist/command/Create/index.js delete mode 100644 packages/@muniz/muniz-plugin-create/dist/command/Update/index.js delete mode 100644 packages/@muniz/muniz-plugin-create/src/command/Create/index.js create mode 100644 packages/@muniz/muniz-plugin-create/src/command/Extension/index.js create mode 100644 packages/@muniz/muniz-plugin-create/src/command/H5/index.js create mode 100644 packages/@muniz/muniz-plugin-create/src/command/Pc/index.js create mode 100644 packages/@muniz/muniz-plugin-create/src/command/Plugin/index.js delete mode 100644 packages/@muniz/muniz-plugin-create/src/command/Update/index.js create mode 100644 packages/@muniz/muniz-plugin-create/src/lib/pkgManger/index.js create mode 100644 packages/@muniz/muniz-plugin-create/src/lib/project/index.js create mode 100644 packages/@muniz/muniz-plugin-create/src/lib/prompts/index.js create mode 100644 packages/@muniz/muniz-plugin-create/src/lib/render/index.js diff --git a/packages/@muniz/cli/dist/configs/locales/en-US.js b/packages/@muniz/cli/dist/configs/locales/en-US.js index ce21040..1f729ba 100644 --- a/packages/@muniz/cli/dist/configs/locales/en-US.js +++ b/packages/@muniz/cli/dist/configs/locales/en-US.js @@ -7,6 +7,8 @@ exports["default"] = void 0; var enUS = { zh_cn: 'Chinese', en_us: 'English', + command: 'command', + options: 'options', language_not_found: '>> The {locale} copy corresponding to the {name} Key was not found <<', help_add_desc: 'add plugin', help_list_desc: 'View the list of plugins', diff --git a/packages/@muniz/cli/dist/configs/locales/zh-CN.js b/packages/@muniz/cli/dist/configs/locales/zh-CN.js index d3e3591..35fbf61 100644 --- a/packages/@muniz/cli/dist/configs/locales/zh-CN.js +++ b/packages/@muniz/cli/dist/configs/locales/zh-CN.js @@ -7,6 +7,8 @@ exports["default"] = void 0; var zhCN = { zh_cn: '中文', en_us: '英文', + command: '命令', + options: '选项', language_not_found: '>> 未找到 {name} 对应的 {locale} 文案 <<', help_add_desc: '添加插件', help_list_desc: '查看插件列表', diff --git a/packages/@muniz/cli/dist/configs/system.json b/packages/@muniz/cli/dist/configs/system.json index 415b8e5..21a4758 100644 --- a/packages/@muniz/cli/dist/configs/system.json +++ b/packages/@muniz/cli/dist/configs/system.json @@ -1,6 +1,11 @@ { - "MUNIZ_CLI_DEBUG": false, + "MUNIZ_CLI_DEBUG": true, "MUNIZ_PLUGIN_DEV": false, "languageLocale": "zhCN", - "plugins": [] -} + "plugins": [ + { + "shortName": "create", + "pkgName": "@muniz/muniz-plugin-create" + } + ] +} \ No newline at end of file diff --git a/packages/@muniz/cli/dist/core/middleWare/helpCommand/index.js b/packages/@muniz/cli/dist/core/middleWare/helpCommand/index.js index c9a335c..8064647 100644 --- a/packages/@muniz/cli/dist/core/middleWare/helpCommand/index.js +++ b/packages/@muniz/cli/dist/core/middleWare/helpCommand/index.js @@ -37,7 +37,7 @@ var helpCommand = function helpCommand(ctx, next) { }], commands: astCommands, usage: { - key: '$ muniz [options]', + key: "$ muniz <".concat(_i18n["default"].getLocale('command'), "> [").concat(_i18n["default"].getLocale('options'), "]"), description: '' } }; @@ -61,7 +61,7 @@ var helpCommand = function helpCommand(ctx, next) { return item.key === argv.command[0]; })[0]; helpData.usage = { - key: "$ muniz ".concat(argv.command[0], " [options]"), + key: "$ muniz ".concat(argv.command[0], " [").concat(_i18n["default"].getLocale('options'), "]"), description: '' }; render( /*#__PURE__*/_react["default"].createElement(_inkUi.Help, { @@ -70,6 +70,10 @@ var helpCommand = function helpCommand(ctx, next) { locale: _i18n["default"].currentLocale })); } else { + helpData.usage = { + key: "$ muniz ".concat(argv.command[0], " <").concat(_i18n["default"].getLocale('command'), "> [").concat(_i18n["default"].getLocale('options'), "]"), + description: '' + }; render( /*#__PURE__*/_react["default"].createElement(_inkUi.Help, { data: helpData, show: "command", @@ -87,7 +91,7 @@ var helpCommand = function helpCommand(ctx, next) { return item.key === argv.command[1]; })[0]; helpData.usage = { - key: "$ muniz ".concat(argv.command[1], " [options]"), + key: "$ muniz ".concat(argv.command[1], " [").concat(_i18n["default"].getLocale('options'), "]"), description: '' }; render( /*#__PURE__*/_react["default"].createElement(_inkUi.Help, { diff --git a/packages/@muniz/cli/dist/core/middleWare/isCommand/index.js b/packages/@muniz/cli/dist/core/middleWare/isCommand/index.js index a4beee0..e8a6640 100644 --- a/packages/@muniz/cli/dist/core/middleWare/isCommand/index.js +++ b/packages/@muniz/cli/dist/core/middleWare/isCommand/index.js @@ -32,7 +32,7 @@ var MunizConfig = require('../../../configs/system.json'); */ var isCommand = /*#__PURE__*/function () { var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(ctx, next) { - var argv, render, isCliCommand, pluginPkgName, _tempPkgPath, pluginConfig, _argv$options, _argv$options2, _argv$options3; + var argv, render, isCliCommand, _argv$options, pluginPkgName, _tempPkgPath, pluginConfig, _argv$options2, _argv$options3, _argv$options4; return _regenerator["default"].wrap(function _callee$(_context) { while (1) { @@ -152,11 +152,14 @@ var isCommand = /*#__PURE__*/function () { locale: MunizConfig.languageLocale }); - if (argv.command.length < 2) { - if ((pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.defaultCommand) && !['', 'function', 'undefined'].includes(pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.defaultCommand)) {// argv.command.push(pluginConfig.defaultCommand); - } else { - argv.options['help'] = true; - } + if (argv.command.length < 2 && !((_argv$options = argv.options) === null || _argv$options === void 0 ? void 0 : _argv$options.help)) { + // if (pluginConfig?.defaultCommand && !['', 'function', 'undefined'].includes(pluginConfig?.defaultCommand)) { + // argv.command.push(pluginConfig.defaultCommand); + // console.log(argv); + // } else { + // argv.options['help'] = true; + // } + argv.options['help'] = true; } _context.next = 31; @@ -180,7 +183,7 @@ var isCommand = /*#__PURE__*/function () { * 如果是 --version,-V 参数,放行 next() * */ - if (Object.keys(argv.options).length >= 0 && !(((_argv$options = argv.options) === null || _argv$options === void 0 ? void 0 : _argv$options.version) || ((_argv$options2 = argv.options) === null || _argv$options2 === void 0 ? void 0 : _argv$options2.v) || ((_argv$options3 = argv.options) === null || _argv$options3 === void 0 ? void 0 : _argv$options3.mode))) { + if (Object.keys(argv.options).length >= 0 && !(((_argv$options2 = argv.options) === null || _argv$options2 === void 0 ? void 0 : _argv$options2.version) || ((_argv$options3 = argv.options) === null || _argv$options3 === void 0 ? void 0 : _argv$options3.v) || ((_argv$options4 = argv.options) === null || _argv$options4 === void 0 ? void 0 : _argv$options4.mode))) { argv.options['help'] = true; } diff --git a/packages/@muniz/cli/dist/core/middleWare/mergeArgv/index.js b/packages/@muniz/cli/dist/core/middleWare/mergeArgv/index.js index b467f64..1078ada 100644 --- a/packages/@muniz/cli/dist/core/middleWare/mergeArgv/index.js +++ b/packages/@muniz/cli/dist/core/middleWare/mergeArgv/index.js @@ -42,19 +42,17 @@ var mergeArgv = /*#__PURE__*/function () { } else { pluginConfig = require(path.join(ctx.pkgPath, '/dist/index.js'))["default"]({ locale: MunizConfig.languageLocale - }); + }); // if (argv.command.length < 2) { + // if (pluginConfig?.defaultCommand && !['', 'function', 'undefined'].includes(pluginConfig?.defaultCommand)) { + // _astCommands = astCommands.filter((item) => item.key === pluginConfig.defaultCommand); + // } + // } else { + // _astCommands = astCommands.filter((item) => item.key === argv.command[1]); + // } - if (argv.command.length < 2) { - if ((pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.defaultCommand) && !['', 'function', 'undefined'].includes(pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.defaultCommand)) { - _astCommands = astCommands.filter(function (item) { - return item.key === pluginConfig.defaultCommand; - }); - } - } else { - _astCommands = astCommands.filter(function (item) { - return item.key === argv.command[1]; - }); - } + _astCommands = astCommands.filter(function (item) { + return item.key === argv.command[1]; + }); } if (Object.keys(argv.options).length > 0) { diff --git a/packages/@muniz/cli/dist/core/middleWare/runCommand/index.js b/packages/@muniz/cli/dist/core/middleWare/runCommand/index.js index caaa8a5..0b33de8 100644 --- a/packages/@muniz/cli/dist/core/middleWare/runCommand/index.js +++ b/packages/@muniz/cli/dist/core/middleWare/runCommand/index.js @@ -49,19 +49,17 @@ var runCommand = /*#__PURE__*/function () { } else { pluginConfig = require(path.join(ctx.pkgPath, '/dist/index.js'))["default"]({ locale: MunizConfig.languageLocale - }); + }); // if (argv.command.length < 2) { + // if (pluginConfig?.defaultCommand && !['', 'function', 'undefined'].includes(pluginConfig?.defaultCommand)) { + // _astCommands = astCommands.filter((item) => item.key === pluginConfig.defaultCommand); + // } + // } else { + // _astCommands = astCommands.filter((item) => item.key === argv.command[1]); + // } - if (argv.command.length < 2) { - if ((pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.defaultCommand) && !['', 'function', 'undefined'].includes(pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.defaultCommand)) { - _astCommands = astCommands.filter(function (item) { - return item.key === pluginConfig.defaultCommand; - }); - } - } else { - _astCommands = astCommands.filter(function (item) { - return item.key === argv.command[1]; - }); - } + _astCommands = astCommands.filter(function (item) { + return item.key === argv.command[1]; + }); } if (_astCommands.length === 0) { diff --git a/packages/@muniz/cli/src/configs/locales/en-US.js b/packages/@muniz/cli/src/configs/locales/en-US.js index 76ae1a2..23f9cb4 100644 --- a/packages/@muniz/cli/src/configs/locales/en-US.js +++ b/packages/@muniz/cli/src/configs/locales/en-US.js @@ -1,6 +1,8 @@ const enUS = { zh_cn: 'Chinese', en_us: 'English', + command: 'command', + options: 'options', language_not_found: '>> The {locale} copy corresponding to the {name} Key was not found <<', help_add_desc: 'add plugin', help_list_desc: 'View the list of plugins', diff --git a/packages/@muniz/cli/src/configs/locales/zh-CN.js b/packages/@muniz/cli/src/configs/locales/zh-CN.js index 446f71e..ea46915 100644 --- a/packages/@muniz/cli/src/configs/locales/zh-CN.js +++ b/packages/@muniz/cli/src/configs/locales/zh-CN.js @@ -1,6 +1,8 @@ const zhCN = { zh_cn: '中文', en_us: '英文', + command: '命令', + options: '选项', language_not_found: '>> 未找到 {name} 对应的 {locale} 文案 <<', help_add_desc: '添加插件', help_list_desc: '查看插件列表', diff --git a/packages/@muniz/cli/src/core/middleWare/helpCommand/index.js b/packages/@muniz/cli/src/core/middleWare/helpCommand/index.js index 2e3b7ee..8e7c4b1 100644 --- a/packages/@muniz/cli/src/core/middleWare/helpCommand/index.js +++ b/packages/@muniz/cli/src/core/middleWare/helpCommand/index.js @@ -24,7 +24,7 @@ const helpCommand = (ctx, next) => { }, ], commands: astCommands, - usage: { key: '$ muniz [options]', description: '' }, + usage: { key: `$ muniz <${i18n.getLocale('command')}> [${i18n.getLocale('options')}]`, description: '' }, }; switch (argv.command.length) { case 0: { @@ -34,17 +34,21 @@ const helpCommand = (ctx, next) => { case 1: { if (ctx.env.command === 'cli') { helpData.commands = astCommands.filter((item) => item.key === argv.command[0])[0]; - helpData.usage = { key: `$ muniz ${argv.command[0]} [options]`, description: '' }; + helpData.usage = { key: `$ muniz ${argv.command[0]} [${i18n.getLocale('options')}]`, description: '' }; render(); } else { + helpData.usage = { + key: `$ muniz ${argv.command[0]} <${i18n.getLocale('command')}> [${i18n.getLocale('options')}]`, + description: '', + }; render(); } break; } default: { helpData.commands = astCommands.filter((item) => item.key === argv.command[1])[0]; - helpData.usage = { key: `$ muniz ${argv.command[1]} [options]`, description: '' }; + helpData.usage = { key: `$ muniz ${argv.command[1]} [${i18n.getLocale('options')}]`, description: '' }; render(); break; } diff --git a/packages/@muniz/cli/src/core/middleWare/isCommand/index.js b/packages/@muniz/cli/src/core/middleWare/isCommand/index.js index 15fddf6..96a7254 100644 --- a/packages/@muniz/cli/src/core/middleWare/isCommand/index.js +++ b/packages/@muniz/cli/src/core/middleWare/isCommand/index.js @@ -101,12 +101,14 @@ const isCommand = async (ctx, next) => { locale: MunizConfig.languageLocale, }); - if (argv.command.length < 2) { - if (pluginConfig?.defaultCommand && !['', 'function', 'undefined'].includes(pluginConfig?.defaultCommand)) { - // argv.command.push(pluginConfig.defaultCommand); - } else { - argv.options['help'] = true; - } + if (argv.command.length < 2 && !argv.options?.help) { + // if (pluginConfig?.defaultCommand && !['', 'function', 'undefined'].includes(pluginConfig?.defaultCommand)) { + // argv.command.push(pluginConfig.defaultCommand); + // console.log(argv); + // } else { + // argv.options['help'] = true; + // } + argv.options['help'] = true; } } else { if (argv.command.length > 1) { diff --git a/packages/@muniz/cli/src/core/middleWare/mergeArgv/index.js b/packages/@muniz/cli/src/core/middleWare/mergeArgv/index.js index 0bf5ed5..23ebe05 100644 --- a/packages/@muniz/cli/src/core/middleWare/mergeArgv/index.js +++ b/packages/@muniz/cli/src/core/middleWare/mergeArgv/index.js @@ -17,13 +17,16 @@ const mergeArgv = async (ctx, next) => { const pluginConfig = require(path.join(ctx.pkgPath, '/dist/index.js')).default({ locale: MunizConfig.languageLocale, }); - if (argv.command.length < 2) { - if (pluginConfig?.defaultCommand && !['', 'function', 'undefined'].includes(pluginConfig?.defaultCommand)) { - _astCommands = astCommands.filter((item) => item.key === pluginConfig.defaultCommand); - } - } else { - _astCommands = astCommands.filter((item) => item.key === argv.command[1]); - } + + // if (argv.command.length < 2) { + // if (pluginConfig?.defaultCommand && !['', 'function', 'undefined'].includes(pluginConfig?.defaultCommand)) { + // _astCommands = astCommands.filter((item) => item.key === pluginConfig.defaultCommand); + // } + // } else { + // _astCommands = astCommands.filter((item) => item.key === argv.command[1]); + // } + + _astCommands = astCommands.filter((item) => item.key === argv.command[1]); } if (Object.keys(argv.options).length > 0) { diff --git a/packages/@muniz/cli/src/core/middleWare/runCommand/index.js b/packages/@muniz/cli/src/core/middleWare/runCommand/index.js index 555b581..0b627bf 100644 --- a/packages/@muniz/cli/src/core/middleWare/runCommand/index.js +++ b/packages/@muniz/cli/src/core/middleWare/runCommand/index.js @@ -15,13 +15,14 @@ const runCommand = async (ctx, next) => { const pluginConfig = require(path.join(ctx.pkgPath, '/dist/index.js')).default({ locale: MunizConfig.languageLocale, }); - if (argv.command.length < 2) { - if (pluginConfig?.defaultCommand && !['', 'function', 'undefined'].includes(pluginConfig?.defaultCommand)) { - _astCommands = astCommands.filter((item) => item.key === pluginConfig.defaultCommand); - } - } else { - _astCommands = astCommands.filter((item) => item.key === argv.command[1]); - } + // if (argv.command.length < 2) { + // if (pluginConfig?.defaultCommand && !['', 'function', 'undefined'].includes(pluginConfig?.defaultCommand)) { + // _astCommands = astCommands.filter((item) => item.key === pluginConfig.defaultCommand); + // } + // } else { + // _astCommands = astCommands.filter((item) => item.key === argv.command[1]); + // } + _astCommands = astCommands.filter((item) => item.key === argv.command[1]); } if (_astCommands.length === 0) { diff --git a/packages/@muniz/muniz-plugin-create/dist/command/Create/index.js b/packages/@muniz/muniz-plugin-create/dist/command/Create/index.js deleted file mode 100644 index d2ee6b1..0000000 --- a/packages/@muniz/muniz-plugin-create/dist/command/Create/index.js +++ /dev/null @@ -1,206 +0,0 @@ -"use strict"; - -var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); - -var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports["default"] = void 0; - -var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); - -var _react = _interopRequireWildcard(require("react")); - -var _propTypes = _interopRequireDefault(require("prop-types")); - -var _inkUi = require("@muniz/ink-ui"); - -var _ink = require("ink"); - -var _reactHookForm = require("react-hook-form"); - -var _yup = require("@hookform/resolvers/yup"); - -var yup = _interopRequireWildcard(require("yup")); - -// 表单验证器规则 -var schema = yup.object().shape({ - name: yup.string().required(), - desc: yup.string().required(), - telmplate: yup.string().required() -}); -/** - * @muniz - * @type react - * @description 创建指令 - * */ - -var Create = function Create(props) { - var _useFocusManager = (0, _ink.useFocusManager)(), - focusNext = _useFocusManager.focusNext; - - var _useApp = (0, _ink.useApp)(), - exit = _useApp.exit; // 执行步骤 - - - var _useState = (0, _react.useState)({ - cloneGit: false, - help: false - }), - _useState2 = (0, _slicedToArray2["default"])(_useState, 2), - step = _useState2[0], - setStep = _useState2[1]; // 表单收集 - - - var _useForm = (0, _reactHookForm.useForm)({ - reValidateMode: 'onChange', - mode: 'all', - resolver: (0, _yup.yupResolver)(schema) - }), - control = _useForm.control, - errors = _useForm.errors, - reset = _useForm.reset, - handleSubmit = _useForm.handleSubmit, - getValues = _useForm.getValues, - setValue = _useForm.setValue; // 提交表单数据 - - - var onSubmit = function onSubmit(data) { - setStep(function (state) { - state.cloneGit = true; - state.help = true; - return state; - }); - }; - - return /*#__PURE__*/_react["default"].createElement(_ink.Box, { - flexDirection: "column" - }, /*#__PURE__*/_react["default"].createElement(_ink.Box, { - marginBottom: "1" - }, /*#__PURE__*/_react["default"].createElement(_ink.Text, { - color: "green" - }, "Step-1: \u6536\u96C6\u7528\u6237\u8F93\u5165\u4FE1\u606F")), /*#__PURE__*/_react["default"].createElement(_reactHookForm.Controller, { - control: control, - name: "name", - defaultValue: "", - render: function render(_ref) { - var _errors$name; - - var onChange = _ref.onChange, - onBlur = _ref.onBlur, - value = _ref.value; - return /*#__PURE__*/_react["default"].createElement(_inkUi.TextInput, { - label: "\u540D\u79F0\uFF1A", - value: value, - placeHolder: "\u8BF7\u8F93\u5165\u9879\u76EE\u540D\u79F0", - onChange: onChange, - onBlur: onBlur, - error: (_errors$name = errors.name) === null || _errors$name === void 0 ? void 0 : _errors$name.message - }); - } - }), /*#__PURE__*/_react["default"].createElement(_reactHookForm.Controller, { - control: control, - name: "desc", - defaultValue: "", - render: function render(_ref2) { - var _errors$desc; - - var onChange = _ref2.onChange, - onBlur = _ref2.onBlur, - value = _ref2.value; - return /*#__PURE__*/_react["default"].createElement(_inkUi.TextInput, { - label: "\u63CF\u8FF0\uFF1A", - value: value, - placeHolder: "\u8BF7\u8F93\u5165\u63CF\u8FF0\u4FE1\u606F", - onChange: onChange, - onBlur: onBlur, - error: (_errors$desc = errors.desc) === null || _errors$desc === void 0 ? void 0 : _errors$desc.message - }); - } - }), /*#__PURE__*/_react["default"].createElement(_reactHookForm.Controller, { - control: control, - name: "telmplate", - defaultValue: "", - render: function render(_ref3) { - var _errors$telmplate; - - var onChange = _ref3.onChange, - onBlur = _ref3.onBlur, - value = _ref3.value; - return /*#__PURE__*/_react["default"].createElement(_inkUi.TextInput, { - type: "number", - label: "\u6A21\u7248\uFF1A", - value: value, - placeHolder: "\u8BF7\u9009\u62E9\u521B\u5EFA\u6A21\u7248\u7C7B\u578B", - onChange: onChange, - onBlur: onBlur, - error: (_errors$telmplate = errors.telmplate) === null || _errors$telmplate === void 0 ? void 0 : _errors$telmplate.message - }); - } - }), !step.cloneGit && /*#__PURE__*/_react["default"].createElement(_inkUi.ButtonGroup, { - marginTop: "1" - }, /*#__PURE__*/_react["default"].createElement(_inkUi.Button, { - marginRight: "3", - disabled: Object.keys(errors).length > 0, - interval: "2", - onBlur: handleSubmit(onSubmit) - }, "\u786E\u8BA4"), /*#__PURE__*/_react["default"].createElement(_inkUi.Button, { - interval: 2, - marginRight: "3", - onBlur: function onBlur() { - exit(); - } - }, "\u53D6\u6D88"), /*#__PURE__*/_react["default"].createElement(_inkUi.Button, { - interval: 2, - onBlur: function onBlur() { - reset(); - setStep(function (state) { - state.cloneGit = false; - return state; - }); - setTimeout(function () { - focusNext(); - }, 100); - } - }, "\u91CD\u7F6E")), step.cloneGit && /*#__PURE__*/_react["default"].createElement(_ink.Box, { - marginTop: "1", - flexDirection: "column" - }, /*#__PURE__*/_react["default"].createElement(_ink.Text, { - color: "green" - }, "Step-2: \u5F00\u59CB\u514B\u9686\u6A21\u7248\u5DE5\u7A0B"), /*#__PURE__*/_react["default"].createElement(_ink.Box, null, /*#__PURE__*/_react["default"].createElement(_ink.Text, null, "\u514B\u9686\u5B8C\u6BD5\uFF1A100%"))), step.help && /*#__PURE__*/_react["default"].createElement(_ink.Box, { - marginTop: "1", - flexDirection: "column" - }, /*#__PURE__*/_react["default"].createElement(_ink.Text, { - color: "green" - }, "Step-3: \u4F7F\u7528\u5E2E\u52A9"), /*#__PURE__*/_react["default"].createElement(_ink.Text, null, "\u8FDB\u5165\u9879\u76EE: cd testProject"), /*#__PURE__*/_react["default"].createElement(_ink.Text, null, "\u8FDB\u5165\u9879\u76EE: npm install"))); -}; - -Create.propTypes = { - /** - * @muniz - * @description falgs哈哈 - */ - flags: _propTypes["default"].string, - - /** - * @muniz - * @description Number类型转换 - */ - count: _propTypes["default"].number, - - /** - * @muniz - * @description 生成项目的名称 - * @alias n - */ - isGit: _propTypes["default"].bool -}; -Create.defaultProps = { - flags: 'wowowoowqqqqqqq', - isGit: false, - count: 1 -}; -var _default = Create; -exports["default"] = _default; \ No newline at end of file diff --git a/packages/@muniz/muniz-plugin-create/dist/command/Update/index.js b/packages/@muniz/muniz-plugin-create/dist/command/Update/index.js deleted file mode 100644 index f72e316..0000000 --- a/packages/@muniz/muniz-plugin-create/dist/command/Update/index.js +++ /dev/null @@ -1,57 +0,0 @@ -"use strict"; - -var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports["default"] = void 0; - -var _react = _interopRequireDefault(require("react")); - -var _propTypes = _interopRequireDefault(require("prop-types")); - -var _ink = require("ink"); - -var _i18n = _interopRequireDefault(require("../../configs/i18n")); - -/** - * @muniz - * @type react - * @description 更新模版命令 - */ -var Update = function Update() { - return /*#__PURE__*/_react["default"].createElement(_ink.Box, { - flexDirection: "column", - padding: 1 - }, /*#__PURE__*/_react["default"].createElement(_ink.Text, null, _i18n["default"].getLocale('command_update_title'))); -}; - -Update.propTypes = { - /** - * @muniz - * @description 描述组件 - * @alias i - */ - inputa: _propTypes["default"].string.isRequired, - - /** - * @muniz - * @positionsArgs 1 - */ - flags: _propTypes["default"].string, - - /** - * @muniz - * @description 生成项目的名称 - * @alias n - */ - isGit: _propTypes["default"].bool -}; -Update.defaultProps = { - inputa: 'ssss', - flags: 'wowowoowqqqqqqq', - isGit: false -}; -var _default = Update; -exports["default"] = _default; \ No newline at end of file diff --git a/packages/@muniz/muniz-plugin-create/dist/configs/commandHelp.json b/packages/@muniz/muniz-plugin-create/dist/configs/commandHelp.json index 61d1527..2fa59ae 100644 --- a/packages/@muniz/muniz-plugin-create/dist/configs/commandHelp.json +++ b/packages/@muniz/muniz-plugin-create/dist/configs/commandHelp.json @@ -1 +1 @@ -{"enUS":[{"key":"create","commandType":"react","description":"创建指令","options":[{"key":"flags","type":"string","description":"falgs哈哈","alias":"","isRequired":false,"default":"wowowoowqqqqqqq"},{"key":"count","type":"number","description":"Number类型转换","alias":"","isRequired":false,"default":1},{"key":"isGit","type":"boolean","description":"生成项目的名称","alias":"n","isRequired":false,"default":false}],"isIndex":false,"name":"Create","path":"Create/index.js"},{"key":"update","commandType":"react","description":"更新模版命令","options":[{"key":"inputa","type":"string","description":"描述组件","alias":"i","isRequired":true,"default":"ssss"},{"key":"flags","type":"string","description":"","alias":"","isRequired":false,"default":"wowowoowqqqqqqq"},{"key":"isGit","type":"boolean","description":"生成项目的名称","alias":"n","isRequired":false,"default":false}],"isIndex":false,"name":"Update","path":"Update/index.js"}],"zhCN":[{"key":"create","commandType":"react","description":"创建指令","options":[{"key":"flags","type":"string","description":"falgs哈哈","alias":"","isRequired":false,"default":"wowowoowqqqqqqq"},{"key":"count","type":"number","description":"Number类型转换","alias":"","isRequired":false,"default":1},{"key":"isGit","type":"boolean","description":"生成项目的名称","alias":"n","isRequired":false,"default":false}],"isIndex":false,"name":"Create","path":"Create/index.js"},{"key":"update","commandType":"react","description":"更新模版命令","options":[{"key":"inputa","type":"string","description":"描述组件","alias":"i","isRequired":true,"default":"ssss"},{"key":"flags","type":"string","description":"","alias":"","isRequired":false,"default":"wowowoowqqqqqqq"},{"key":"isGit","type":"boolean","description":"生成项目的名称","alias":"n","isRequired":false,"default":false}],"isIndex":false,"name":"Update","path":"Update/index.js"}]} +{"enUS":[{"key":"extension","commandType":"function","description":"创建Chrome插件扩展","options":[{"key":"flags","type":"string","description":"falgs哈哈","alias":"","isRequired":false,"default":"wowowoowqqqqqqq"},{"key":"count","type":"number","description":"Number类型转换","alias":"","isRequired":false,"default":1},{"key":"isGit","type":"boolean","description":"生成项目的名称","alias":"n","isRequired":false,"default":false}],"isIndex":false,"name":"Extension","path":"Extension/index.js"},{"key":"h5","commandType":"function","description":"创建H5开发模版","options":[{"key":"flags","type":"string","description":"创建H5开发模版","alias":"","isRequired":false,"default":"wowowoowqqqqqqq"},{"key":"count","type":"number","description":"Number类型转换","alias":"","isRequired":false,"default":1},{"key":"isGit","type":"boolean","description":"生成项目的名称","alias":"n","isRequired":false,"default":false}],"isIndex":false,"name":"H5","path":"H5/index.js"},{"key":"pc","commandType":"function","description":"创建PC端开发模版","options":[{"key":"flags","type":"string","description":"falgs哈哈","alias":"","isRequired":false,"default":"wowowoowqqqqqqq"},{"key":"count","type":"number","description":"Number类型转换","alias":"","isRequired":false,"default":1},{"key":"isGit","type":"boolean","description":"生成项目的名称","alias":"n","isRequired":false,"default":false}],"isIndex":false,"name":"Pc","path":"Pc/index.js"},{"key":"plugin","commandType":"function","description":"创建脚手架插件模版","options":[{"key":"flags","type":"string","description":"falgs哈哈","alias":"","isRequired":false,"default":"wowowoowqqqqqqq"},{"key":"count","type":"number","description":"Number类型转换","alias":"","isRequired":false,"default":1},{"key":"isGit","type":"boolean","description":"生成项目的名称","alias":"n","isRequired":false,"default":false}],"isIndex":false,"name":"Plugin","path":"Plugin/index.js"}],"zhCN":[{"key":"extension","commandType":"function","description":"创建Chrome插件扩展","options":[{"key":"flags","type":"string","description":"falgs哈哈","alias":"","isRequired":false,"default":"wowowoowqqqqqqq"},{"key":"count","type":"number","description":"Number类型转换","alias":"","isRequired":false,"default":1},{"key":"isGit","type":"boolean","description":"生成项目的名称","alias":"n","isRequired":false,"default":false}],"isIndex":false,"name":"Extension","path":"Extension/index.js"},{"key":"h5","commandType":"function","description":"创建H5开发模版","options":[{"key":"flags","type":"string","description":"创建H5开发模版","alias":"","isRequired":false,"default":"wowowoowqqqqqqq"},{"key":"count","type":"number","description":"Number类型转换","alias":"","isRequired":false,"default":1},{"key":"isGit","type":"boolean","description":"生成项目的名称","alias":"n","isRequired":false,"default":false}],"isIndex":false,"name":"H5","path":"H5/index.js"},{"key":"pc","commandType":"function","description":"创建PC端开发模版","options":[{"key":"flags","type":"string","description":"falgs哈哈","alias":"","isRequired":false,"default":"wowowoowqqqqqqq"},{"key":"count","type":"number","description":"Number类型转换","alias":"","isRequired":false,"default":1},{"key":"isGit","type":"boolean","description":"生成项目的名称","alias":"n","isRequired":false,"default":false}],"isIndex":false,"name":"Pc","path":"Pc/index.js"},{"key":"plugin","commandType":"function","description":"创建脚手架插件模版","options":[{"key":"flags","type":"string","description":"falgs哈哈","alias":"","isRequired":false,"default":"wowowoowqqqqqqq"},{"key":"count","type":"number","description":"Number类型转换","alias":"","isRequired":false,"default":1},{"key":"isGit","type":"boolean","description":"生成项目的名称","alias":"n","isRequired":false,"default":false}],"isIndex":false,"name":"Plugin","path":"Plugin/index.js"}]} diff --git a/packages/@muniz/muniz-plugin-create/dist/index.js b/packages/@muniz/muniz-plugin-create/dist/index.js index c9b2ba3..04e2253 100644 --- a/packages/@muniz/muniz-plugin-create/dist/index.js +++ b/packages/@muniz/muniz-plugin-create/dist/index.js @@ -21,8 +21,10 @@ var Life = function Life() { (0, _classCallCheck2["default"])(this, Life); this.isStart = true; // 安装成功后是否立即执行 - this.defaultCommand = 'create'; // 插件默认执行命令, 以 muniz 插件名 运行时,执行那条命令,无配置 为 cli 打印 help 命令 -}; + this.autoUpgrade = false; // 是否动态感知最新版本,以实现自动升级 + // this.defaultCommand = 'create'; // 插件默认执行命令, 以 muniz 插件名 运行时,执行那条命令,无配置 为 cli 打印 help 命令 +} // +; var _default = function _default(props) { var locale = props.locale; // 初始化多语言 diff --git a/packages/@muniz/muniz-plugin-create/package.json b/packages/@muniz/muniz-plugin-create/package.json index 26f8590..0e59737 100755 --- a/packages/@muniz/muniz-plugin-create/package.json +++ b/packages/@muniz/muniz-plugin-create/package.json @@ -32,14 +32,9 @@ "test": "echo \"Error: run tests from root\" && exit 1" }, "dependencies": { - "@hookform/resolvers": "^1.0.0", "@muniz/cli-i18n": "^1.0.18", - "@muniz/ink-ui": "^1.0.18", - "ink": "^3.0.8", "react": "^17.0.1", - "react-hook-form": "^6.9.6", - "react-intl-universal": "^2.4.1", - "yup": "^0.29.3" + "react-intl-universal": "^2.4.1" }, "gitHead": "391b557ac73fcecb98af872ed0f0d642eb9ae60e" } diff --git a/packages/@muniz/muniz-plugin-create/src/command/Create/index.js b/packages/@muniz/muniz-plugin-create/src/command/Create/index.js deleted file mode 100644 index 04d19c1..0000000 --- a/packages/@muniz/muniz-plugin-create/src/command/Create/index.js +++ /dev/null @@ -1,185 +0,0 @@ -import React, { useState } from 'react'; -import PropTypes from 'prop-types'; -import { TextInput, Button, ButtonGroup } from '@muniz/ink-ui'; -import { Box, Text, useApp, useFocusManager } from 'ink'; -import { useForm, Controller } from 'react-hook-form'; -import { yupResolver } from '@hookform/resolvers/yup'; -import * as yup from 'yup'; - -// 表单验证器规则 -const schema = yup.object().shape({ - name: yup.string().required(), - desc: yup.string().required(), - telmplate: yup.string().required(), -}); - -/** - * @muniz - * @type react - * @description 创建指令 - * */ -const Create = (props) => { - const { focusNext } = useFocusManager(); - const { exit } = useApp(); - // 执行步骤 - const [step, setStep] = useState({ - cloneGit: false, - help: false, - }); - // 表单收集 - const { control, errors, reset, handleSubmit, getValues, setValue } = useForm({ - reValidateMode: 'onChange', - mode: 'all', - resolver: yupResolver(schema), - }); - - // 提交表单数据 - const onSubmit = (data) => { - setStep((state) => { - state.cloneGit = true; - state.help = true; - return state; - }); - }; - - return ( - - - Step-1: 收集用户输入信息 - - { - return ( - - ); - }} - /> - { - return ( - - ); - }} - /> - { - return ( - - ); - }} - /> - {!step.cloneGit && ( - - - - - - )} - - {step.cloneGit && ( - - Step-2: 开始克隆模版工程 - - - 克隆完毕:100% - - - )} - - {step.help && ( - - Step-3: 使用帮助 - 进入项目: cd testProject - 进入项目: npm install - - )} - - ); -}; - -Create.propTypes = { - /** - * @muniz - * @description falgs哈哈 - */ - flags: PropTypes.string, - /** - * @muniz - * @description Number类型转换 - */ - count: PropTypes.number, - /** - * @muniz - * @description 生成项目的名称 - * @alias n - */ - isGit: PropTypes.bool, -}; - -Create.defaultProps = { - flags: 'wowowoowqqqqqqq', - isGit: false, - count: 1, -}; - -export default Create; diff --git a/packages/@muniz/muniz-plugin-create/src/command/Extension/index.js b/packages/@muniz/muniz-plugin-create/src/command/Extension/index.js new file mode 100644 index 0000000..1ee87e4 --- /dev/null +++ b/packages/@muniz/muniz-plugin-create/src/command/Extension/index.js @@ -0,0 +1,38 @@ +import React, { useState } from 'react'; +import PropTypes from 'prop-types'; + +/** + * @muniz + * @type function + * @description 创建Chrome插件扩展 + * */ +function Extension(props) { + console.log('创建 Chrome extensions 扩展插件 React 开发模版 , 暂未接入脚手架'); +} + +Extension.propTypes = { + /** + * @muniz + * @description falgs哈哈 + */ + flags: PropTypes.string, + /** + * @muniz + * @description Number类型转换 + */ + count: PropTypes.number, + /** + * @muniz + * @description 生成项目的名称 + * @alias n + */ + isGit: PropTypes.bool, +}; + +Extension.defaultProps = { + flags: 'wowowoowqqqqqqq', + isGit: false, + count: 1, +}; + +export default Extension; diff --git a/packages/@muniz/muniz-plugin-create/src/command/H5/index.js b/packages/@muniz/muniz-plugin-create/src/command/H5/index.js new file mode 100644 index 0000000..c4cbfe6 --- /dev/null +++ b/packages/@muniz/muniz-plugin-create/src/command/H5/index.js @@ -0,0 +1,38 @@ +import React, { useState } from 'react'; +import PropTypes from 'prop-types'; + +/** + * @muniz + * @type function + * @description 创建H5开发模版 + * */ +function H5(props) { + console.log('创建 H5 React 开发模版 , 暂未接入脚手架'); +} + +H5.propTypes = { + /** + * @muniz + * @description 创建H5开发模版 + */ + flags: PropTypes.string, + /** + * @muniz + * @description Number类型转换 + */ + count: PropTypes.number, + /** + * @muniz + * @description 生成项目的名称 + * @alias n + */ + isGit: PropTypes.bool, +}; + +H5.defaultProps = { + flags: 'wowowoowqqqqqqq', + isGit: false, + count: 1, +}; + +export default H5; diff --git a/packages/@muniz/muniz-plugin-create/src/command/Pc/index.js b/packages/@muniz/muniz-plugin-create/src/command/Pc/index.js new file mode 100644 index 0000000..9b0a6a5 --- /dev/null +++ b/packages/@muniz/muniz-plugin-create/src/command/Pc/index.js @@ -0,0 +1,38 @@ +import React, { useState } from 'react'; +import PropTypes from 'prop-types'; + +/** + * @muniz + * @type function + * @description 创建PC端开发模版 + * */ +function Pc(props) { + console.log('创建 PC React 开发模版'); +} + +Pc.propTypes = { + /** + * @muniz + * @description falgs哈哈 + */ + flags: PropTypes.string, + /** + * @muniz + * @description Number类型转换 + */ + count: PropTypes.number, + /** + * @muniz + * @description 生成项目的名称 + * @alias n + */ + isGit: PropTypes.bool, +}; + +Pc.defaultProps = { + flags: 'wowowoowqqqqqqq', + isGit: false, + count: 1, +}; + +export default Pc; diff --git a/packages/@muniz/muniz-plugin-create/src/command/Plugin/index.js b/packages/@muniz/muniz-plugin-create/src/command/Plugin/index.js new file mode 100644 index 0000000..c19bb79 --- /dev/null +++ b/packages/@muniz/muniz-plugin-create/src/command/Plugin/index.js @@ -0,0 +1,38 @@ +import React, { useState } from 'react'; +import PropTypes from 'prop-types'; + +/** + * @muniz + * @type function + * @description 创建脚手架插件模版 + * */ +function Plugin(props) { + console.log('创建 脚手架 Muniz plugin 开发模版'); +} + +Plugin.propTypes = { + /** + * @muniz + * @description falgs哈哈 + */ + flags: PropTypes.string, + /** + * @muniz + * @description Number类型转换 + */ + count: PropTypes.number, + /** + * @muniz + * @description 生成项目的名称 + * @alias n + */ + isGit: PropTypes.bool, +}; + +Plugin.defaultProps = { + flags: 'wowowoowqqqqqqq', + isGit: false, + count: 1, +}; + +export default Plugin; diff --git a/packages/@muniz/muniz-plugin-create/src/command/Update/index.js b/packages/@muniz/muniz-plugin-create/src/command/Update/index.js deleted file mode 100644 index c24dce1..0000000 --- a/packages/@muniz/muniz-plugin-create/src/command/Update/index.js +++ /dev/null @@ -1,45 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import { Text, Box } from 'ink'; -import i18n from '../../configs/i18n'; - -/** - * @muniz - * @type react - * @description 更新模版命令 - */ -const Update = () => { - return ( - - {i18n.getLocale('command_update_title')} - - ); -}; - -Update.propTypes = { - /** - * @muniz - * @description 描述组件 - * @alias i - */ - inputa: PropTypes.string.isRequired, - /** - * @muniz - * @positionsArgs 1 - */ - flags: PropTypes.string, - /** - * @muniz - * @description 生成项目的名称 - * @alias n - */ - isGit: PropTypes.bool, -}; - -Update.defaultProps = { - inputa: 'ssss', - flags: 'wowowoowqqqqqqq', - isGit: false, -}; - -export default Update; diff --git a/packages/@muniz/muniz-plugin-create/src/index.js b/packages/@muniz/muniz-plugin-create/src/index.js index 969554b..40002a2 100644 --- a/packages/@muniz/muniz-plugin-create/src/index.js +++ b/packages/@muniz/muniz-plugin-create/src/index.js @@ -6,8 +6,10 @@ i18n.initI18n(); class Life { constructor() { this.isStart = true; // 安装成功后是否立即执行 - this.defaultCommand = 'create'; // 插件默认执行命令, 以 muniz 插件名 运行时,执行那条命令,无配置 为 cli 打印 help 命令 + this.autoUpgrade = false; // 是否动态感知最新版本,以实现自动升级 + // this.defaultCommand = 'create'; // 插件默认执行命令, 以 muniz 插件名 运行时,执行那条命令,无配置 为 cli 打印 help 命令 } + // } export default (props) => { diff --git a/packages/@muniz/muniz-plugin-create/src/lib/pkgManger/index.js b/packages/@muniz/muniz-plugin-create/src/lib/pkgManger/index.js new file mode 100644 index 0000000..5723e9b --- /dev/null +++ b/packages/@muniz/muniz-plugin-create/src/lib/pkgManger/index.js @@ -0,0 +1,7 @@ +/** + * 包管理器, 负责执行如下事情 + * 1、安装依赖 + * 2、替换项目名称 + * 3、替换项目描述 + * 4、替换项目版本号 + */ diff --git a/packages/@muniz/muniz-plugin-create/src/lib/project/index.js b/packages/@muniz/muniz-plugin-create/src/lib/project/index.js new file mode 100644 index 0000000..608bfe9 --- /dev/null +++ b/packages/@muniz/muniz-plugin-create/src/lib/project/index.js @@ -0,0 +1,6 @@ +/** + * 项目处理库,负责处理如下事情: + * 1、是否已存在带创建的项目 + * 2、通过 Git 拉取项目 + * 3、通过 本地 绝对 路径 拉取项目 + */ diff --git a/packages/@muniz/muniz-plugin-create/src/lib/prompts/index.js b/packages/@muniz/muniz-plugin-create/src/lib/prompts/index.js new file mode 100644 index 0000000..cb1ee33 --- /dev/null +++ b/packages/@muniz/muniz-plugin-create/src/lib/prompts/index.js @@ -0,0 +1,11 @@ +/** + * 提示库,处理如下事情: + * 1、收集项目名称 + * 2、收集项目描述 + * 3、是否启动Git + * + * 4、插件每次运行是否检查更新 + * 5、插件安装完毕是否自动运行 + * + * 6、扩展插件短名称 + */ diff --git a/packages/@muniz/muniz-plugin-create/src/lib/render/index.js b/packages/@muniz/muniz-plugin-create/src/lib/render/index.js new file mode 100644 index 0000000..eb788c9 --- /dev/null +++ b/packages/@muniz/muniz-plugin-create/src/lib/render/index.js @@ -0,0 +1,4 @@ +/** + * 渲染库,负责渲染预设中的内容到模版: + * 1、替换 项目中的 ejs 数据 + */ From 79304e40d5d28c39e360c3fbd8d57998f19d1202 Mon Sep 17 00:00:00 2001 From: muniz <1160007652@qq.com> Date: Mon, 30 Nov 2020 18:13:57 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat(create):=20=E5=BC=80=E5=8F=91=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E6=A8=A1=E7=89=88=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit affects: @muniz/muniz-plugin-create 创建PC插件 --- .../dist/configs/locales/en-US.js | 7 ++- .../dist/configs/locales/zh-CN.js | 7 ++- .../@muniz/muniz-plugin-create/package.json | 2 + .../src/command/Extension/index.js | 6 +- .../src/command/Extension/prompts.js | 9 +++ .../src/command/Pc/index.js | 6 +- .../src/command/Pc/prompts.js | 9 +++ .../src/command/Plugin/index.js | 6 +- .../src/command/Plugin/prompts.js | 31 ++++++++++ .../src/configs/locales/en-US.js | 8 ++- .../src/configs/locales/zh-CN.js | 8 ++- .../src/lib/prompts/index.js | 60 +++++++++++++++---- 12 files changed, 141 insertions(+), 18 deletions(-) create mode 100644 packages/@muniz/muniz-plugin-create/src/command/Extension/prompts.js create mode 100644 packages/@muniz/muniz-plugin-create/src/command/Pc/prompts.js create mode 100644 packages/@muniz/muniz-plugin-create/src/command/Plugin/prompts.js diff --git a/packages/@muniz/muniz-plugin-create/dist/configs/locales/en-US.js b/packages/@muniz/muniz-plugin-create/dist/configs/locales/en-US.js index b374859..2ed8e1e 100644 --- a/packages/@muniz/muniz-plugin-create/dist/configs/locales/en-US.js +++ b/packages/@muniz/muniz-plugin-create/dist/configs/locales/en-US.js @@ -5,7 +5,12 @@ Object.defineProperty(exports, "__esModule", { }); exports["default"] = void 0; var enUS = { - command_update_title: 'update template' + command_pc_desc: 'Create APP development template', + projectName: 'Please enter the project name', + projectDesc: 'Please enter a project description', + extensionShortName: 'Please enter Chrome extension-short name', + isGit: 'Whether to start Git?', + create_project_have_existed: 'Warning: The project already exists, please change the project name' }; var _default = enUS; exports["default"] = _default; \ No newline at end of file diff --git a/packages/@muniz/muniz-plugin-create/dist/configs/locales/zh-CN.js b/packages/@muniz/muniz-plugin-create/dist/configs/locales/zh-CN.js index 2a1757f..439dc8d 100644 --- a/packages/@muniz/muniz-plugin-create/dist/configs/locales/zh-CN.js +++ b/packages/@muniz/muniz-plugin-create/dist/configs/locales/zh-CN.js @@ -5,7 +5,12 @@ Object.defineProperty(exports, "__esModule", { }); exports["default"] = void 0; var zhCN = { - command_update_title: '更新模版' + command_pc_desc: '创建PC开发模版', + projectName: '请输入项目名称', + projectDesc: '请输入项目描述', + extensionShortName: '请输入Chrome扩展-短名称', + isGit: '是否启动Git', + create_project_have_existed: '警告: 该项目已存在,请重新更换一个项目名称' }; var _default = zhCN; exports["default"] = _default; \ No newline at end of file diff --git a/packages/@muniz/muniz-plugin-create/package.json b/packages/@muniz/muniz-plugin-create/package.json index 0e59737..ad7c9d1 100755 --- a/packages/@muniz/muniz-plugin-create/package.json +++ b/packages/@muniz/muniz-plugin-create/package.json @@ -33,6 +33,8 @@ }, "dependencies": { "@muniz/cli-i18n": "^1.0.18", + "chalk": "^4.1.0", + "fs-extra": "^9.0.1", "react": "^17.0.1", "react-intl-universal": "^2.4.1" }, diff --git a/packages/@muniz/muniz-plugin-create/src/command/Extension/index.js b/packages/@muniz/muniz-plugin-create/src/command/Extension/index.js index 1ee87e4..ea2177f 100644 --- a/packages/@muniz/muniz-plugin-create/src/command/Extension/index.js +++ b/packages/@muniz/muniz-plugin-create/src/command/Extension/index.js @@ -1,12 +1,16 @@ import React, { useState } from 'react'; import PropTypes from 'prop-types'; +import prompts from './prompts'; + /** * @muniz * @type function * @description 创建Chrome插件扩展 * */ -function Extension(props) { +async function Extension(props) { + const anwser = await prompts(); + console.log(anwser); console.log('创建 Chrome extensions 扩展插件 React 开发模版 , 暂未接入脚手架'); } diff --git a/packages/@muniz/muniz-plugin-create/src/command/Extension/prompts.js b/packages/@muniz/muniz-plugin-create/src/command/Extension/prompts.js new file mode 100644 index 0000000..5848951 --- /dev/null +++ b/packages/@muniz/muniz-plugin-create/src/command/Extension/prompts.js @@ -0,0 +1,9 @@ +import { prokectName, projectDesc, isGit, extensionShortName } from '../../lib/prompts'; +import i18n from '../../configs/i18n'; + +const inquirer = require('inquirer'); + +export default async () => { + const answers = await inquirer.prompt([prokectName, extensionShortName, projectDesc, isGit]); + return answers; +}; diff --git a/packages/@muniz/muniz-plugin-create/src/command/Pc/index.js b/packages/@muniz/muniz-plugin-create/src/command/Pc/index.js index 9b0a6a5..b36cf20 100644 --- a/packages/@muniz/muniz-plugin-create/src/command/Pc/index.js +++ b/packages/@muniz/muniz-plugin-create/src/command/Pc/index.js @@ -1,12 +1,16 @@ import React, { useState } from 'react'; import PropTypes from 'prop-types'; +import prompts from './prompts'; + /** * @muniz * @type function * @description 创建PC端开发模版 * */ -function Pc(props) { +async function Pc(props) { + const anwser = await prompts(); + console.log(anwser); console.log('创建 PC React 开发模版'); } diff --git a/packages/@muniz/muniz-plugin-create/src/command/Pc/prompts.js b/packages/@muniz/muniz-plugin-create/src/command/Pc/prompts.js new file mode 100644 index 0000000..d0914e3 --- /dev/null +++ b/packages/@muniz/muniz-plugin-create/src/command/Pc/prompts.js @@ -0,0 +1,9 @@ +const inquirer = require('inquirer'); + +import { prokectName, projectDesc, isGit } from '../../lib/prompts'; +import i18n from '../../configs/i18n'; + +export default async () => { + const answers = await inquirer.prompt([prokectName, projectDesc, isGit]); + return answers; +}; diff --git a/packages/@muniz/muniz-plugin-create/src/command/Plugin/index.js b/packages/@muniz/muniz-plugin-create/src/command/Plugin/index.js index c19bb79..47d86fc 100644 --- a/packages/@muniz/muniz-plugin-create/src/command/Plugin/index.js +++ b/packages/@muniz/muniz-plugin-create/src/command/Plugin/index.js @@ -1,12 +1,16 @@ import React, { useState } from 'react'; import PropTypes from 'prop-types'; +import prompts from './prompts'; + /** * @muniz * @type function * @description 创建脚手架插件模版 * */ -function Plugin(props) { +async function Plugin(props) { + const anwser = await prompts(); + console.log(anwser); console.log('创建 脚手架 Muniz plugin 开发模版'); } diff --git a/packages/@muniz/muniz-plugin-create/src/command/Plugin/prompts.js b/packages/@muniz/muniz-plugin-create/src/command/Plugin/prompts.js new file mode 100644 index 0000000..541233e --- /dev/null +++ b/packages/@muniz/muniz-plugin-create/src/command/Plugin/prompts.js @@ -0,0 +1,31 @@ +import { prokectName, projectDesc, isGit } from '../../lib/prompts'; +import i18n from '../../configs/i18n'; + +const fse = require('fs-extra'); +const path = require('path'); +const chalk = require('chalk'); +const inquirer = require('inquirer'); + +export default async () => { + const answers = await inquirer.prompt([ + { + ...prokectName, + validate: (projectName) => { + // 生成项目目录 + const destDir = path.resolve(process.cwd(), `muniz-plugin-${projectName}` || '.'); + + // 判断项目是否有重名的文件夹 + const isProjectExist = fse.existsSync(destDir); + + if (isProjectExist) { + return i18n.getLocale('create_project_have_existed'); + } else { + return true; + } + }, + }, + projectDesc, + isGit, + ]); + return answers; +}; diff --git a/packages/@muniz/muniz-plugin-create/src/configs/locales/en-US.js b/packages/@muniz/muniz-plugin-create/src/configs/locales/en-US.js index 36e85fe..4f9f9c5 100644 --- a/packages/@muniz/muniz-plugin-create/src/configs/locales/en-US.js +++ b/packages/@muniz/muniz-plugin-create/src/configs/locales/en-US.js @@ -1,5 +1,11 @@ const enUS = { - command_update_title: 'update template', + command_pc_desc: 'Create APP development template', + projectName: 'Please enter the project name', + projectDesc: 'Please enter a project description', + extensionShortName: 'Please enter Chrome extension-short name', + isGit: 'Whether to start Git?', + + create_project_have_existed: 'Warning: The project already exists, please change the project name', }; export default enUS; diff --git a/packages/@muniz/muniz-plugin-create/src/configs/locales/zh-CN.js b/packages/@muniz/muniz-plugin-create/src/configs/locales/zh-CN.js index d0ad8a9..a010c47 100644 --- a/packages/@muniz/muniz-plugin-create/src/configs/locales/zh-CN.js +++ b/packages/@muniz/muniz-plugin-create/src/configs/locales/zh-CN.js @@ -1,5 +1,11 @@ const zhCN = { - command_update_title: '更新模版', + command_pc_desc: '创建PC开发模版', + projectName: '请输入项目名称', + projectDesc: '请输入项目描述', + extensionShortName: '请输入Chrome扩展-短名称', + isGit: '是否启动Git', + + create_project_have_existed: '警告: 该项目已存在,请重新更换一个项目名称', }; export default zhCN; diff --git a/packages/@muniz/muniz-plugin-create/src/lib/prompts/index.js b/packages/@muniz/muniz-plugin-create/src/lib/prompts/index.js index cb1ee33..4cbb154 100644 --- a/packages/@muniz/muniz-plugin-create/src/lib/prompts/index.js +++ b/packages/@muniz/muniz-plugin-create/src/lib/prompts/index.js @@ -1,11 +1,49 @@ -/** - * 提示库,处理如下事情: - * 1、收集项目名称 - * 2、收集项目描述 - * 3、是否启动Git - * - * 4、插件每次运行是否检查更新 - * 5、插件安装完毕是否自动运行 - * - * 6、扩展插件短名称 - */ +import i18n from '../../configs/i18n'; + +const fse = require('fs-extra'); +const path = require('path'); + +// 1、收集项目名称 +export const prokectName = { + type: 'input', + message: i18n.getLocale('projectName'), + name: 'prokectName', + default: '', + validate: (projectName) => { + // 生成项目目录 + const destDir = path.resolve(process.cwd(), projectName || '.'); + + // 判断项目是否有重名的文件夹 + const isProjectExist = fse.existsSync(destDir); + + if (isProjectExist) { + return i18n.getLocale('create_project_have_existed'); + } else { + return true; + } + }, +}; + +// 2、收集项目描述 +export const projectDesc = { + type: 'input', + message: i18n.getLocale('projectDesc'), + name: 'projectDesc', + default: '', +}; + +// 3、是否启动Git +export const isGit = { + type: 'confirm', + message: i18n.getLocale('isGit'), + name: 'isGit', + default: true, +}; + +// 4、chrome 扩展短名称 +export const extensionShortName = { + type: 'input', + message: i18n.getLocale('extensionShortName'), + name: 'extensionShortName', + default: '', +};