Skip to content

Commit

Permalink
feat: Check supported theme version
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Mar 31, 2023
1 parent 78f4a3c commit 09cae99
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 19 deletions.
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@
[![](https://img.shields.io/badge/dynamic-blog-blue)](https://github.com/terwer/zhi/tree/dev/packages/zhi-blog)
[![](https://img.shields.io/badge/static-blog-purple)](https://github.com/terwer/zhi/tree/dev/packages/zhi-blog-astro)

> ⚠️ Special Reminder 1: 1.0.0 is an early version that is available for testing purposes only and its functionality is
> not yet comprehensive. Please feel free to raise issues to provide valuable feedback. For the features of this
> version,
> please refer to [Core Features](#Core Features).
> ⚠️ WARNING 1: Attention: The `zhi` theme only supports the `2.7.6+` version of [siyuan-note](https://github.com/siyuan-note/siyuan) , and the plugin function only supports `2.8.1+`. Otherwise, you need to upgrade [siyuan-note](https://github.com/siyuan-note/siyuan) to a new version.
> ⚠️ Special Reminder 2: The plugin system defaults to `Safe Mode` , You need to click the settings menu in the upper
> right corner to turn off Safe Mode before you can enable the
> plugin system.
> ⚠️ WARNING 2: `1.0.0` is an available version in the early stage, and the function is not comprehensive yet. It is only used for testing and welcomes valuable opinions through issuing. Please refer to [core features](#core-features) for this version's characteristics.
> ⚠️ Special Reminder 3: All plugins except for the theme core plugin are
> disabled by default, so you need to manually enable the corresponding plugins in the plugin list to use them.
> ⚠️ WARNING 3: The plugin system is set to `security mode` by default, and you need to click on the settings menu in the upper right corner to turn off the security mode before you can activate the plugin system.
> ⚠️ WARNING 4: Except for the theme's core plugins, all plugins are disabled by default and need to be enabled in the plugin list before the first use.
## Quick start

Expand Down
10 changes: 6 additions & 4 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@
[![](https://img.shields.io/badge/动态-博客-blue)](https://github.com/terwer/zhi/tree/dev/packages/zhi-blog)
[![](https://img.shields.io/badge/静态-博客-purple)](https://github.com/terwer/zhi/tree/dev/packages/zhi-blog-astro)

> ⚠️ 特别提醒 1: `1.0.0` 为前期可用版本,功能上尚不全面,仅作为测试使用,欢迎 issue
> ⚠️ 特别提醒 1: 注意:`zhi` 主题仅支持 [思源笔记](https://github.com/siyuan-note/siyuan) `2.7.6+` 以上版本,插件功能仅支持 `2.8.1+` ,否则您需要升级 [思源笔记](https://github.com/siyuan-note/siyuan) 到新版本。
> ⚠️ 特别提醒 2: `1.0.0` 为前期可用版本,功能上尚不全面,仅作为测试使用,欢迎 issue
> 提出宝贵意见。此版本特性,请参照 [核心特性](#核心特性)
> ⚠️ 特别提醒 2: 插件系统默认为 `安全模式` ,需要点击右上角设置菜单关闭安全模式,才能开启插件系统。
> ⚠️ 特别提醒 3: 插件系统默认为 `安全模式` ,需要点击右上角设置菜单关闭安全模式,才能开启插件系统。
> ⚠️ 特别提醒 4: 除主题核心插件外,所有插件默认禁用,需要在首次使用之前,在插件列表开启。
> ⚠️ 特别提醒 3: 除主题核心插件外,所有插件默认禁用,需要在首次使用之前,在插件列表开启。

## 快速上手

直接在思源笔记 `集市` 下载 `zhi` 主题,然后在 <kbd>设置</kbd> - <kbd>外观</kbd> - <kbd>主题</kbd> 选择 `zhi` 主题即可

注意:`zhi` 主题仅支持思源笔记 `2.7.6+` 以上版本,否则您需要升级思源笔记到新版本。

## 设计哲学

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"dependencies": {
"callsites": "^4.0.0",
"commander": "^10.0.0",
"compare-versions": "6.0.0-rc.1",
"enquirer": "^2.3.6",
"git-clone": "^0.2.0",
"handlebars": "^4.7.7",
Expand Down
73 changes: 73 additions & 0 deletions packages/zhi-common/src/lib/versionUtil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* 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 { compareVersions } from "compare-versions"

/**
* 版本号比较
*
* @public
* @author terwer
* @since 1.0.2
*/
class VersionUtil {
/**
* Compare [semver](https://semver.org/) version strings
* This library supports the full semver specification, including comparing versions with different number of digits like `1.0.0`, `1.0`, `1`, and pre-release versions like `1.0.0-alpha`.
*
* @param v1 - First version to compare
* @param v2 - Second version to compare
* @returns boolean true if v1 is higher than v2
*/
public greater(v1: string, v2: string): boolean {
return compareVersions(v1, v2) > 0
}

/**
* Compare [semver](https://semver.org/) version strings
* This library supports the full semver specification, including comparing versions with different number of digits like `1.0.0`, `1.0`, `1`, and pre-release versions like `1.0.0-alpha`.
*
* @param v1 - First version to compare
* @param v2 - Second version to compare
* @returns boolean true if v1 is equal to v2
*/
public equal(v1: string, v2: string): boolean {
return compareVersions(v1, v2) === 0
}

/**
* Compare [semver](https://semver.org/) version strings
* This library supports the full semver specification, including comparing versions with different number of digits like `1.0.0`, `1.0`, `1`, and pre-release versions like `1.0.0-alpha`.
*
* @param v1 - First version to compare
* @param v2 - Second version to compare
* @returns boolean true if v1 is lesser than v2
*/
public lesser(v1: string, v2: string): boolean {
return compareVersions(v1, v2) < 0
}
}

export default VersionUtil
3 changes: 3 additions & 0 deletions packages/zhi-common/src/lib/zhi-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import DateUtil from "./dateUtil"
import StrUtil from "./strUtil"
import DeviceUtil from "./deviceUtil"
import SiyuanUtil from "./siyuanUtil"
import VersionUtil from "./versionUtil";

/**
* 平台无关的通用工具类
Expand All @@ -39,12 +40,14 @@ class ZhiCommon {
public readonly strUtil
public readonly deviceUtil
public readonly siyuanUtil
public readonly versionUtil

constructor() {
this.dateUtil = new DateUtil()
this.strUtil = new StrUtil()
this.deviceUtil = DeviceUtil
this.siyuanUtil = new SiyuanUtil()
this.versionUtil = new VersionUtil()
}
}

Expand Down
37 changes: 37 additions & 0 deletions packages/zhi/src/lib/zhi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ class Zhi {
private readonly common
private readonly runAs

/**
* 主题样式最低支持版本
* @private
*/
private readonly SUPPORTED_THEME_VERSION = "2.7.6"

/**
* 内核最低支持版本
* @private
*/
private readonly SUPPORTED_KERNEL_VERSION = "2.8.1"

/**
* 主题初始化
*
Expand Down Expand Up @@ -70,6 +82,31 @@ class Zhi {
try {
this.logger.info(this.common.strUtil.f("Theme runAs {0}", this.runAs))

// 检测内核版本
// const kernelVersion = this.common.siyuanUtil.siyuanWindow().siyuan.config.system.kernelVersion
const kernelVersion = "2.7.5"
if (this.common.versionUtil.lesser(kernelVersion, this.SUPPORTED_THEME_VERSION)) {
const errMsg = this.common.strUtil.f(
"Your siyuan-note kernel version {0} is not supported by zhi theme, style will look weird, you must install siyuan-note {1}+ to use zhi-theme",
kernelVersion,
this.SUPPORTED_THEME_VERSION
)
this.logger.error(errMsg)
alert(errMsg)
return
}

if (this.common.versionUtil.lesser(kernelVersion, this.SUPPORTED_KERNEL_VERSION)) {
this.logger.warn(
this.common.strUtil.f(
"Your siyuan-note kernel version {0} is too low, plugin system will not work, you must install siyuan-note {1}+ to use plugin feature",
kernelVersion,
this.SUPPORTED_KERNEL_VERSION
)
)
return
}

// 初始化第三方依赖
const dynamicImports = await this.main([])
for (const item of dynamicImports) {
Expand Down
13 changes: 10 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tech.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ nx publish zhi-env --ver=0.0.1 --tag=latest
nx publish zhi-log --ver=0.0.1 --tag=latest
nx publish zhi-cli --ver=0.0.1 --tag=latest
nx publish zhi-common --ver=0.0.1 --tag=latest
nx publish zhi --ver=0.0.1 --tag=latest
nx publish zhi-blog-api --ver=0.0.1 --tag=latest
```

## Further help
Expand Down
10 changes: 7 additions & 3 deletions tech_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ nx generate @nrwl/js:library zhi-env --publishable --importPath zhi-env
## zhi-cli, zhi-theme, zhi-plugins
## https://nx.dev/packages/vite
nx generate @nrwl/js:library zhi-cli --publishable --importPath=zhi-cli --bundler=vite
nx generate @nrwl/js:library zhi --publishable --importPath=zhi --bundler=vite
nx generate @nrwl/js:library zhi --publishable --importPath=zhi --bundler=vite --unitTestRunner=vitest
nx generate @nrwl/js:library zhi --publishable --importPath=zhi --bundler=vite --unitTestRunner=vitest

## node library
## nx generate @nrwl/node:library zhi-cli --publishable --importPath=zhi-cli --unitTestRunner=none
Expand Down Expand Up @@ -65,8 +66,9 @@ pnpm lint

## 测试

>pnpm test
</code></div></div></pre>
```
pnpm test
```

## 发布

Expand All @@ -75,6 +77,8 @@ nx publish zhi-env --ver=0.0.1 --tag=latest
nx publish zhi-log --ver=0.0.1 --tag=latest
nx publish zhi-cli --ver=0.0.1 --tag=latest
nx publish zhi-common --ver=0.0.1 --tag=latest
nx publish zhi --ver=0.0.1 --tag=latest
nx publish zhi-blog-api --ver=0.0.1 --tag=latest
```

## 更多帮助
Expand Down

0 comments on commit 09cae99

Please sign in to comment.