From 7390e8c12baf17a19e463fec770c51e9b8be27a1 Mon Sep 17 00:00:00 2001 From: cenfun Date: Mon, 1 Jan 2024 23:34:22 +0800 Subject: [PATCH] add open script --- package.json | 1 + scripts/open.js | 23 +++++++++++++++++++++++ test/package.json | 1 + 3 files changed, 25 insertions(+) create mode 100644 scripts/open.js diff --git a/package.json b/package.json index ce71b50c..0b132ca5 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "test-browser": "node ./test/test.js", "test": "npm run test-browser && npm run test-node && npm run build-docs", "dev": "sf d v8", + "open": "node ./scripts/open.js", "patch": "npm run build && sf publish patch -r" }, "workspaces": [ diff --git a/scripts/open.js b/scripts/open.js new file mode 100644 index 00000000..538c4bea --- /dev/null +++ b/scripts/open.js @@ -0,0 +1,23 @@ +const fs = require('fs'); +const path = require('path'); + +const openUrl = async (p) => { + const open = await import('open'); + await open.default(p); +}; + +const main = async () => { + const list = fs.readdirSync(path.resolve('docs'), { + withFileTypes: true + }); + for (const item of list) { + if (item.isDirectory()) { + const indexPath = path.resolve('docs', item.name, 'index.html'); + if (fs.existsSync(indexPath)) { + await openUrl(indexPath); + } + } + } +}; + +main(); diff --git a/test/package.json b/test/package.json index a196aa80..f42dbd91 100644 --- a/test/package.json +++ b/test/package.json @@ -19,6 +19,7 @@ "koa": "^2.15.0", "koa-static-resolver": "^1.0.4", "marked": "^11.1.1", + "open": "^10.0.2", "playwright": "^1.40.1", "rollup": "^4.9.2", "ts-loader": "^9.5.1",