Skip to content

Commit

Permalink
refactor: api
Browse files Browse the repository at this point in the history
  • Loading branch information
aooiuu committed Jul 17, 2024
1 parent 5e7245b commit 8b8015b
Show file tree
Hide file tree
Showing 97 changed files with 10,975 additions and 9,292 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ on:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+
branches:
- master

jobs:
docker:
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ignore-workspace-root-check=true
strict-peer-dependencies=false
auto-install-peers=true
link-workspace-packages=true

# https://github.com/electron-userland/electron-builder
node-linker=hoisted
Expand Down
54 changes: 30 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "module",
"version": "1.8.2",
"private": true,
"packageManager": "pnpm@8.6.5",
"packageManager": "pnpm@9.4.0",
"description": "",
"author": "aooiuu <aooiu@qq.com>",
"license": "GPL3",
Expand All @@ -25,43 +25,47 @@
"*.d.ts"
],
"scripts": {
"start": "esno index.ts",
"start": "tsx index.ts",
"release": "bumpp -r --no-push",
"clean": "rimraf packages/*/dist --glob",
"clean:npm": "rimraf packages/*/node_modules --glob && rimraf node_modules",
"run:core": "npm -C packages/core run start",
"rule-utils:build": "npm -C packages/rule-utils run build",
"core:build": "npm -C packages/core run build",
"shared:build": "npm -C packages/shared run build",
"epub:build": "npm -C packages/epub run build",
"build:web": "npm -C packages/web run build",
"build:web-w": "npm -C packages/web run build:w",
"run:core": "pnpm --filter=@any-reader/core start",
"rule-utils:build": "pnpm --filter=@any-reader/rule-utils build",
"core:build": "pnpm --filter=@any-reader/core build",
"shared:build": "pnpm --filter=@any-reader/shared build",
"epub:build": "pnpm --filter=@any-reader/epub build",
"build:web": "pnpm --filter=@any-reader/web build",
"build:web-w": "pnpm --filter=@any-reader/web build:w",
"run:vsc": "npm-run-all core:build build:web-w",
"docs": "npm -C docs run docs:dev",
"build:docs": "npm -C docs run docs:build",
"server": "npm -C packages/server run dev",
"docs": "pnpm --filter docs docs:dev",
"build:docs": "pnpm --filter docs docs:build",
"run:server": "run-p server run:web",
"test": "jest",
"coveralls": "jest --coverage",
"prepare": "husky install",
"web:server": "npm -C packages/web run dev",
"web:build-b": "npm -C packages/web run build:b",
"web:server": "pnpm --filter=@any-reader/web dev",
"web:build-b": "pnpm --filter=@any-reader/web build:b",
"web:dev": "npm-run-all --parallel web:server server",
"electron:server": "npm -C packages/web run electron:dev",
"electron:build": "npm -C packages/web run electron:build",
"vscode:server": "npm -C packages/web run vscode:dev",
"electron:server": "pnpm --filter=@any-reader/web electron:dev",
"electron:build": "pnpm --filter=@any-reader/web electron:build",
"vscode:server": "pnpm --filter=@any-reader/web vscode:dev",
"vscode:dev": "npm-run-all core:build shared:build --parallel vscode:server server",
"vscode:build-tpl": "npm -C packages/web run vscode:build",
"vscode:build-vsx": "npm -C packages/vscode run build",
"vscode:build-tpl": "pnpm --filter=@any-reader/web vscode:build",
"vscode:build-vsx": "pnpm --filter=@any-reader/vscode build",
"vscode:build": "npm-run-all vscode:build-tpl vscode:build-vsx",
"server:build": "npm -C packages/server run build",
"cli:build-tpl": "npm -C packages/web run cli:build",
"cli:build-js": "npm -C packages/cli run build",
"server": "pnpm --filter=@any-reader/server dev",
"server:build": "pnpm --filter=@any-reader/server build",
"cli:build-tpl": "pnpm --filter=@any-reader/web cli:build",
"cli:build-js": "pnpm --filter=@any-reader/cli build",
"cli:build": "npm-run-all cli:build-tpl cli:build-js",
"utools:build": "npm -C packages/web run utools:build && npm -C packages/utools run build",
"rubick:build": "npm -C packages/rubick run build",
"utools:build": "pnpm --filter=@any-reader/web utools:build && pnpm --filter=@any-reader/utools build",
"rubick:build": "pnpm --filter=@any-reader/rubick build",
"build": "npm-run-all rule-utils:build core:build epub:build shared:build server:build cli:build"
},
"dependencies": {
"sql.js": "^1.10.3",
"sqlite3": "5.1.6"
},
"optionalDependencies": {
"bufferutil": "^4.0.8",
"utf-8-validate": "^6.0.4"
Expand All @@ -70,8 +74,10 @@
"@types/mime": "3.0.4",
"@types/uuid": "^9.0.8",
"bumpp": "^9.4.1",
"cross-env": "^7.0.3",
"husky": "^8.0.0",
"npm-run-all": "^4.1.5",
"tsx": "^4.16.2",
"unbuild": "^2.0.0"
},
"lint-staged": {
Expand Down
24 changes: 12 additions & 12 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"name": "@any-reader/cli",
"type": "commonjs",
"version": "1.8.2",
"description": "",
"type": "commonjs",
"files": [
"dist",
"public"
],
"bin": {
"any-reader": "./bin/index.mjs"
},
"scripts": {
"build": "esno ./scripts/publish.cjs && unbuild"
},
"keywords": [],
"author": "aooiuu <aooiu@qq.com>",
"license": "GPL3",
"repository": {
"type": "git",
"url": "https://github.com/aooiuu/any-reader"
},
"keywords": [],
"bin": {
"any-reader": "./bin/index.mjs"
},
"files": [
"dist",
"public"
],
"scripts": {
"build": "tsx ./scripts/publish.cjs && unbuild"
},
"dependencies": {
"@any-reader/server": "workspace:^",
"open": "^10.1.0"
Expand Down
3 changes: 1 addition & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dist"
],
"scripts": {
"start": "esno src/start.ts",
"start": "tsx src/start.ts",
"build": "unbuild",
"stub": "unbuild --stub"
},
Expand All @@ -45,7 +45,6 @@
"@types/node": "^18.16.19",
"@types/xmldom": "^0.1.34",
"eslint": "^8.44.0",
"esno": "^0.16.3",
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"typescript": "^5.1.6"
Expand Down
24 changes: 24 additions & 0 deletions packages/rule-utils/src/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,27 @@ export function createRule(rule: Rule | any): Rule {
viewStyle: 0,
}, rule)
}

/**
*
* @param {string} str
* @returns {boolean}
*/
export function isEsoStr(str: string): boolean {
return str.startsWith('eso://')
}

/**
*
* @param rule
* @returns {boolean}
*/
export function isRule(rule: any): boolean {
if (typeof rule === 'string')
return isEsoStr(rule)

if (typeof rule !== 'object')
return false

return rule.id && rule.host && typeof rule.contentType !== 'undefined'
}
9 changes: 5 additions & 4 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"scripts": {
"build": "unbuild",
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "esno watch src/run.ts"
"dev": "tsx watch src/run.ts"
},
"dependencies": {
"@any-reader/core": "workspace:^",
Expand All @@ -36,14 +36,15 @@
"koa-bodyparser": "2",
"koa-router": "^12.0.1",
"koa-session": "^6.4.0",
"koa-static": "^5.0.0"
"koa-static": "^5.0.0",
"sql.js": "^1.10.3",
"sqlite3": "5.1.6"
},
"devDependencies": {
"@types/bcryptjs": "^2.4.6",
"@types/koa-router": "^7.4.8",
"@types/koa-session": "^6.4.5",
"@types/koa-static": "^4.0.4",
"@types/koa__cors": "^5.0.0",
"esno": "^0.16.3"
"@types/koa__cors": "^5.0.0"
}
}
4 changes: 2 additions & 2 deletions packages/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { bodyParser } from '@koa/bodyparser'
import cors from '@koa/cors'
import serve from 'koa-static'
import session from 'koa-session'
import { Api } from '@any-reader/shared'
import { createApp } from '@any-reader/shared'
import { createRoute } from './routes'

const __filename = fileURLToPath(import.meta.url)
Expand All @@ -18,7 +18,7 @@ const CONFIG_PATH = path.join(ROOT_PATH, 'config.desktop.json')
const app = new Koa()

export async function start(port = 8898, root = resolve(__dirname, 'public')) {
const api = new Api({
const api = createApp({
configPath: CONFIG_PATH,
})
const router = createRoute(api)
Expand Down
6 changes: 3 additions & 3 deletions packages/server/src/routes.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Router from 'koa-router'
import bcrypt from 'bcryptjs'
import type { Api } from '@any-reader/shared'
import type { App } from '@any-reader/shared'

export function createRoute(api: Api) {
export function createRoute(api: App) {
const router = new Router()

router.post('/login', (ctx) => {
Expand Down Expand Up @@ -62,7 +62,7 @@ export function createRoute(api: Api) {
const paths = path.split('@')
if (paths.length !== 2)
return
const method = paths[0] as 'post' | 'get'
const method = paths[0].toLocaleLowerCase() as 'post' | 'get'
router[method](`/${paths[1]}`, async (ctx) => {
const data = method === 'get' ? ctx.query : ctx.request.body
ctx.body = await cb(data)
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# README

server 和 vscode 一些通用逻辑
通用逻辑
1 change: 1 addition & 0 deletions packages/shared/build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default defineBuildConfig({
externals: [],
clean: true,
declaration: true,
sourcemap: true,
rollup: {
inlineDependencies: true,
emitCJS: true,
Expand Down
5 changes: 2 additions & 3 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
],
"scripts": {
"build": "unbuild",
"stub": "unbuild --stub",
"start": "esno src/start.ts"
"stub": "unbuild --stub"
},
"dependencies": {
"@any-reader/core": "workspace:^",
Expand All @@ -37,6 +36,7 @@
"iconv-lite": "^0.6.3",
"lodash-es": "^4.17.21",
"lowdb": "^7.0.1",
"sql.js": "^1.10.3",
"sqlite3": "5.1.6",
"typeorm": "^0.3.20",
"uuid": "^9.0.1"
Expand All @@ -50,7 +50,6 @@
"@types/encoding-japanese": "^2.0.5",
"@types/lodash-es": "^4.17.12",
"@types/node": "^18.16.19",
"esno": "^0.16.3",
"reflect-metadata": "^0.2.2",
"rollup": "^3.26.0",
"rollup-plugin-dts": "^5.3.0",
Expand Down
73 changes: 0 additions & 73 deletions packages/shared/src/RecordFile.ts

This file was deleted.

Loading

0 comments on commit 8b8015b

Please sign in to comment.