Skip to content

Commit

Permalink
feat(muniz-plugin-create): 完成create插件的pc命令
Browse files Browse the repository at this point in the history
affects: @muniz/cli, @muniz/muniz-plugin-create

目前可以创建pc开发模版
  • Loading branch information
1160007652 committed Dec 13, 2020
2 parents ea7a053 + 79304e4 commit 5112ea4
Show file tree
Hide file tree
Showing 37 changed files with 501 additions and 306 deletions.
2 changes: 2 additions & 0 deletions packages/@muniz/cli/dist/configs/locales/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions packages/@muniz/cli/dist/configs/locales/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '查看插件列表',
Expand Down
10 changes: 7 additions & 3 deletions packages/@muniz/cli/dist/core/middleWare/helpCommand/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var helpCommand = function helpCommand(ctx, next) {
}],
commands: astCommands,
usage: {
key: '$ muniz <command> [options]',
key: "$ muniz <".concat(_i18n["default"].getLocale('command'), "> [").concat(_i18n["default"].getLocale('options'), "]"),
description: ''
}
};
Expand All @@ -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, {
Expand All @@ -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",
Expand All @@ -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, {
Expand Down
17 changes: 10 additions & 7 deletions packages/@muniz/cli/dist/core/middleWare/isCommand/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down
22 changes: 10 additions & 12 deletions packages/@muniz/cli/dist/core/middleWare/mergeArgv/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
22 changes: 10 additions & 12 deletions packages/@muniz/cli/dist/core/middleWare/runCommand/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions packages/@muniz/cli/src/configs/locales/en-US.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
2 changes: 2 additions & 0 deletions packages/@muniz/cli/src/configs/locales/zh-CN.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const zhCN = {
zh_cn: '中文',
en_us: '英文',
command: '命令',
options: '选项',
language_not_found: '>> 未找到 {name} 对应的 {locale} 文案 <<',
help_add_desc: '添加插件',
help_list_desc: '查看插件列表',
Expand Down
10 changes: 7 additions & 3 deletions packages/@muniz/cli/src/core/middleWare/helpCommand/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const helpCommand = (ctx, next) => {
},
],
commands: astCommands,
usage: { key: '$ muniz <command> [options]', description: '' },
usage: { key: `$ muniz <${i18n.getLocale('command')}> [${i18n.getLocale('options')}]`, description: '' },
};
switch (argv.command.length) {
case 0: {
Expand All @@ -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(<Help data={helpData} show="options" locale={i18n.currentLocale} />);
} else {
helpData.usage = {
key: `$ muniz ${argv.command[0]} <${i18n.getLocale('command')}> [${i18n.getLocale('options')}]`,
description: '',
};
render(<Help data={helpData} show="command" usage={``} locale={i18n.currentLocale} />);
}
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(<Help data={helpData} show="options" locale={i18n.currentLocale} />);
break;
}
Expand Down
14 changes: 8 additions & 6 deletions packages/@muniz/cli/src/core/middleWare/isCommand/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 10 additions & 7 deletions packages/@muniz/cli/src/core/middleWare/mergeArgv/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 8 additions & 7 deletions packages/@muniz/cli/src/core/middleWare/runCommand/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
80 changes: 0 additions & 80 deletions packages/@muniz/muniz-plugin-create/dist/command/Create/index.js

This file was deleted.

Loading

0 comments on commit 5112ea4

Please sign in to comment.