From 1b3d2c0ed430b98d02d5f6ad56521ed707156a20 Mon Sep 17 00:00:00 2001 From: terwer Date: Wed, 3 May 2023 17:54:39 +0800 Subject: [PATCH] feat(zhi-core): add basic loading --- packages/zhi-core/project.json | 5 +- packages/zhi-core/src/config/deps.js | 3 + .../zhi-core/src/{map.ts => config/map.js} | 3 +- packages/zhi-core/src/config/zhi-schema.js | 154 ++++++++++++++++ packages/zhi-core/src/config/zhi.example.js | 64 +++++++ packages/zhi-core/src/config/zhi.js | 48 +++++ packages/zhi-core/src/core/npm/deps.json | 3 - .../core/npm/node_modules/.package-lock.json | 6 +- .../@siyuan-community/zhi-device/README.md | 14 +- .../@siyuan-community/zhi-device/package.json | 2 +- .../zhi-device/src/lib/siyuanDevice.d.ts | 30 +--- .../zhi-device/src/lib/siyuanDevice.js | 69 +------ .../zhi-device/src/lib/siyuanDevice.js.map | 2 +- .../zhi-core/src/core/npm/package-lock.json | 14 +- packages/zhi-core/src/core/npm/package.json | 2 +- .../src/lib/common/models/DependencyItem.ts | 105 +++++++++++ packages/zhi-core/src/lib/core/Bootstrap.ts | 47 +++++ packages/zhi-core/src/lib/core/lifecycle.ts | 169 ++++++++++++++++++ .../zhi-core/src/lib/utils/zhi-core-util.ts | 16 ++ packages/zhi-core/src/lib/zhi-core.spec.ts | 5 +- packages/zhi-core/src/lib/zhi-core.ts | 1 + packages/zhi-core/src/lib/zhi.ts | 60 +++++-- packages/zhi-core/src/main.ts | 5 +- packages/zhi-core/src/theme.js | 5 +- packages/zhi-lib-device/README.md | 12 +- packages/zhi-lib-device/package.json | 2 +- .../zhi-lib-device/src/lib/siyuanDevice.ts | 74 +------- 27 files changed, 698 insertions(+), 222 deletions(-) create mode 100644 packages/zhi-core/src/config/deps.js rename packages/zhi-core/src/{map.ts => config/map.js} (87%) create mode 100644 packages/zhi-core/src/config/zhi-schema.js create mode 100644 packages/zhi-core/src/config/zhi.example.js create mode 100644 packages/zhi-core/src/config/zhi.js delete mode 100644 packages/zhi-core/src/core/npm/deps.json create mode 100644 packages/zhi-core/src/lib/common/models/DependencyItem.ts create mode 100644 packages/zhi-core/src/lib/core/Bootstrap.ts create mode 100644 packages/zhi-core/src/lib/core/lifecycle.ts diff --git a/packages/zhi-core/project.json b/packages/zhi-core/project.json index aff9cf90..3f10dcae 100644 --- a/packages/zhi-core/project.json +++ b/packages/zhi-core/project.json @@ -22,12 +22,11 @@ "assets": [ "packages/zhi-core/*.md", "packages/zhi-core/src/core/**", + "packages/zhi-core/src/config/**", "packages/zhi-core/src/theme.js", "packages/zhi-core/src/theme.json", "packages/zhi-core/src/theme.css", - "packages/zhi-core/src/style/common/fonts/webfont.css", - "packages/zhi-core/src/hello.js", - "packages/zhi-core/src/index.html" + "packages/zhi-core/src/style/common/fonts/webfont.css" ] } }, diff --git a/packages/zhi-core/src/config/deps.js b/packages/zhi-core/src/config/deps.js new file mode 100644 index 00000000..4b2e7b53 --- /dev/null +++ b/packages/zhi-core/src/config/deps.js @@ -0,0 +1,3 @@ +export default { + vue: "^3.2.47", +} diff --git a/packages/zhi-core/src/map.ts b/packages/zhi-core/src/config/map.js similarity index 87% rename from packages/zhi-core/src/map.ts rename to packages/zhi-core/src/config/map.js index 3639b0c1..89db0d29 100644 --- a/packages/zhi-core/src/map.ts +++ b/packages/zhi-core/src/config/map.js @@ -26,7 +26,6 @@ export default { imports: { "@siyuan-community/zhi-device": - // "/appearance/themes/zhi/core/npm/node_modules/@siyuan-community/zhi-device/src/index.js", - "/Users/terwer/Documents/mydocs/zhi/dist/packages/zhi-lib-device/src/index.js", + "/appearance/themes/zhi/core/npm/node_modules/@siyuan-community/zhi-device/src/index.js", }, } diff --git a/packages/zhi-core/src/config/zhi-schema.js b/packages/zhi-core/src/config/zhi-schema.js new file mode 100644 index 00000000..8faa448d --- /dev/null +++ b/packages/zhi-core/src/config/zhi-schema.js @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2023, Terwer . All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Terwer designates this + * particular file as subject to the "Classpath" exception as provided + * by Terwer in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com + * or visit www.terwer.space if you need additional information or have any + * questions. + */ + +const schema = { + type: "object", + properties: { + dependencies: { + type: "object", + properties: { + core: { + type: "array", + items: { + type: "object", + properties: { + libpath: { + type: "string", + }, + baseType: { + type: "string", + }, + format: { + type: "string", + }, + importType: { + type: "string", + }, + runAs: { + type: "array", + items: { + type: "string", + }, + }, + }, + required: ["libpath", "baseType", "format", "importType", "runAs"], + }, + }, + server: { + type: "array", + items: { + type: "object", + properties: { + libpath: { + type: "string", + }, + baseType: { + type: "string", + }, + format: { + type: "string", + }, + importType: { + type: "string", + }, + runAs: { + type: "array", + items: { + type: "string", + }, + }, + }, + required: ["libpath", "baseType", "format", "importType", "runAs"], + }, + }, + web: { + type: "array", + items: { + type: "object", + properties: { + libpath: { + type: "string", + }, + baseType: { + type: "string", + }, + format: { + type: "string", + }, + importType: { + type: "string", + }, + runAs: { + type: "array", + items: { + type: "string", + }, + }, + }, + required: ["libpath", "baseType", "format", "importType", "runAs"], + }, + }, + vendor: { + type: "array", + items: { + type: "object", + properties: { + name: { + type: "string", + }, + enabled: { + type: "boolean", + }, + }, + required: ["name", "enabled"], + }, + }, + plugin: { + type: "array", + items: { + type: "object", + properties: { + name: { + type: "string", + }, + enabled: { + type: "boolean", + }, + }, + required: ["name", "enabled"], + }, + }, + }, + required: ["core", "server", "web", "vendor", "plugin"], + }, + }, + required: ["dependencies"], +} + +export default { + $schema: "http://json-schema.org/draft-07/schema#", + $id: "https://terwer.space/zhi-schema.json", + ...schema, +} diff --git a/packages/zhi-core/src/config/zhi.example.js b/packages/zhi-core/src/config/zhi.example.js new file mode 100644 index 00000000..f0762dae --- /dev/null +++ b/packages/zhi-core/src/config/zhi.example.js @@ -0,0 +1,64 @@ +export default { + dependencies: { + core: [ + { + libpath: "core/plugin-system/plugin.js", + baseType: "ZhiTheme", + format: "esm", + importType: "import", + runAs: ["Siyuan_MainWindow", "Siyuan_Browser"], + order: 1, + }, + { + libpath: "core/plugin-system/zhi-plugin-loader.js", + baseType: "ZhiTheme", + format: "esm", + importType: "import", + runAs: ["Siyuan_MainWindow", "Siyuan_Browser"], + order: 2, + }, + ], + server: [ + { + libpath: "server/electron/index.js", + baseType: "ZhiTheme", + format: "esm", + importType: "import", + runAs: ["Siyuan_MainWindow"], + order: 3, + }, + { + libpath: "server/cmd/index.js", + baseType: "ZhiTheme", + format: "esm", + importType: "import", + runAs: ["Siyuan_MainWindow"], + order: 4, + }, + { + libpath: "server/infra/index.js", + baseType: "ZhiTheme", + format: "esm", + importType: "import", + runAs: ["Siyuan_MainWindow"], + order: 5, + }, + { + libpath: "server/custom/start.js", + baseType: "ZhiTheme", + format: "esm", + importType: "import", + runAs: ["Siyuan_MainWindow"], + order: 6, + }, + ], + web: [], + vendor: [], + plugin: [], + }, + blog: { + server: { + post: "3333", + }, + }, +} diff --git a/packages/zhi-core/src/config/zhi.js b/packages/zhi-core/src/config/zhi.js new file mode 100644 index 00000000..46d5fc4d --- /dev/null +++ b/packages/zhi-core/src/config/zhi.js @@ -0,0 +1,48 @@ +export default { + dependencies: { + core: [ + { + libpath: "server/infra/index.cjs", + baseType: "ZhiTheme", + format: "cjs", + importType: "require", + runAs: ["Siyuan_MainWindow"], + order: 0, + }, + { + libpath: "core/plugin-system/plugin.js", + baseType: "ZhiTheme", + format: "esm", + importType: "import", + runAs: ["Siyuan_MainWindow", "Siyuan_Browser"], + order: 1, + }, + { + libpath: "core/plugin-system/zhi-plugin-loader.js", + baseType: "ZhiTheme", + format: "esm", + importType: "import", + runAs: ["Siyuan_MainWindow", "Siyuan_Browser"], + order: 2, + }, + ], + server: [ + { + libpath: "server/electron/index.js", + baseType: "ZhiTheme", + format: "esm", + importType: "import", + runAs: ["Siyuan_MainWindow"], + order: 3, + }, + ], + web: [], + vendor: [], + plugin: [], + }, + blog: { + server: { + post: "3333", + }, + }, +} diff --git a/packages/zhi-core/src/core/npm/deps.json b/packages/zhi-core/src/core/npm/deps.json deleted file mode 100644 index f9154326..00000000 --- a/packages/zhi-core/src/core/npm/deps.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "vue": "^3.2.47" -} \ No newline at end of file diff --git a/packages/zhi-core/src/core/npm/node_modules/.package-lock.json b/packages/zhi-core/src/core/npm/node_modules/.package-lock.json index 41bdf68a..89ef0793 100644 --- a/packages/zhi-core/src/core/npm/node_modules/.package-lock.json +++ b/packages/zhi-core/src/core/npm/node_modules/.package-lock.json @@ -5,9 +5,9 @@ "requires": true, "packages": { "node_modules/@siyuan-community/zhi-device": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/@siyuan-community/zhi-device/-/zhi-device-0.1.0.tgz", - "integrity": "sha512-xJYt96nJ1/kcDXGNBFDqUqDqjbtB3Mc7EN0F6HFRd7/gdmKHGkt7STzJXB4j9uMXrT+q7hVLpq7tNN8hPhwiew==", + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/@siyuan-community/zhi-device/-/zhi-device-0.1.4.tgz", + "integrity": "sha512-+a/v2tODkJsIk/ThVWiEXZTgJCJgH+DJGF3RhihlFlKB0UbFnU8iRuBBSW+AVXRE9mCFtj4RhsxDbolYhOEVuw==", "peerDependencies": { "tslib": "2.5.0" } diff --git a/packages/zhi-core/src/core/npm/node_modules/@siyuan-community/zhi-device/README.md b/packages/zhi-core/src/core/npm/node_modules/@siyuan-community/zhi-device/README.md index 88ae8c8f..89862fe5 100644 --- a/packages/zhi-core/src/core/npm/node_modules/@siyuan-community/zhi-device/README.md +++ b/packages/zhi-core/src/core/npm/node_modules/@siyuan-community/zhi-device/README.md @@ -4,12 +4,12 @@ auto check environment whether in browser, browser extension, electron, node and ## Usage -```ts -import { DeviceDetection, BrowserUtil, DeviceTypeEnum } from "@siyuan-community/zhi-device" +```js +import { DeviceDetection, BrowserUtil } from "@siyuan-community/zhi-device" console.log("isInBrowser=>", BrowserUtil.isInBrowser) -const deviceType: DeviceTypeEnum = DeviceDetection.getDevice() +const deviceType = DeviceDetection.getDevice() console.log("deviceType=>", deviceType) // supported platforms @@ -42,7 +42,7 @@ nx build zhi-lib-device ## Test -Execute the unit tests via [jest](https://jestjs.io/docs/getting-started#via-ts-jest) +Execute the unit tests via [vitest](https://vitest.dev) ```bash nx test zhi-lib-device @@ -51,5 +51,7 @@ nx test zhi-lib-device ## Publish ```bash -nx publish zhi-lib-device --ver=0.1.0 --tag=latest -``` \ No newline at end of file +## systemjs tag is systemjs, latest tag is esm +nx publish zhi-lib-device --ver=0.1.0 --tag=systemjs +nx publish zhi-lib-device --ver=0.1.1 --tag=latest +``` diff --git a/packages/zhi-core/src/core/npm/node_modules/@siyuan-community/zhi-device/package.json b/packages/zhi-core/src/core/npm/node_modules/@siyuan-community/zhi-device/package.json index 44e80b9e..249dc9ab 100644 --- a/packages/zhi-core/src/core/npm/node_modules/@siyuan-community/zhi-device/package.json +++ b/packages/zhi-core/src/core/npm/node_modules/@siyuan-community/zhi-device/package.json @@ -1,6 +1,6 @@ { "name": "@siyuan-community/zhi-device", - "version": "0.1.0", + "version": "0.1.4", "type": "module", "description": "auto check environment whether in browser, browser extension, electron, node and more", "repository": "terwer/zhi", diff --git a/packages/zhi-core/src/core/npm/node_modules/@siyuan-community/zhi-device/src/lib/siyuanDevice.d.ts b/packages/zhi-core/src/core/npm/node_modules/@siyuan-community/zhi-device/src/lib/siyuanDevice.d.ts index 690e30df..39b7ebe4 100644 --- a/packages/zhi-core/src/core/npm/node_modules/@siyuan-community/zhi-device/src/lib/siyuanDevice.d.ts +++ b/packages/zhi-core/src/core/npm/node_modules/@siyuan-community/zhi-device/src/lib/siyuanDevice.d.ts @@ -67,39 +67,13 @@ declare class SiyuanDevice { * @param jsPath - js相对路径全路径 * @param type - 类型 */ - static importJs(jsPath: string, type: BasePathTypeEnum): Promise; - /** - * 引入json - * - * @param jsonPath - json相对路径全路径 - * @param type - 类型 - */ - /** - * 引入 json - 以 data 为基本路径 - * - * @param jsonPath - 相对于 data 的相对路径 - */ - /** - * 引入 json - 以 appearance 为基本路径 - * - * @param jsonPath - 相对于 appearance 的相对路径 - */ - /** - * 引入 json - 以 themes 为基本路径 - * - * @param jsonPath - 相对于 themes 的相对路径 - */ - /** - * 引入 zhi 主题的 json - 以 zhi 主题 的根路径为基本路径 - * - * @param jsonPath - 相对于 zhi 主题根路径的相对路径 - */ + static getImportJsPath(jsPath: string, type: BasePathTypeEnum): string; /** * 引入 zhi 主题的 js - 以 zhi 主题 的根路径为基本路径 * * @param jsPath - 相对于 zhi 主题根路径的相对路径 */ - static importZhiThemeJs(jsPath: string): Promise; + static getZhiThemeImportJsPath(jsPath: string): string; /** * 路径拼接 * diff --git a/packages/zhi-core/src/core/npm/node_modules/@siyuan-community/zhi-device/src/lib/siyuanDevice.js b/packages/zhi-core/src/core/npm/node_modules/@siyuan-community/zhi-device/src/lib/siyuanDevice.js index b3f5dc92..a3f81db2 100644 --- a/packages/zhi-core/src/core/npm/node_modules/@siyuan-community/zhi-device/src/lib/siyuanDevice.js +++ b/packages/zhi-core/src/core/npm/node_modules/@siyuan-community/zhi-device/src/lib/siyuanDevice.js @@ -196,7 +196,7 @@ System.register(["./browserUtil.js", "./basePathTypeEnum.js"], function (exports * @param jsPath - js相对路径全路径 * @param type - 类型 */ - static async importJs(jsPath, type) { + static getImportJsPath(jsPath, type) { let fullJsonPath = jsPath; switch (type) { case basePathTypeEnum_js_1.default.BasePathType_Appearance: @@ -214,76 +214,15 @@ System.register(["./browserUtil.js", "./basePathTypeEnum.js"], function (exports default: throw new Error("type must be provided"); } - const { default: data } = await context_1.import(/* @vite-ignore */ fullJsonPath); - return data; + return fullJsonPath; } - /** - * 引入json - * - * @param jsonPath - json相对路径全路径 - * @param type - 类型 - */ - // public static async importJson(jsonPath: string, type: BasePathTypeEnum) { - // let fullJsonPath = jsonPath - // switch (type) { - // case BasePathTypeEnum.BasePathType_Appearance: - // fullJsonPath = this.browserJoinPath(this.siyuanAppearanceRelativePath(), jsonPath) - // break - // case BasePathTypeEnum.BasePathType_Data: - // fullJsonPath = this.browserJoinPath(this.siyuanDataRelativePath(), jsonPath) - // break - // case BasePathTypeEnum.BasePathType_Themes: - // fullJsonPath = this.browserJoinPath(this.siyuanThemeRelativePath(), jsonPath) - // break - // case BasePathTypeEnum.BasePathType_ZhiTheme: - // fullJsonPath = this.browserJoinPath(this.zhiThemeRelativePath(), jsonPath) - // break - // default: - // throw new Error("type must be provided") - // } - // - // const { default: data } = await import(/* @vite-ignore */ fullJsonPath, { assert: { type: "json" } }) - // return data - // } - /** - * 引入 json - 以 data 为基本路径 - * - * @param jsonPath - 相对于 data 的相对路径 - */ - // public static async importDataJson(jsonPath: string) { - // return await this.importJson(jsonPath, BasePathTypeEnum.BasePathType_Data) - // } - /** - * 引入 json - 以 appearance 为基本路径 - * - * @param jsonPath - 相对于 appearance 的相对路径 - */ - // public static async importAppearanceJson(jsonPath: string) { - // return await this.importJson(jsonPath, BasePathTypeEnum.BasePathType_Appearance) - // } - /** - * 引入 json - 以 themes 为基本路径 - * - * @param jsonPath - 相对于 themes 的相对路径 - */ - // public static async importThemesJson(jsonPath: string) { - // return await this.importJson(jsonPath, BasePathTypeEnum.BasePathType_Themes) - // } - /** - * 引入 zhi 主题的 json - 以 zhi 主题 的根路径为基本路径 - * - * @param jsonPath - 相对于 zhi 主题根路径的相对路径 - */ - // public static async importZhiThemeJson(jsonPath: string) { - // return await this.importJson(jsonPath, BasePathTypeEnum.BasePathType_ZhiTheme) - // } /** * 引入 zhi 主题的 js - 以 zhi 主题 的根路径为基本路径 * * @param jsPath - 相对于 zhi 主题根路径的相对路径 */ - static async importZhiThemeJs(jsPath) { - return await this.importJs(jsPath, basePathTypeEnum_js_1.default.BasePathType_ZhiTheme); + static getZhiThemeImportJsPath(jsPath) { + return this.getImportJsPath(jsPath, basePathTypeEnum_js_1.default.BasePathType_ZhiTheme); } // ========================= // import start diff --git a/packages/zhi-core/src/core/npm/node_modules/@siyuan-community/zhi-device/src/lib/siyuanDevice.js.map b/packages/zhi-core/src/core/npm/node_modules/@siyuan-community/zhi-device/src/lib/siyuanDevice.js.map index 4810620c..46e00ad3 100644 --- a/packages/zhi-core/src/core/npm/node_modules/@siyuan-community/zhi-device/src/lib/siyuanDevice.js.map +++ b/packages/zhi-core/src/core/npm/node_modules/@siyuan-community/zhi-device/src/lib/siyuanDevice.js.map @@ -1 +1 @@ -{"version":3,"file":"siyuanDevice.js","sourceRoot":"","sources":["../../../../../packages/zhi-lib-device/src/lib/siyuanDevice.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;;;;;;;;;;;;;;YAKH;;;;;;;eAOG;YACH,eAAA,MAAM,YAAY;gBAChB;;mBAEG;gBACI,MAAM,CAAC,gBAAgB,GAAG,GAAG,EAAE;oBACpC,IAAI,CAAC,wBAAW,CAAC,WAAW,EAAE;wBAC5B,OAAO,KAAK,CAAA;qBACb;oBACD,OAAO,CACL,MAAM,CAAC,YAAY,IAAI,IAAI;wBAC3B,MAAM,CAAC,YAAY,CAAC,aAAa,IAAI,IAAI;wBACzC,MAAM,CAAC,YAAY,CAAC,aAAa,CAAC,aAAa,IAAI,IAAI;wBACvD,MAAM,CAAC,YAAY,CAAC,aAAa,CAAC,aAAa,CAAC,YAAY,CAAC,cAAc,CAAC,KAAK,EAAE,CACpF,CAAA;gBACH,CAAC,CAAA;gBAED;;;;;;;mBAOG;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,CAAC;gBAED;;mBAEG;gBACI,MAAM,CAAC,YAAY;oBACxB,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,eAAe,EAAE,EAAE,KAAK,CAAC,CAAA;gBACrD,CAAC;gBAED;;mBAEG;gBACI,MAAM,CAAC,oBAAoB;oBAChC,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,uBAAuB,EAAE,EAAE,KAAK,CAAC,CAAA;gBACpE,CAAC;aACF,CAAA;iCAEc,YAAY"} \ No newline at end of file +{"version":3,"file":"siyuanDevice.js","sourceRoot":"","sources":["../../../../../packages/zhi-lib-device/src/lib/siyuanDevice.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;;;;;;;;;;;;;;YAKH;;;;;;;eAOG;YACH,eAAA,MAAM,YAAY;gBAChB;;mBAEG;gBACI,MAAM,CAAC,gBAAgB,GAAG,GAAG,EAAE;oBACpC,IAAI,CAAC,wBAAW,CAAC,WAAW,EAAE;wBAC5B,OAAO,KAAK,CAAA;qBACb;oBACD,OAAO,CACL,MAAM,CAAC,YAAY,IAAI,IAAI;wBAC3B,MAAM,CAAC,YAAY,CAAC,aAAa,IAAI,IAAI;wBACzC,MAAM,CAAC,YAAY,CAAC,aAAa,CAAC,aAAa,IAAI,IAAI;wBACvD,MAAM,CAAC,YAAY,CAAC,aAAa,CAAC,aAAa,CAAC,YAAY,CAAC,cAAc,CAAC,KAAK,EAAE,CACpF,CAAA;gBACH,CAAC,CAAA;gBAED;;;;;;;mBAOG;gBACI,MAAM,CAAC,gBAAgB,GAAG,GAAG,EAAE;oBACpC,IAAI,CAAC,wBAAW,CAAC,WAAW,EAAE;wBAC5B,OAAO,KAAK,CAAA;qBACb;oBACD,IAAI,CAAC,wBAAW,CAAC,UAAU,EAAE,EAAE;wBAC7B,OAAO,KAAK,CAAA;qBACb;oBAED;;uBAEG;oBACH,OAAO,OAAQ,MAAc,CAAC,MAAM,KAAK,WAAW,IAAI,OAA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,uBAAuB;oBACnC,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,EAAE,CAAA;oBACjC,IAAI,CAAC,KAAK,EAAE;wBACV,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;qBACrC;oBACD,OAAO,IAAI,CAAC,eAAe,CAAC,EAAE,EAAE,YAAY,EAAE,QAAQ,CAAC,CAAA;gBACzD,CAAC;gBAED;;mBAEG;gBACI,MAAM,CAAC,YAAY;oBACxB,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,eAAe,EAAE,EAAE,KAAK,CAAC,CAAA;gBACrD,CAAC;gBAED;;mBAEG;gBACI,MAAM,CAAC,oBAAoB;oBAChC,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,uBAAuB,EAAE,EAAE,KAAK,CAAC,CAAA;gBACpE,CAAC;aACF,CAAA;iCAEc,YAAY"} \ No newline at end of file diff --git a/packages/zhi-core/src/core/npm/package-lock.json b/packages/zhi-core/src/core/npm/package-lock.json index 58b903ca..9fd3a6e9 100644 --- a/packages/zhi-core/src/core/npm/package-lock.json +++ b/packages/zhi-core/src/core/npm/package-lock.json @@ -9,15 +9,15 @@ "version": "1.0.0", "license": "GPL", "dependencies": { - "@siyuan-community/zhi-device": "^0.1.0", + "@siyuan-community/zhi-device": "^0.1.4", "execa": "^7.1.1", "systemjs": "^6.14.1" } }, "node_modules/@siyuan-community/zhi-device": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/@siyuan-community/zhi-device/-/zhi-device-0.1.0.tgz", - "integrity": "sha512-xJYt96nJ1/kcDXGNBFDqUqDqjbtB3Mc7EN0F6HFRd7/gdmKHGkt7STzJXB4j9uMXrT+q7hVLpq7tNN8hPhwiew==", + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/@siyuan-community/zhi-device/-/zhi-device-0.1.4.tgz", + "integrity": "sha512-+a/v2tODkJsIk/ThVWiEXZTgJCJgH+DJGF3RhihlFlKB0UbFnU8iRuBBSW+AVXRE9mCFtj4RhsxDbolYhOEVuw==", "peerDependencies": { "tslib": "2.5.0" } @@ -194,9 +194,9 @@ }, "dependencies": { "@siyuan-community/zhi-device": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/@siyuan-community/zhi-device/-/zhi-device-0.1.0.tgz", - "integrity": "sha512-xJYt96nJ1/kcDXGNBFDqUqDqjbtB3Mc7EN0F6HFRd7/gdmKHGkt7STzJXB4j9uMXrT+q7hVLpq7tNN8hPhwiew==", + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/@siyuan-community/zhi-device/-/zhi-device-0.1.4.tgz", + "integrity": "sha512-+a/v2tODkJsIk/ThVWiEXZTgJCJgH+DJGF3RhihlFlKB0UbFnU8iRuBBSW+AVXRE9mCFtj4RhsxDbolYhOEVuw==", "requires": {} }, "cross-spawn": { diff --git a/packages/zhi-core/src/core/npm/package.json b/packages/zhi-core/src/core/npm/package.json index ec60905f..6fe3f4ee 100644 --- a/packages/zhi-core/src/core/npm/package.json +++ b/packages/zhi-core/src/core/npm/package.json @@ -21,7 +21,7 @@ }, "homepage": "https://github.com/terwer/zhi#readme", "dependencies": { - "@siyuan-community/zhi-device": "^0.1.0", + "@siyuan-community/zhi-device": "^0.1.4", "execa": "^7.1.1", "systemjs": "^6.14.1" } diff --git a/packages/zhi-core/src/lib/common/models/DependencyItem.ts b/packages/zhi-core/src/lib/common/models/DependencyItem.ts new file mode 100644 index 00000000..107e37d9 --- /dev/null +++ b/packages/zhi-core/src/lib/common/models/DependencyItem.ts @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2023, Terwer . All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Terwer designates this + * particular file as subject to the "Classpath" exception as provided + * by Terwer in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com + * or visit www.terwer.space if you need additional information or have any + * questions. + */ + +/** + * 依赖项类型定义 + * + * @public + * @author terwer + * @version 0.1.0 + * @since 0.1.0 + */ +class DependencyItem { + /** + * 依赖库相对路径 + */ + libpath: string + baseType: string + /** + * 格式 + */ + format: "cjs" | "esm" | "js" + /** + * 引入方式 + */ + importType: "require" | "import" + /** + * 支持的设备列表 + */ + runAs: string[] + /** + * 加载属性,数组越越靠前 + */ + order: number + + constructor() { + this.libpath = "" + this.baseType = "ZhiTheme" + this.format = "cjs" + this.importType = "require" + this.runAs = ["Siyuan_MainWindow", "Node"] + this.order = 0 + } + + /** + * 将 json 转换为 DependencyItem + * @param jsonObj + */ + public fromJson(jsonObj: any) { + // 从一个 JSON 对象中读取 libpath 属性并赋值给实例的 libpath 属性 + this.libpath = jsonObj.libpath + + // 读取并赋值 baseType 属性 + if ("baseType" in jsonObj) { + this.baseType = jsonObj.baseType + } + + // 读取并赋值 format 属性 + if ("format" in jsonObj) { + this.format = jsonObj.format + } + + // 读取并赋值 importType 属性 + if ("importType" in jsonObj) { + this.importType = jsonObj.importType + } + + // 读取并赋值 runAs 属性 + if ("runAs" in jsonObj) { + if (Array.isArray(jsonObj.runAs)) { + this.runAs = jsonObj.runAs + } else { + throw new Error(`fromJson: "runAs" is not an array.`) + } + } + + // 读取并赋值 order 属性 + if ("order" in jsonObj) { + this.order = jsonObj.order + } + } +} + +export default DependencyItem diff --git a/packages/zhi-core/src/lib/core/Bootstrap.ts b/packages/zhi-core/src/lib/core/Bootstrap.ts new file mode 100644 index 00000000..e67540e4 --- /dev/null +++ b/packages/zhi-core/src/lib/core/Bootstrap.ts @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023, Terwer . All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Terwer designates this + * particular file as subject to the "Classpath" exception as provided + * by Terwer in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com + * or visit www.terwer.space if you need additional information or have any + * questions. + */ + +import Lifecycle from "./lifecycle.js" +import DependencyItem from "../common/models/DependencyItem.js" + +/** + * zhi主题唯一激活入口 + * + * @author terwer + * @since 0.1.0 + */ +class Bootstrap { + private static lifecycle = new Lifecycle() + + /** + * 主题激活 + */ + public static async start(): Promise { + await this.lifecycle.init() + return await this.lifecycle.load() + } +} + +export default Bootstrap diff --git a/packages/zhi-core/src/lib/core/lifecycle.ts b/packages/zhi-core/src/lib/core/lifecycle.ts new file mode 100644 index 00000000..416cf38a --- /dev/null +++ b/packages/zhi-core/src/lib/core/lifecycle.ts @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2023, Terwer . All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Terwer designates this + * particular file as subject to the "Classpath" exception as provided + * by Terwer in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com + * or visit www.terwer.space if you need additional information or have any + * questions. + */ + +import DependencyItem from "../common/models/DependencyItem.js" +import { createCoreLogger, SystemImport } from "../utils/index.js" + +/** + * zhi主题统一生命周期管理 + * + * @author terwer + * @version 0.1.0 + * @since 0.1.0 + */ +class Lifecycle { + private zhiDevice: any + private readonly logger + private siyuanDevice: any + private ZHI_JSON_SCHEMA = "config/zhi-schema.js" + private ZHI_JSON = "config/zhi.js" + + constructor() { + this.logger = createCoreLogger("lifecycle") + } + + async init() { + this.zhiDevice = await SystemImport("@siyuan-community/zhi-device") + + this.siyuanDevice = this.zhiDevice.SiyuanDevice + } + + /** + * 加载依赖,核心加载顺序按照下面描述的顺序加载,内部的加载顺序由 order 字段决定, + * 所有依赖定义在主题根目录的 `zhi.json` + * + * ``` + * 加载顺序如下: + * 1 核心模块-require-hacker、infra、browser-window、插件系统、内部插件 + * 2 后端模块 + * 3 前端模块 + * 4 第三方库 + * ``` + */ + public async load() { + const allImports = [] + + // json-schema 校验 + // json读取 + // const { default: data } = await import("/appearance/themes/zhi/zhi.js");data + // const { default: data } = await import("/appearance/themes/zhi/zhi.json", { assert: { type: "json" } });data + const zhiSchemaPath = this.siyuanDevice.getZhiThemeImportJsPath(this.ZHI_JSON_SCHEMA) + const { default: zhiSchema } = await import(zhiSchemaPath) + const zhiJsonPath = this.siyuanDevice.getZhiThemeImportJsPath(this.ZHI_JSON) + const { default: zhiJson } = await import(zhiJsonPath) + this.logger.debug("zhiSchema=>", zhiSchema) + this.logger.debug("zhiJson=>", zhiJson) + // const valiResult = this.common.jsonUtil.validateObjectSchema(zhiSchema, zhiJson) + // if (!valiResult.valid) { + // throw new Error( + // `${this.ZHI_JSON} is not valid, error msg: ${valiResult.error ?? "None"}, please check ${this.ZHI_JSON_SCHEMA}` + // ) + // } else { + // this.logger.info(`Success, ${this.ZHI_JSON} is ok`) + // } + + // 解析json + // 核心模块 + const cores = zhiJson.dependencies.core + const coreModuleImports = await this.loadCoreModules(cores) + // 后端模块 + const servers = zhiJson.dependencies.server + const backendImports = await this.loadBackendModules(servers) + // 前端模块 + const webs = zhiJson.dependencies.web + const frontendImports = await this.loadFrontendModules(webs) + // 第三方组件 + const vendors = zhiJson.dependencies.vendor + const vendorImports = await this.loadVendors(vendors) + + return allImports.concat(coreModuleImports).concat(backendImports).concat(frontendImports).concat(vendorImports) + } + + /** + * 加载核心模块 + * + * @private + */ + private async loadCoreModules(deps: object[]): Promise { + const coreModulesImports: DependencyItem[] = deps.map((dep: object) => { + const dependency = new DependencyItem() + dependency.fromJson(dep) + return dependency + }) + + this.logger.info(`Registered ${coreModulesImports.length} Core modules`) + return coreModulesImports + } + + /** + * 加载后端模块 + * + * @private + */ + private async loadBackendModules(deps: object[]): Promise { + const backendModulesImports: DependencyItem[] = deps.map((dep: object) => { + const dependency = new DependencyItem() + dependency.fromJson(dep) + return dependency + }) + + this.logger.info(`Registered ${backendModulesImports.length} Backend modules`) + return backendModulesImports + } + + /** + * 加载前端模块 + * + * @private + */ + private async loadFrontendModules(deps: object[]): Promise { + const frontendModulesImports: DependencyItem[] = deps.map((dep: object) => { + const dependency = new DependencyItem() + dependency.fromJson(dep) + return dependency + }) + + this.logger.info(`Registered ${frontendModulesImports.length} Frontend modules`) + return frontendModulesImports + } + + /** + * 加载第三方库 + * + * @private + */ + private async loadVendors(deps: object[]): Promise { + const vendorImports: DependencyItem[] = deps.map((dep: object) => { + const dependency = new DependencyItem() + dependency.fromJson(dep) + return dependency + }) + + this.logger.info(`Registered ${vendorImports.length} Vendors`) + return vendorImports + } +} + +export default Lifecycle diff --git a/packages/zhi-core/src/lib/utils/zhi-core-util.ts b/packages/zhi-core/src/lib/utils/zhi-core-util.ts index 08d1c16a..ffc4afbc 100644 --- a/packages/zhi-core/src/lib/utils/zhi-core-util.ts +++ b/packages/zhi-core/src/lib/utils/zhi-core-util.ts @@ -27,6 +27,7 @@ * 简单的日志接口 */ interface ILogger { + debug: (msg: string, obj?: any) => void info: (msg: string, obj?: any) => void error: (msg: string | Error, obj?: any) => void } @@ -62,6 +63,7 @@ export const createCoreLogger = (name: string): ILogger => { } return { + debug: (msg: string, obj?: any) => log("DEBUG", msg, obj), info: (msg: string, obj?: any) => log("INFO", msg, obj), error: (msg: string | Error, obj?: any) => { if (typeof msg == "string") { @@ -104,3 +106,17 @@ export const isFileExists = async (p: string, type: string) => { return false } } + +/** + * 动态加载 SystemJs 模块 + * + * @param moduleName - 模块名称 + */ +export const SystemImport = async (moduleName: string) => { + const System = win.System + if (!System) { + throw new Error("SystemJs not work, zhi-core will stop loading!") + } + + return await System.import(moduleName) +} diff --git a/packages/zhi-core/src/lib/zhi-core.spec.ts b/packages/zhi-core/src/lib/zhi-core.spec.ts index 2c5b7a05..732b1cc4 100644 --- a/packages/zhi-core/src/lib/zhi-core.spec.ts +++ b/packages/zhi-core/src/lib/zhi-core.spec.ts @@ -26,8 +26,7 @@ import { zhiCore } from "./zhi-core" describe("zhiCore", () => { - it("test zhiCore object", () => { - expect(zhiCore).toBeTruthy() - zhiCore.init() + it("test zhiCore object", async () => { + await zhiCore.init() }) }) diff --git a/packages/zhi-core/src/lib/zhi-core.ts b/packages/zhi-core/src/lib/zhi-core.ts index 2f800f0e..0d704917 100644 --- a/packages/zhi-core/src/lib/zhi-core.ts +++ b/packages/zhi-core/src/lib/zhi-core.ts @@ -50,6 +50,7 @@ const addScriptToHead = (script: string, type?: string) => { const loadTheme = async (): Promise => { const zhi = new Zhi() await zhi.init() + await zhi.start() } /** diff --git a/packages/zhi-core/src/lib/zhi.ts b/packages/zhi-core/src/lib/zhi.ts index d507e9a0..d2c2c843 100644 --- a/packages/zhi-core/src/lib/zhi.ts +++ b/packages/zhi-core/src/lib/zhi.ts @@ -23,8 +23,10 @@ * questions. */ -import { createCoreLogger, getFile, isElectron, win } from "./utils/index.js" +import { createCoreLogger, getFile, isElectron, SystemImport, win } from "./utils/index.js" import { initRequireHacker, shellCmd } from "./node/index.js" +import DependencyItem from "./common/models/DependencyItem.js" +import Bootstrap from "./core/Bootstrap.js" /** * 主题通用类(由theme.js动态调用,除了单元测试之外请勿主动调用) @@ -34,7 +36,7 @@ import { initRequireHacker, shellCmd } from "./node/index.js" * @since 0.1.0 */ export class Zhi { - private zhiDeviceModule: any + private zhiDevice: any private readonly logger private runAs @@ -50,16 +52,36 @@ export class Zhi { } /** - * 主流程加载 + * 初始化 */ public async init(): Promise { - this.logger.info("zhi initiating...") + this.zhiDevice = await SystemImport("@siyuan-community/zhi-device") + this.logger.info("zhiDevice=>", this.zhiDevice) + } + + /** + * 生命周期入口 + * + * @param args - 参数 + * @private + */ + private async main(args: string[]): Promise { + this.logger.info("Parsing args...", args) + return await Bootstrap.start() + } + + /** + * 主流程加载 + */ + public async start(): Promise { + this.logger.info("Zhi initiating...") - // 因为后面可能会用到一些依赖,所以这里需要先hack if (isElectron()) { + // require方式已使用时,为了加载自定义目录的类库,需要先hack await initRequireHacker() + // 挂载命令行 win.shellCmd = shellCmd - this.logger.info("Electron only modules hacked") + this.logger.info("Electron only core modules hacked") } // ========================================================================= @@ -73,24 +95,26 @@ export class Zhi { // @since 0.1.0 // ========================================================================= - const System = win.System - if (!System) { - this.logger.error("SystemJs not work, zhi-core will stop loading!") - return - } - this.zhiDeviceModule = await System.import("@siyuan-community/zhi-device") - this.logger.info("zhiDeviceModule=>", this.zhiDeviceModule) - - const deviceDetection = this.zhiDeviceModule.DeviceDetection - // const siyuanDevice = this.zhiDeviceModule.SiyuanDevice - + const deviceDetection = this.zhiDevice.DeviceDetection this.runAs = deviceDetection.getDevice() - // this.logger.info(`Hello, this is zhi theme You are from ${this.runAs}`) const pkgJson = JSON.parse(await getFile("/data/storage/zhi/package.json", "text")) as any // this.logger.info("pkgJson=>", pkgJson) this.logger.info( `Hello, this is zhi theme v${pkgJson.version}, ${pkgJson.description} by ${pkgJson.author}! You are from ${this.runAs}` ) + + // 初始化第三方依赖 + // import + // browser esm path: "/[libpath]" + // electron esm path: "/[libpath]" + // custom-path X + // + // require + // browser X + // electron cjs path: "[abspath][libpath]" + // custom-path require-hacker + const dynamicImports = await this.main([]) + console.log("dynamicImports=>", dynamicImports) } } diff --git a/packages/zhi-core/src/main.ts b/packages/zhi-core/src/main.ts index 1a447ebc..c329044e 100644 --- a/packages/zhi-core/src/main.ts +++ b/packages/zhi-core/src/main.ts @@ -23,12 +23,11 @@ * questions. */ -import { Zhi } from "./lib/zhi.js" +import { zhiCore } from "./lib/zhi-core.js" /** * 主题的真实入口,由 systemjs 动态加载,支持 esm */ ;(async () => { - const zhi = new Zhi() - await zhi.init() + await zhiCore.init() })() diff --git a/packages/zhi-core/src/theme.js b/packages/zhi-core/src/theme.js index 26e73357..f331cd3a 100644 --- a/packages/zhi-core/src/theme.js +++ b/packages/zhi-core/src/theme.js @@ -48,7 +48,7 @@ const customMapImport = await import("./customMap.js") customMap = customMapImport.default } - const defaultImportMap = await import("./map.js") + const defaultImportMap = await import("./config/map.js") logger.info("defaultImportMap=>", defaultImportMap) const importMap = { imports: { @@ -70,6 +70,7 @@ }, 500) // 4 初始化主题 - // 由于 esm 的问题,不推荐在这里直接初始化,而是在上面动态加载 main.js + // 由于 esm 在浏览器端的限制,需要再上面用 systemjs-import 的方式,使用动态 importmap ,动态加载 main.js + // 实际执行的逻辑类似 // await zhiCore.zhiCore.init() })() diff --git a/packages/zhi-lib-device/README.md b/packages/zhi-lib-device/README.md index 07dbce4f..89862fe5 100644 --- a/packages/zhi-lib-device/README.md +++ b/packages/zhi-lib-device/README.md @@ -4,12 +4,12 @@ auto check environment whether in browser, browser extension, electron, node and ## Usage -```ts -import { DeviceDetection, BrowserUtil, DeviceTypeEnum } from "@siyuan-community/zhi-device" +```js +import { DeviceDetection, BrowserUtil } from "@siyuan-community/zhi-device" console.log("isInBrowser=>", BrowserUtil.isInBrowser) -const deviceType: DeviceTypeEnum = DeviceDetection.getDevice() +const deviceType = DeviceDetection.getDevice() console.log("deviceType=>", deviceType) // supported platforms @@ -51,5 +51,7 @@ nx test zhi-lib-device ## Publish ```bash -nx publish zhi-lib-device --ver=0.1.0 --tag=latest -``` \ No newline at end of file +## systemjs tag is systemjs, latest tag is esm +nx publish zhi-lib-device --ver=0.1.0 --tag=systemjs +nx publish zhi-lib-device --ver=0.1.1 --tag=latest +``` diff --git a/packages/zhi-lib-device/package.json b/packages/zhi-lib-device/package.json index c2a65ca7..688b80b4 100644 --- a/packages/zhi-lib-device/package.json +++ b/packages/zhi-lib-device/package.json @@ -1,6 +1,6 @@ { "name": "@siyuan-community/zhi-device", - "version": "0.1.0", + "version": "0.1.5", "type": "module", "description": "auto check environment whether in browser, browser extension, electron, node and more", "repository": "terwer/zhi", diff --git a/packages/zhi-lib-device/src/lib/siyuanDevice.ts b/packages/zhi-lib-device/src/lib/siyuanDevice.ts index 5009848a..259a4115 100644 --- a/packages/zhi-lib-device/src/lib/siyuanDevice.ts +++ b/packages/zhi-lib-device/src/lib/siyuanDevice.ts @@ -199,7 +199,7 @@ class SiyuanDevice { * @param jsPath - js相对路径全路径 * @param type - 类型 */ - public static async importJs(jsPath: string, type: BasePathTypeEnum) { + public static getImportJsPath(jsPath: string, type: BasePathTypeEnum) { let fullJsonPath = jsPath switch (type) { case BasePathTypeEnum.BasePathType_Appearance: @@ -218,82 +218,16 @@ class SiyuanDevice { throw new Error("type must be provided") } - const { default: data } = await import(/* @vite-ignore */ fullJsonPath) - return data + return fullJsonPath } - /** - * 引入json - * - * @param jsonPath - json相对路径全路径 - * @param type - 类型 - */ - // public static async importJson(jsonPath: string, type: BasePathTypeEnum) { - // let fullJsonPath = jsonPath - // switch (type) { - // case BasePathTypeEnum.BasePathType_Appearance: - // fullJsonPath = this.browserJoinPath(this.siyuanAppearanceRelativePath(), jsonPath) - // break - // case BasePathTypeEnum.BasePathType_Data: - // fullJsonPath = this.browserJoinPath(this.siyuanDataRelativePath(), jsonPath) - // break - // case BasePathTypeEnum.BasePathType_Themes: - // fullJsonPath = this.browserJoinPath(this.siyuanThemeRelativePath(), jsonPath) - // break - // case BasePathTypeEnum.BasePathType_ZhiTheme: - // fullJsonPath = this.browserJoinPath(this.zhiThemeRelativePath(), jsonPath) - // break - // default: - // throw new Error("type must be provided") - // } - // - // const { default: data } = await import(/* @vite-ignore */ fullJsonPath, { assert: { type: "json" } }) - // return data - // } - - /** - * 引入 json - 以 data 为基本路径 - * - * @param jsonPath - 相对于 data 的相对路径 - */ - // public static async importDataJson(jsonPath: string) { - // return await this.importJson(jsonPath, BasePathTypeEnum.BasePathType_Data) - // } - - /** - * 引入 json - 以 appearance 为基本路径 - * - * @param jsonPath - 相对于 appearance 的相对路径 - */ - // public static async importAppearanceJson(jsonPath: string) { - // return await this.importJson(jsonPath, BasePathTypeEnum.BasePathType_Appearance) - // } - - /** - * 引入 json - 以 themes 为基本路径 - * - * @param jsonPath - 相对于 themes 的相对路径 - */ - // public static async importThemesJson(jsonPath: string) { - // return await this.importJson(jsonPath, BasePathTypeEnum.BasePathType_Themes) - // } - - /** - * 引入 zhi 主题的 json - 以 zhi 主题 的根路径为基本路径 - * - * @param jsonPath - 相对于 zhi 主题根路径的相对路径 - */ - // public static async importZhiThemeJson(jsonPath: string) { - // return await this.importJson(jsonPath, BasePathTypeEnum.BasePathType_ZhiTheme) - // } - /** * 引入 zhi 主题的 js - 以 zhi 主题 的根路径为基本路径 * * @param jsPath - 相对于 zhi 主题根路径的相对路径 */ - public static async importZhiThemeJs(jsPath: string) { - return await this.importJs(jsPath, BasePathTypeEnum.BasePathType_ZhiTheme) + public static getZhiThemeImportJsPath(jsPath: string) { + return this.getImportJsPath(jsPath, BasePathTypeEnum.BasePathType_ZhiTheme) } // =========================