From 115a86d15a6b2aedd928e3242331e71b5d44ed5a Mon Sep 17 00:00:00 2001 From: terwer Date: Thu, 9 Mar 2023 23:20:20 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=BD=BF=E7=94=A8=20zhi-cli=20?= =?UTF-8?q?=E9=87=8D=E6=9E=84=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 ++- src/apps/zhi/zhi.ts | 10 ++++-- src/models/DependencyItem.ts | 44 +++++++++++++++++++++++++ src/utils/ZhiUtil.ts | 46 +++++++++++++++++++++++++++ src/utils/zhiSdkUtil.ts | 3 +- test/{index.test.ts => theme.test.ts} | 8 +++-- theme.ts | 6 +++- vite.config.ts | 13 +++----- 8 files changed, 117 insertions(+), 17 deletions(-) create mode 100644 src/models/DependencyItem.ts create mode 100644 src/utils/ZhiUtil.ts rename test/{index.test.ts => theme.test.ts} (89%) diff --git a/.gitignore b/.gitignore index fa06e346..7a3b9a7f 100644 --- a/.gitignore +++ b/.gitignore @@ -31,4 +31,6 @@ docs/doc # Theme theme.css -theme.js \ No newline at end of file +theme.js +vendor +zhi.js \ No newline at end of file diff --git a/src/apps/zhi/zhi.ts b/src/apps/zhi/zhi.ts index a0de4313..e5a8369a 100644 --- a/src/apps/zhi/zhi.ts +++ b/src/apps/zhi/zhi.ts @@ -24,10 +24,10 @@ */ import { version } from "~/package.json" -import zhiSdkUtil from "~/src/utils/zhiSdkUtil" import ThemeFromEnum from "~/src/enums/themeFromEnum" import strUtil from "~/src/utils/strUtil" import DependencyItem from "~/src/models/DependencyItem" +import ZhiUtil from "~/src/utils/ZhiUtil" /** * 主题入口 @@ -36,9 +36,15 @@ import DependencyItem from "~/src/models/DependencyItem" * @since 1.0.0 */ class Zhi { - private logger = zhiSdkUtil.getLogger() + private logger + + constructor() { + this.logger = ZhiUtil.zhiSdk().getLogger() + } public async main(args: string[]): Promise { + this.logger.info(strUtil.f("parsing args <{0}>", args)) + this.hello(ThemeFromEnum.ThemeFrom_Siyuan) return Promise.resolve([]) } diff --git a/src/models/DependencyItem.ts b/src/models/DependencyItem.ts new file mode 100644 index 00000000..ed2a909a --- /dev/null +++ b/src/models/DependencyItem.ts @@ -0,0 +1,44 @@ +/* + * 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. + */ + +/** + * 依赖项类型定义 + * + * @author terwer + * @since 1.0.0 + */ +class DependencyItem { + libpath: string + format: "cjs" | "esm" | "js" + importType: "require" | "import" + + constructor() { + this.libpath = "" + this.format = "cjs" + this.importType = "require" + } +} + +export default DependencyItem diff --git a/src/utils/ZhiUtil.ts b/src/utils/ZhiUtil.ts new file mode 100644 index 00000000..07c652fd --- /dev/null +++ b/src/utils/ZhiUtil.ts @@ -0,0 +1,46 @@ +/* + * 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 ZhiSdkUtil from "~/src/utils/zhiSdkUtil" + +/** + * 工具类统一入口 + * + * @author terwer + * @since 1.0.0 + */ +class ZhiUtil { + private static zhiSdkUtil: ZhiSdkUtil + public static zhiSdk() { + if (!ZhiUtil.zhiSdkUtil) { + console.log("[zhi] zhiSdkUtil Not found, initiating...") + ZhiUtil.zhiSdkUtil = new ZhiSdkUtil() + console.log("[zhi] zhiSdkUtil inited.") + } + return ZhiUtil.zhiSdkUtil + } +} + +export default ZhiUtil diff --git a/src/utils/zhiSdkUtil.ts b/src/utils/zhiSdkUtil.ts index 6c413e05..bd87f162 100644 --- a/src/utils/zhiSdkUtil.ts +++ b/src/utils/zhiSdkUtil.ts @@ -57,5 +57,4 @@ class ZhiSdkUtil { } } -const zhiSdkUtil = new ZhiSdkUtil() -export default zhiSdkUtil +export default ZhiSdkUtil diff --git a/test/index.test.ts b/test/theme.test.ts similarity index 89% rename from test/index.test.ts rename to test/theme.test.ts index 4f3dbcda..05707e1f 100644 --- a/test/index.test.ts +++ b/test/theme.test.ts @@ -24,9 +24,11 @@ */ import { describe, it } from "vitest" +import Theme from "~/theme" -describe("test index", () => { - it("test hello", function () { - console.log("hello") +describe("test theme", () => { + it("test main", async () => { + const theme = new Theme() + await theme.init() }) }) diff --git a/theme.ts b/theme.ts index 171d7155..1c8322d8 100644 --- a/theme.ts +++ b/theme.ts @@ -49,8 +49,10 @@ class Theme { this.zhiTheme = new Zhi() } + /** + * 主流程加载 + */ public async init(): Promise { - // 主流程加载 return await this.zhiTheme.main([]) } } @@ -59,3 +61,5 @@ class Theme { const theme = new Theme() await theme.init() })() + +export default Theme diff --git a/vite.config.ts b/vite.config.ts index fd7cfbbe..fdd4ac7f 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -44,17 +44,14 @@ export default defineConfig({ }, commonjsOptions: { defaultIsModuleExports: true, - }, - rollupOptions: { - output: { - esModule: "if-default-prop", - manualChunks: undefined, - }, - external: ["siyuan"], + include: [], }, // 构建后是否生成 source map 文件 sourcemap: false, // 是否混淆 - minify: false, + minify: true, + }, + optimizeDeps: { + disabled: false, }, })