@vnejs/desktop 0.0.13 → 0.0.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/desktop",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "description": "Tools to run desktop app of @vnejs",
5
5
  "source": "src/index.js",
6
6
  "main": "dist/index.js",
@@ -16,10 +16,7 @@
16
16
  "author": "",
17
17
  "license": "ISC",
18
18
  "dependencies": {
19
- "commander": "13.1.0",
20
- "express": "4.21.2",
21
- "get-port": "5.1.1",
22
- "electron": "30.3.1",
23
- "open": "8.2.1"
19
+ "@vnejs/server": "0.0.2",
20
+ "commander": "13.1.0"
24
21
  }
25
22
  }
package/src/index.js CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  const { Command } = require("commander");
4
4
 
5
- const electronAction = require("./electron");
6
5
  const webAction = require("./web");
7
6
 
8
7
  const packageJson = require("../package.json");
@@ -11,7 +10,6 @@ const program = new Command();
11
10
 
12
11
  program.name(packageJson.name).description(packageJson.description).version(packageJson.version);
13
12
 
14
- program.command("electron").action(electronAction);
15
13
  program.command("web").action(webAction);
16
14
 
17
15
  program.parse();
package/src/web.js CHANGED
@@ -1,4 +1,4 @@
1
1
  const open = require("open");
2
- const { runServer } = require("./server");
2
+ const { runServer } = require("@vnejs/server");
3
3
 
4
4
  module.exports = () => runServer({ rootDir: process.env.PWD }).then((port) => open(`http://localhost:${port}`));
@@ -1,6 +0,0 @@
1
- require("./electron")();
2
-
3
- const { runServer } = require("./server");
4
- const { runElectron } = require("./electron.utils");
5
-
6
- runServer({ rootDir: process.env.PWD }).then((port) => runElectron({ port }));
package/src/electron.js DELETED
@@ -1,10 +0,0 @@
1
- const electron = require("electron");
2
- const proc = require("node:child_process");
3
-
4
- module.exports = () => {
5
- console.log(11111111111, electron);
6
-
7
- proc.spawn(`${electron} ${__dirname}/electron.entry.js --trace-warnings`);
8
-
9
- console.log(22222222222, electron);
10
- };
@@ -1,23 +0,0 @@
1
- const { app, BrowserWindow } = require("electron");
2
-
3
- let mainWindow;
4
-
5
- const isProd = process.env.NODE_ENV === "production";
6
-
7
- const createWindow = (options) => {
8
- mainWindow = new BrowserWindow({ autoHideMenuBar: isProd, fullscreen: true, frame: true });
9
-
10
- if (options.port) mainWindow.loadURL(`http://localhost:${options.port}/`);
11
- if (options.file) mainWindow.loadFile(options.file);
12
-
13
- mainWindow.on("closed", () => (mainWindow = null));
14
- isProd ? mainWindow.removeMenu() : mainWindow.webContents.openDevTools();
15
- };
16
-
17
- const runElectron = (options) => {
18
- app.whenReady().then(() => createWindow(options));
19
- app.on("window-all-closed", () => process.platform !== "darwin" && app.quit());
20
- app.on("activate", () => mainWindow === null && createWindow(options));
21
- };
22
-
23
- module.exports = { runElectron };
package/src/server.js DELETED
@@ -1,70 +0,0 @@
1
- const path = require("path");
2
- const express = require("express");
3
- const getPort = require("get-port");
4
- const bodyParser = require("body-parser");
5
- const { writeFile, appendFile, readdirSync, existsSync, readFile } = require("fs");
6
-
7
- const runServer = async ({ rootDir, oldApp } = {}) => {
8
- const port = await getPort();
9
-
10
- const stateJson = path.join(rootDir, "state.json");
11
- const gamePath = path.join(rootDir, "game");
12
-
13
- const onSaveState = (req, res) =>
14
- writeFile(stateJson, JSON.stringify(req.body), (err) =>
15
- err ? res.json({ status: "error" }) : res.json({ status: "ok" })
16
- );
17
-
18
- const onGetState = (req, res) =>
19
- readFile(stateJson, (err, data) =>
20
- err
21
- ? writeFile(stateJson, "{}", () => res.json({ status: "ok", state: {} }))
22
- : res.json({ status: "ok", state: JSON.parse(data.toString()) })
23
- );
24
-
25
- const onLog = (req, res) => {
26
- res.end("ok");
27
-
28
- appendFile(path.join(rootDir, "log.txt"), `${req.body.log}\n`);
29
- };
30
-
31
- console.log("server will try to start on localhost: ", port);
32
-
33
- const app =
34
- oldApp ||
35
- express()
36
- .use(bodyParser.json({ limit: "50mb" }))
37
- .use(express.static(path.join(rootDir, "dist")))
38
- .use("/state/save", onSaveState)
39
- .use("/state/get", onGetState)
40
- .use("/log", onLog);
41
-
42
- readdirSync(gamePath).forEach((modDir) => {
43
- const mediaDir = path.join(gamePath, modDir, "media");
44
- const publicDir = path.join(gamePath, modDir, "public");
45
-
46
- existsSync(mediaDir) && app.use("/media", express.static(mediaDir));
47
- existsSync(publicDir) && app.use(express.static(publicDir));
48
- });
49
-
50
- return new Promise(async (resolve) => {
51
- const server = app.listen(port);
52
-
53
- server.on("listening", () => {
54
- console.log("server started on port: ", port);
55
-
56
- resolve(port);
57
- });
58
- server.on("error", async (error) => {
59
- if (error.code === "EADDRINUSE") {
60
- console.log("server not started on port: ", port);
61
-
62
- await runServer({ rootDir, oldApp: app });
63
-
64
- resolve(port);
65
- }
66
- });
67
- });
68
- };
69
-
70
- module.exports = { runServer };