Skip to content

Commit d255b97

Browse files
committed
feat: deprecate the legacy workflow and recommend the new one
1 parent 59a7310 commit d255b97

15 files changed

+239
-28
lines changed

lib/bootstrap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ $injector.require("hmrStatusService", "./services/hmr-status-service");
190190
$injector.require("pacoteService", "./services/pacote-service");
191191
$injector.require("qrCodeTerminalService", "./services/qr-code-terminal-service");
192192
$injector.require("testInitializationService", "./services/test-initialization-service");
193+
$injector.require("workflowService", "./services/workflow-service");
193194

194195
$injector.require("networkConnectivityValidator", "./helpers/network-connectivity-validator");
195196
$injector.requirePublic("cleanupService", "./services/cleanup-service");

lib/commands/preview.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ export class PreviewCommand implements ICommand {
1414
private $options: IOptions,
1515
private $previewAppLogProvider: IPreviewAppLogProvider,
1616
private $previewQrCodeService: IPreviewQrCodeService,
17+
protected $workflowService: IWorkflowService,
1718
$cleanupService: ICleanupService) {
18-
this.$analyticsService.setShouldDispose(false);
19-
$cleanupService.setShouldDispose(false);
20-
}
19+
this.$analyticsService.setShouldDispose(false);
20+
$cleanupService.setShouldDispose(false);
21+
}
2122

2223
public async execute(): Promise<void> {
24+
await this.$workflowService.handleLegacyWorkflow(this.$projectData.projectDir, this.$options);
2325
this.$previewAppLogProvider.on(DEVICE_LOG_EVENT_NAME, (deviceId: string, message: string) => {
2426
this.$logger.info(message);
2527
});

lib/commands/test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ abstract class TestCommandBase {
1111
protected abstract $platformEnvironmentRequirements: IPlatformEnvironmentRequirements;
1212
protected abstract $errors: IErrors;
1313
protected abstract $cleanupService: ICleanupService;
14+
protected abstract $workflowService: IWorkflowService;
1415

1516
async execute(args: string[]): Promise<void> {
17+
await this.$workflowService.handleLegacyWorkflow(this.$projectData.projectDir, this.$options);
1618
await this.$testExecutionService.startKarmaServer(this.platform, this.$projectData, this.projectFilesConfig);
1719
}
1820

@@ -54,7 +56,8 @@ class TestAndroidCommand extends TestCommandBase implements ICommand {
5456
protected $options: IOptions,
5557
protected $platformEnvironmentRequirements: IPlatformEnvironmentRequirements,
5658
protected $errors: IErrors,
57-
protected $cleanupService: ICleanupService) {
59+
protected $cleanupService: ICleanupService,
60+
protected $workflowService: IWorkflowService) {
5861
super();
5962
}
6063

@@ -69,7 +72,8 @@ class TestIosCommand extends TestCommandBase implements ICommand {
6972
protected $options: IOptions,
7073
protected $platformEnvironmentRequirements: IPlatformEnvironmentRequirements,
7174
protected $errors: IErrors,
72-
protected $cleanupService: ICleanupService) {
75+
protected $cleanupService: ICleanupService,
76+
protected $workflowService: IWorkflowService) {
7377
super();
7478
}
7579

lib/commands/update.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export class UpdateCommand extends ValidatePlatformCommandBase implements IComma
1212
private $pluginsService: IPluginsService,
1313
private $projectDataService: IProjectDataService,
1414
private $fs: IFileSystem,
15-
private $logger: ILogger) {
15+
private $logger: ILogger,
16+
private $workflowService: IWorkflowService) {
1617
super($options, $platformsData, $platformService, $projectData);
1718
this.$projectData.initializeProjectData();
1819
}
@@ -28,6 +29,12 @@ export class UpdateCommand extends ValidatePlatformCommandBase implements IComma
2829
static readonly backupFailMessage: string = "Could not backup project folders!";
2930

3031
public async execute(args: string[]): Promise<void> {
32+
if (this.$options.workflow) {
33+
const forceWebpackWorkflow = true;
34+
await this.$workflowService.handleLegacyWorkflow(this.$projectData.projectDir, this.$options, forceWebpackWorkflow);
35+
return;
36+
}
37+
3138
const tmpDir = path.join(this.$projectData.projectDir, UpdateCommand.tempFolder);
3239

3340
try {

lib/declarations.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ interface IOptions extends IRelease, IDeviceIdentifier, IJustLaunch, IAvd, IAvai
571571
performance: Object;
572572
setupOptions(projectData: IProjectData): void;
573573
cleanupLogFile: string;
574+
workflow: boolean;
574575
}
575576

576577
interface IEnvOptions {
@@ -940,6 +941,12 @@ interface IBundleValidatorHelper {
940941
* @return {void}
941942
*/
942943
validate(minSupportedVersion?: string): void;
944+
945+
/**
946+
* Returns the installed bundler version.
947+
* @return {string}
948+
*/
949+
getBundlerDependencyVersion(bundlerName?: string): string;
943950
}
944951

945952

lib/definitions/platform.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ interface IBuildPlatformAction {
1414
buildPlatform(platform: string, buildConfig: IBuildConfig, projectData: IProjectData): Promise<string>;
1515
}
1616

17+
interface IWorkflowService {
18+
handleLegacyWorkflow(projectDir: string, settings: IWebpackWorkflowSettings, force?: boolean): Promise<void>;
19+
}
20+
21+
interface IWebpackWorkflowSettings {
22+
bundle?: boolean | string;
23+
useHotModuleReload?: boolean;
24+
release?: boolean;
25+
}
26+
1727
interface IPlatformService extends IBuildPlatformAction, NodeJS.EventEmitter {
1828
cleanPlatforms(platforms: string[], platformTemplate: string, projectData: IProjectData, config: IPlatformOptions, framework?: string): Promise<void>;
1929

lib/definitions/project.d.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ interface IProjectDataService {
142142
*/
143143
setNSValue(projectDir: string, key: string, value: any): void;
144144

145+
/**
146+
* Sets a value in the `useLegacyWorkflow` key in a project's nsconfig.json.
147+
* @param {string} projectDir The project directory - the place where the root package.json is located.
148+
* @param {any} value Value of the key to be set to `useLegacyWorkflow` key in project's nsconfig.json.
149+
* @returns {void}
150+
*/
151+
setUseLegacyWorkflow(projectDir: string, value: any): void;
152+
145153
/**
146154
* Removes a property from `nativescript` key in project's package.json.
147155
* @param {string} projectDir The project directory - the place where the root package.json is located.
@@ -584,7 +592,7 @@ interface IIOSExtensionsService {
584592
removeExtensions(options: IRemoveExtensionsOptions): void;
585593
}
586594

587-
interface IAddExtensionsFromPathOptions{
595+
interface IAddExtensionsFromPathOptions {
588596
extensionsFolderPath: string;
589597
projectData: IProjectData;
590598
platformData: IPlatformData;

lib/helpers/bundle-validator-helper.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,28 @@ export class BundleValidatorHelper extends VersionValidatorHelper implements IBu
1616

1717
public validate(minSupportedVersion?: string): void {
1818
if (this.$options.bundle) {
19-
const bundlePluginName = this.bundlersMap[this.$options.bundle];
20-
const bundlerVersionInDependencies = this.$projectData.dependencies && this.$projectData.dependencies[bundlePluginName];
21-
const bundlerVersionInDevDependencies = this.$projectData.devDependencies && this.$projectData.devDependencies[bundlePluginName];
22-
if (!bundlePluginName || (!bundlerVersionInDependencies && !bundlerVersionInDevDependencies)) {
19+
const currentVersion = this.getBundlerDependencyVersion();
20+
if (!currentVersion) {
2321
this.$errors.failWithoutHelp(BundleValidatorMessages.MissingBundlePlugin);
2422
}
2523

26-
const currentVersion = bundlerVersionInDependencies || bundlerVersionInDevDependencies;
2724
const shouldThrowError = minSupportedVersion && this.isValidVersion(currentVersion) && this.isVersionLowerThan(currentVersion, minSupportedVersion);
2825
if (shouldThrowError) {
29-
this.$errors.failWithoutHelp(util.format(BundleValidatorMessages.NotSupportedVersion, minSupportedVersion));
26+
this.$errors.failWithoutHelp(util.format(BundleValidatorMessages.NotSupportedVersion, minSupportedVersion));
3027
}
3128
}
3229
}
30+
31+
public getBundlerDependencyVersion(bundlerName?: string): string {
32+
let dependencyVersion = null;
33+
const bundlePluginName = bundlerName || this.bundlersMap[this.$options.bundle];
34+
const bundlerVersionInDependencies = this.$projectData.dependencies && this.$projectData.dependencies[bundlePluginName];
35+
const bundlerVersionInDevDependencies = this.$projectData.devDependencies && this.$projectData.devDependencies[bundlePluginName];
36+
dependencyVersion = bundlerVersionInDependencies || bundlerVersionInDevDependencies;
37+
38+
return dependencyVersion;
39+
40+
}
3341
}
3442

3543
$injector.register("bundleValidatorHelper", BundleValidatorHelper);

lib/options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export class Options {
136136
file: { type: OptionType.String, hasSensitiveValue: true },
137137
force: { type: OptionType.Boolean, alias: "f", hasSensitiveValue: false },
138138
// remove legacy
139+
workflow: { type: OptionType.Boolean, hasSensitiveValue: false },
139140
companion: { type: OptionType.Boolean, hasSensitiveValue: false },
140141
emulator: { type: OptionType.Boolean, hasSensitiveValue: false },
141142
sdk: { type: OptionType.String, hasSensitiveValue: false },

lib/project-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,4 @@ export class ProjectData implements IProjectData {
263263
this.$logger.warnWithLabel("IProjectData.projectId is deprecated. Please use IProjectData.projectIdentifiers[platform].");
264264
}
265265
}
266-
$injector.register("projectData", ProjectData);
266+
$injector.register("projectData", ProjectData, true);

0 commit comments

Comments
 (0)