Skip to content

Commit

Permalink
feat(zhi-lib-device): release zhi-lib-device 0.1.0, support systemjs …
Browse files Browse the repository at this point in the history
…only
  • Loading branch information
terwer committed Apr 27, 2023
1 parent 2666c5d commit dd15283
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Expose Astro dependencies for \`pnpm\` users
registry=https://registry.npmjs.com
shamefully-hoist=true
8 changes: 6 additions & 2 deletions package-lock.json

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

15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
{
"name": "zhi-next",
"version": "0.0.0",
"name": "zhi",
"version": "0.1.0",
"type": "module",
"license": "MIT",
"description": "A siyuan-note theme with plugin and blog bundled",
"homepage": "https://github.com/terwer/zhi",
"author": "terwer",
"license": "GPL",
"keywords": [
"zhi",
"siyuan-note",
"theme",
"blog"
],
"scripts": {
"reset": "nx reset",
"build": "nx run-many --target=build --exclude=zhi-docs",
Expand Down
8 changes: 7 additions & 1 deletion packages/zhi-core/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# zhi-core

This library was generated with [Nx](https://nx.dev).
core module for zhi

## Dev

Run `nx dev zhi-core` for development in siyuan-note.

## Building

This library was generated with [Nx](https://nx.dev).

Run `nx build zhi-core` to build the library.

## Running unit tests
Expand Down
14 changes: 12 additions & 2 deletions packages/zhi-core/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"name": "@siyuan-community/zhi-core",
"version": "0.0.1",
"type": "commonjs"
"version": "0.1.0",
"type": "module",
"description": "a pluggable siyuan-note theme",
"homepage": "https://github.com/terwer/zhi/tree/main/packages/zhi-core",
"author": "terwer",
"license": "GPL",
"keywords": [
"zhi",
"zhi-core",
"siyuan-note",
"theme"
]
}
28 changes: 16 additions & 12 deletions packages/zhi-core/src/lib/zhi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* questions.
*/

import { createCoreLogger, isElectron } from "./utils/index.js"
import { createCoreLogger, getFile, isElectron, win } from "./utils/index.js"
import { initRequireHacker, shellCmd } from "./node/index.js"

/**
Expand Down Expand Up @@ -57,10 +57,8 @@ export class Zhi {

// 因为后面可能会用到一些依赖,所以这里需要先hack
if (isElectron()) {
const syWin = window as any

await initRequireHacker()
syWin.shellCmd = shellCmd
win.shellCmd = shellCmd
this.logger.info("Electron only modules hacked")
}

Expand All @@ -75,18 +73,24 @@ export class Zhi {
// @since 0.1.0
// =========================================================================

const syWin = window as any
const System = syWin.System
const System = win.System
if (!System) {
this.logger.error("SystemJs not work, zhi-core will stop loading!")
return
}
this.zhiDeviceModule = await System.import("@siyuan-community/zhi-device")
this.logger.info("zhiDeviceModule=>", this.zhiDeviceModule)

const deviceDetection = this.zhiDeviceModule.DeviceDetection
// const siyuanDevice = this.zhiDeviceModule.SiyuanDevice

this.runAs = deviceDetection.getDevice()
this.logger.info(`Hello, this is zhi theme You are from ${this.runAs}`)
// this.logger.info(
// `Hello, this is zhi theme v${this.pkgJson.version}, ${this.pkgJson.description} by ${crossChalk.green(
// this.pkgJson.author
// )}! You are from ${from}`
// )
// this.logger.info(`Hello, this is zhi theme You are from ${this.runAs}`)

const pkgJson = JSON.parse(await getFile("/data/storage/zhi/package.json", "text")) as any
// this.logger.info("pkgJson=>", pkgJson)
this.logger.info(
`Hello, this is zhi theme v${pkgJson.version}, ${pkgJson.description} by ${pkgJson.author}! You are from ${this.runAs}`
)
}
}
54 changes: 49 additions & 5 deletions packages/zhi-lib-device/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,55 @@
# zhi-lib-device

This library was generated with [Nx](https://nx.dev).
auto check environment whether in browser, browser extension, electron, node and more

## Building
## Usage

Run `nx build zhi-lib-device` to build the library.
```ts
import { DeviceDetection, BrowserUtil, DeviceTypeEnum } from "@siyuan-community/zhi-device"

## Running unit tests
console.log("isInBrowser=>", BrowserUtil.isInBrowser)

Run `nx test zhi-lib-device` to execute the unit tests via [Jest](https://jestjs.io).
const deviceType: DeviceTypeEnum = 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 [jest](https://jestjs.io/docs/getting-started#via-ts-jest)

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

## Publish

```bash
nx publish zhi-lib-device --ver=0.1.0 --tag=latest
```
14 changes: 13 additions & 1 deletion packages/zhi-lib-device/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
{
"name": "@siyuan-community/zhi-device",
"version": "0.1.0",
"type": "module"
"type": "module",
"description": "auto check environment whether in browser, browser extension, electron, node and more",
"repository": "terwer/zhi",
"homepage": "https://github.com/terwer/zhi/tree/main/packages/zhi-lib-device",
"author": "terwer",
"license": "GPL",
"keywords": [
"zhi",
"device",
"browser",
"node",
"electron"
]
}
8 changes: 8 additions & 0 deletions scripts/packages/zhi-core/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import path from "path"
import { copyDir } from "../../utils/fileutils.js"
import fs from "fs-extra"

async function main() {
// const projectRoot = path.resolve("../../../")
Expand All @@ -10,7 +11,14 @@ async function main() {
const dest = "/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/conf/appearance/themes/zhi"

// 复制文件
// src
await copyDir(src, dest)
// package.json
const pkgJsonDest = path.join(
"/Users/terwer/Documents/mydocs/SiYuanWorkspace/public/data/storage/zhi",
"package.json"
)
fs.copyFileSync(path.join(projectRoot, "dist/packages/zhi-core/package.json"), pkgJsonDest)
}

;(async () => {
Expand Down
23 changes: 16 additions & 7 deletions tech.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@ Run `nx graph` to see a diagram of the dependencies of the projects.

## Dependency

- zhi-core - 0


- zhi-blog-vite - 0


- zhi-server-blog-astro - 0
- zhi-core - [0, 1]
- deps - 0
- dynamic deps - 1
- zhi-lib-device

- zhi-lib-device - [0, 0]
- deps - 0
- dynamic deps - 0

- zhi-blog-vite - [0, 0]
- deps - 0
- dynamic deps - 0

- zhi-server-blog-astro - [0, 0]
- deps - 0
- dynamic deps - 0

## Remote caching

Expand Down
4 changes: 3 additions & 1 deletion tools/scripts/publish.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
* You might need to authenticate with NPM before running this script.
*/

import { readCachedProjectGraph } from "@nrwl/devkit"
import pkg from "@nrwl/devkit"
import { execSync } from "child_process"
import { readFileSync, writeFileSync } from "fs"
import chalk from "chalk"

const { readCachedProjectGraph } = pkg

function invariant(condition, message) {
if (!condition) {
console.error(chalk.bold.red(message))
Expand Down

0 comments on commit dd15283

Please sign in to comment.