From e70baea22e68bff7b1e1a68f22d7a717d45413e3 Mon Sep 17 00:00:00 2001 From: shirtiny <1849468240@qq.com> Date: Fri, 25 Jun 2021 21:36:35 +0800 Subject: [PATCH] minor --- .node/server.js | 67 +++++++++++++++++++++++++++++++++++++++++++++ .scripts/publish.sh | 4 +-- node/open.js | 5 ---- 3 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 .node/server.js delete mode 100644 node/open.js diff --git a/.node/server.js b/.node/server.js new file mode 100644 index 0000000..d8c99e9 --- /dev/null +++ b/.node/server.js @@ -0,0 +1,67 @@ +/* + * @Author: Shirtiny + * @Date: 2021-06-25 17:35:25 + * @LastEditTime: 2021-06-25 21:18:09 + * @Description: + */ +"use strict"; + +const esbuild = require("esbuild"); +const http = require("http"); +const path = require("path"); +const open = require("open"); +const chalk = require("chalk"); + +esbuild + .serve( + { + servedir: path.resolve(__dirname, "../dist"), + host: "localhost", + }, + { + entryPoints: [path.resolve(__dirname, "../src/main.ts")], + outfile: path.resolve(__dirname, "../dist/main.dev.js"), + platform: "browser", + globalName: "bvplayer_core", + bundle: true, + sourcemap: "external", + }, + ) + .then((result) => { + const { host, port } = result; + + const proxyServerPort = 2021; + + http + .createServer((req, res) => { + const options = { + hostname: host, + port: port, + path: req.url, + method: req.method, + headers: req.headers, + }; + + console.log( + `${chalk.greenBright.bold( + req.method.toUpperCase(), + )} ${chalk.blueBright.underline.italic(`${req.url}`)} ${chalk.cyan( + "->", + )} ${chalk.yellowBright(res.statusCode)}`, + ); + + const proxyReq = http.request(options, (proxyRes) => { + res.writeHead(proxyRes.statusCode, proxyRes.headers); + proxyRes.pipe(res, { end: true }); + }); + + req.pipe(proxyReq, { end: true }); + }) + .listen(proxyServerPort); + + open(`http://${host}:${proxyServerPort}`); + + console.log( + `build server listen in ${host}:${port} ,proxy server listen in ${host}:${proxyServerPort}`, + ); + }); diff --git a/.scripts/publish.sh b/.scripts/publish.sh index 6e1037e..6c33d87 100644 --- a/.scripts/publish.sh +++ b/.scripts/publish.sh @@ -2,7 +2,7 @@ ### # @Author: Shirtiny # @Date: 2021-06-11 10:01:14 - # @LastEditTime: 2021-06-25 14:39:31 +# @LastEditTime: 2021-06-25 21:35:45 # @Description: ### @@ -39,7 +39,7 @@ assert_ready_to_publish() { publish() { echo "Publish" echo "Confirm version" - yarn publish --access public + # yarn publish --access public git push --tags git push } diff --git a/node/open.js b/node/open.js deleted file mode 100644 index 61b1119..0000000 --- a/node/open.js +++ /dev/null @@ -1,5 +0,0 @@ -"use strict"; - -const open = require("open"); - -open("http://localhost:2021");