脚手架 mkdir 指令不可用提示文件不存在
现状:
lhb mkdir 指令报错,提示ui-rc-cli内容不存在
思路:
1.先查下lhb命令的安装路径
where lhb | which lhb
很明显能看到lhb mkdir要求的路径跟我本地安装不一致导致的。
- 查看mkdir指令源码
function mkdirComponent(name, option) {
// 默认为 --reactPC
if (option.reactPC || JSON.stringify(option) == "{}") { // --reactPC or -rc
shell.exec('node $(which node)/../../lib/node_modules/lhb-cli/node_modules/ui-rc-cli/bin/index.js copy ' + name, copyCallback);
}
if (option.reactNative) { // --reactNative or -rn
shell.exec('node $(which node)/../../lib/node_modules/lhb-cli/node_modules/ui-rn-cli/bin/index.js copy ' + name, copyCallback);
}
}
可以看到源码实现方式是which node,查找node的路径,但是呢lhb路径不一定是跟node的路径一致,导致了以上的问题。
- 修改mkdir源码
function mkdirComponent(name, option) {
// 默认为 --reactPC
if (option.reactPC || JSON.stringify(option) == "{}") { // --reactPC or -rc
shell.exec('node $(which lhb)/../../lib/node_modules/lhb-cli/node_modules/ui-rc-cli/bin/index.js copy ' + name, copyCallback);
}
if (option.reactNative) { // --reactNative or -rn
shell.exec('node $(which lhb)/../../lib/node_modules/lhb-cli/node_modules/ui-rn-cli/bin/index.js copy ' + name, copyCallback);
}
}
- 最后呈现效果