@@ -16,174 +16,165 @@ let electronProcess = null
1616let manualRestart = false
1717let hotMiddleware
1818
19- function logStats ( proc , data ) {
20- let log = ''
21-
22- log += chalk . yellow . bold ( `┏ ${ proc } Process ${ new Array ( ( 19 - proc . length ) + 1 ) . join ( '-' ) } ` )
23- log += '\n\n'
24-
25- if ( typeof data === 'object' ) {
26- data . toString ( {
27- colors : true ,
28- chunks : false
29- } ) . split ( / \r ? \n / ) . forEach ( line => {
30- log += ' ' + line + '\n'
31- } )
32- } else {
33- log += ` ${ data } \n`
34- }
35-
36- log += '\n' + chalk . yellow . bold ( `┗ ${ new Array ( 28 + 1 ) . join ( '-' ) } ` ) + '\n'
37-
38- console . log ( log )
19+ function logStats ( proc , data ) {
20+ let log = ''
21+
22+ log += chalk . yellow . bold ( `┏ ${ proc } Process ${ new Array ( 19 - proc . length + 1 ) . join ( '-' ) } ` )
23+ log += '\n\n'
24+
25+ if ( typeof data === 'object' ) {
26+ data
27+ . toString ( {
28+ colors : true ,
29+ chunks : false ,
30+ } )
31+ . split ( / \r ? \n / )
32+ . forEach ( line => {
33+ log += ' ' + line + '\n'
34+ } )
35+ } else {
36+ log += ` ${ data } \n`
37+ }
38+
39+ log += '\n' + chalk . yellow . bold ( `┗ ${ new Array ( 28 + 1 ) . join ( '-' ) } ` ) + '\n'
40+
41+ console . log ( log )
3942}
4043
41- function startRenderer ( ) {
42- return new Promise ( ( resolve , reject ) => {
43- rendererConfig . entry . renderer = [ path . join ( __dirname , 'dev-client' ) ] . concat ( rendererConfig . entry . renderer )
44- rendererConfig . mode = 'development'
45- const compiler = webpack ( rendererConfig )
46- hotMiddleware = webpackHotMiddleware ( compiler , {
47- log : false ,
48- heartbeat : 2500
49- } )
44+ function startRenderer ( ) {
45+ return new Promise ( ( resolve , reject ) => {
46+ rendererConfig . entry . renderer = [ path . join ( __dirname , 'dev-client' ) ] . concat ( rendererConfig . entry . renderer )
47+ rendererConfig . mode = 'development'
48+ const compiler = webpack ( rendererConfig )
49+ hotMiddleware = webpackHotMiddleware ( compiler , {
50+ log : false ,
51+ heartbeat : 2500 ,
52+ } )
5053
51- compiler . hooks . compilation . tap ( 'compilation' , compilation => {
52- compilation . hooks . htmlWebpackPluginAfterEmit . tapAsync ( 'html-webpack-plugin-after-emit' , ( data , cb ) => {
53- hotMiddleware . publish ( { action : 'reload' } )
54- cb ( )
55- } )
56- } )
54+ compiler . hooks . compilation . tap ( 'compilation' , compilation => {
55+ compilation . hooks . htmlWebpackPluginAfterEmit . tapAsync ( 'html-webpack-plugin-after-emit' , ( data , cb ) => {
56+ hotMiddleware . publish ( { action : 'reload' } )
57+ cb ( )
58+ } )
59+ } )
5760
58- compiler . hooks . done . tap ( 'done' , stats => {
59- logStats ( 'Renderer' , stats )
60- } )
61+ compiler . hooks . done . tap ( 'done' , stats => {
62+ logStats ( 'Renderer' , stats )
63+ } )
6164
62- const server = new WebpackDevServer (
63- compiler ,
64- {
65- contentBase : path . join ( __dirname , '../' ) ,
66- quiet : true ,
67- before ( app , ctx ) {
68- app . use ( hotMiddleware )
69- ctx . middleware . waitUntilValid ( ( ) => {
70- resolve ( )
71- } )
72- }
73- }
74- )
75-
76- server . listen ( 9080 )
65+ const server = new WebpackDevServer ( compiler , {
66+ contentBase : path . join ( __dirname , '../' ) ,
67+ quiet : true ,
68+ before ( app , ctx ) {
69+ app . use ( hotMiddleware )
70+ ctx . middleware . waitUntilValid ( ( ) => {
71+ resolve ( )
72+ } )
73+ } ,
7774 } )
75+
76+ server . listen ( 9080 )
77+ } )
7878}
7979
80- function startMain ( ) {
81- return new Promise ( ( resolve , reject ) => {
82- mainConfig . entry . main = [ path . join ( __dirname , '../src/main/index.dev.js' ) ] . concat ( mainConfig . entry . main )
83- mainConfig . mode = 'development'
84- const compiler = webpack ( mainConfig )
80+ function startMain ( ) {
81+ return new Promise ( ( resolve , reject ) => {
82+ mainConfig . entry . main = [ path . join ( __dirname , '../src/main/index.dev.js' ) ] . concat ( mainConfig . entry . main )
83+ mainConfig . mode = 'development'
84+ const compiler = webpack ( mainConfig )
8585
86- compiler . hooks . watchRun . tapAsync ( 'watch-run' , ( compilation , done ) => {
87- logStats ( 'Main' , chalk . white . bold ( 'compiling...' ) )
88- hotMiddleware . publish ( { action : 'compiling' } )
89- done ( )
90- } )
86+ compiler . hooks . watchRun . tapAsync ( 'watch-run' , ( compilation , done ) => {
87+ logStats ( 'Main' , chalk . white . bold ( 'compiling...' ) )
88+ hotMiddleware . publish ( { action : 'compiling' } )
89+ done ( )
90+ } )
9191
92- compiler . watch ( { } , ( err , stats ) => {
93- if ( err ) {
94- console . log ( err )
95- return
96- }
92+ compiler . watch ( { } , ( err , stats ) => {
93+ if ( err ) {
94+ console . log ( err )
95+ return
96+ }
9797
98- logStats ( 'Main' , stats )
98+ logStats ( 'Main' , stats )
9999
100- if ( electronProcess && electronProcess . kill ) {
101- manualRestart = true
102- process . kill ( electronProcess . pid )
103- electronProcess = null
104- startElectron ( )
100+ if ( electronProcess && electronProcess . kill ) {
101+ manualRestart = true
102+ process . kill ( electronProcess . pid )
103+ electronProcess = null
104+ startElectron ( )
105105
106- setTimeout ( ( ) => {
107- manualRestart = false
108- } , 5000 )
109- }
106+ setTimeout ( ( ) => {
107+ manualRestart = false
108+ } , 5000 )
109+ }
110110
111- resolve ( )
112- } )
111+ resolve ( )
113112 } )
113+ } )
114114}
115115
116- function startElectron ( ) {
117- var args = [
118- '--inspect=5858' ,
119- path . join ( __dirname , '../dist/electron/main.js' )
120- ]
116+ function startElectron ( ) {
117+ var args = [ '--inspect=5858' , '--trace-warnings' , path . join ( __dirname , '../dist/electron/main.js' ) ]
121118
122- // detect yarn or npm and process commandline args accordingly
123- if ( process . env . npm_execpath . endsWith ( 'yarn.js' ) ) {
124- args = args . concat ( process . argv . slice ( 3 ) )
125- } else if ( process . env . npm_execpath . endsWith ( 'npm-cli.js' ) ) {
126- args = args . concat ( process . argv . slice ( 2 ) )
127- }
119+ // detect yarn or npm and process commandline args accordingly
120+ if ( process . env . npm_execpath . endsWith ( 'yarn.js' ) ) {
121+ args = args . concat ( process . argv . slice ( 3 ) )
122+ } else if ( process . env . npm_execpath . endsWith ( 'npm-cli.js' ) ) {
123+ args = args . concat ( process . argv . slice ( 2 ) )
124+ }
128125
129- electronProcess = spawn ( electron , args )
126+ electronProcess = spawn ( electron , args )
130127
131- electronProcess . stdout . on ( 'data' , data => {
132- electronLog ( data , 'blue' )
133- } )
134- electronProcess . stderr . on ( 'data' , data => {
135- electronLog ( data , 'red' )
136- } )
128+ electronProcess . stdout . on ( 'data' , data => {
129+ electronLog ( data , 'blue' )
130+ } )
131+ electronProcess . stderr . on ( 'data' , data => {
132+ electronLog ( data , 'red' )
133+ } )
137134
138- electronProcess . on ( 'close' , ( ) => {
139- if ( ! manualRestart ) process . exit ( )
140- } )
135+ electronProcess . on ( 'close' , ( ) => {
136+ if ( ! manualRestart ) process . exit ( )
137+ } )
141138}
142139
143- function electronLog ( data , color ) {
144- let log = ''
145- data = data . toString ( ) . split ( / \r ? \n / )
146- data . forEach ( line => {
147- log += ` ${ line } \n`
148- } )
149- if ( / [ 0 - 9 A - z ] + / . test ( log ) ) {
150- console . log (
151- chalk [ color ] . bold ( '┏ Electron -------------------' ) +
152- '\n\n' +
153- log +
154- chalk [ color ] . bold ( '┗ ----------------------------' ) +
155- '\n'
156- )
157- }
140+ function electronLog ( data , color ) {
141+ let log = ''
142+ data = data . toString ( ) . split ( / \r ? \n / )
143+ data . forEach ( line => {
144+ log += ` ${ line } \n`
145+ } )
146+ if ( / [ 0 - 9 A - z ] + / . test ( log ) ) {
147+ console . log ( chalk [ color ] . bold ( '┏ Electron -------------------' ) + '\n\n' + log + chalk [ color ] . bold ( '┗ ----------------------------' ) + '\n' )
148+ }
158149}
159150
160- function greeting ( ) {
161- const cols = process . stdout . columns
162- let text = ''
151+ function greeting ( ) {
152+ const cols = process . stdout . columns
153+ let text = ''
163154
164- if ( cols > 104 ) text = 'electron-vue'
165- else if ( cols > 76 ) text = 'electron-|vue'
166- else text = false
155+ if ( cols > 104 ) text = 'electron-vue'
156+ else if ( cols > 76 ) text = 'electron-|vue'
157+ else text = false
167158
168- if ( text ) {
169- say ( text , {
170- colors : [ 'yellow' ] ,
171- font : 'simple3d' ,
172- space : false
173- } )
174- } else console . log ( chalk . yellow . bold ( '\n electron-vue' ) )
175- console . log ( chalk . blue ( ' getting ready...' ) + '\n' )
159+ if ( text ) {
160+ say ( text , {
161+ colors : [ 'yellow' ] ,
162+ font : 'simple3d' ,
163+ space : false ,
164+ } )
165+ } else console . log ( chalk . yellow . bold ( '\n electron-vue' ) )
166+ console . log ( chalk . blue ( ' getting ready...' ) + '\n' )
176167}
177168
178- function init ( ) {
179- greeting ( )
169+ function init ( ) {
170+ greeting ( )
180171
181- Promise . all ( [ startRenderer ( ) , startMain ( ) ] )
172+ Promise . all ( [ startRenderer ( ) , startMain ( ) ] )
182173 . then ( ( ) => {
183- startElectron ( )
174+ startElectron ( )
184175 } )
185176 . catch ( err => {
186- console . error ( err )
177+ console . error ( err )
187178 } )
188179}
189180
0 commit comments