Foreword
之前刚好看过一点VScode插件原理,这里就能用上了,看一下nRF-Kconfig是怎么实现的,改一个通用版本来,方便大家使用
nRF-Kconfig
Kconfig插件的安装目录在这里
C:\Users\用户名\.vscode\extensions\nordic-semiconductor.nrf-kconfig-2024.12.13
实际这个插件也没有加密或者混淆什么的,可以直接看
尝试build
"scripts": {
"vscode:prepublish": "npm run build && npm run changelog",
"build": "rimraf dist && tsx ./scripts/build.js --production",
"watch": "tsx ./scripts/build.js --watch",
"dev": "tsx ./scripts/build.js --watch",
"type-check": "tsc --noEmit",
"lint": "tsx ../scripts/lint.ts nrf-kconfig",
"lintfix": "tsx ../scripts/lint.ts --fix nrf-kconfig",
"changelog": "tsx ../scripts/changelog.ts kconfig",
"copyright": "npm run --prefix ../ copyright",
"buildHeaderFiles": "tsx ../scripts/buildHeaderFiles.ts",
"update-build-number": "node ../scripts/updateBuildNumber.js kconfig",
"copy-css": "copyfiles \"src/**/*.css\" \"src/**/*.scss\" out/nrf-kconfig && copyfiles \"../common/src/**/*.css\" \"../common/src/**/*.scss\" out/common",
"build-tests": "tsc -p . --outDir out",
"watch-tests": "tsc -p . -w --outDir out",
"pretest": "npm run build-tests && npm run build && npm run copy-css",
"test": "node ./out/nrf-kconfig/test/runTests.js"
},
直接使用Package.js中的script部分,可以直接build或者prepublish
可能会遇到下面的错误
npm : 无法加载文件 D:\nodejs\npm.ps1,因为在此系统上禁止运行脚本
查看脚本允许策略,可以看到返回值是严格,这样不允许npm调用ps1的脚本
Get-ExecutionPolicy
修改策略,改为允许远程运行
Set-ExecutionPolicy RemoteSigned
修改完成,再次进行build,正常了
依然提示缺少rimraf命令,但是至少说明脚本跑起来了,这个问题后面再处理
安装一下rimraf就行了,实际上后续还会有tsx也缺少,一起都安装了
npm install --save rimraf
npm install --save tsx
继续往下跑就会发现,这样copy的代码缺少一个script文件夹,这里面包含了各种打包的脚本文件,这里只能先到此为止了
源码分析
{
"contributes": {
# 这里注册了各种使用的按钮
"commands": [
{
"command": "kconfig.add",
"category": "nRF Kconfig",
"title": "Kconfig: Add build folder"
},
{
"command": "kconfig.showGui",
"category": "nRF Kconfig",
"title": "Kconfig: Show Config GUI"
},
{
"command": "kconfig.goToSymDefinition",
"category": "nRF Kconfig",
"title": "Go to Symbol Definition"
},
{
"command": "kconfig.expandSubtree",
"category": "nRF Kconfig",
"title": "Expand Subtree"
},
{
"command": "kconfig.collapseSubtree",
"category": "nRF Kconfig",
"title": "Collapse Subtree"
},
{
"command": "kconfig.ctx.setActive