diff --git a/package.json b/package.json deleted file mode 100644 index 8346a4276ab0f2e4789116627f99ac62bf5b7d25..0000000000000000000000000000000000000000 --- 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" - ] - } -} 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 8b9dbd9179f23d4bc1ae9a54f3f1f7ddfc832aa8..314e089c05cf9f8b0ac20e6d809a9924b97424ca 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/analyze.js b/src/cli/dts2cpp/src/gen/analyze.js index 962b8a0f9c66efa3b5d852204e38beed99387ef1..2671ad219f8d2a60b536de001867af0107415320 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 84612563440d79274351b11ad31fb95cb30b7304..5eec4f9aec518b45619ee62d53ec08702b4b97a0 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/dts2cpp/src/gen/tools/common.js b/src/cli/dts2cpp/src/gen/tools/common.js index 1c69ecea51816fd8e3afd1ba91eb8555c0a9da39..e1dcb7f7fd16760d005176300f63c65d2befd73f 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 dbbe7a6e59bf20d6806380343f23e7ecd593ac26..ca51073fd17d2e4acb70adffabe71f4f92292202 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/analyze.js b/src/cli/dts2ets/appCodeGen/src/analyze.js index 36cc38f4929a9995c99c8fcd042f6941cd9c1603..ca55b6532ba1762de73956a7425820c8b1990dbf 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) diff --git a/src/cli/dts2ets/appCodeGen/src/tools/common.js b/src/cli/dts2ets/appCodeGen/src/tools/common.js index cb8cd75f397e61cc88080e66fdc831ca038cef7f..5f2634c53f21e23aa4657bc42275f79e37326f24 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 ee4b666a7f5695fcc4b8e94657ced91a0cb8fbe8..1894512b6a7dc2c515dd75b90a4582a1467011d7 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 90746e06559dce8c18525885c51f7a64be5f8c83..5b4869dd07562f5a638e127499de52605a33bd07 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 085d29eb9ac4bf34e3be3fe3cf9882b9e519b5aa..5423081a08d9298513a0cefcd6b710c636c4f4fe 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 1bca9146220f2dcc5d77674e6ba957f0d5021652..ece3ecfd00065022b60fe8ba530fce03429b627f 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 52bddb4cdbb4b7d95715e36977abd34e3ddd96c6..f5d4ea47bea31c873381f1e25044ca2e762cb8c0 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 = {