From bdd1cad492ab40e57430f81e18c70b8c706ba12c Mon Sep 17 00:00:00 2001 From: leihaohao Date: Tue, 17 Aug 2021 21:47:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20devui-cli=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复变量未声明使用 bug - 修复 vitepress/sidebar 读取 status 类型 bug --- devui-cli/shared/utils.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/devui-cli/shared/utils.js b/devui-cli/shared/utils.js index cf8dc240..16acce59 100644 --- a/devui-cli/shared/utils.js +++ b/devui-cli/shared/utils.js @@ -64,7 +64,7 @@ exports.parseExportByFileInfo = (fileInfo, ignoreParseError) => { .split(',') .forEach((p) => parts.push(p)) - searchContent = indexContent.slice(partEndIndex) + searchContent = indexContent.slice(reStartIndex + partContent.length) } exportModule.default = fileInfo.name + 'Install' @@ -81,12 +81,16 @@ exports.parseComponentInfo = (name) => { const defaultRe = /export default/ if (!defaultRe.test(indexContent)) { - logger.warning(`${fileInfo.path} must have "export default" and component info.`) + logger.warning(`${this.bigCamelCase(name)} must have "export default" and component info.`) } else { const reStartIndex = indexContent.indexOf('export default {') - componentInfo.title = this.extractStr(indexContent, 'title:', ',', reStartIndex).replace(/['"]/g, '') - componentInfo.category = this.extractStr(indexContent, 'category:', ',', reStartIndex).replace(/['"]/g, '') - componentInfo.status = this.extractStr(indexContent, 'status:', ',', reStartIndex).replace(/['"]/g, '') + const extraRe = /((^['"])|(['"]$))/g + + componentInfo.title = this.extractStr(indexContent, 'title:', ',', reStartIndex).trim().replace(extraRe, '') + componentInfo.category = this.extractStr(indexContent, 'category:', ',', reStartIndex).trim().replace(extraRe, '') + componentInfo.status = this.transformNullishStr( + this.extractStr(indexContent, 'status:', ',', reStartIndex).trim().replace(extraRe, '') + ) } componentInfo.name = this.bigCamelCase(name) @@ -94,11 +98,23 @@ exports.parseComponentInfo = (name) => { return componentInfo } +exports.transformNullishStr = (str) => { + console.log(str) + switch (str) { + case 'null': + return null + case 'undefined': + return undefined + default: + return str + } +} + exports.extractStr = (content = '', startKeywords = '', endKeywords = '', startIndex = 0) => { const keywordsStartIndex = content.indexOf(startKeywords, startIndex) + startKeywords.length const keywordsEndIndex = content.indexOf(endKeywords, keywordsStartIndex) if ([keywordsStartIndex - startIndex, keywordsEndIndex].some((index) => index < 0)) return '' - return content.slice(keywordsStartIndex, keywordsEndIndex).trim() + return content.slice(keywordsStartIndex, keywordsEndIndex) } -- Gitee