From dd152830e6d84ca7f11c5f6463f0ede2eeb0ceb3 Mon Sep 17 00:00:00 2001 From: terwer Date: Fri, 28 Apr 2023 00:41:21 +0800 Subject: [PATCH] feat(zhi-lib-device): release zhi-lib-device 0.1.0, support systemjs only --- .npmrc | 2 +- package-lock.json | 8 +++-- package.json | 15 ++++++-- packages/zhi-core/README.md | 8 ++++- packages/zhi-core/package.json | 14 ++++++-- packages/zhi-core/src/lib/zhi.ts | 28 ++++++++------- packages/zhi-lib-device/README.md | 54 +++++++++++++++++++++++++--- packages/zhi-lib-device/package.json | 14 +++++++- scripts/packages/zhi-core/dev.js | 8 +++++ tech.md | 23 ++++++++---- tools/scripts/publish.mjs | 4 ++- 11 files changed, 143 insertions(+), 35 deletions(-) diff --git a/.npmrc b/.npmrc index 79a5e9c9..293eb14a 100644 --- a/.npmrc +++ b/.npmrc @@ -1,2 +1,2 @@ -# Expose Astro dependencies for \`pnpm\` users +registry=https://registry.npmjs.com shamefully-hoist=true \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 58c49f08..e405b96b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19430,10 +19430,14 @@ "dev": true }, "packages/zhi-core": { - "version": "0.0.1" + "name": "@siyuan-community/zhi-core", + "version": "0.1.0", + "license": "GPL" }, "packages/zhi-lib-device": { - "version": "0.1.0" + "name": "@siyuan-community/zhi-device", + "version": "0.1.0", + "license": "GPL" } } } diff --git a/package.json b/package.json index 93b17ff7..2eb3633d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/zhi-core/README.md b/packages/zhi-core/README.md index e11ed4a3..b114ecb7 100644 --- a/packages/zhi-core/README.md +++ b/packages/zhi-core/README.md @@ -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 diff --git a/packages/zhi-core/package.json b/packages/zhi-core/package.json index 1100d89a..8c9c75ff 100644 --- a/packages/zhi-core/package.json +++ b/packages/zhi-core/package.json @@ -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" + ] } diff --git a/packages/zhi-core/src/lib/zhi.ts b/packages/zhi-core/src/lib/zhi.ts index 445e8fd2..17ad7640 100644 --- a/packages/zhi-core/src/lib/zhi.ts +++ b/packages/zhi-core/src/lib/zhi.ts @@ -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" /** @@ -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") } @@ -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}` + ) } } diff --git a/packages/zhi-lib-device/README.md b/packages/zhi-lib-device/README.md index a6a4819a..88ae8c8f 100644 --- a/packages/zhi-lib-device/README.md +++ b/packages/zhi-lib-device/README.md @@ -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 +``` \ No newline at end of file diff --git a/packages/zhi-lib-device/package.json b/packages/zhi-lib-device/package.json index d0e1e039..c2a65ca7 100644 --- a/packages/zhi-lib-device/package.json +++ b/packages/zhi-lib-device/package.json @@ -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" + ] } diff --git a/scripts/packages/zhi-core/dev.js b/scripts/packages/zhi-core/dev.js index aad96a9a..748434c7 100644 --- a/scripts/packages/zhi-core/dev.js +++ b/scripts/packages/zhi-core/dev.js @@ -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("../../../") @@ -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 () => { diff --git a/tech.md b/tech.md index 4cbdf962..b1569b50 100644 --- a/tech.md +++ b/tech.md @@ -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 diff --git a/tools/scripts/publish.mjs b/tools/scripts/publish.mjs index 1cfa3b24..07594d65 100644 --- a/tools/scripts/publish.mjs +++ b/tools/scripts/publish.mjs @@ -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))