From 3c19fd46ddbd24dec86cd9c0566284ce8b9cde2b Mon Sep 17 00:00:00 2001 From: zksu <565338107@qq.com> Date: Sat, 2 Mar 2024 17:22:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20typeorm=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BE=9D=E8=B5=96.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- snippets/comment_value.js | 15 +++++++++++++++ snippets/typeorm_manytoone.js | 16 ++++++++++++++++ snippets/typeorm_onetomany.js | 13 +++++++++++++ src/visualStudio/Adapter.js | 23 +++++++++++++++++------ vscode-extension/package.json | 10 +++++++++- 5 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 snippets/comment_value.js create mode 100644 snippets/typeorm_manytoone.js create mode 100644 snippets/typeorm_onetomany.js diff --git a/snippets/comment_value.js b/snippets/comment_value.js new file mode 100644 index 0000000..24ce50d --- /dev/null +++ b/snippets/comment_value.js @@ -0,0 +1,15 @@ +const { TYPES } = require("../src/common/consts/types"); +const body = ` +/** + * 说明: + * @description: + */ +`; +const description = ""; + +module.exports = { + prefix: ["!comment_value"], + type: [TYPES.javascript], + description: description || body, + body: body.trim(), +}; diff --git a/snippets/typeorm_manytoone.js b/snippets/typeorm_manytoone.js new file mode 100644 index 0000000..838ce79 --- /dev/null +++ b/snippets/typeorm_manytoone.js @@ -0,0 +1,16 @@ +const { TYPES } = require("../src/common/consts/types"); +const body = ` +/** + * 说明: + */ +@ManyToOne(() => $2, ($1) => $1.\${2:values}) +\${1:obj}: \${2:Type}; +`; +const description = ""; + +module.exports = { + prefix: ["!typeorm_manytoone"], + type: [TYPES.typescript], + description: description || body, + body: body.trim(), +}; diff --git a/snippets/typeorm_onetomany.js b/snippets/typeorm_onetomany.js new file mode 100644 index 0000000..81dc140 --- /dev/null +++ b/snippets/typeorm_onetomany.js @@ -0,0 +1,13 @@ +const { TYPES } = require("../src/common/consts/types"); +const body = ` + @OneToMany(() => $2, ($1) => $1.user) + \${1:object}s: \${2:Type}[] +`; +const description = ""; + +module.exports = { + prefix: ["!typeorm_onetomany"], + type: [TYPES.typescript], + description: description || body, + body: body.trim(), +}; diff --git a/src/visualStudio/Adapter.js b/src/visualStudio/Adapter.js index d705da6..931790b 100644 --- a/src/visualStudio/Adapter.js +++ b/src/visualStudio/Adapter.js @@ -17,7 +17,7 @@ const path = require("path"); const { isArray } = require("../common/funcs"); const logger = require("../common/logger"); const snippetDir = path.join(__dirname, "../../.build-vs"); -if(!fs.existsSync(snippetDir)){ +if (!fs.existsSync(snippetDir)) { fs.mkdirSync(snippetDir); } const SnippetGetter = require("../common/SnippetGetter"); @@ -46,10 +46,16 @@ class Adapter { ? snippetOption.type : [snippetOption.type]; types.forEach((type) => { - const xml = this.tranSnippet({ ...snippetOption, type }); const fileType = languageFileMap[type]; if (!fileType) { - logger.error("这个类型暂不支持"); + logger.error("这个类型暂不支持", type); + return; + } + let xml; + try { + xml = this.tranSnippet({ ...snippetOption, type }); + } catch (error) { + logger.error("snippet转换出错", snippetOption, error); return; } // 存储 @@ -68,7 +74,7 @@ class Adapter { logger.info("结束生成"); } tranSnippet(snippetOption = {}) { - let { key, type, body, description, prefix } = snippetOption; + let { key, type, body = "", description, prefix } = snippetOption; const root = getRoot(); const header = create() .ele("Header") @@ -91,8 +97,13 @@ class Adapter { .ele("SnippetType") .txt("SurroundsWith") .up(); - // 替换 body中的 变量 - let _body = body.join("\n"); + // body 变成字符串才能转换 + let _body = body; + if (typeof body !== "string") { + if (Array.isArray(body)) { + _body = body.join("\n"); + } + } const snippet = create({ version: "1.0", encoding: "123", diff --git a/vscode-extension/package.json b/vscode-extension/package.json index 76c905e..c9dbd44 100644 --- a/vscode-extension/package.json +++ b/vscode-extension/package.json @@ -2,7 +2,7 @@ "name": "tikkhun-vscode-snippets", "displayName": "tikkhun-vscode-snippets", "description": "tikkhun-vscode-snippets", - "version": "2023.9.15", + "version": "2024.3.2", "publisher": "tikkhun", "engines": { "vscode": "^1.69.0" @@ -48,6 +48,10 @@ "language": "html", "path": "./snippets/html.json" }, + { + "language": "ignore", + "path": "./snippets/ignore.json" + }, { "language": "java", "path": "./snippets/java.json" @@ -84,6 +88,10 @@ "language": "powershell", "path": "./snippets/powershell.json" }, + { + "language": "rust", + "path": "./snippets/rust.json" + }, { "language": "sass", "path": "./snippets/sass.json"