1+ const fetch = require ( 'node-fetch' ) ;
2+ const fs = require ( 'fs' ) ;
3+ const path = require ( 'path' ) ;
4+ const semver = require ( 'semver' ) ;
5+ const os = require ( "node:os" ) ;
6+ const yauzl = require ( 'yauzl' ) ;
7+ const proc = require ( 'child_process' ) ;
8+
9+
10+ function toPromise ( api ) {
11+ return function ( ...args ) {
12+ return new Promise ( ( resolve , reject ) => {
13+ api ( ...args , ( error , response ) => {
14+ if ( error ) {
15+ return reject ( error ) ;
16+ }
17+ resolve ( response ) ;
18+ } ) ;
19+ } ) ;
20+ }
21+ }
22+
23+ async function decompress ( file ) {
24+ let yauzlPromise = toPromise ( yauzl . open ) ;
25+ let zipfile = await yauzlPromise ( file , { lazyEntries : true } ) ;
26+ let openReadStream = toPromise ( zipfile . openReadStream . bind ( zipfile ) ) ;
27+ zipfile . readEntry ( ) ;
28+ zipfile . on ( "entry" , async ( entry ) => {
29+ if ( / \/ $ / . test ( entry . fileName ) ) {
30+ console . log ( `Folder?: ${ entry . fileName } ` )
31+ if ( ! fs . existsSync ( path . join ( __dirname , 'dist' , entry . fileName ) ) ) {
32+ fs . mkdirSync ( path . join ( __dirname , 'dist' , entry . fileName ) ) ;
33+ }
34+ zipfile . readEntry ( ) ;
35+ }
36+ else {
37+ const zipStream = fs . createWriteStream ( path . join ( __dirname , 'dist' , entry . fileName ) ) ;
38+ let stream = await openReadStream ( entry ) ;
39+ stream . on ( "end" , ( ) => {
40+ zipfile . readEntry ( ) ;
41+ } ) ;
42+ stream . pipe ( zipStream ) ;
43+ zipStream . on ( "finish" , ( ) => {
44+ console . log ( `Updated ${ entry . fileName } ` ) ;
45+ } ) ;
46+ }
47+ } ) ;
48+ }
49+
50+ async function runMain ( ) {
51+ await decompress ( path . join ( __dirname , 'dist' , 'main2.zip' ) ) ;
52+ let command = path . join ( __dirname , 'dist' , 'main' , 'main' )
53+ let args = [ ]
54+ // if(isDev) {
55+ // console.log("DEV-Build");
56+ // command = 'python';
57+ // args = ['-u','main.py']
58+ // }
59+ //let child = proc.spawn('python', ['-u','main.py']);
60+ console . log ( command ) ;
61+ let child = proc . spawn ( command , args ) ;
62+
63+ let eel_started = false ;
64+
65+ child . stdout . on ( 'data' , function ( data ) {
66+ console . log ( 'stdout: ' + data ) ;
67+
68+ if ( data . toString ( ) . includes ( '[eel]: Start' ) ) {
69+ eel_started = true ;
70+ }
71+ } ) ;
72+
73+ child . stderr . on ( 'data' , function ( data ) {
74+ console . log ( 'stderr: ' + data ) ;
75+ } ) ;
76+ }
77+
78+ runMain ( ) ;
0 commit comments