Skip to content

Commit a91140f

Browse files
committed
Merge branch 'master' into alpha
2 parents 968e8c5 + 7ff9b31 commit a91140f

File tree

18 files changed

+364
-175
lines changed

18 files changed

+364
-175
lines changed

.github/workflows/run-e2e.yml renamed to .github/workflows/e2e.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Run e2e tests
1+
name: e2e
22

33
on:
44
push:

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(The MIT License)
22

3-
Copyright (c) 2020 Trafilea.
3+
Copyright (c) 2021 Trafilea.
44

55
Permission is hereby granted, free of charge, to any person obtaining
66
a copy of this software and associated documentation files (the

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<div align="center">
1717

18-
[![documentation](https://github.com/trafilea/nx-shopify/workflows/documentation/badge.svg)](https://trafilea.github.io/nx-shopify/)
18+
[![e2e](https://github.com/trafilea/nx-shopify/actions/workflows/e2e.yml/badge.svg)](https://github.com/trafilea/nx-shopify/actions/workflows/e2e.yml)
1919
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
2020
[![License](https://img.shields.io/github/license/trafilea/nx-shopify)](https://github.com/trafilea/nx-shopify/blob/master/LICENSE)
2121
![npm (scoped)](https://img.shields.io/npm/v/@trafilea/nx-shopify)

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
"dependencies": {
3535
"@angular-devkit/architect": "~0.1100.1",
3636
"@angular-devkit/build-webpack": "~0.1100.1",
37-
"@nrwl/devkit": "11.2.12",
38-
"@nrwl/workspace": "11.2.12",
37+
"@nrwl/devkit": "11.4.0",
38+
"@nrwl/workspace": "11.4.0",
3939
"@shopify/themekit": "^1.1.7",
4040
"browser-sync": "^2.26.14",
4141
"camelcase-keys": "^6.2.2",
@@ -75,11 +75,11 @@
7575
"webpack-merge": "5"
7676
},
7777
"devDependencies": {
78-
"@nrwl/cli": "11.2.12",
79-
"@nrwl/eslint-plugin-nx": "11.2.12",
80-
"@nrwl/jest": "11.2.12",
81-
"@nrwl/nx-plugin": "11.2.12",
82-
"@nrwl/tao": "11.2.12",
78+
"@nrwl/cli": "11.4.0",
79+
"@nrwl/eslint-plugin-nx": "11.4.0",
80+
"@nrwl/jest": "11.4.0",
81+
"@nrwl/nx-plugin": "11.4.0",
82+
"@nrwl/tao": "11.4.0",
8383
"@semantic-release/changelog": "^5.0.1",
8484
"@semantic-release/git": "^9.0.0",
8585
"@types/browser-sync": "^2.26.1",

packages/nx-shopify/src/executors/serve/local-assets-server/local-assets-server.ts

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,66 @@ import * as figures from 'figures';
44
import { createServer } from 'https';
55
import * as ora from 'ora';
66
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';
916
import { isHotUpdateFile } from '../../../webpack/utils';
1017
import { LocalDevelopmentServer } from '../local-development-server';
11-
import { ShopifySyncClient } from './shopify-sync/shopify-sync-client';
1218
import {
1319
getSslKeyCert,
1420
SslKeyCert,
1521
} from '../local-development-server/ssl/server-ssl';
1622
import { ServeExecutorSchema } from '../schema';
1723
import { AssetsServerApp } from './assets-server-app';
24+
import { ShopifySyncClient } from './shopify-sync/shopify-sync-client';
1825

1926
const spinner = ora(chalk.magenta(' Compiling...'));
20-
export class LocalAssetServer {
21-
assetHashes;
27+
28+
export interface LocalAssetServerConfig {
2229
address: string;
23-
options;
30+
allowLive: boolean;
31+
devServer: LocalDevelopmentServer;
2432
port: number;
33+
themekitEnvConfig: ThemekitEnvironmentConfig;
34+
skipFirstDeploy: boolean;
35+
webpackConfig: WebpackConfiguration;
36+
}
37+
export class LocalAssetServer {
38+
assetHashes;
39+
config: LocalAssetServerConfig;
2540
webpackCompiler: WebpackCompiler;
2641
assetsServerApp: AssetsServerApp;
2742
shopifySyncClient: ShopifySyncClient;
2843
ssl: SslKeyCert;
2944
httpsServer;
30-
firstSync: boolean;
45+
isFirstSync: boolean;
3146
devServer: LocalDevelopmentServer;
32-
themekitEnvConfig: ThemekitEnvironmentConfig;
47+
themekitFlags: ThemeKitFlags;
3348

34-
constructor(options) {
35-
const { devServer, address, port, themekitEnvConfig } = options;
49+
constructor(config: LocalAssetServerConfig) {
50+
const { devServer, address, port, webpackConfig, allowLive } = config;
3651

37-
options.webpackConfig.output.publicPath = `https://${address}:${port}/`;
52+
config.webpackConfig.output.publicPath = `https://${address}:${port}/`;
53+
this.config = config;
3854
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);
4456
this.assetsServerApp = new AssetsServerApp(this.webpackCompiler);
4557
this.shopifySyncClient = new ShopifySyncClient();
4658
this.shopifySyncClient.hooks.afterSync.tap(
4759
'HotMiddleWare',
4860
this.onAfterSync.bind(this)
4961
);
50-
this.firstSync = true;
62+
this.isFirstSync = true;
5163
this.devServer = devServer;
64+
this.themekitFlags = {
65+
allowLive,
66+
};
5267
}
5368

5469
start(options: ServeExecutorSchema) {
@@ -59,7 +74,7 @@ export class LocalAssetServer {
5974
this.webpackCompiler.hooks.done.tap('CLI', this.onCompilerDone.bind(this));
6075
this.shopifySyncClient.hooks.beforeSync.tapPromise(
6176
'CLI',
62-
this.onClientBeforeSync(options).bind(this)
77+
this.onClientBeforeSync().bind(this)
6378
);
6479
this.shopifySyncClient.hooks.syncSkipped.tap(
6580
'CLI',
@@ -85,7 +100,7 @@ export class LocalAssetServer {
85100
this.assetsServerApp.buildServer()
86101
);
87102

88-
this.httpsServer.listen(this.port);
103+
this.httpsServer.listen(this.config.port);
89104
}
90105

91106
set skipDeploy(value: boolean) {
@@ -94,7 +109,11 @@ export class LocalAssetServer {
94109

95110
private onCompileDone(stats: WebpackStats) {
96111
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+
);
98117
}
99118

100119
private onAfterSync(files: string[]) {
@@ -187,11 +206,11 @@ export class LocalAssetServer {
187206
}
188207
}
189208

190-
onClientBeforeSync(options: ServeExecutorSchema) {
209+
onClientBeforeSync() {
191210
return async (files: string[]) => {
192211
const themeID = 'getThemeIdValue()';
193212

194-
if (this.firstSync && options.skipFirstDeploy) {
213+
if (this.isFirstSync && this.config.skipFirstDeploy) {
195214
this.skipDeploy = true;
196215

197216
return;
@@ -225,7 +244,7 @@ export class LocalAssetServer {
225244

226245
onClientSyncSkipped(options: ServeExecutorSchema) {
227246
return () => {
228-
if (!(this.firstSync && options.skipFirstDeploy)) return;
247+
if (!(this.isFirstSync && options.skipFirstDeploy)) return;
229248
console.log(
230249
`\n${chalk.blue(
231250
figures.info
@@ -246,8 +265,8 @@ export class LocalAssetServer {
246265
}
247266

248267
async onClientAfterSync() {
249-
if (this.firstSync) {
250-
this.firstSync = false;
268+
if (this.isFirstSync) {
269+
this.isFirstSync = false;
251270
await this.devServer.start();
252271
}
253272

@@ -257,10 +276,11 @@ export class LocalAssetServer {
257276
`${chalk.yellow(
258277
figures.star
259278
)} You are editing files in theme ${chalk.green(
260-
this.themekitEnvConfig.themeId
279+
this.config.themekitEnvConfig.themeId
261280
)} on the following store:\n`
262281
);
263282

283+
const { address, port } = this.config;
264284
const { target, themeId } = this.devServer;
265285

266286
const previewUrl = `${target}?preview_theme_id=${themeId}`;
@@ -282,16 +302,16 @@ export class LocalAssetServer {
282302
console.log(` Assets are being served from:\n`);
283303

284304
console.log(
285-
` ${chalk.cyan(`https://localhost:${this.port}`)} ${chalk.grey(
305+
` ${chalk.cyan(`https://localhost:${port}`)} ${chalk.grey(
286306
'(Local)'
287307
)}`
288308
);
289309

290-
if (this.address !== 'localhost') {
310+
if (address !== 'localhost') {
291311
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+
)}`
295315
);
296316
}
297317

packages/nx-shopify/src/executors/serve/local-assets-server/shopify-sync/shopify-sync-client.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ export class ShopifySyncClient {
2727
this.filesPendingDeploy = [];
2828
}
2929

30-
async syncChangedFiles(changedFiles: string[], stats: WebpackStats) {
30+
async syncChangedFiles(
31+
changedFiles: string[],
32+
stats: WebpackStats,
33+
themekitFlags: ThemeKitFlags
34+
) {
3135
if (this.isDeploymentInProgress) {
3236
this.filesPendingDeploy = [
3337
...new Set([...this.filesPendingDeploy, ...changedFiles]),
@@ -50,7 +54,7 @@ export class ShopifySyncClient {
5054
outputOptions: { path: outputPath },
5155
} = stats.compilation;
5256

53-
await this.deployPendingFiles(outputPath);
57+
await this.deployPendingFiles(outputPath, themekitFlags);
5458
this.skipNextSync = false;
5559
this.hooks.syncDone.call(changedFiles, stats);
5660
}
@@ -60,8 +64,12 @@ export class ShopifySyncClient {
6064
this.skipNextSync = false;
6165
}
6266

63-
async deployPendingFiles(compiledOutputPath: string) {
67+
async deployPendingFiles(
68+
compiledOutputPath: string,
69+
themekitFlags: ThemeKitFlags
70+
) {
6471
const flags: ThemeKitFlags = {
72+
...themekitFlags,
6573
files: this.filesPendingDeploy,
6674
};
6775

packages/nx-shopify/src/executors/serve/local-development-server/local-development-server.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface LocalDevelopmentServerOptions {
1212
address: string;
1313
port: number;
1414
uiPort: number;
15+
openBrowser: boolean;
1516
}
1617

1718
export class LocalDevelopmentServer {
@@ -23,17 +24,21 @@ export class LocalDevelopmentServer {
2324
proxyTarget: string;
2425
browserSyncInstance: BrowserSyncInstance;
2526
browserSyncServer: BrowserSyncInstance;
27+
openBrowser: boolean;
2628

2729
constructor(options: LocalDevelopmentServerOptions) {
30+
const { target, themeId, port, address, uiPort, openBrowser } = options;
31+
2832
this.browserSyncInstance = browserSync.create();
29-
this.target = `https://${options.target}`;
30-
this.themeId = options.themeId;
31-
this.port = options.port;
32-
this.address = options.address;
33-
this.uiPort = options.uiPort;
33+
this.target = `https://${target}`;
34+
this.themeId = themeId;
35+
this.port = port;
36+
this.address = address;
37+
this.uiPort = uiPort;
3438
this.proxyTarget =
3539
this.target +
3640
(this.themeId === 'live' ? '' : `?preview_theme_id=${this.themeId}`);
41+
this.openBrowser = openBrowser;
3742
}
3843

3944
start() {
@@ -68,7 +73,7 @@ export class LocalDevelopmentServer {
6873
ui: {
6974
port: this.uiPort,
7075
},
71-
open: false,
76+
open: this.openBrowser,
7277
};
7378

7479
return new Promise((resolve) => {

packages/nx-shopify/src/executors/serve/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"themekitEnv": {
1818
"type": "string",
19-
"description": "Name of the themekit config.yml environment to be used in the deployment ('development' by default)",
19+
"description": "Name of the themekit config.yml environment to be used in the deployment",
2020
"default": "development"
2121
},
2222
"allowLive": {

0 commit comments

Comments
 (0)