Skip to content

Commit

Permalink
feat(zhi-lib-log): init log system
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed May 5, 2023
1 parent 66aec39 commit 60e8ba3
Show file tree
Hide file tree
Showing 13 changed files with 254 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/zhi-lib-env/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ nx build zhi-lib-env

## Test

Execute the unit tests via [jest](https://jestjs.io/docs/getting-started#via-ts-jest)
Execute the unit tests via [vitest](https://vitest.dev)

```bash
nx test zhi-lib-env
Expand Down
18 changes: 18 additions & 0 deletions packages/zhi-lib-log/.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": {}
}
]
}
53 changes: 53 additions & 0 deletions packages/zhi-lib-log/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# zhi-lib-log

a simple logger for Node and Browser

## Usage

```ts
import LogFactory from "@siyuan-community/zhi-log"

const env = new Env(import.meta.env)
const logger = LogFactory.defaultLogger(env)
logger.debug("debug msg")
logger.info("info msg")
logger.error("error msg")
```

## Deps

```
├── @siyuan-community/zhi-device
├── @siyuan-community/zhi-env
├── loglevel
├── callsites
├── loglevel-plugin-prefix
├── ansi-colors
├── kleur
```

## Dev

```bash
nx dev zhi-lib-log
```

## Build

```bash
nx build zhi-lib-log
```

## Test

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

```bash
nx test zhi-lib-log
```

## Publish

```
nx publish zhi-lib-log --ver=0.0.1 --tag=latest
```
17 changes: 17 additions & 0 deletions packages/zhi-lib-log/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "@siyuan-community/zhi-log",
"version": "1.10.0",
"type": "module",
"description": "a simple logger for Node and Browser",
"main": "./index.js",
"typings": "./index.d.ts",
"repository": "terwer/zhi",
"homepage": "https://github.com/terwer/zhi/tree/main/packages/zhi-lib-log",
"author": "terwer",
"license": "GPL",
"keywords": [
"zhi",
"log",
"zhi-log"
]
}
35 changes: 35 additions & 0 deletions packages/zhi-lib-log/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "zhi-lib-log",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/zhi-lib-log/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/vite:build",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/packages/zhi-lib-log"
}
},
"publish": {
"command": "node tools/scripts/publish.mjs zhi-lib-log {args.ver} {args.tag}",
"dependsOn": ["build"]
},
"test": {
"executor": "@nx/vite:test",
"outputs": ["coverage/packages/zhi-lib-log"],
"options": {
"passWithNoTests": true,
"reportsDirectory": "../../coverage/packages/zhi-lib-log"
}
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["packages/zhi-lib-log/**/*.ts"]
}
}
},
"tags": []
}
1 change: 1 addition & 0 deletions packages/zhi-lib-log/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./lib/zhi-lib-log"
7 changes: 7 additions & 0 deletions packages/zhi-lib-log/src/lib/zhi-lib-log.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { zhiLibLog } from "./zhi-lib-log"

describe("zhiLibLog", () => {
it("should work", () => {
expect(zhiLibLog()).toEqual("zhi-lib-log")
})
})
3 changes: 3 additions & 0 deletions packages/zhi-lib-log/src/lib/zhi-lib-log.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function zhiLibLog(): string {
return "zhi-lib-log"
}
23 changes: 23 additions & 0 deletions packages/zhi-lib-log/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"types": ["vitest"]
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
10 changes: 10 additions & 0 deletions packages/zhi-lib-log/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"include": ["src/**/*.ts"],
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
}
19 changes: 19 additions & 0 deletions packages/zhi-lib-log/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": ["vitest/globals", "vitest/importMeta", "vite/client", "node"]
},
"include": [
"vite.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.test.tsx",
"src/**/*.spec.tsx",
"src/**/*.test.js",
"src/**/*.spec.js",
"src/**/*.test.jsx",
"src/**/*.spec.jsx",
"src/**/*.d.ts"
]
}
66 changes: 66 additions & 0 deletions packages/zhi-lib-log/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/// <reference types="vitest" />
import { defineConfig } from "vite"

import viteTsConfigPaths from "vite-tsconfig-paths"
import dts from "vite-plugin-dts"
import { join } from "path"
import noBundlePlugin from "vite-plugin-no-bundle"
import { viteStaticCopy } from "vite-plugin-static-copy"

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

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

plugins: [
dts({
entryRoot: "src",
tsConfigFilePath: join(__dirname, "tsconfig.lib.json"),
skipDiagnostics: true,
}),

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

!isTest && noBundlePlugin(),

viteStaticCopy({
targets: [
{
src: "README.md",
dest: ".",
},
],
}),
],

// Configuration for building your library.
// See: https://vitejs.dev/guide/build.html#library-mode
build: {
lib: {
// Could also be a dictionary or array of multiple entry points.
entry: "src/index.ts",
name: "zhi-lib-log",
fileName: "index",
// Change this to the formats you want to support.
// Don't forgot to update your package.json as well.
formats: ["es"],
},
rollupOptions: {
// External packages that should not be bundled into your library.
external: [],
},
},

test: {
globals: true,
cache: {
dir: "../../node_modules/.vitest",
},
environment: "jsdom",
include: ["src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
},
})
1 change: 1 addition & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"paths": {
"@siyuan-community/zhi-device": ["packages/zhi-lib-device/src/index.ts"],
"@siyuan-community/zhi-env": ["packages/zhi-lib-env/src/index.ts"],
"@siyuan-community/zhi-log": ["packages/zhi-lib-log/src/index.ts"],
"@zhi/zhi-core": ["packages/zhi-core/src/index.ts"],
"@zhi/zhi-loader": ["packages/zhi-loader/src/index.ts"]
}
Expand Down

0 comments on commit 60e8ba3

Please sign in to comment.