Skip to content

Commit

Permalink
添加本地版本获取及更新
Browse files Browse the repository at this point in the history
  • Loading branch information
1226085293 committed Jun 19, 2024
1 parent fabd051 commit ed6b6d1
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 2 deletions.
13 changes: 13 additions & 0 deletions extensions/mk-framework/dist/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,19 @@ async function default_1() {
tabWidth: 4,
useTabs: true,
}));
})
// 更新框架版本信息
.then(async () => {
console.log(Editor.I18n.t("mk-framework.更新框架版本信息"));
if (!project_package["mk-framework"]) {
project_package["mk-framework"] = {};
}
project_package["mk-framework"].version_s = version_s;
fs_extra_1.default.writeFileSync(path_1.default.join(Editor.Project.path, "package.json"), await prettier_1.default.format(JSON.stringify(project_package), {
filepath: "*.json",
tabWidth: 4,
useTabs: true,
}));
})
// 清理临时文件
.then(() => {
Expand Down
18 changes: 18 additions & 0 deletions extensions/mk-framework/dist/local_version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const cjson_1 = __importDefault(require("cjson"));
function default_1() {
var _a;
/** 包配置 */
const project_package = cjson_1.default.load(path_1.default.join(Editor.Project.path, "package.json"));
if (!((_a = project_package["mk-framework"]) === null || _a === void 0 ? void 0 : _a.version_s)) {
console.log(Editor.I18n.t("mk-framework.当前项目未安装框架"));
return;
}
console.log(Editor.I18n.t("mk-framework.当前项目框架版本为") + project_package["mk-framework"].version_s);
}
exports.default = default_1;
4 changes: 4 additions & 0 deletions extensions/mk-framework/dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ delete require.cache[__dirname + "\\help.js"];
const build_dts_1 = __importDefault(require("./build_dts"));
const help_1 = __importDefault(require("./help"));
const install_1 = __importDefault(require("./install"));
const local_version_1 = __importDefault(require("./local_version"));
/**
* @en Methods within the extension can be triggered by message
* @zh 扩展内的方法,可以通过 message 触发
Expand All @@ -25,6 +26,9 @@ exports.methods = {
await (0, install_1.default)();
console.log("安装完成");
},
local_version() {
(0, local_version_1.default)();
},
async build() {
console.log("构建 d.ts...");
await (0, build_dts_1.default)();
Expand Down
6 changes: 5 additions & 1 deletion extensions/mk-framework/i18n/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
名字: "mk-framework",
说明: "3.x game framework",
安装框架: "Install framework",
本地版本: "Local version",
构建dts: "Build d.ts",
帮助: "Help",
确认安装: "Are you sure you want to overwrite the old framework for installation?",
Expand All @@ -18,5 +19,8 @@ module.exports = {
注入声明文件: "Inject declaration file",
添加导入映射: "Add import mapping",
屏蔽vscode框架文件提示: "Suppress vscode framework file hints",
清理临时文件: "Clean temporary files"
清理临时文件: "Clean temporary files",
更新框架版本信息: "Update framework version information",
当前项目未安装框架: "The current project has no framework installed",
当前项目框架版本为: "The current project framework version is",
};
6 changes: 5 additions & 1 deletion extensions/mk-framework/i18n/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
名字: "mk-framework",
说明: "3.x 游戏框架",
安装框架: "安装框架",
本地版本: "本地版本",
构建dts: "构建 d.ts",
帮助: "帮助",
确认安装: "确定覆盖旧框架进行安装?",
Expand All @@ -18,5 +19,8 @@ module.exports = {
注入声明文件: "注入声明文件",
添加导入映射: "添加导入映射",
屏蔽vscode框架文件提示: "屏蔽 vscode 框架文件提示",
清理临时文件: "清理临时文件"
清理临时文件: "清理临时文件",
更新框架版本信息: "更新框架版本信息",
当前项目未安装框架: "当前项目未安装框架",
当前项目框架版本为: "当前项目框架版本为",
};
10 changes: 10 additions & 0 deletions extensions/mk-framework/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
"install"
]
},
"local_version": {
"methods": [
"local_version"
]
},
"build": {
"methods": [
"build"
Expand All @@ -35,6 +40,11 @@
"label": "i18n:mk-framework.安装框架",
"message": "install"
},
{
"path": "i18n:menu.extension/i18n:mk-framework.名字",
"label": "i18n:mk-framework.本地版本",
"message": "local_version"
},
{
"path": "i18n:menu.extension/i18n:mk-framework.名字",
"label": "i18n:mk-framework.构建dts",
Expand Down
17 changes: 17 additions & 0 deletions extensions/mk-framework/source/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,23 @@ export default async function (): Promise<void> {
})
);
})
// 更新框架版本信息
.then(async () => {
console.log(Editor.I18n.t("mk-framework.更新框架版本信息"));
if (!project_package["mk-framework"]) {
project_package["mk-framework"] = {};
}
project_package["mk-framework"].version_s = version_s;

fs.writeFileSync(
path.join(Editor.Project.path, "package.json"),
await prettier.format(JSON.stringify(project_package), {
filepath: "*.json",
tabWidth: 4,
useTabs: true,
})
);
})
// 清理临时文件
.then(() => {
console.log(Editor.I18n.t("mk-framework.清理临时文件"));
Expand Down
14 changes: 14 additions & 0 deletions extensions/mk-framework/source/local_version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import path from "path";
import cjson from "cjson";

export default function () {
/** 包配置 */
const project_package = cjson.load(path.join(Editor.Project.path, "package.json"));

if (!project_package["mk-framework"]?.version_s) {
console.log(Editor.I18n.t("mk-framework.当前项目未安装框架"));
return;
}

console.log(Editor.I18n.t("mk-framework.当前项目框架版本为") + project_package["mk-framework"].version_s);
}
5 changes: 5 additions & 0 deletions extensions/mk-framework/source/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ delete require.cache[__dirname + "\\help.js"];
import build_dts from "./build_dts";
import help from "./help";
import install from "./install";
import local_version from "./local_version";

/**
* @en Methods within the extension can be triggered by message
Expand All @@ -21,6 +22,10 @@ export const methods: Record<string, (...any: any) => any> = {
console.log("安装完成");
},

local_version() {
local_version();
},

async build() {
console.log("构建 d.ts...");
await build_dts();
Expand Down

0 comments on commit ed6b6d1

Please sign in to comment.