-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathpreview.ts
51 lines (44 loc) · 1.77 KB
/
preview.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { DEVICE_LOG_EVENT_NAME } from "../common/constants";
export class PreviewCommand implements ICommand {
public allowedParameters: ICommandParameter[] = [];
private static MIN_SUPPORTED_WEBPACK_VERSION = "0.17.0";
constructor(private $analyticsService: IAnalyticsService,
private $bundleValidatorHelper: IBundleValidatorHelper,
private $errors: IErrors,
private $liveSyncService: ILiveSyncService,
private $logger: ILogger,
private $networkConnectivityValidator: INetworkConnectivityValidator,
private $projectData: IProjectData,
private $options: IOptions,
private $previewAppLogProvider: IPreviewAppLogProvider,
private $previewQrCodeService: IPreviewQrCodeService,
$cleanupService: ICleanupService) {
this.$analyticsService.setShouldDispose(false);
$cleanupService.setShouldDispose(false);
}
public async execute(): Promise<void> {
this.$previewAppLogProvider.on(DEVICE_LOG_EVENT_NAME, (deviceId: string, message: string) => {
this.$logger.info(message);
});
await this.$liveSyncService.liveSyncToPreviewApp({
bundle: !!this.$options.bundle,
useHotModuleReload: this.$options.hmr,
projectDir: this.$projectData.projectDir,
env: this.$options.env
});
await this.$previewQrCodeService.printLiveSyncQrCode({
projectDir: this.$projectData.projectDir,
useHotModuleReload: this.$options.hmr,
link: this.$options.link
});
}
public async canExecute(args: string[]): Promise<boolean> {
if (args && args.length) {
this.$errors.fail(`The arguments '${args.join(" ")}' are not valid for the preview command.`);
}
await this.$networkConnectivityValidator.validate();
this.$bundleValidatorHelper.validate(PreviewCommand.MIN_SUPPORTED_WEBPACK_VERSION);
return true;
}
}
$injector.registerCommand("preview", PreviewCommand);