ee-bin 5.0.0-beta.2 → 5.0.0-beta.5

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.
Files changed (73) hide show
  1. package/dist/cjs/config/bin_default.js +69 -29
  2. package/dist/cjs/config/bin_default.js.map +1 -1
  3. package/dist/cjs/index.js +125 -4
  4. package/dist/cjs/index.js.map +1 -1
  5. package/dist/cjs/lib/extend.js +49 -15
  6. package/dist/cjs/lib/extend.js.map +1 -1
  7. package/dist/cjs/lib/helpers.js +71 -22
  8. package/dist/cjs/lib/helpers.js.map +1 -1
  9. package/dist/cjs/lib/utils.js +71 -30
  10. package/dist/cjs/lib/utils.js.map +1 -1
  11. package/dist/cjs/plugins/bundle_registry_plugin.js +156 -0
  12. package/dist/cjs/plugins/bundle_registry_plugin.js.map +1 -0
  13. package/dist/cjs/tools/encrypt.js +190 -29
  14. package/dist/cjs/tools/encrypt.js.map +1 -1
  15. package/dist/cjs/tools/iconGen.js +118 -30
  16. package/dist/cjs/tools/iconGen.js.map +1 -1
  17. package/dist/cjs/tools/incrUpdater.js +95 -33
  18. package/dist/cjs/tools/incrUpdater.js.map +1 -1
  19. package/dist/cjs/tools/move.js +71 -11
  20. package/dist/cjs/tools/move.js.map +1 -1
  21. package/dist/cjs/tools/serve.js +406 -81
  22. package/dist/cjs/tools/serve.js.map +1 -1
  23. package/dist/cjs/types/config.js +13 -0
  24. package/dist/cjs/types/config.js.map +1 -0
  25. package/dist/esm/config/bin_default.d.ts +19 -147
  26. package/dist/esm/config/bin_default.d.ts.map +1 -1
  27. package/dist/esm/config/bin_default.js +69 -29
  28. package/dist/esm/config/bin_default.js.map +1 -1
  29. package/dist/esm/index.d.ts +20 -0
  30. package/dist/esm/index.d.ts.map +1 -1
  31. package/dist/esm/index.js +125 -4
  32. package/dist/esm/index.js.map +1 -1
  33. package/dist/esm/lib/extend.d.ts +33 -0
  34. package/dist/esm/lib/extend.d.ts.map +1 -1
  35. package/dist/esm/lib/extend.js +49 -15
  36. package/dist/esm/lib/extend.js.map +1 -1
  37. package/dist/esm/lib/helpers.d.ts +44 -3
  38. package/dist/esm/lib/helpers.d.ts.map +1 -1
  39. package/dist/esm/lib/helpers.js +71 -22
  40. package/dist/esm/lib/helpers.js.map +1 -1
  41. package/dist/esm/lib/utils.d.ts +57 -3
  42. package/dist/esm/lib/utils.d.ts.map +1 -1
  43. package/dist/esm/lib/utils.js +71 -30
  44. package/dist/esm/lib/utils.js.map +1 -1
  45. package/dist/esm/plugins/bundle_registry_plugin.d.ts +33 -0
  46. package/dist/esm/plugins/bundle_registry_plugin.d.ts.map +1 -0
  47. package/dist/esm/plugins/bundle_registry_plugin.js +156 -0
  48. package/dist/esm/plugins/bundle_registry_plugin.js.map +1 -0
  49. package/dist/esm/tools/encrypt.d.ts +37 -1
  50. package/dist/esm/tools/encrypt.d.ts.map +1 -1
  51. package/dist/esm/tools/encrypt.js +190 -29
  52. package/dist/esm/tools/encrypt.js.map +1 -1
  53. package/dist/esm/tools/iconGen.d.ts +27 -1
  54. package/dist/esm/tools/iconGen.d.ts.map +1 -1
  55. package/dist/esm/tools/iconGen.js +118 -30
  56. package/dist/esm/tools/iconGen.js.map +1 -1
  57. package/dist/esm/tools/incrUpdater.d.ts +60 -13
  58. package/dist/esm/tools/incrUpdater.d.ts.map +1 -1
  59. package/dist/esm/tools/incrUpdater.js +95 -33
  60. package/dist/esm/tools/incrUpdater.js.map +1 -1
  61. package/dist/esm/tools/move.d.ts +41 -0
  62. package/dist/esm/tools/move.d.ts.map +1 -1
  63. package/dist/esm/tools/move.js +71 -11
  64. package/dist/esm/tools/move.js.map +1 -1
  65. package/dist/esm/tools/serve.d.ts +162 -25
  66. package/dist/esm/tools/serve.d.ts.map +1 -1
  67. package/dist/esm/tools/serve.js +406 -81
  68. package/dist/esm/tools/serve.js.map +1 -1
  69. package/dist/esm/types/config.d.ts +211 -0
  70. package/dist/esm/types/config.d.ts.map +1 -0
  71. package/dist/esm/types/config.js +13 -0
  72. package/dist/esm/types/config.js.map +1 -0
  73. package/package.json +16 -13
@@ -1,15 +1,27 @@
1
- import crossSpawn from 'cross-spawn';
2
- interface ExecConfig {
3
- directory: string;
4
- cmd: string;
5
- args?: string[] | string;
6
- stdio?: string;
7
- sync?: boolean;
8
- protocol?: string;
9
- watch?: boolean;
10
- delay?: number;
11
- [key: string]: unknown;
12
- }
1
+ /**
2
+ * Dev/Build/Start Manager — ee-bin's core dispatcher
3
+ *
4
+ * The ServeProcess class manages the full dev/build/start/exec lifecycle and is the
5
+ * most complex module in ee-bin. Core responsibilities:
6
+ * 1. dev — Start frontend dev server + Electron process, optional watch mode with auto-rebuild
7
+ * 2. build — Bundle Electron code + execute electron-builder platform build commands
8
+ * 3. start — Start Electron in production mode
9
+ * 4. exec — Execute user-defined custom commands
10
+ *
11
+ * Process management strategy:
12
+ * - execProcess only tracks async ChildProcess instances (sync executions are already
13
+ * complete, so there's no process to manage)
14
+ * - SIGINT/SIGTERM signal handlers close all child processes and restore package.json main field
15
+ * - In watch mode, debounce + tree-kill terminate the old Electron process before restarting
16
+ *
17
+ * Bundling strategy:
18
+ * - bundle mode: esbuild bundles into a single file + virtual registry plugin
19
+ * - copy mode: directly copies the entire electron/ directory (for non-bundling scenarios)
20
+ * - After bundling, switches package.json main field to point to ./public/electron/main.js
21
+ */
22
+ import { ChildProcess } from 'child_process';
23
+ import type { ExecConfig, BundleConfig } from '../types/config.js';
24
+ /** Common options for ServeProcess methods — corresponds to Commander CLI parameters */
13
25
  interface ServeOptions {
14
26
  config?: string;
15
27
  serve?: string;
@@ -17,25 +29,150 @@ interface ServeOptions {
17
29
  env?: string;
18
30
  }
19
31
  declare class ServeProcess {
20
- execProcess: Record<string, ReturnType<typeof crossSpawn>>;
21
- electronDir: string;
22
- bundleDir: string;
23
- pkgPath: string;
32
+ /** Async child process reference table (only async ChildProcess instances; sync processes are already complete and don't need tracking) */
33
+ execProcess: Record<string, ChildProcess>;
34
+ /** Original value of package.json main field (used by _restorePkgMain to restore) */
35
+ private originalPkgMain;
24
36
  constructor();
25
- _init(): void;
26
- _closeProcess(): Promise<void>;
27
- dev(options?: ServeOptions): void;
28
- start(options?: ServeOptions): void;
29
- sleep(ms: number): Promise<void>;
30
- build(options?: ServeOptions): void;
37
+ /** Register SIGINT/SIGTERM signal handlers to ensure child processes are closed and config is restored on exit */
38
+ private _init;
39
+ /**
40
+ * Close all child processes, restore package.json, then exit
41
+ *
42
+ * Flow: kill all child processes → restore pkgMain → sleep 500ms → process.exit(0)
43
+ * NOTE: The 500ms sleep is a compromise. The ideal approach would be to listen for each
44
+ * child process's exit event before exiting, but that's complex to implement (multi-process
45
+ * racing, nested processes, etc.). If a child process doesn't close in time, it may be orphaned.
46
+ */
47
+ private _closeProcess;
48
+ /**
49
+ * Dev mode — start frontend dev server + Electron process
50
+ *
51
+ * Complete flow:
52
+ * 1. Set NODE_ENV=dev
53
+ * 2. Load config, parse command names to start
54
+ * 3. If electron command is included:
55
+ * a. First bundle Electron code (via esbuild)
56
+ * b. Switch package.json main field
57
+ * c. If electron.watch=true, watch electron/ directory for changes
58
+ * → on change: debounce → re-bundle → kill old process → re-spawn
59
+ * 4. multiExec starts all commands (frontend + Electron)
60
+ */
61
+ dev(options?: ServeOptions): Promise<void>;
62
+ /**
63
+ * Production start — directly run the Electron process (no bundling)
64
+ * Prerequisite: the project has already been built via the build command
65
+ */
66
+ start(options?: ServeOptions): Promise<void>;
67
+ /** Helper: sleep for the specified number of milliseconds */
68
+ private sleep;
69
+ /**
70
+ * Build mode — bundle Electron code + execute platform build commands
71
+ *
72
+ * Complete flow:
73
+ * 1. Set NODE_ENV=prod (or user-specified environment)
74
+ * 2. If cmds includes 'electron': bundle first → remove electron from command list → switch pkgMain
75
+ * 3. multiExec executes remaining commands (e.g. frontend, win64, mac, etc.)
76
+ * 4. After build completes, restore package.json main field
77
+ *
78
+ * The 'electron' command only triggers bundling, not an Electron process launch,
79
+ * so it's removed from the command list and not processed by multiExec
80
+ */
81
+ build(options?: ServeOptions): Promise<void>;
82
+ /** Execute user-defined custom commands from the "exec" config section */
31
83
  exec(options?: ServeOptions): void;
84
+ /**
85
+ * Execute multiple commands — iterate the command list and start a subprocess for each
86
+ *
87
+ * Design decisions:
88
+ * - Frontend file:// protocol is skipped in dev mode (frontend is already served via HTTP)
89
+ * - sync mode uses crossSpawnSync for blocking execution; result is not stored in execProcess (process already complete)
90
+ * - async mode uses crossSpawn for non-blocking execution; stored in execProcess for later kill
91
+ * - async processes listen for exit events; in dev mode, a message is logged when a process exits
92
+ */
32
93
  multiExec(opt: {
33
94
  binCmd: string;
34
- binCmdConfig: Record<string, ExecConfig>;
95
+ binCmdConfig: Record<string, ExecConfig | undefined>;
35
96
  command: string;
36
97
  }): void;
37
- bundle(bundleConfig?: Record<string, unknown>): void;
38
- _switchPkgMain(isDebugger?: boolean): void;
98
+ /**
99
+ * Bundle Electron main process code
100
+ *
101
+ * Two modes:
102
+ * - 'bundle': Use esbuild + bundleRegistryPlugin to bundle into a single file
103
+ * - 'copy': Directly copy the entire electron/ directory to public/electron/
104
+ *
105
+ * Clears the output directory (rm outdir) before bundling to ensure a clean build
106
+ */
107
+ bundle(bundleConfig?: BundleConfig): Promise<void>;
108
+ /**
109
+ * Resolve the esbuild options shared by the main bundle and the per-file copy transpile.
110
+ *
111
+ * Both the bundled main.js and the separately-transpiled jobs/copy files must use identical
112
+ * compilation settings, otherwise main process code and job code would diverge (e.g. main.js
113
+ * minified but jobs not, or different module format / target / define). This method centralizes
114
+ * everything that should be consistent; callers add only the mode-specific keys (bundle,
115
+ * entryPoints/outfile, externals, plugins, banner, logLevel).
116
+ *
117
+ * sourcemap auto mode: dev → inline (debuggable), prod → off (smaller output).
118
+ */
119
+ private _resolveBaseBuildOptions;
120
+ /**
121
+ * Bundle Electron code using esbuild + registry plugin
122
+ *
123
+ * esbuild configuration strategy:
124
+ * - entryPoints: Virtual module 'app:bundle-entry' (generated by the plugin)
125
+ * - format: Default cjs (recommended for Electron), optional esm
126
+ * - sourcemap: Auto-inferred (dev→inline, prod→off), user can override
127
+ * - external: Framework externals (ee-core/electron/better-sqlite3 etc.) + user-defined
128
+ * - banner: Injects process.env.EE_BUNDLED = "true" so ee-core detects bundle mode
129
+ * - packages: 'external' tells esbuild to automatically exclude all node_modules packages
130
+ *
131
+ * Post-bundle steps:
132
+ * 1. Rename output file (app_bundle-entry.js → main.js)
133
+ * 2. Copy non-bundlable files (jobs directory, preload/bridge.js, user-defined copy targets)
134
+ */
135
+ private _bundleWithRegistry;
136
+ /**
137
+ * Copy a directory or single file from electron/ to the bundle output WITH per-file transpilation.
138
+ *
139
+ * Script files (.ts/.js/.mts/.cts/.tsx/.jsx) are compiled to Node-loadable .js using
140
+ * esbuild with bundle:false, so their imports stay as runtime require()/import calls:
141
+ * - relative imports (./foo) resolve to the sibling transpiled .js
142
+ * - ee-core/* and other packages resolve from node_modules at runtime
143
+ * Non-script files (e.g. .json) are copied verbatim. Directory structure is preserved.
144
+ *
145
+ * @param src Absolute path to a source directory or file
146
+ * @param dest Absolute path to the destination directory (for a dir src) or file (for a file src)
147
+ * @param baseOptions Shared esbuild options from _resolveBaseBuildOptions — same compilation
148
+ * settings (format/target/minify/define/...) as the main bundle, so copied
149
+ * code stays consistent with main.js. bundle:false is forced for per-file output.
150
+ */
151
+ private _transpileDir;
152
+ /**
153
+ * Copy non-bundlable files — two-tier strategy
154
+ *
155
+ * 1. preload/bridge.js (BrowserWindow preload script must be a separate file, loaded directly by Electron)
156
+ * 2. Copy targets: framework defaults (jobs/) + user-defined (bundleConfig.copy), all handled
157
+ * per-file by _transpileDir — script files transpiled to CJS .js (so Node's require()/
158
+ * child_process.fork() can load them), other files copied verbatim, structure preserved
159
+ */
160
+ private _copyUnbundledFiles;
161
+ /**
162
+ * Switch package.json main field
163
+ *
164
+ * After bundling, Electron needs to point to ./public/electron/main.js instead of
165
+ * ./electron/main.js, because the bundle output is in the public/electron/ directory.
166
+ * The original value is saved before switching so it can be restored later.
167
+ */
168
+ private _switchPkgMain;
169
+ /**
170
+ * Restore package.json main field
171
+ *
172
+ * Restores the original main value after build completes or on SIGINT/SIGTERM,
173
+ * preventing package.json from being permanently modified (which would break dev mode)
174
+ */
175
+ private _restorePkgMain;
39
176
  }
40
177
  export declare const serveProcess: ServeProcess;
41
178
  export { ServeProcess };
@@ -1 +1 @@
1
- {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../../src/tools/serve.ts"],"names":[],"mappings":"AAOA,OAAO,UAAsC,MAAM,aAAa,CAAC;AAKjE,UAAU,UAAU;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,UAAU,YAAY;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,cAAM,YAAY;IAChB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC,CAAC;IAC3D,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;;IAUhB,KAAK,IAAI,IAAI;IAYP,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAkBpC,GAAG,CAAC,OAAO,GAAE,YAAiB,GAAG,IAAI;IAgErC,KAAK,CAAC,OAAO,GAAE,YAAiB,GAAG,IAAI;IAiBvC,KAAK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