@nemigo/electron 0.0.1 → 0.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.
@@ -0,0 +1,5 @@
1
+ import type { Plugin } from "vite";
2
+ /**
3
+ * Перезапуск Electron-приложения, если какие-то файлы изменились
4
+ */
5
+ export declare const electronHotReboot: () => Plugin;
@@ -0,0 +1,28 @@
1
+ import { spawn } from "node:child_process";
2
+ import { exit } from "node:process";
3
+ import electron from "electron";
4
+ /**
5
+ * Перезапуск Electron-приложения, если какие-то файлы изменились
6
+ */
7
+ export const electronHotReboot = () => {
8
+ let electronApp = null;
9
+ return {
10
+ name: "@stedia/electron-hot-reboot",
11
+ config() {
12
+ return { build: { watch: {} } };
13
+ },
14
+ writeBundle() {
15
+ // Убиваем прошлый экземпляр, если он существовал
16
+ if (electronApp !== null) {
17
+ electronApp.removeListener("exit", exit);
18
+ electronApp.kill("SIGINT");
19
+ electronApp = null;
20
+ }
21
+ // Запускаем новый экземпляр
22
+ // @ts-expect-error <в "electron" лежит путь к бинарнику, но TS об это не знает>
23
+ electronApp = spawn(electron, ["--inspect", "."], { stdio: "inherit" });
24
+ // Выходим из процесса вместе с выходом из приложения
25
+ electronApp.addListener("exit", exit);
26
+ },
27
+ };
28
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nemigo/electron",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "private": false,
5
5
  "author": {
6
6
  "name": "Vlad Logvin",
@@ -14,6 +14,10 @@
14
14
  "format": "prettier --write ./"
15
15
  },
16
16
  "exports": {
17
+ "./vite/hot-reboot": {
18
+ "types": "./dist/vite/hot-reboot.d.ts",
19
+ "default": "./dist/vite/hot-reboot.js"
20
+ },
17
21
  "./security": {
18
22
  "types": "./dist/security.d.ts",
19
23
  "default": "./dist/security.js"