Skip to content

Commit

Permalink
feat: 添加 typeorm相关依赖.
Browse files Browse the repository at this point in the history
  • Loading branch information
radiorz committed Mar 2, 2024
1 parent fdabd85 commit 3c19fd4
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 7 deletions.
15 changes: 15 additions & 0 deletions snippets/comment_value.js
Original file line number Diff line number Diff line change
@@ -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(),
};
16 changes: 16 additions & 0 deletions snippets/typeorm_manytoone.js
Original file line number Diff line number Diff line change
@@ -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(),
};
13 changes: 13 additions & 0 deletions snippets/typeorm_onetomany.js
Original file line number Diff line number Diff line change
@@ -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(),
};
23 changes: 17 additions & 6 deletions src/visualStudio/Adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}
// 存储
Expand All @@ -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")
Expand All @@ -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",
Expand Down
10 changes: 9 additions & 1 deletion vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -48,6 +48,10 @@
"language": "html",
"path": "./snippets/html.json"
},
{
"language": "ignore",
"path": "./snippets/ignore.json"
},
{
"language": "java",
"path": "./snippets/java.json"
Expand Down Expand Up @@ -84,6 +88,10 @@
"language": "powershell",
"path": "./snippets/powershell.json"
},
{
"language": "rust",
"path": "./snippets/rust.json"
},
{
"language": "sass",
"path": "./snippets/sass.json"
Expand Down

0 comments on commit 3c19fd4

Please sign in to comment.