Skip to content

Commit

Permalink
feat(zhi-lib-device): add device libiary
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed May 5, 2023
1 parent 0fcbd46 commit 29d6a48
Show file tree
Hide file tree
Showing 32 changed files with 1,356 additions and 112 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"vite": "^4.0.1",
"vite-plugin-dts": "~2.3.0",
"vite-plugin-eslint": "^1.8.1",
"vite-plugin-lib-inject-css": "^1.2.0",
"vite-plugin-no-bundle": "^2.0.2",
"vite-plugin-static-copy": "^0.14.0",
"vite-tsconfig-paths": "^4.0.2",
"vitest": "^0.31.0"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/zhi-core/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@siyuan-community/zhi-core",
"name": "@zhi/zhi-core",
"version": "0.1.0",
"type": "module"
}
10 changes: 7 additions & 3 deletions packages/zhi-core/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ import { defineConfig } from "vite"

import viteTsConfigPaths from "vite-tsconfig-paths"

const isTest = process.env["npm_command"] === "test"
console.log("isTest=>", isTest)

export default defineConfig({
cacheDir: "../../node_modules/.vite/zhi-core",

plugins: [
viteTsConfigPaths({
root: "../../",
}),
!isTest &&
viteTsConfigPaths({
root: "../../",
}),
],

// Uncomment this if you are using workers.
Expand Down
18 changes: 18 additions & 0 deletions packages/zhi-lib-device/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
55 changes: 55 additions & 0 deletions packages/zhi-lib-device/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# zhi-lib-device

auto check environment whether in browser, browser extension, electron, node and more

## Usage

```js
import { DeviceDetection, BrowserUtil } from "@siyuan-community/zhi-device"

console.log("isInBrowser=>", BrowserUtil.isInBrowser)

const deviceType = DeviceDetection.getDevice()
console.log("deviceType=>", deviceType)

// supported platforms
// Mobile
// Siyuan_Widget
// Siyuan_NewWindow
// Siyuan_MainWindow
// Chrome_Extension
// Chrome_Browser
// Node
```

## Deps

```
## Congregations! zhi-lib-device need no deps, it is just pure js code 🎉
```

## Dev

```bash
nx dev zhi-lib-device
```

## Build

```bash
nx build zhi-lib-device
```

## Test

Execute the unit tests via [vitest](https://vitest.dev)

```bash
nx test zhi-lib-device
```

## Publish

```bash
nx publish zhi-lib-device --ver=0.0.1 --tag=latest
```
19 changes: 19 additions & 0 deletions packages/zhi-lib-device/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@siyuan-community/zhi-device",
"version": "0.2.2",
"type": "module",
"description": "auto check environment whether in browser, browser extension, electron, node and more",
"main": "./index.js",
"typings": "./index.d.ts",
"repository": "terwer/zhi",
"homepage": "https://github.com/terwer/zhi/tree/main/apps/zhi-device",
"author": "terwer",
"license": "GPL",
"keywords": [
"zhi",
"device",
"browser",
"node",
"electron"
]
}
36 changes: 36 additions & 0 deletions packages/zhi-lib-device/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "zhi-lib-device",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/zhi-lib-device/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/vite:build",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/packages/zhi-lib-device",
"assets": ["packages/zhi-core/*.md"]
}
},
"publish": {
"command": "node tools/scripts/publish.mjs zhi-lib-device {args.ver} {args.tag}",
"dependsOn": ["build"]
},
"test": {
"executor": "@nx/vite:test",
"outputs": ["coverage/packages/zhi-lib-device"],
"options": {
"passWithNoTests": true,
"reportsDirectory": "../../coverage/packages/zhi-lib-device"
}
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["packages/zhi-lib-device/**/*.ts"]
}
}
},
"tags": []
}
26 changes: 26 additions & 0 deletions packages/zhi-lib-device/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.
*/

export * from "./lib/zhi-lib-device"
61 changes: 61 additions & 0 deletions packages/zhi-lib-device/src/lib/basePathTypeEnum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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
*/
enum BasePathTypeEnum {
/**
* Appearance
*/
BasePathType_Appearance = "Appearance",

/**
* Data
*/
BasePathType_Data = "Data",

/**
* Themes
*/
BasePathType_Themes = "Themes",

/**
* Zhi 主题目录
*/
BasePathType_ZhiTheme = "ZhiTheme",

/**
* 未设置
*/
BasePathType_None = "None",
}

export default BasePathTypeEnum
Loading

0 comments on commit 29d6a48

Please sign in to comment.