Skip to content

Commit

Permalink
feat(all): 调整插件国际化语言
Browse files Browse the repository at this point in the history
affects: @muniz/cli, @muniz/muniz-plugin-create

优化插件国际化语言调用方式
优化插件开发环境的help 帮助文档
  • Loading branch information
1160007652 committed Nov 6, 2020
1 parent 8ba225e commit 483b365
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 43 deletions.
2 changes: 1 addition & 1 deletion packages/@muniz/cli/dist/configs/commandHelp.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"enUS":[{"key":"add","commandType":"function","description":"add plugin","options":[],"isIndex":false,"name":"Add","path":"Add/index.js"},{"key":"list","commandType":"react","description":"View the list of plugins","options":[],"isIndex":false,"name":"List","path":"List/index.js"},{"key":"locale","commandType":"function","description":"Multi-language switching","options":[],"isIndex":false,"name":"locale","path":"locale/index.js"},{"key":"remove","commandType":"function","description":"Remove plugin","options":[],"isIndex":false,"name":"Remove","path":"Remove/index.js"}],"zhCN":[{"key":"add","commandType":"function","description":"添加插件","options":[],"isIndex":false,"name":"Add","path":"Add/index.js"},{"key":"list","commandType":"react","description":"查看插件列表","options":[],"isIndex":false,"name":"List","path":"List/index.js"},{"key":"locale","commandType":"function","description":"多语言切换","options":[],"isIndex":false,"name":"locale","path":"locale/index.js"},{"key":"remove","commandType":"function","description":"删除插件","options":[],"isIndex":false,"name":"Remove","path":"Remove/index.js"}]}
{"enUS":[{"key":"add","commandType":"function","description":"add plugin","options":[],"isIndex":false,"name":"Add","path":"Add/index.js"},{"key":"list","commandType":"react","description":"View the list of plugins","options":[],"isIndex":false,"name":"List","path":"List/index.js"},{"key":"remove","commandType":"function","description":"Remove plugin","options":[],"isIndex":false,"name":"Remove","path":"Remove/index.js"},{"key":"locale","commandType":"function","description":"Multi-language switching","options":[],"isIndex":false,"name":"locale","path":"locale/index.js"}],"zhCN":[{"key":"add","commandType":"function","description":"添加插件","options":[],"isIndex":false,"name":"Add","path":"Add/index.js"},{"key":"list","commandType":"react","description":"查看插件列表","options":[],"isIndex":false,"name":"List","path":"List/index.js"},{"key":"remove","commandType":"function","description":"删除插件","options":[],"isIndex":false,"name":"Remove","path":"Remove/index.js"},{"key":"locale","commandType":"function","description":"多语言切换","options":[],"isIndex":false,"name":"locale","path":"locale/index.js"}]}
34 changes: 9 additions & 25 deletions packages/@muniz/cli/dist/core/middleWare/isCommand/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var isCommand = /*#__PURE__*/function () {

case 11:
if (!(argv.command.length > 0)) {
_context.next = 43;
_context.next = 37;
break;
}

Expand All @@ -79,7 +79,7 @@ var isCommand = /*#__PURE__*/function () {
}); // 执行 非内置命令 =》 插件命令

if (isCliCommand) {
_context.next = 39;
_context.next = 33;
break;
}

Expand Down Expand Up @@ -151,24 +151,8 @@ var isCommand = /*#__PURE__*/function () {

ctx.pkg = require(path.join(ctx.pkgPath, '/package.json')); // 读取命令AST信息

if (!MunizConfig.MUNIZ_CLI_DEBUG) {
_context.next = 34;
break;
}

_context.next = 31;
return (0, _servers.generateCommand)(path.join(ctx.pkgPath, '/src/command'), path.join(ctx.pkgPath, '/src/command'));

case 31:
ctx.astCommands = _context.sent;
_context.next = 35;
break;

case 34:
ctx.astCommands = fs.readJsonSync(path.join(ctx.pkgPath, '/dist/configs/commandHelp.json'))[MunizConfig.languageLocale];
ctx.astCommands = fs.readJsonSync(path.join(ctx.pkgPath, '/dist/configs/commandHelp.json'))[MunizConfig.languageLocale]; // 读取插件配置信息

case 35:
// 读取插件配置信息
pluginConfig = require(path.join(ctx.pkgPath, '/dist/index.js'))["default"]({
locale: MunizConfig.languageLocale
});
Expand All @@ -180,20 +164,20 @@ var isCommand = /*#__PURE__*/function () {
}
}

_context.next = 40;
_context.next = 34;
break;

case 39:
case 33:
if (argv.command.length > 1) {
argv.input.unshift(argv.command.pop());
}

case 40:
case 34:
next();
_context.next = 45;
_context.next = 39;
break;

case 43:
case 37:
/**
*
* 如果 argv.input === 0, 且 argv.options === 0 时, 置入 argv.options.help = true , 走 打印中间件 显示“帮助”命令
Expand All @@ -207,7 +191,7 @@ var isCommand = /*#__PURE__*/function () {

next();

case 45:
case 39:
case "end":
return _context.stop();
}
Expand Down
4 changes: 3 additions & 1 deletion packages/@muniz/cli/dist/core/middleWare/runCommand/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,18 @@ var runCommand = /*#__PURE__*/function () {
} else {
// 当前执行插件是否是 走 开发状态 通道
if (MunizConfig.MUNIZ_PLUGIN_DEV) {
_require = require(path.join(ctx.pkgPath, '/dist/index.js')), pluginCommand = _require.pluginCommand;
_require = require(path.join(ctx.pkgPath)), pluginCommand = _require.pluginCommand;
pluginCommand({
commandPath: _astCommands[0].path,
commandType: _astCommands[0].commandType,
data: commandModuleProps
});
} else {
_require2 = require("".concat(ctx.pkgName)), _pluginCommand = _require2.pluginCommand;

_pluginCommand({
commandPath: _astCommands[0].path,
commandType: _astCommands[0].commandType,
data: commandModuleProps
});
}
Expand Down
13 changes: 3 additions & 10 deletions packages/@muniz/cli/src/core/middleWare/isCommand/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,9 @@ const isCommand = async (ctx, next) => {

ctx.pkg = require(path.join(ctx.pkgPath, '/package.json'));
// 读取命令AST信息
if (MunizConfig.MUNIZ_CLI_DEBUG) {
ctx.astCommands = await generateCommand(
path.join(ctx.pkgPath, '/src/command'),
path.join(ctx.pkgPath, '/src/command'),
);
} else {
ctx.astCommands = fs.readJsonSync(path.join(ctx.pkgPath, '/dist/configs/commandHelp.json'))[
MunizConfig.languageLocale
];
}
ctx.astCommands = fs.readJsonSync(path.join(ctx.pkgPath, '/dist/configs/commandHelp.json'))[
MunizConfig.languageLocale
];

// 读取插件配置信息
const pluginConfig = require(path.join(ctx.pkgPath, '/dist/index.js')).default({
Expand Down
14 changes: 11 additions & 3 deletions packages/@muniz/cli/src/core/middleWare/runCommand/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,19 @@ const runCommand = async (ctx, next) => {
} else {
// 当前执行插件是否是 走 开发状态 通道
if (MunizConfig.MUNIZ_PLUGIN_DEV) {
const { pluginCommand } = require(path.join(ctx.pkgPath, '/dist/index.js'));
pluginCommand({ commandPath: _astCommands[0].path, data: commandModuleProps });
const { pluginCommand } = require(path.join(ctx.pkgPath));
pluginCommand({
commandPath: _astCommands[0].path,
commandType: _astCommands[0].commandType,
data: commandModuleProps,
});
} else {
const { pluginCommand } = require(`${ctx.pkgName}`);
pluginCommand({ commandPath: _astCommands[0].path, data: commandModuleProps });
pluginCommand({
commandPath: _astCommands[0].path,
commandType: _astCommands[0].commandType,
data: commandModuleProps,
});
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@muniz/muniz-plugin-create/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var pluginCommand = function pluginCommand(_ref) {
var _command = require("./command/".concat(commandPath))["default"];

if (commandType === 'function') {
_command(commandModuleProps);
_command(data);
} else {
(0, _ink.render)( /*#__PURE__*/_react["default"].createElement(_command, data));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@muniz/muniz-plugin-create/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default (props) => {
export const pluginCommand = ({ commandType, commandPath, data }) => {
const _command = require(`./command/${commandPath}`).default;
if (commandType === 'function') {
_command(commandModuleProps);
_command(data);
} else {
render(React.createElement(_command, data));
}
Expand Down
8 changes: 7 additions & 1 deletion scripts/dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
rm -rf ./packages/@muniz/*/dist

# 进行文件打包
lerna run dev --parallel
lerna run dev

# 修改 命令行执行权限,【由于 Babel 编译出的文件权限不够】
chmod +x ./packages/@muniz/cli/dist/bin/cli.js

# 拷贝文件
cp -f ./packages/@muniz/cli/src/configs/system.json ./packages/@muniz/cli/dist/configs/system.json

# 生成命令
lerna run generateCommandDesc

# 提示打包成功
echo 'Muniz 脚手架 项目打包成功'

0 comments on commit 483b365

Please sign in to comment.