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 10, 2023
1 parent ebbc476 commit f32d3ee
Show file tree
Hide file tree
Showing 30 changed files with 2,561 additions and 39 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ vendor
zhi.js
dist-cjs
*.d.ts
*.map
*.map
styles/**/**.css
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
},
"typings": "./typings/index.d.ts",
"scripts": {
"dev": "node --experimental-specifier-resolution=node --loader ts-node/esm build.ts",
"build": "vite build",
"theme": "node --experimental-specifier-resolution=node --loader ts-node/esm build.ts",
"blog": "vite build",
"test": "vitest",
"coverage": "vitest run --coverage",
"lint": "eslint --ext .ts ./src",
Expand Down
6 changes: 3 additions & 3 deletions src/apps/zhi/plugin-system/pluginSystemUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class HackPluginSystem {
try {
return JSON.parse(content)
} catch (e) {
this.logger.error("loading manifest: " + manifest, e)
this.logger.error("Lading manifest: " + manifest, e)
return null
}
}
Expand Down Expand Up @@ -140,10 +140,10 @@ const initPluginSystem = async () => {
)
)
const script = data.toString("utf8")
logger.info("local plugin system found, loading...")
logger.info("Local plugin system found, loading...")
eval(script)
} catch (e) {
logger.info("local plugin system not found, load online", e)
logger.info("Local plugin system not found, load online", e)
return fetch(
"https://gitee.com/zuoez02/siyuan-plugin-system/raw/main/main.js",
{ cache: "no-cache" }
Expand Down
4 changes: 2 additions & 2 deletions src/apps/zhi/zhi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ class Zhi {
}

public async main(args: string[]): Promise<DependencyItem[]> {
this.logger.debug(strUtil.f("parsing args <{0}>", args))
this.logger.debug(strUtil.f("Parsing args <{0}>", args))
this.hello(ThemeFromEnum.ThemeFrom_Siyuan)
return await Bootstrap.start()
}

public hello(from: string): void {
this.logger.info(
strUtil.f(
"hello, {0} {1} v{2}! You are from {3}",
"Hello, {0} {1} v{2}! You are from {3}",
"zhi",
"theme",
version,
Expand Down
10 changes: 9 additions & 1 deletion src/utils/ZhiUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
*/

import ZhiSdkUtil from "~/src/utils/zhiSdkUtil"
import callsites from "callsites"
import strUtil from "~/src/utils/strUtil"
import dateUtil from "~/src/utils/dateUtil"

/**
* 工具类统一入口
Expand All @@ -36,7 +39,12 @@ class ZhiUtil {
public static zhiSdk() {
if (!ZhiUtil.zhiSdkUtil) {
ZhiUtil.zhiSdkUtil = new ZhiSdkUtil()
console.log("[zhi] zhiSdk inited.")
const logger = ZhiUtil.zhiSdkUtil.getLogger()
logger.info(
strUtil.f(
"ZhiSdk inited, components are available now,like logger, env and so on."
)
)
}
return ZhiUtil.zhiSdkUtil
}
Expand Down
129 changes: 129 additions & 0 deletions src/utils/dateUtil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* 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 DateUtil {
private readonly TIME_SPLIT = " "

/**
* 给日期添加小时
* @param date
* @param numOfHours
* @returns {*}
*
* @author terwer
* @since 1.0.0
*/
private addHoursToDate(date: Date, numOfHours: number): Date {
date.setTime(date.getTime() + numOfHours * 60 * 60 * 1000)
return date
}

/**
* 转换ISO日期为中文日期
*
* @param str '2022-07-18T06:25:48.000Z
* @param isAddTimeZone 是否增加时区(默认不增加)
* @param isShort 是否只返回日期
* @returns {string|*}
* @author terwer
* @since 1.0.0
*/
public formatIsoToZhDate = (
str: string,
isAddTimeZone?: boolean,
isShort?: boolean
): string => {
if (!str) {
return ""
}
let newstr = str

// https://www.regextester.com/112232
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match
const isoDateRegex =
/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(.\d{3})Z$/gm
const matches = newstr.match(isoDateRegex)
if (matches == null) {
return str
}
for (let i = 0; i < matches.length; i++) {
const match = matches[i]

let newmatch = match
if (isAddTimeZone) {
// ISO日期默认晚8小时
// logUtil.logInfo(addHoursToDate(new Date(match), 8))
newmatch = this.addHoursToDate(new Date(match), 8).toISOString()
}

const dts = newmatch.split("T")
const d = dts[0]
const t = dts[1].split(".")[0]

let result = d + this.TIME_SPLIT + t
if (isShort) {
result = d
}

newstr = newstr.replace(match, result)
// logUtil.logInfo("formatZhDate match=>", match)
// logUtil.logInfo("formatZhDate result=>", result)
}

// logUtil.logInfo("formatZhDate=>", newstr)
return newstr
}

/**
* 当前日期时间完整格式,格式:2023-03-10 02:03:43
*/
public nowZh() {
return this.formatIsoToZhDate(new Date().toISOString())
}

/**
* 当前日期,格式:2023-03-10
*/
public nowDateZh() {
return this.formatIsoToZhDate(new Date().toISOString(), true, true)
}

/**
* 当前时间,格式:02:03:43
*/
public nowTimeZh() {
const now = this.formatIsoToZhDate(new Date().toISOString(), true)
return now.split(this.TIME_SPLIT)[1]
}
}

const dateUtil = new DateUtil()
export default dateUtil
3 changes: 3 additions & 0 deletions styles/blog/blog-theme.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* 博客主题首页入口 */
@require "../common/vars/vars-blog"
@require "./default/main.styl"
2 changes: 2 additions & 0 deletions styles/blog/default/main.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
body
margin: 0 auto
14 changes: 14 additions & 0 deletions styles/common/basic/basic-dark.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* -------------------------------------------------颜色定义-暗黑模式--------------------------------------------------- */
html[data-theme-mode="dark"]
--zhi-body-bg: _body-bg-dark
--zhi-main-bg: _main-bg-dark
--zhi-sidebar-bg: _sidebar-bg-dark
//--zhi-blur-bg: _blur-bg-dark
//--zhi-custom-block-bg: _custom-block-bg-dark
--zhi-primary-color: _primary-color-dark
--zhi-text-color: _text-color-dark
//--zhi-text-lighten-color: _text-lighten-color-dark
--zhi-border-color: _border-color-dark
//--zhi-code-bg: _code-bg-dark
//--zhi-code-color: _code-color-dark
--zhi-list-hover: _list-hover-dark
14 changes: 14 additions & 0 deletions styles/common/basic/basic-green.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* -------------------------------------------------颜色定义-阅读模式--------------------------------------------------- */
html[data-theme-mode="green"]
--zhi-body-bg: _body-bg-green
--zhi-main-bg: _main-bg-green
--zhi-sidebar-bg: _sidebar-bg-green
//--zhi-blur-bg: _blur-bg-green
//--zhi-custom-block-bg: _custom-block-bg-green
--zhi-primary-color: _primary-color-green
--zhi-text-color: _text-color-green
//--zhi-text-lighten-color: _text-lighten-color-green
--zhi-border-color: _border-color-green
//--zhi-code-bg: _code-bg-green
//--zhi-code-color: _code-color-green
--zhi-list-hover: _list-hover-green
14 changes: 14 additions & 0 deletions styles/common/basic/basic-light.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* -------------------------------------------------颜色定义-浅色模式--------------------------------------------------- */
html[data-theme-mode="light"]
--zhi-body-bg: _body-bg-light
--zhi-main-bg: _main-bg-light
--zhi-sidebar-bg: _sidebar-bg-light
//--zhi-blur-bg: _blur-bg-light
//--zhi-custom-block-bg: _custom-block-bg-light
--zhi-primary-color: _primary-color-light
--zhi-text-color: _text-color-light
//--zhi-text-lighten-color: _text-lighten-color-light
--zhi-border-color: _border-color-light
//--zhi-code-bg: _code-bg-light
//--zhi-code-color: _code-color-light
--zhi-list-hover: _list-hover-light
Loading

0 comments on commit f32d3ee

Please sign in to comment.