当前位置: 首页 > news >正文

HbuilderX 插件开发-模板创建

实现思路

  • 使用HbuilderX 打开某个文档时右键
  • 点击的时候获取当前打开的文档内容
  • 使用 API 替换为自己的模板

示例

  • package.json
{"id": "SL-HbuilderX-Tool","name": "SL-HbuilderX-Tool","description": "快速创建html,vue2模板","displayName": "SL-HbuilderX-Tool","version": "1.0.1","publisher": "SL","engines": {"HBuilderX": "^3.8.0"},"categories": ["Other"],"keywords": ["html","vue2","template"],"main": "./extension","activationEvents": ["onCommand:extension.html","onCommand:extension.vue2"],"contributes": {"commands": [{"command": "extension.html","title": "创建HTML模板"},{"command": "extension.vue2","title": "创建VUE2模板"}],"menus": {"editor/context": [{"id": "foo","title": "SL-HbuilderX-Tool","group": "goto"},{"command": "extension.html","group": "foo@1","when": "editorTextFocus"},{"command": "extension.vue2","group": "foo@1","when": "editorTextFocus"},{"group": "goto"}]}},"extensionDependencies": ["plugin-manager"],"dependencies": {}
}
  • extension.js
var hx = require("hbuilderx");let htmlTemp = `<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title></title>
</head>
<body><div>Hello World!!!</div>
</body>
</html>`
let vue2Temp = `<template><div>Hello World!!!</div>
</template><script>
export default {name: "Index",props: {},watch:{},computed:{},data() {return {}},beforeCreate() {},created() {},beforeMount() {},mounted() {},beforeDestroy() {},destroyed() {},methods: {}
}
</script><style scoped></style>`//该方法将在插件激活的时候调用
function activate(context) {let htmldisposable = hx.commands.registerCommand('extension.html', () => {let activeEditor = hx.window.getActiveTextEditor();activeEditor.then(function(editor) { let text = editor.document.getText({});editor.edit(editBuilder => {editBuilder.replace({start:0,end:text.length}, htmlTemp);});});});let vue2disposable = hx.commands.registerCommand('extension.vue2', () => {let activeEditor = hx.window.getActiveTextEditor();activeEditor.then(function(editor) { let text = editor.document.getText({});editor.edit(editBuilder => {editBuilder.replace({start:0,end:text.length}, vue2Temp);});});});//订阅销毁钩子,插件禁用的时候,自动注销该command。context.subscriptions.push(htmldisposable);context.subscriptions.push(vue2disposable);
}
//该方法将在插件禁用的时候调用(目前是在插件卸载的时候触发)
function deactivate() {}module.exports = {activate,deactivate
}

源代码

SL-HbuilderX-Tool

http://www.lryc.cn/news/486504.html

相关文章:

  • 打造专业问答社区:Windows部署Apache Answer结合cpolar实现公网访问
  • YOLO-SLD: An Attention Mechanism-ImprovedYOLO for License Plate Detection
  • ArcGIS的汉字(亚洲文本)垂直标注
  • 【面试题】
  • Leetcode 寻找峰值
  • 探索大规模语言模型(LLM)在心理健康护理领域中的应用与潜力
  • Infisical开源密钥管理平台实战指南
  • AI大模型:重塑软件开发流程与模式
  • AMD(Xilinx) FPGA配置Flash大小选择
  • 基于Java Springboot图书借阅系统
  • DDRPHY数字IC后端设计实现系列专题之数字后端floorplanpowerplan设计
  • 【Mysql】Mysql函数(上)
  • Java连接MySQL(测试build path功能)
  • 卡尔曼滤波器
  • 基于BERT的情感分析
  • 推荐15个2024最新精选wordpress模板
  • AWTK-WIDGET-WEB-VIEW 实现笔记 (2) - Windows
  • Linux四剑客及正则表达式
  • ALS 推荐算法案例演示(python)
  • labview中连接sql server数据库查询语句
  • leetcode_二叉树最大深度
  • Elasticsearch 重建索引 数据迁移
  • 2411rust,异步函数
  • 前端网络性能优化问题
  • 优选算法——双指针
  • 【Rabbitmq篇】RabbitMQ⾼级特性----消息确认
  • 开源TTS语音克隆神器GPT-SoVITS_V2版本地整合包部署与远程使用生成音频
  • 【idea】更换快捷键
  • 最小的子数组(leetcode 209)
  • IDEA-Plugins无法下载插件(网络连接问题-HTTP Proxy Settings)