Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

现代化与工程化 #15

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 18 additions & 28 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,29 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v1
uses: actions/checkout@v3
with:
node-version: 16.x
- name: Cache node modules
uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
- name: Install & Build
run: >
rm -rf .gitignore

echo "node_modules" >> .gitignore

echo "doc/node_modules" >> .gitignore
fetch-depth: 0

npm i -D
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 7.16.1

npm install -D webpack-cli webpack
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "18"
cache: "pnpm"

npm run build
- name: Install dependencies
run: pnpm install --prefer-offline

- name: Install & Build
run: |
pnpm run build
echo "clientworker.js.org" > ./dist/CNAME

cd doc

npm add --dev vitepress vue

npm run "docs:build"


pnpm docs:build

- name: Deploy to GithubPage
uses: peaceiris/actions-gh-pages@v3
Expand All @@ -49,4 +39,4 @@ jobs:
- name: Publish to NPM
uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM }}
token: ${{ secrets.NPM }}
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
node_modules
package-lock.json
doc/node_modules
dist/
dist
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
23 changes: 23 additions & 0 deletions build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { build } from "esbuild";
import copyStaticFiles from "esbuild-copy-static-files";
import { writeFile } from "fs/promises";
import { configSchema } from "./types/configType";

(async () => {
await build({
entryPoints: ["./main/entry.js"],
entryNames: "[dir]/cw",
bundle: true,
outdir: "dist",
minify: true,
sourcemap: true,
target: ["es2015"],
plugins: [copyStaticFiles({ src: "static", dest: "dist" })],
});
await writeFile(
"dist/config.schema.json",
JSON.stringify(configSchema, null, 2)
);
})();

export {};
1 change: 0 additions & 1 deletion doc/.gitignore

This file was deleted.

6 changes: 5 additions & 1 deletion doc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@
},
"author": "",
"license": "ISC",
"description": ""
"description": "",
"dependencies": {
"vitepress": "^1.0.0-alpha.4",
"vue": "^3.2.37"
}
}
44 changes: 0 additions & 44 deletions main/entry.js

This file was deleted.

54 changes: 54 additions & 0 deletions main/entry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import CacheDB from "@chenyfan/cache-db";
import pkgjson from "../package.json";
import clientworkerhandle from "./handle/main";
import cons from "./utils/cons";

// For compatibility

self.clientworkerhandle = clientworkerhandle;

cons.s(`ClientWorker${pkgjson.version} Started!`);
const db = new CacheDB();
db.read("hotpatch").then((script) => {
if (!!script) {
cons.s("Hotpatch Loaded!");
eval(script as string);
} else {
cons.w("Hotpatch Not Found!");
}
});

db.read<string>("config").then((config) => {
const cfg = JSON.parse(config) || {};
config = cfg;
setInterval(() => {
cons.s(`ClientWorker@${pkgjson.version} Start to Clean Expired Cache!`);
caches.open("ClientWorker_ResponseCache").then((cache) => {
cache.keys().then((keys) => {
keys.forEach((key) => {
cache.match(key).then((res) => {
if (
Number(res!.headers.get("ClientWorker_ExpireTime")) <=
new Date().getTime()
) {
cache.delete(key);
}
});
});
});
});
}, eval(cfg.cleaninterval) || 60 * 1000);
});
addEventListener("fetch", (event) => {
(event as FetchEvent).respondWith(
self.clientworkerhandle((event as FetchEvent).request)
);
});
addEventListener("install", function () {
cons.s(`ClientWorker@${pkgjson.version} Installed!`);
self.skipWaiting();
});
addEventListener("activate", function () {
cons.s(`ClientWorker@${pkgjson.version} Activated!`);
self.clients.claim();
});
80 changes: 0 additions & 80 deletions main/handle/cgi.js

This file was deleted.

Loading