Skip to content

Commit

Permalink
chore: 使用 zhi-cli 重构项目
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Mar 9, 2023
1 parent 2e5181d commit 115a86d
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 17 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ docs/doc

# Theme
theme.css
theme.js
theme.js
vendor
zhi.js
10 changes: 8 additions & 2 deletions src/apps/zhi/zhi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

/**
* 主题入口
Expand All @@ -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<DependencyItem[]> {
this.logger.info(strUtil.f("parsing args <{0}>", args))

this.hello(ThemeFromEnum.ThemeFrom_Siyuan)
return Promise.resolve([])
}
Expand Down
44 changes: 44 additions & 0 deletions src/models/DependencyItem.ts
Original file line number Diff line number Diff line change
@@ -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
46 changes: 46 additions & 0 deletions src/utils/ZhiUtil.ts
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions src/utils/zhiSdkUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,4 @@ class ZhiSdkUtil {
}
}

const zhiSdkUtil = new ZhiSdkUtil()
export default zhiSdkUtil
export default ZhiSdkUtil
8 changes: 5 additions & 3 deletions test/index.test.ts → test/theme.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
6 changes: 5 additions & 1 deletion theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ class Theme {
this.zhiTheme = new Zhi()
}

/**
* 主流程加载
*/
public async init(): Promise<DependencyItem[]> {
// 主流程加载
return await this.zhiTheme.main([])
}
}
Expand All @@ -59,3 +61,5 @@ class Theme {
const theme = new Theme()
await theme.init()
})()

export default Theme
13 changes: 5 additions & 8 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
})

0 comments on commit 115a86d

Please sign in to comment.