@olenbetong/appframe-vite 4.0.0 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
+ import bodyParser from "body-parser";
1
2
  import { watch } from "chokidar";
2
3
  import { addAppframeBuildConfig } from "./build.js";
3
4
  import { createDevMiddleware, getLoginInfo, getProxyRoutes } from "./devServer.js";
4
- import { importJson } from "./importJson.js";
5
5
  import { getLastSession, login } from "./proxy.js";
6
6
  let interval;
7
7
  let server;
@@ -10,8 +10,6 @@ try {
10
10
  let appPkgUrl = `file://${process.cwd()}/package.json`;
11
11
  watch(appPkgUrl).on("all", async () => {
12
12
  if (server) {
13
- let appPkg = await importJson("./package.json", true);
14
- let config = appPkg.appframe;
15
13
  let { hostname } = await getLoginInfo();
16
14
  if (lastHostname !== hostname) {
17
15
  server.restart(false);
@@ -22,6 +20,7 @@ try {
22
20
  catch (error) {
23
21
  console.log(`Failed to watch package.json: ${error.message}`);
24
22
  }
23
+ const jsonParser = bodyParser.json();
25
24
  export default function appframe() {
26
25
  return {
27
26
  name: "appframe",
@@ -99,6 +98,16 @@ export default function appframe() {
99
98
  },
100
99
  async configureServer(_server) {
101
100
  server = _server;
101
+ _server.middlewares.use("/data/Logger/LogError", jsonParser);
102
+ _server.middlewares.use("/data/Logger/LogError", (req, res) => {
103
+ // @ts-ignore
104
+ if (req.body?.error) {
105
+ // @ts-ignore
106
+ console.log("[Client error]", req.body?.error);
107
+ }
108
+ res.statusCode = 200;
109
+ res.end("");
110
+ });
102
111
  return () => {
103
112
  _server.middlewares.use(createDevMiddleware(_server));
104
113
  };
package/lib/proxy.js CHANGED
@@ -2,6 +2,15 @@ import chalk from "chalk";
2
2
  import https from "node:https";
3
3
  const lastLogin = new Map();
4
4
  let currentLogin = null;
5
+ const isInteractive = process.stdout.isTTY;
6
+ function write(text) {
7
+ if (isInteractive) {
8
+ process.stdout.write?.(text);
9
+ }
10
+ else {
11
+ console.log(text);
12
+ }
13
+ }
5
14
  export function getLastSession(hostname) {
6
15
  return lastLogin.get(hostname);
7
16
  }
@@ -17,7 +26,7 @@ export async function login(hostname, username, password) {
17
26
  return;
18
27
  }
19
28
  else {
20
- process.stdout.write(`${chalk.bgBlueBright(hostname)}: Renewing authentication cookies...`);
29
+ write(`${chalk.bgBlueBright(hostname)}: Renewing authentication cookies...`);
21
30
  lastLogin.delete(hostname);
22
31
  }
23
32
  }
@@ -33,11 +42,13 @@ export async function login(hostname, username, password) {
33
42
  "Content-Length": data.length,
34
43
  },
35
44
  };
36
- process.stdout.clearLine(0);
37
- process.stdout.write(`\r${chalk.bgBlueBright(hostname)}: Authenticating`);
45
+ process.stdout.clearLine?.(0);
46
+ write(`\r${chalk.bgBlueBright(hostname)}: Authenticating`);
38
47
  let start = performance.now();
39
48
  let interval = setInterval(() => {
40
- process.stdout.write(`.`);
49
+ if (isInteractive) {
50
+ write(`.`);
51
+ }
41
52
  }, 100);
42
53
  let request = https.request(options, (response) => {
43
54
  clearInterval(interval);
@@ -52,8 +63,8 @@ export async function login(hostname, username, password) {
52
63
  cookieObj[key] = value;
53
64
  }
54
65
  }
55
- process.stdout.clearLine(0);
56
- process.stdout.write(`\r${chalk.bgBlueBright(hostname)}: Authenticated (${Math.floor(performance.now() - start)}ms)\n`);
66
+ process.stdout.clearLine?.(0);
67
+ write(`${chalk.bgBlueBright(hostname)}: Authenticated (${Math.floor(performance.now() - start)}ms)\n`);
57
68
  lastLogin.set(hostname, {
58
69
  timestamp: Date.now(),
59
70
  authCookies: cookieObj,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@olenbetong/appframe-vite",
3
- "version": "4.0.0",
3
+ "version": "4.0.2",
4
4
  "description": "Tools to use and deploy Vite applications to Appframe",
5
5
  "main": "./lib/index.js",
6
6
  "type": "module",
@@ -19,7 +19,7 @@
19
19
  "author": "Bjørnar Vister Hansen <bvh@olenbetong.no>",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@olenbetong/appframe-data": "^0.8.10",
22
+ "@olenbetong/appframe-data": "^0.9.0",
23
23
  "chalk": "^5.3.0",
24
24
  "chokidar": "^3.5.3",
25
25
  "dotenv": "^16.3.1",
@@ -43,5 +43,5 @@
43
43
  "open": "^9.1.0",
44
44
  "tcp-port-used": "^1.0.2"
45
45
  },
46
- "gitHead": "d4c8d2d9010a49c9052947bbf7593c6bd13af9b4"
46
+ "gitHead": "61bcfff5dd6ef273708619b792fe9b8ece68c5d3"
47
47
  }