From becef483758b6f7b7de31ebcd2eaeb99c3419b58 Mon Sep 17 00:00:00 2001 From: huruitao Date: Thu, 18 Jul 2024 11:46:09 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9png=E7=85=A7=E7=89=87?= =?UTF-8?q?=E5=90=8D=E5=AD=97=E5=92=8C=E7=BB=9F=E4=B8=80return?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huruitao --- ...l_generate_clang.png => curl_generate.png} | Bin ...te_clang_log.png => curl_generate_log.png} | Bin ...nd_google.png => libphnum_not_find_gg.png} | Bin ...png => libphnum_not_find_gg_sourcedir.png} | Bin src/cli/cmake2gn/docs/guide/FAQ.md | 8 +- src/cli/dts2cpp/src/gen/tools/common.js | 3 +- src/cli/dts2cpp/src/gen/tools/tool.js | 1 + .../dts2ets/appCodeGen/src/tools/common.js | 3 +- src/cli/dts2ets/appCodeGen/src/tools/tool.js | 3 +- .../src/gen/tools/VsPluginTool.js | 155 +++++++++--------- .../dts2cpp/napi_vs_plugin/src/extension.js | 78 ++++----- .../h2dts/ts_vs_plugin/src/extension.js | 119 +++++++------- .../h2sa/service_vs_plugin/src/extension.js | 107 ++++++------ 13 files changed, 241 insertions(+), 236 deletions(-) rename src/cli/cmake2gn/docs/figures/{curl_generate_clang.png => curl_generate.png} (100%) rename src/cli/cmake2gn/docs/figures/{curl_generate_clang_log.png => curl_generate_log.png} (100%) rename src/cli/cmake2gn/docs/figures/{libphnum_not_find_google.png => libphnum_not_find_gg.png} (100%) rename src/cli/cmake2gn/docs/figures/{libphnum_not_find_google_sourcedir.png => libphnum_not_find_gg_sourcedir.png} (100%) diff --git a/src/cli/cmake2gn/docs/figures/curl_generate_clang.png b/src/cli/cmake2gn/docs/figures/curl_generate.png similarity index 100% rename from src/cli/cmake2gn/docs/figures/curl_generate_clang.png rename to src/cli/cmake2gn/docs/figures/curl_generate.png diff --git a/src/cli/cmake2gn/docs/figures/curl_generate_clang_log.png b/src/cli/cmake2gn/docs/figures/curl_generate_log.png similarity index 100% rename from src/cli/cmake2gn/docs/figures/curl_generate_clang_log.png rename to src/cli/cmake2gn/docs/figures/curl_generate_log.png diff --git a/src/cli/cmake2gn/docs/figures/libphnum_not_find_google.png b/src/cli/cmake2gn/docs/figures/libphnum_not_find_gg.png similarity index 100% rename from src/cli/cmake2gn/docs/figures/libphnum_not_find_google.png rename to src/cli/cmake2gn/docs/figures/libphnum_not_find_gg.png diff --git a/src/cli/cmake2gn/docs/figures/libphnum_not_find_google_sourcedir.png b/src/cli/cmake2gn/docs/figures/libphnum_not_find_gg_sourcedir.png similarity index 100% rename from src/cli/cmake2gn/docs/figures/libphnum_not_find_google_sourcedir.png rename to src/cli/cmake2gn/docs/figures/libphnum_not_find_gg_sourcedir.png diff --git a/src/cli/cmake2gn/docs/guide/FAQ.md b/src/cli/cmake2gn/docs/guide/FAQ.md index 8b9dbd91..314e089c 100644 --- a/src/cli/cmake2gn/docs/guide/FAQ.md +++ b/src/cli/cmake2gn/docs/guide/FAQ.md @@ -44,11 +44,11 @@ (-DOPENSSL_ROOT_DIR=abc,-DOPENSSL_INCLUDE_DIR=/home/harmony/OpenHarmony/third_party/boringssl/src/include,-DOPENSSL_CRYPTO_LIBRARY=/home/harmony/OpenHarmony/out/khdvk_rk3568_a/developtools/profiler/libcrypto.z.so,-DOPENSSL_SSL_LIBRARY=/home/harmony/OpenHarmony/out/khdvk_rk3568_a/developtools/profiler/libssl.z.so) -![](./../figures/curl_generate_clang.png) +![](./../figures/curl_generate.png) 3、根据步骤2后再次发现新的错误,具体报错日志为:“clang未解析参数 /home/harmony/OpenHarmony/third_party/boringssl/src/include”,具体日志信息如下: -![](./../figures/curl_generate_clang_log.png) +![](./../figures/curl_generate_log.png) 问题定位:编译脚本中存在工具不支持的特殊编译选项。 @@ -60,7 +60,7 @@ 1、使用VS Code插件转换libphonenumber库时,参数填写如图所示,点击ok之后,右下角弹出genError日志,可将日志信息全部复制到日记本等工具,查看日志显示: "Can't find Google C++ Testing Framework"。 -![](./../figures/libphnum_not_find_google.png) +![](./../figures/libphnum_not_find_gg.png) ![](./../figures/libphnum_not_find_gtest.png) @@ -70,7 +70,7 @@ (-DGTEST_INCLUDE_DIR=/home/harmony/OpenHarmony/third_party/googletest/googletest/include) -![](./../figures/libphnum_not_find_google_sourcedir.png) +![](./../figures/libphnum_not_find_gg_sourcedir.png) 2、根据步骤1后发现新的错误,具体报错日志为未设置GTEST_SOURCE_DIR路径。 diff --git a/src/cli/dts2cpp/src/gen/tools/common.js b/src/cli/dts2cpp/src/gen/tools/common.js index 1c69ecea..e1dcb7f7 100644 --- a/src/cli/dts2cpp/src/gen/tools/common.js +++ b/src/cli/dts2cpp/src/gen/tools/common.js @@ -444,8 +444,7 @@ JsonCfgList.getValue = function (className, inter) { }; function getLogErrInfo() { - let errInfo = ' Please refer to for support capacity:' + - 'https://gitee.com/openharmony/' + 'napi_generator/tree/master/release-notes'; + let errInfo = ' Please refer to for support capacity'; return errInfo; } diff --git a/src/cli/dts2cpp/src/gen/tools/tool.js b/src/cli/dts2cpp/src/gen/tools/tool.js index dbbe7a6e..ca51073f 100644 --- a/src/cli/dts2cpp/src/gen/tools/tool.js +++ b/src/cli/dts2cpp/src/gen/tools/tool.js @@ -167,6 +167,7 @@ function getLicense(data) { return ''; } } + return ''; } function removeEmptyLine(data) { diff --git a/src/cli/dts2ets/appCodeGen/src/tools/common.js b/src/cli/dts2ets/appCodeGen/src/tools/common.js index cb8cd75f..5f2634c5 100644 --- a/src/cli/dts2ets/appCodeGen/src/tools/common.js +++ b/src/cli/dts2ets/appCodeGen/src/tools/common.js @@ -443,8 +443,7 @@ JsonCfgList.getValue = function (className, inter) { }; function getLogErrInfo() { - let errInfo = ' Please refer to for support capacity:' + - 'https://gitee.com/openharmony/' + 'napi_generator/tree/master/release-notes'; + let errInfo = ' Please refer to for support capacity'; return errInfo; } diff --git a/src/cli/dts2ets/appCodeGen/src/tools/tool.js b/src/cli/dts2ets/appCodeGen/src/tools/tool.js index ee4b666a..1894512b 100644 --- a/src/cli/dts2ets/appCodeGen/src/tools/tool.js +++ b/src/cli/dts2ets/appCodeGen/src/tools/tool.js @@ -159,9 +159,10 @@ function getLicense(data) { if (licenseData.search('Copyright') !== -1) { return licenseData; } else { - return null; + return ''; } } + return ''; } function removeEmptyLine(data) { diff --git a/src/vscode_plugin/cmake2gn/gn_vs_plugin/src/gen/tools/VsPluginTool.js b/src/vscode_plugin/cmake2gn/gn_vs_plugin/src/gen/tools/VsPluginTool.js index 90746e06..5b4869dd 100644 --- a/src/vscode_plugin/cmake2gn/gn_vs_plugin/src/gen/tools/VsPluginTool.js +++ b/src/vscode_plugin/cmake2gn/gn_vs_plugin/src/gen/tools/VsPluginTool.js @@ -17,106 +17,107 @@ const tsc = require('../../node_modules/typescript'); const fs = require('fs'); let vscode = null; try { - vscode = require('vscode'); + vscode = require('vscode'); } catch (err) { - vscode = null; + vscode = null; } function replaceAll(s, sfrom, sto) { - while (s.indexOf(sfrom) >= 0) { - s = s.replace(sfrom, sto); - } - return s; + while (s.indexOf(sfrom) >= 0) { + s = s.replace(sfrom, sto); + } + return s; } function detectPlatform() { let result = ''; - if (os.type() === 'Windows_NT') { - result = 'win'; - } else if (os.type() === 'Darwin') { - result = 'mac'; - } else if (os.type() === 'Linux') { - result = 'Linux'; - } + if (os.type() === 'Windows_NT') { + result = 'win'; + } else if (os.type() === 'Darwin') { + result = 'mac'; + } else if (os.type() === 'Linux') { + result = 'Linux'; + } return result; } function checkFileError(ifname) { - let program = tsc.createProgram([ifname], {}); - let emitResult = program.emit(); - let allDiagnostics = tsc.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); - - let errorMsg = ''; - allDiagnostics.forEach(diagnostic => { - if (diagnostic.file) { - let { line, character } = tsc.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start); - let message = tsc.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); - errorMsg += `${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}\n`; - } else { - errorMsg += tsc.flattenDiagnosticMessageText(diagnostic.messageText, '\n') + '\n'; - } - }); + let program = tsc.createProgram([ifname], {}); + let emitResult = program.emit(); + let allDiagnostics = tsc.getPreEmitDiagnostics(program).concat(emitResult.diagnostics); - if (allDiagnostics.length > 0) { - return [false, errorMsg]; + let errorMsg = ''; + allDiagnostics.forEach(diagnostic => { + if (diagnostic.file) { + let { line, character } = tsc.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start); + let message = tsc.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); + errorMsg += `${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}\n`; + } else { + errorMsg += tsc.flattenDiagnosticMessageText(diagnostic.messageText, '\n') + '\n'; } - return [true, '']; + }); + + if (allDiagnostics.length > 0) { + return [false, errorMsg]; + } + return [true, '']; } function utf8ArrayToStr(array) { - var out, i, len, c; - var char2, char3; - - out = ''; - len = array.length; - i = 0; - while (i < len) { - c = array[i++]; - switch (c >> 4) { - case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: - // 0xxxxxxx - out += String.fromCharCode(c); - break; - case 12: case 13: - // 110x xxxx 10xx xxxx - char2 = array[i++]; - out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F)); - break; - case 14: - // 1110 xxxx 10xx xxxx 10xx xxxx - char2 = array[i++]; - char3 = array[i++]; - out += String.fromCharCode(((c & 0x0F) << 12) | - ((char2 & 0x3F) << 6) | - ((char3 & 0x3F) << 0)); - break; - } + var out, i, len, c; + var char2, char3; + + out = ''; + len = array.length; + i = 0; + while (i < len) { + c = array[i++]; + switch (c >> 4) { + case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: + // 0xxxxxxx + out += String.fromCharCode(c); + break; + case 12: case 13: + // 110x xxxx 10xx xxxx + char2 = array[i++]; + out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F)); + break; + case 14: + // 1110 xxxx 10xx xxxx 10xx xxxx + char2 = array[i++]; + char3 = array[i++]; + out += String.fromCharCode(((c & 0x0F) << 12) | + ((char2 & 0x3F) << 6) | + ((char3 & 0x3F) << 0)); + break; } - - return out; } - - function readFile(fn) { - if (!fs.existsSync(fn)) { - return ''; - } - let data = fs.readFileSync(fn); - data = utf8ArrayToStr(data); - return data; + + return out; +} + +function readFile(fn) { + if (!fs.existsSync(fn)) { + return ''; } + let data = fs.readFileSync(fn); + data = utf8ArrayToStr(data); + return data; +} - function writeFile(fn, content) { - if (!fs.existsSync(fn)) { - return ''; - } - fs.writeFileSync(fn, content); +function writeFile(fn, content) { + if (!fs.existsSync(fn)) { + return ''; } + fs.writeFileSync(fn, content); + return 'writeFileSync success'; +} module.exports = { - replaceAll, - detectPlatform, - checkFileError, - readFile, - writeFile + replaceAll, + detectPlatform, + checkFileError, + readFile, + writeFile }; \ No newline at end of file diff --git a/src/vscode_plugin/dts2cpp/napi_vs_plugin/src/extension.js b/src/vscode_plugin/dts2cpp/napi_vs_plugin/src/extension.js index 085d29eb..5423081a 100644 --- a/src/vscode_plugin/dts2cpp/napi_vs_plugin/src/extension.js +++ b/src/vscode_plugin/dts2cpp/napi_vs_plugin/src/extension.js @@ -66,7 +66,7 @@ function executor(name, genDir, mode, numberType, importIsCheck) { error : '') + stdout); return VsPluginLog.logError('VsPlugin:' + error + stdout); } - vscode.window.showInformationMessage('Generated successfully'); + return vscode.window.showInformationMessage('Generated successfully'); }); } @@ -95,23 +95,23 @@ function exeFileExit() { } function register(context, command) { - let disposable = vscode.commands.registerCommand(command, function (uri, boolValue, items) { - // The code you place here will be executed every time your command is executed - // Display a message box to the user - globalPanel = vscode.window.createWebviewPanel( - 'generate', // Identifies the type of WebView - 'Generate Napi Frame', // Title of the panel displayed to the user - vscode.ViewColumn.Two, // Display the WebView panel in the form of new columns in the editor - { - enableScripts: true, // Enable or disable JS, default is Enable - retainContextWhenHidden: true, // Keep the WebView state when it is hidden to avoid being reset - } - ); - - checkBoolval(boolValue, items); - globalPanel.webview.html = getWebviewContent(context, importToolChain); - let msg; - globalPanel.webview.onDidReceiveMessage(message => { + let disposable = vscode.commands.registerCommand(command, function (uri, boolValue, items) { + // The code you place here will be executed every time your command is executed + // Display a message box to the user + globalPanel = vscode.window.createWebviewPanel( + 'generate', // Identifies the type of WebView + 'Generate Napi Frame', // Title of the panel displayed to the user + vscode.ViewColumn.Two, // Display the WebView panel in the form of new columns in the editor + { + enableScripts: true, // Enable or disable JS, default is Enable + retainContextWhenHidden: true, // Keep the WebView state when it is hidden to avoid being reset + } + ); + + checkBoolval(boolValue, items); + globalPanel.webview.html = getWebviewContent(context, importToolChain); + let msg; + globalPanel.webview.onDidReceiveMessage(message => { msg = handleMsg(msg, message, context); }, undefined, context.subscriptions); // 路径有效性判断 @@ -129,16 +129,16 @@ function register(context, command) { } function handleMsg(msg, message, context) { - msg = message.msg; - if (msg === 'cancel') { - globalPanel.dispose(); - } else if (msg === 'param') { - if (configList.length !== 0) { - writeCfgJson(); // 写cfg.json文件 - } - checkReceiveMsg(message); - } else if (msg === 'config') { - // 若选择文件夹或者选择了多个文件则不能配置业务代码 + msg = message.msg; + if (msg === 'cancel') { + globalPanel.dispose(); + } else if (msg === 'param') { + if (configList.length !== 0) { + writeCfgJson(); // 写cfg.json文件 + } + checkReceiveMsg(message); + } else if (msg === 'config') { + // 若选择文件夹或者选择了多个文件则不能配置业务代码 getMsgCfg(message, context); } else { selectPath(globalPanel, message); @@ -155,8 +155,8 @@ function getMsgCfg(message, context) { } else { configServiceCode(message, context); } - } - +} + function checkBoolval(boolValue, items) { if (typeof (boolValue) === 'boolean' && Array.isArray(items)) { if (boolValue === true) { @@ -396,7 +396,7 @@ function selectConfigPath(panel, message, generateDir) { filters: mode === SELECT_H_FILE ? { 'Text files': ['h', 'hpp', 'hxx'] } : { 'Text files': ['cpp', 'cc', 'C', 'cxx', 'c++'] }, }; - return vscode.window.showOpenDialog(options).then(fileUri => { + return vscode.window.showOpenDialog(options).then(fileUri => { if (fileUri && fileUri[0]) { console.log('Selected file: ' + fileUri[0].fsPath); let fileObsPath = fileUri[0].fsPath; @@ -410,6 +410,7 @@ function selectConfigPath(panel, message, generateDir) { panel.webview.postMessage(result); return fileUri[0].fsPath; } + return ''; }); } @@ -445,6 +446,7 @@ function selectPath(panel, message) { panel.webview.postMessage(result); return fileUri[0].fsPath; } + return ''; }); } @@ -481,7 +483,7 @@ function getCommonWebViewContent(context, html) { } // this method is called when your extension is deactivated -function deactivate() {} +function deactivate() { } function getWebviewContent(context, importToolChain) { let data = readFile(__dirname + '/vs_plugin_view.html'); @@ -498,12 +500,12 @@ function getWebViewContent(context, templatePath, panel) { const dirPath = path.dirname(resourcePath); let html = fs.readFileSync(resourcePath, 'utf-8'); html = html.replace(/( { - if ($2.indexOf('https://') < 0) { - return ($1 + panel.webview.asWebviewUri(vscode.Uri.file(path.resolve(dirPath, $2))) + '"'); - } else { - return $1 + $2 + '"'; - } - }); + if ($2.indexOf('https://') < 0) { + return ($1 + panel.webview.asWebviewUri(vscode.Uri.file(path.resolve(dirPath, $2))) + '"'); + } else { + return $1 + $2 + '"'; + } + }); return html; } diff --git a/src/vscode_plugin/h2dts/ts_vs_plugin/src/extension.js b/src/vscode_plugin/h2dts/ts_vs_plugin/src/extension.js index 1bca9146..ece3ecfd 100644 --- a/src/vscode_plugin/h2dts/ts_vs_plugin/src/extension.js +++ b/src/vscode_plugin/h2dts/ts_vs_plugin/src/extension.js @@ -41,7 +41,7 @@ function activate(context) { let disposableMenu = register(context, 'generate_ts_menu'); context.subscriptions.push(disposable); context.subscriptions.push(disposableMenu); - + let platform = detectPlatform(); if (platform === 'win') { exeFilePath = __dirname + '/napi_generator-win.exe'; @@ -59,10 +59,10 @@ function executorH2Ts(name, genDir) { VsPluginLog.logInfo('VsPlugin: stdout =' + stdout + ', stderr =' + stderr); if (error || stdout.indexOf('success') < 0) { vscode.window.showErrorMessage('genError:' + ((error !== null && error !== undefined) ? - error : '') + stdout); + error : '') + stdout); return VsPluginLog.logError('VsPlugin:' + error + stdout); } - vscode.window.showInformationMessage('Generated successfully'); + return vscode.window.showInformationMessage('Generated successfully'); }); } @@ -86,55 +86,55 @@ function register(context, command) { retainContextWhenHidden: true, // Keep the WebView state when it is hidden to avoid being reset } ); - - checkBoolval(boolValue, items); + + checkBoolval(boolValue, items); globalPanel.webview.html = getWebviewContent(context, importToolChain); let msg; globalPanel.webview.onDidReceiveMessage(message => { msg = message.msg; if (msg === 'cancel') { globalPanel.dispose(); - } + } else if (msg === 'h2ts') { checkReceiveMsg(message); } else { selectPath(globalPanel, message); } }, undefined, context.subscriptions); - // 路径有效性判断 - if (uri.fsPath !== undefined) { - let fn = re.getFileInPath(uri.fsPath); - let tt = re.match('([a-zA-Z_0-9]+.h)', fn); - let result = { - msg: 'selectHFilePath', - path: tt ? uri.fsPath : '' - }; - globalPanel.webview.postMessage(result); - } + // 路径有效性判断 + if (uri.fsPath !== undefined) { + let fn = re.getFileInPath(uri.fsPath); + let tt = re.match('([a-zA-Z_0-9]+.h)', fn); + let result = { + msg: 'selectHFilePath', + path: tt ? uri.fsPath : '' + }; + globalPanel.webview.postMessage(result); + } }); return disposable; } function checkBoolval(boolValue, items) { - if (typeof (boolValue) === 'boolean' && Array.isArray(items)) { - if (boolValue === true) { - //遍历数组item,查看当前插件id是数组的第几个元素,并拿出下一个元素,并判断当前id是否是最后一个元素并做相应处理 - getNextPlugin(items, boolValue); - } - } + if (typeof (boolValue) === 'boolean' && Array.isArray(items)) { + if (boolValue === true) { + //遍历数组item,查看当前插件id是数组的第几个元素,并拿出下一个元素,并判断当前id是否是最后一个元素并做相应处理 + getNextPlugin(items, boolValue); + } + } } function getNextPlugin(items, boolValue) { - let myExtensionId = 'kaihong.ts-gen'; - for (let i = 0; i < items.length; i++) { - if (myExtensionId === items[i] && (i === items.length - 1)) { - importToolChain = false; - } else if (myExtensionId === items[i] && (i !== items.length - 1)) { - importToolChain = boolValue; - nextPluginId = items[i + 1]; - } - extensionIds.push(items[i]); - } + let myExtensionId = 'kaihong.ts-gen'; + for (let i = 0; i < items.length; i++) { + if (myExtensionId === items[i] && (i === items.length - 1)) { + importToolChain = false; + } else if (myExtensionId === items[i] && (i !== items.length - 1)) { + importToolChain = boolValue; + nextPluginId = items[i + 1]; + } + extensionIds.push(items[i]); + } } function checkReceiveMsg(message) { let name = message.fileNames; @@ -159,7 +159,7 @@ function checkReceiveMsg(message) { * 获取插件执行命令 */ function nextPluginExeCommand(nextPluginId) { - if (nextPluginId === 'kaihong.ApiScan') { + if (nextPluginId === 'kaihong.ApiScan') { return 'api_scan'; } else if (nextPluginId === 'kaihong.gn-gen') { return 'generate_gn'; @@ -192,7 +192,7 @@ function startNextPlugin() { /** * 选择本地目录/文件夹 */ - function selectPath(panel, message) { +function selectPath(panel, message) { let mode = 1; if (message.mode !== undefined && message.mode !== null) { mode = message.mode; @@ -202,27 +202,28 @@ function startNextPlugin() { openLabel: mode === 0 ? '选择文件' : '选择文件夹', //打开选择的右下角按钮label canSelectFiles: mode === 0 ? true : false, //是否选择文件 canSelectFolders: mode === 0 ? false : true, //是否选择文件夹 - defaultUri:vscode.Uri.file(''), //默认打开本地路径 + defaultUri: vscode.Uri.file(''), //默认打开本地路径 filters: mode === 1 ? {} : { // 文件过滤选项,在文件夹选择模式下不可设置此配置,否则ubuntu系统下无法选择文件夹 'Text files': ['h'] - } + } }; - + return vscode.window.showOpenDialog(options).then(fileUri => { - if (fileUri && fileUri[0]) { - console.log('Selected file: ' + fileUri[0].fsPath); - let filePath = ''; - for (let index = 0; index < fileUri.length; index++) { + if (fileUri && fileUri[0]) { + console.log('Selected file: ' + fileUri[0].fsPath); + let filePath = ''; + for (let index = 0; index < fileUri.length; index++) { filePath += fileUri[index].fsPath.concat(','); - } - let result = { + } + let result = { msg: message.msg, path: filePath.length > 0 ? filePath.substring(0, filePath.length - 1) : filePath - }; - panel.webview.postMessage(result); - return fileUri[0].fsPath; - } - }); + }; + panel.webview.postMessage(result); + return fileUri[0].fsPath; + } + return ''; + }); } // this method is called when your extension is deactivated @@ -239,17 +240,17 @@ function getWebviewContent(context, importToolChain) { } function getWebViewContent(context, templatePath) { - const resourcePath = path.join(context.extensionPath, templatePath); - const dirPath = path.dirname(resourcePath); - let html = fs.readFileSync(resourcePath, 'utf-8'); - html = html.replace(/( { - if ($2.indexOf('https://') < 0) { - return $1 + globalPanel.webview.asWebviewUri(vscode.Uri.file(path.resolve(dirPath, $2))) + '"'; - } else { - return $1 + $2 + '"'; - } - }); - return html; + const resourcePath = path.join(context.extensionPath, templatePath); + const dirPath = path.dirname(resourcePath); + let html = fs.readFileSync(resourcePath, 'utf-8'); + html = html.replace(/( { + if ($2.indexOf('https://') < 0) { + return $1 + globalPanel.webview.asWebviewUri(vscode.Uri.file(path.resolve(dirPath, $2))) + '"'; + } else { + return $1 + $2 + '"'; + } + }); + return html; } module.exports = { diff --git a/src/vscode_plugin/h2sa/service_vs_plugin/src/extension.js b/src/vscode_plugin/h2sa/service_vs_plugin/src/extension.js index 52bddb4c..f5d4ea47 100644 --- a/src/vscode_plugin/h2sa/service_vs_plugin/src/extension.js +++ b/src/vscode_plugin/h2sa/service_vs_plugin/src/extension.js @@ -64,10 +64,10 @@ function executorService(name, genDir, serviceId) { VsPluginLog.logInfo('VsPlugin: stdout =' + stdout + ', stderr =' + stderr); if (error || stdout.indexOf('success') < 0) { vscode.window.showErrorMessage('genError:' + ((error !== null && error !== undefined) ? - error : '') + stdout); + error : '') + stdout); return VsPluginLog.logError('VsPlugin:' + error + stdout); } - vscode.window.showInformationMessage('Generated successfully'); + return vscode.window.showInformationMessage('Generated successfully'); }); } @@ -91,8 +91,8 @@ function register(context, command) { retainContextWhenHidden: true, // Keep the WebView state when it is hidden to avoid being reset } ); - - checkBoolval(boolValue, items); + + checkBoolval(boolValue, items); globalPanel.webview.html = getWebviewContent(context, importToolChain); let msg; globalPanel.webview.onDidReceiveMessage(message => { @@ -105,40 +105,40 @@ function register(context, command) { selectPath(globalPanel, message); } }, undefined, context.subscriptions); - // 路径有效性判断 - if (uri.fsPath !== undefined) { - let fn = re.getFileInPath(uri.fsPath); - let tt = re.match('([a-zA-Z_0-9]+.h)', fn); - let result = { - msg: 'selectHFilePath', - path: tt ? uri.fsPath : '' - }; - globalPanel.webview.postMessage(result); - } + // 路径有效性判断 + if (uri.fsPath !== undefined) { + let fn = re.getFileInPath(uri.fsPath); + let tt = re.match('([a-zA-Z_0-9]+.h)', fn); + let result = { + msg: 'selectHFilePath', + path: tt ? uri.fsPath : '' + }; + globalPanel.webview.postMessage(result); + } }); return disposable; } function checkBoolval(boolValue, items) { - if (typeof (boolValue) === 'boolean' && Array.isArray(items)) { - if (boolValue === true) { - //遍历数组item,查看当前插件id是数组的第几个元素,并拿出下一个元素,并判断当前id是否是最后一个元素并做相应处理 - getNextPlugin(items, boolValue); - } - } + if (typeof (boolValue) === 'boolean' && Array.isArray(items)) { + if (boolValue === true) { + //遍历数组item,查看当前插件id是数组的第几个元素,并拿出下一个元素,并判断当前id是否是最后一个元素并做相应处理 + getNextPlugin(items, boolValue); + } + } } function getNextPlugin(items, boolValue) { - let myExtensionId = 'kaihong.service-gen'; - for (let i = 0; i < items.length; i++) { - if (myExtensionId === items[i] && (i === items.length - 1)) { - importToolChain = false; - } else if (myExtensionId === items[i] && (i !== items.length - 1)) { - importToolChain = boolValue; - nextPluginId = items[i + 1]; - } - extensionIds.push(items[i]); - } + let myExtensionId = 'kaihong.service-gen'; + for (let i = 0; i < items.length; i++) { + if (myExtensionId === items[i] && (i === items.length - 1)) { + importToolChain = false; + } else if (myExtensionId === items[i] && (i !== items.length - 1)) { + importToolChain = boolValue; + nextPluginId = items[i + 1]; + } + extensionIds.push(items[i]); + } } function checkReceiveMsg(message) { let name = message.fileNames; @@ -164,7 +164,7 @@ function checkReceiveMsg(message) { * 获取插件执行命令 */ function nextPluginExeCommand(nextPluginId) { - if (nextPluginId === 'kaihong.ApiScan') { + if (nextPluginId === 'kaihong.ApiScan') { return 'api_scan'; } else if (nextPluginId === 'kaihong.gn-gen') { return 'generate_gn'; @@ -198,7 +198,7 @@ function startNextPlugin() { /** * 选择本地目录/文件夹 */ - function selectPath(panel, message) { +function selectPath(panel, message) { let mode = 1; if (message.mode !== undefined && message.mode !== null) { mode = message.mode; @@ -206,27 +206,28 @@ function startNextPlugin() { const options = { canSelectFiles: mode === 0 ? true : false, //是否选择文件 canSelectFolders: mode === 0 ? false : true, //是否选择文件夹 - defaultUri:vscode.Uri.file(message.filePath), //默认打开本地路径 - filters: mode === 0 ? { + defaultUri: vscode.Uri.file(message.filePath), //默认打开本地路径 + filters: mode === 0 ? { 'All files': ['h'] } : {} }; - + return vscode.window.showOpenDialog(options).then(fileUri => { - if (fileUri && fileUri[0]) { - console.log('Selected file: ' + fileUri[0].fsPath); - let filePath = ''; - for (let index = 0; index < fileUri.length; index++) { + if (fileUri && fileUri[0]) { + console.log('Selected file: ' + fileUri[0].fsPath); + let filePath = ''; + for (let index = 0; index < fileUri.length; index++) { filePath += fileUri[index].fsPath.concat(','); - } - let result = { + } + let result = { msg: message.msg, path: filePath.length > 0 ? filePath.substring(0, filePath.length - 1) : filePath - }; - panel.webview.postMessage(result); - return fileUri[0].fsPath; - } - }); + }; + panel.webview.postMessage(result); + return fileUri[0].fsPath; + } + return ''; + }); } // this method is called when your extension is deactivated @@ -243,17 +244,17 @@ function getWebviewContent(context, importToolChain) { } function getWebViewContent(context, templatePath) { - const resourcePath = path.join(context.extensionPath, templatePath); - const dirPath = path.dirname(resourcePath); - let html = fs.readFileSync(resourcePath, 'utf-8'); - html = html.replace(/( { - if ($2.indexOf('https://') < 0) { + const resourcePath = path.join(context.extensionPath, templatePath); + const dirPath = path.dirname(resourcePath); + let html = fs.readFileSync(resourcePath, 'utf-8'); + html = html.replace(/( { + if ($2.indexOf('https://') < 0) { return $1 + globalPanel.webview.asWebviewUri(vscode.Uri.file(path.resolve(dirPath, $2))) + '"'; } else { return $1 + $2 + '"'; } - }); - return html; + }); + return html; } module.exports = { -- Gitee From f32347b17d041399ae78e353fa6465a5394b0abc Mon Sep 17 00:00:00 2001 From: huruitao Date: Thu, 18 Jul 2024 14:03:42 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=80=BC=E7=9A=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huruitao --- src/cli/dts2cpp/src/gen/analyze.js | 2 +- src/cli/dts2cpp/src/gen/analyzeRaw.js | 2 +- src/cli/dts2ets/appCodeGen/src/analyze.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cli/dts2cpp/src/gen/analyze.js b/src/cli/dts2cpp/src/gen/analyze.js index 962b8a0f..2671ad21 100644 --- a/src/cli/dts2cpp/src/gen/analyze.js +++ b/src/cli/dts2cpp/src/gen/analyze.js @@ -51,7 +51,7 @@ function analyzeFile(fn) { } } - if (null !== licenseData && undefined !== licenseData) { + if ('' !== licenseData) { result.declareLicense.push(licenseData) } return analyze(data, result) diff --git a/src/cli/dts2cpp/src/gen/analyzeRaw.js b/src/cli/dts2cpp/src/gen/analyzeRaw.js index 84612563..5eec4f9a 100644 --- a/src/cli/dts2cpp/src/gen/analyzeRaw.js +++ b/src/cli/dts2cpp/src/gen/analyzeRaw.js @@ -64,7 +64,7 @@ function analyzeFileRaw(fn) { let data = statements[0].getFullText(); let licenseData = getLicense(data); - if (null !== licenseData && undefined !== licenseData) { + if ('' !== licenseData) { result.declareLicense.push(licenseData) } diff --git a/src/cli/dts2ets/appCodeGen/src/analyze.js b/src/cli/dts2ets/appCodeGen/src/analyze.js index 36cc38f4..ca55b653 100644 --- a/src/cli/dts2ets/appCodeGen/src/analyze.js +++ b/src/cli/dts2ets/appCodeGen/src/analyze.js @@ -50,7 +50,7 @@ function analyzeFile(fn) { else break; } - if (null !== licenseData && undefined !== licenseData) { + if ('' !== licenseData) { result.declareLicense.push(licenseData) } return analyze(data, result) -- Gitee From 64492886ed321ffe8cfdd4ade6f803699c07cb8b Mon Sep 17 00:00:00 2001 From: huruitao Date: Thu, 18 Jul 2024 14:28:50 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=88=A0=E9=99=A4package.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huruitao --- package.json | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 package.json diff --git a/package.json b/package.json deleted file mode 100644 index 8346a427..00000000 --- a/package.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "name": "napi_generator", - "version": "1.0.0", - "description": "This paper mainly introduces the NAPI framework code generation tool, which can generate NAPI framework code, business code framework and designed.The GN file according to the TS interface file in the path specified by the user. So developers need to focus on Nodejs related grammar framework layer, interface between c + + with JS type conversion, data type conversion, etc.. This tool is mainly used in the scenario of JS application calling interface, can focus on business logic implementation, Thus, the development efficiency can be greatly improved. Currently, the tool supports command line and VSCode plug-in.", - "main": "index.js", - "directories": { - "doc": "docs" - }, - "dependencies": { - "mocha": "^9.2.1", - "node-gyp": "^8.4.1", - "stdio": "^2.1.1", - "typescript": "^4.5.5" - }, - "devDependencies": { - "@types/node": "14.x" - }, - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "repository": { - "type": "git", - "url": "git@gitee.com:joeysun001/napi_generator.git" - }, - "author": "", - "license": "ISC", - "bin": "./src/gen/cmd_gen.js", - "pkg": { - "assets": [ - "src/node_modules/typescript/**/*", - "clang-format.exe", - "clang-format", - ".clang-format" - ] - } -} -- Gitee