Skip to content

Commit dfbc087

Browse files
committed
fix: recommend the new workflow before executing run/test/debug/prepare/build/preview
1 parent d255b97 commit dfbc087

File tree

9 files changed

+45
-37
lines changed

9 files changed

+45
-37
lines changed

lib/commands/build.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
99
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
1010
$platformService: IPlatformService,
1111
private $bundleValidatorHelper: IBundleValidatorHelper,
12-
protected $logger: ILogger) {
13-
super($options, $platformsData, $platformService, $projectData);
14-
this.$projectData.initializeProjectData();
12+
protected $logger: ILogger,
13+
protected $workflowService: IWorkflowService) {
14+
super($options, $platformsData, $platformService, $projectData);
15+
this.$projectData.initializeProjectData();
1516
}
1617

1718
public async executeCore(args: string[]): Promise<string> {
19+
await this.$workflowService.handleLegacyWorkflow(this.$projectData.projectDir, this.$options, true);
1820
const platform = args[0].toLowerCase();
1921
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = {
2022
bundle: !!this.$options.bundle,
@@ -94,8 +96,9 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
9496
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
9597
$platformService: IPlatformService,
9698
$bundleValidatorHelper: IBundleValidatorHelper,
97-
$logger: ILogger) {
98-
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService, $bundleValidatorHelper, $logger);
99+
$logger: ILogger,
100+
$workflowService: IWorkflowService) {
101+
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService, $bundleValidatorHelper, $logger, $workflowService);
99102
}
100103

101104
public async execute(args: string[]): Promise<void> {
@@ -107,7 +110,7 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
107110

108111
super.validatePlatform(platform);
109112

110-
let result = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true }});
113+
let result = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true } });
111114
if (result.canExecute) {
112115
result = await super.validateArgs(args, platform);
113116
}
@@ -129,8 +132,9 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
129132
$platformService: IPlatformService,
130133
$bundleValidatorHelper: IBundleValidatorHelper,
131134
protected $androidBundleValidatorHelper: IAndroidBundleValidatorHelper,
132-
protected $logger: ILogger) {
133-
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService, $bundleValidatorHelper, $logger);
135+
protected $logger: ILogger,
136+
$workflowService: IWorkflowService) {
137+
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService, $bundleValidatorHelper, $logger, $workflowService);
134138
}
135139

136140
public async execute(args: string[]): Promise<void> {
@@ -149,7 +153,7 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
149153
const platform = this.$devicePlatformsConstants.Android;
150154
super.validatePlatform(platform);
151155
this.$androidBundleValidatorHelper.validateRuntimeVersion(this.$projectData);
152-
let result = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true }});
156+
let result = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true } });
153157
if (result.canExecute) {
154158
if (this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
155159
this.$errors.fail(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);

lib/commands/debug.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ export class DebugPlatformCommand extends ValidatePlatformCommandBase implements
1818
private $debugDataService: IDebugDataService,
1919
private $liveSyncService: IDebugLiveSyncService,
2020
private $liveSyncCommandHelper: ILiveSyncCommandHelper,
21-
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper) {
21+
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper,
22+
private $workflowService: IWorkflowService) {
2223
super($options, $platformsData, $platformService, $projectData);
2324
}
2425

2526
public async execute(args: string[]): Promise<void> {
27+
await this.$workflowService.handleLegacyWorkflow(this.$projectData.projectDir, this.$options, true);
2628
await this.$devicesService.initialize({
2729
platform: this.platform,
2830
deviceId: this.$options.device,

lib/commands/prepare.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ export class PrepareCommand extends ValidatePlatformCommandBase implements IComm
77
$platformService: IPlatformService,
88
$projectData: IProjectData,
99
private $platformCommandParameter: ICommandParameter,
10-
$platformsData: IPlatformsData) {
11-
super($options, $platformsData, $platformService, $projectData);
12-
this.$projectData.initializeProjectData();
10+
$platformsData: IPlatformsData,
11+
private $workflowService: IWorkflowService) {
12+
super($options, $platformsData, $platformService, $projectData);
13+
this.$projectData.initializeProjectData();
1314
}
1415

1516
public async execute(args: string[]): Promise<void> {
17+
await this.$workflowService.handleLegacyWorkflow(this.$projectData.projectDir, this.$options, true);
1618
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = {
1719
bundle: !!this.$options.bundle,
1820
release: this.$options.release,

lib/commands/preview.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class PreviewCommand implements ICommand {
2121
}
2222

2323
public async execute(): Promise<void> {
24-
await this.$workflowService.handleLegacyWorkflow(this.$projectData.projectDir, this.$options);
24+
await this.$workflowService.handleLegacyWorkflow(this.$projectData.projectDir, this.$options, true);
2525
this.$previewAppLogProvider.on(DEVICE_LOG_EVENT_NAME, (deviceId: string, message: string) => {
2626
this.$logger.info(message);
2727
});

lib/commands/run.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ export class RunCommandBase implements ICommand {
1313
private $errors: IErrors,
1414
private $hostInfo: IHostInfo,
1515
private $liveSyncCommandHelper: ILiveSyncCommandHelper,
16-
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper) { }
16+
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper,
17+
private $options: IOptions,
18+
private $workflowService: IWorkflowService) { }
1719

1820
public allowedParameters: ICommandParameter[] = [];
1921
public async execute(args: string[]): Promise<void> {
22+
await this.$workflowService.handleLegacyWorkflow(this.$projectData.projectDir, this.$options, true);
2023
await this.$analyticsService.trackPreviewAppData(this.platform, this.$projectData.projectDir);
2124
return this.$liveSyncCommandHelper.executeCommandLiveSync(this.platform, this.liveSyncCommandHelperAdditionalOptions);
2225
}

lib/commands/test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ abstract class TestCommandBase {
1414
protected abstract $workflowService: IWorkflowService;
1515

1616
async execute(args: string[]): Promise<void> {
17-
await this.$workflowService.handleLegacyWorkflow(this.$projectData.projectDir, this.$options);
17+
await this.$workflowService.handleLegacyWorkflow(this.$projectData.projectDir, this.$options, true);
1818
await this.$testExecutionService.startKarmaServer(this.platform, this.$projectData, this.projectFilesConfig);
1919
}
2020

lib/definitions/platform.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface IBuildPlatformAction {
1515
}
1616

1717
interface IWorkflowService {
18-
handleLegacyWorkflow(projectDir: string, settings: IWebpackWorkflowSettings, force?: boolean): Promise<void>;
18+
handleLegacyWorkflow(projectDir: string, settings: IWebpackWorkflowSettings, skipWarnings?: boolean, force?: boolean): Promise<void>;
1919
}
2020

2121
interface IWebpackWorkflowSettings {

lib/services/project-data-service.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,10 @@ export class ProjectDataService implements IProjectDataService {
137137
}
138138

139139
public setUseLegacyWorkflow(projectDir: string, value: any): void {
140-
// TODO: use trace
141-
this.$logger.info(`useLegacyWorkflow will be set to ${value}`);
140+
this.$logger.trace(`useLegacyWorkflow will be set to ${value}`);
142141
this.updateNsConfigValue(projectDir, { useLegacyWorkflow: value });
143142
this.refreshProjectData(projectDir);
144-
this.$logger.info(`useLegacyWorkflow was set to ${value}`);
143+
this.$logger.trace(`useLegacyWorkflow was set to ${value}`);
145144
}
146145

147146
public getAppExecutableFiles(projectDir: string): string[] {

lib/services/workflow-service.ts

+15-17
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ export class WorkflowService implements IWorkflowService {
1313
) {
1414
}
1515

16-
public async handleLegacyWorkflow(projectDir: string, settings: IWebpackWorkflowSettings, force?: boolean): Promise<void> {
16+
public async handleLegacyWorkflow(projectDir: string, settings: IWebpackWorkflowSettings, skipWarnings?: boolean, force?: boolean): Promise<void> {
1717
if (!settings.bundle || force) {
1818
const projectData = this.$projectDataService.getProjectData(projectDir);
19-
if (projectData.useLegacyWorkflow === null || projectData.useLegacyWorkflow === undefined || force) {
20-
const hasSwitched = await this.handleWebpackWorkflowSwitch(projectData, force);
19+
if (typeof (projectData.useLegacyWorkflow) !== "boolean" || force) {
20+
const hasSwitched = await this.handleWebpackWorkflowSwitch(projectData, skipWarnings, force);
2121
if (hasSwitched) {
2222
this.$options.bundle = "webpack";
2323
this.$options.hmr = !settings.release;
@@ -28,15 +28,15 @@ export class WorkflowService implements IWorkflowService {
2828
}
2929
settings.useHotModuleReload = this.$options.hmr;
3030
}
31-
} else if (projectData.useLegacyWorkflow === true) {
31+
} else if (!skipWarnings && projectData.useLegacyWorkflow === true) {
3232
this.showLegacyWorkflowWarning();
33-
} else {
33+
} else if (!skipWarnings && projectData.useLegacyWorkflow === false) {
3434
this.showNoBundleWarning();
3535
}
3636
}
3737
}
3838

39-
private async handleWebpackWorkflowSwitch(projectData: IProjectData, force: boolean): Promise<boolean> {
39+
private async handleWebpackWorkflowSwitch(projectData: IProjectData, skipWarnings: boolean, force: boolean): Promise<boolean> {
4040
let hasSwitched = false;
4141
if (force || helpers.isInteractive()) {
4242
hasSwitched = force || await this.$prompter.confirm("Please use webpack!", () => true);
@@ -45,21 +45,20 @@ export class WorkflowService implements IWorkflowService {
4545
await this.ensureWebpackPluginInstalled(projectData);
4646
} else {
4747
this.$projectDataService.setUseLegacyWorkflow(projectData.projectDir, true);
48-
await this.showLegacyWorkflowWarning();
4948
}
50-
} else {
49+
} else if (!skipWarnings) {
5150
await this.showLegacyWorkflowWarning();
5251
}
5352

5453
return hasSwitched;
5554
}
5655

57-
private async showLegacyWorkflowWarning() {
58-
this.$logger.warn("WARNINGGGGG LEGACY TRUE!!!");
56+
private showLegacyWorkflowWarning() {
57+
this.$logger.warn("TODO: <Add a legacy workflow warning here>");
5958
}
6059

6160
private showNoBundleWarning() {
62-
this.$logger.warn("WARNINGGGGG NO BUNDLE!!!");
61+
this.$logger.warn("TODO: <Add a `--no-bundle` workflow warning here>");
6362
}
6463

6564
private async ensureWebpackPluginInstalled(projectData: IProjectData) {
@@ -70,20 +69,19 @@ export class WorkflowService implements IWorkflowService {
7069

7170
let isInstalledVersionSupported = true;
7271
const installedVersion = this.$bundleValidatorHelper.getBundlerDependencyVersion(webpackPluginName);
73-
// TODO: use trace
74-
this.$logger.info(`Updating to webpack workflow: Found ${webpackPluginName} v${installedVersion}`);
72+
this.$logger.trace(`Updating to webpack workflow: Found ${webpackPluginName} v${installedVersion}`);
7573
if (validWebpackPluginTags.indexOf(installedVersion) === -1) {
7674
const isInstalledVersionValid = !!semver.valid(installedVersion) || !!semver.coerce(installedVersion);
7775
isInstalledVersionSupported =
7876
isInstalledVersionValid && semver.gte(semver.coerce(installedVersion), hmrOutOfBetaWebpackPluginVersion);
79-
this.$logger.info(`Updating to webpack workflow: Is installedVersion valid: ${isInstalledVersionValid}`);
77+
this.$logger.trace(`Updating to webpack workflow: Is installed version valid?: ${isInstalledVersionValid}`);
8078
}
8179

82-
this.$logger.info(`Updating to webpack workflow: Is installedVersion supported: ${isInstalledVersionSupported}`);
80+
this.$logger.trace(`Updating to webpack workflow: Is installed version supported?: ${isInstalledVersionSupported}`);
8381
if (!isInstalledVersionSupported) {
8482
const webpackConfigPath = path.join(projectData.projectDir, webpackConfigFileName);
8583
if (this.$fs.exists(webpackConfigPath)) {
86-
this.$logger.info(`Your Webpack config was stored to .bak!!`);
84+
this.$logger.info(`<TODO: Add a webpack cofnig backup info here>`);
8785
this.$fs.rename(webpackConfigPath, `${webpackConfigPath}.bak`);
8886
}
8987

@@ -94,7 +92,7 @@ export class WorkflowService implements IWorkflowService {
9492
frameworkPath: null,
9593
ignoreScripts: false,
9694
});
97-
this.$logger.info(`Updating to webpack workflow: The ${webpackPluginName} was updated to v${installResult.version}`);
95+
this.$logger.trace(`Updating to webpack workflow: The ${webpackPluginName} was updated to v${installResult.version}`);
9896
}
9997
}
10098
}

0 commit comments

Comments
 (0)