@@ -4,51 +4,66 @@ import * as figures from 'figures';
4
4
import { createServer } from 'https' ;
5
5
import * as ora from 'ora' ;
6
6
import * as webpack from 'webpack' ;
7
- import { Compiler as WebpackCompiler , Stats as WebpackStats } from 'webpack' ;
8
- import { ThemekitEnvironmentConfig } from '../../../utils/themekit' ;
7
+ import {
8
+ Compiler as WebpackCompiler ,
9
+ Configuration as WebpackConfiguration ,
10
+ Stats as WebpackStats ,
11
+ } from 'webpack' ;
12
+ import {
13
+ ThemekitEnvironmentConfig ,
14
+ ThemeKitFlags ,
15
+ } from '../../../utils/themekit' ;
9
16
import { isHotUpdateFile } from '../../../webpack/utils' ;
10
17
import { LocalDevelopmentServer } from '../local-development-server' ;
11
- import { ShopifySyncClient } from './shopify-sync/shopify-sync-client' ;
12
18
import {
13
19
getSslKeyCert ,
14
20
SslKeyCert ,
15
21
} from '../local-development-server/ssl/server-ssl' ;
16
22
import { ServeExecutorSchema } from '../schema' ;
17
23
import { AssetsServerApp } from './assets-server-app' ;
24
+ import { ShopifySyncClient } from './shopify-sync/shopify-sync-client' ;
18
25
19
26
const spinner = ora ( chalk . magenta ( ' Compiling...' ) ) ;
20
- export class LocalAssetServer {
21
- assetHashes ;
27
+
28
+ export interface LocalAssetServerConfig {
22
29
address : string ;
23
- options ;
30
+ allowLive : boolean ;
31
+ devServer : LocalDevelopmentServer ;
24
32
port : number ;
33
+ themekitEnvConfig : ThemekitEnvironmentConfig ;
34
+ skipFirstDeploy : boolean ;
35
+ webpackConfig : WebpackConfiguration ;
36
+ }
37
+ export class LocalAssetServer {
38
+ assetHashes ;
39
+ config : LocalAssetServerConfig ;
25
40
webpackCompiler : WebpackCompiler ;
26
41
assetsServerApp : AssetsServerApp ;
27
42
shopifySyncClient : ShopifySyncClient ;
28
43
ssl : SslKeyCert ;
29
44
httpsServer ;
30
- firstSync : boolean ;
45
+ isFirstSync : boolean ;
31
46
devServer : LocalDevelopmentServer ;
32
- themekitEnvConfig : ThemekitEnvironmentConfig ;
47
+ themekitFlags : ThemeKitFlags ;
33
48
34
- constructor ( options ) {
35
- const { devServer, address, port, themekitEnvConfig } = options ;
49
+ constructor ( config : LocalAssetServerConfig ) {
50
+ const { devServer, address, port, webpackConfig , allowLive } = config ;
36
51
37
- options . webpackConfig . output . publicPath = `https://${ address } :${ port } /` ;
52
+ config . webpackConfig . output . publicPath = `https://${ address } :${ port } /` ;
53
+ this . config = config ;
38
54
this . assetHashes = { } ;
39
- this . address = address ;
40
- this . options = options ;
41
- this . port = options . port ;
42
- this . themekitEnvConfig = themekitEnvConfig ;
43
- this . webpackCompiler = webpack ( options . webpackConfig ) ;
55
+ this . webpackCompiler = webpack ( webpackConfig ) ;
44
56
this . assetsServerApp = new AssetsServerApp ( this . webpackCompiler ) ;
45
57
this . shopifySyncClient = new ShopifySyncClient ( ) ;
46
58
this . shopifySyncClient . hooks . afterSync . tap (
47
59
'HotMiddleWare' ,
48
60
this . onAfterSync . bind ( this )
49
61
) ;
50
- this . firstSync = true ;
62
+ this . isFirstSync = true ;
51
63
this . devServer = devServer ;
64
+ this . themekitFlags = {
65
+ allowLive,
66
+ } ;
52
67
}
53
68
54
69
start ( options : ServeExecutorSchema ) {
@@ -59,7 +74,7 @@ export class LocalAssetServer {
59
74
this . webpackCompiler . hooks . done . tap ( 'CLI' , this . onCompilerDone . bind ( this ) ) ;
60
75
this . shopifySyncClient . hooks . beforeSync . tapPromise (
61
76
'CLI' ,
62
- this . onClientBeforeSync ( options ) . bind ( this )
77
+ this . onClientBeforeSync ( ) . bind ( this )
63
78
) ;
64
79
this . shopifySyncClient . hooks . syncSkipped . tap (
65
80
'CLI' ,
@@ -85,7 +100,7 @@ export class LocalAssetServer {
85
100
this . assetsServerApp . buildServer ( )
86
101
) ;
87
102
88
- this . httpsServer . listen ( this . port ) ;
103
+ this . httpsServer . listen ( this . config . port ) ;
89
104
}
90
105
91
106
set skipDeploy ( value : boolean ) {
@@ -94,7 +109,11 @@ export class LocalAssetServer {
94
109
95
110
private onCompileDone ( stats : WebpackStats ) {
96
111
const files = this . _getAssetsToUpload ( stats ) ;
97
- return this . shopifySyncClient . syncChangedFiles ( files , stats ) ;
112
+ return this . shopifySyncClient . syncChangedFiles (
113
+ files ,
114
+ stats ,
115
+ this . themekitFlags
116
+ ) ;
98
117
}
99
118
100
119
private onAfterSync ( files : string [ ] ) {
@@ -187,11 +206,11 @@ export class LocalAssetServer {
187
206
}
188
207
}
189
208
190
- onClientBeforeSync ( options : ServeExecutorSchema ) {
209
+ onClientBeforeSync ( ) {
191
210
return async ( files : string [ ] ) => {
192
211
const themeID = 'getThemeIdValue()' ;
193
212
194
- if ( this . firstSync && options . skipFirstDeploy ) {
213
+ if ( this . isFirstSync && this . config . skipFirstDeploy ) {
195
214
this . skipDeploy = true ;
196
215
197
216
return ;
@@ -225,7 +244,7 @@ export class LocalAssetServer {
225
244
226
245
onClientSyncSkipped ( options : ServeExecutorSchema ) {
227
246
return ( ) => {
228
- if ( ! ( this . firstSync && options . skipFirstDeploy ) ) return ;
247
+ if ( ! ( this . isFirstSync && options . skipFirstDeploy ) ) return ;
229
248
console . log (
230
249
`\n${ chalk . blue (
231
250
figures . info
@@ -246,8 +265,8 @@ export class LocalAssetServer {
246
265
}
247
266
248
267
async onClientAfterSync ( ) {
249
- if ( this . firstSync ) {
250
- this . firstSync = false ;
268
+ if ( this . isFirstSync ) {
269
+ this . isFirstSync = false ;
251
270
await this . devServer . start ( ) ;
252
271
}
253
272
@@ -257,10 +276,11 @@ export class LocalAssetServer {
257
276
`${ chalk . yellow (
258
277
figures . star
259
278
) } You are editing files in theme ${ chalk . green (
260
- this . themekitEnvConfig . themeId
279
+ this . config . themekitEnvConfig . themeId
261
280
) } on the following store:\n`
262
281
) ;
263
282
283
+ const { address, port } = this . config ;
264
284
const { target, themeId } = this . devServer ;
265
285
266
286
const previewUrl = `${ target } ?preview_theme_id=${ themeId } ` ;
@@ -282,16 +302,16 @@ export class LocalAssetServer {
282
302
console . log ( ` Assets are being served from:\n` ) ;
283
303
284
304
console . log (
285
- ` ${ chalk . cyan ( `https://localhost:${ this . port } ` ) } ${ chalk . grey (
305
+ ` ${ chalk . cyan ( `https://localhost:${ port } ` ) } ${ chalk . grey (
286
306
'(Local)'
287
307
) } `
288
308
) ;
289
309
290
- if ( this . address !== 'localhost' ) {
310
+ if ( address !== 'localhost' ) {
291
311
console . log (
292
- ` ${ chalk . cyan (
293
- `https:// ${ this . address } : ${ this . port } `
294
- ) } ${ chalk . grey ( '(External)' ) } `
312
+ ` ${ chalk . cyan ( `https:// ${ address } : ${ port } ` ) } ${ chalk . grey (
313
+ '(External)'
314
+ ) } `
295
315
) ;
296
316
}
297
317
0 commit comments