Skip to content

Commit 8b83f91

Browse files
author
Dimitar Tachev
authored
Merge pull request #4546 from NativeScript/tachev/legacy-workflow-warnings
feat: deprecate the legacy workflow and recommend the new one
2 parents 713855f + f9be51d commit 8b83f91

30 files changed

+365
-71
lines changed

lib/bootstrap.ts

+1
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/build.ts

+14-10
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({ projectDir: this.$projectData.projectDir, settings: this.$options, skipWarnings: true });
1820
const platform = args[0].toLowerCase();
1921
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = {
2022
bundle: !!this.$options.bundle,
@@ -63,7 +65,7 @@ export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
6365
this.$errors.fail(`Applications for platform ${platform} can not be built on this OS`);
6466
}
6567

66-
this.$bundleValidatorHelper.validate();
68+
this.$bundleValidatorHelper.validate(this.$projectData);
6769
}
6870

6971
protected async validateArgs(args: string[], platform: string): Promise<ICanExecuteCommandOutput> {
@@ -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

+4-2
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({ projectDir: this.$projectData.projectDir, settings: this.$options, skipWarnings: true });
2628
await this.$devicesService.initialize({
2729
platform: this.platform,
2830
deviceId: this.$options.device,
@@ -67,7 +69,7 @@ export class DebugPlatformCommand extends ValidatePlatformCommandBase implements
6769
}
6870

6971
const minSupportedWebpackVersion = this.$options.hmr ? LiveSyncCommandHelper.MIN_SUPPORTED_WEBPACK_VERSION_WITH_HMR : null;
70-
this.$bundleValidatorHelper.validate(minSupportedWebpackVersion);
72+
this.$bundleValidatorHelper.validate(this.$projectData, minSupportedWebpackVersion);
7173

7274
const result = await super.canExecuteCommandBase(this.platform, { validateOptions: true, notConfiguredEnvOptions: { hideCloudBuildOption: true, hideSyncToPreviewAppOption: true } });
7375
return result;

lib/commands/deploy.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export class DeployOnDeviceCommand extends ValidatePlatformCommandBase implement
1414
$platformsData: IPlatformsData,
1515
private $bundleValidatorHelper: IBundleValidatorHelper,
1616
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper) {
17-
super($options, $platformsData, $platformService, $projectData);
18-
this.$projectData.initializeProjectData();
17+
super($options, $platformsData, $platformService, $projectData);
18+
this.$projectData.initializeProjectData();
1919
}
2020

2121
public async execute(args: string[]): Promise<void> {
@@ -26,7 +26,7 @@ export class DeployOnDeviceCommand extends ValidatePlatformCommandBase implement
2626

2727
public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
2828
this.$androidBundleValidatorHelper.validateNoAab();
29-
this.$bundleValidatorHelper.validate();
29+
this.$bundleValidatorHelper.validate(this.$projectData);
3030
if (!args || !args.length || args.length > 1) {
3131
return false;
3232
}

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({ projectDir: this.$projectData.projectDir, settings: this.$options, skipWarnings: true });
1618
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = {
1719
bundle: !!this.$options.bundle,
1820
release: this.$options.release,

lib/commands/preview.ts

+6-4
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({ projectDir: this.$projectData.projectDir, settings: this.$options, skipWarnings: true });
2325
this.$previewAppLogProvider.on(DEVICE_LOG_EVENT_NAME, (deviceId: string, message: string) => {
2426
this.$logger.info(message);
2527
});
@@ -44,7 +46,7 @@ export class PreviewCommand implements ICommand {
4446
}
4547

4648
await this.$networkConnectivityValidator.validate();
47-
this.$bundleValidatorHelper.validate(PreviewCommand.MIN_SUPPORTED_WEBPACK_VERSION);
49+
this.$bundleValidatorHelper.validate(this.$projectData, PreviewCommand.MIN_SUPPORTED_WEBPACK_VERSION);
4850
return true;
4951
}
5052
}

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({ projectDir: this.$projectData.projectDir, settings: this.$options, skipWarnings: 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

+6-2
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({ projectDir: this.$projectData.projectDir, settings: this.$options, skipWarnings: true });
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

+7-1
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,11 @@ 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+
await this.$workflowService.handleLegacyWorkflow({ projectDir: this.$projectData.projectDir, settings: this.$options, force: true });
34+
return;
35+
}
36+
3137
const tmpDir = path.join(this.$projectData.projectDir, UpdateCommand.tempFolder);
3238

3339
try {

lib/common/helpers.ts

+29
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,35 @@ export function createTable(headers: string[], data: string[][]): any {
384384
return table;
385385
}
386386

387+
export function getMessageWithBorders(message: string, spanLength = 3): string {
388+
if (!message) {
389+
return "";
390+
}
391+
392+
const longestRowLength = message.split(EOL).sort((a, b) => { return b.length - a.length; })[0].length;
393+
let border = "*".repeat(longestRowLength + 2 * spanLength); // * 2 for both sides
394+
if (border.length % 2 === 0) {
395+
border += "*"; // the * should always be an odd number in order to get * in each edge (we will remove the even *s below)
396+
}
397+
border = border.replace(/\*\*/g, "* "); // ***** => * * * in order to have similar padding to the side borders
398+
const formatRow = function (row: string) {
399+
return _.padEnd("*", spanLength) + _.padEnd(row, border.length - (2 * spanLength)) + _.padStart("*", spanLength) + EOL;
400+
};
401+
const emptyRow = formatRow("");
402+
403+
const messageWithBorders = [];
404+
messageWithBorders.push(
405+
EOL,
406+
border + EOL,
407+
emptyRow,
408+
...message.split(EOL).map(row => formatRow(row)),
409+
emptyRow,
410+
border + EOL,
411+
EOL
412+
);
413+
return messageWithBorders.join("");
414+
}
415+
387416
export function remove<T>(array: T[], predicate: (element: T) => boolean, numberOfElements?: number): T[] {
388417
numberOfElements = numberOfElements || 1;
389418
const index = _.findIndex(array, predicate);

lib/declarations.d.ts

+8-1
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 {
@@ -938,7 +939,13 @@ interface IBundleValidatorHelper {
938939
* @param {string} minSupportedVersion the minimum supported version of nativescript-dev-webpack
939940
* @return {void}
940941
*/
941-
validate(minSupportedVersion?: string): void;
942+
validate(projectData: IProjectData, minSupportedVersion?: string): void;
943+
944+
/**
945+
* Returns the installed bundler version.
946+
* @return {string}
947+
*/
948+
getBundlerDependencyVersion(projectData: IProjectData, bundlerName?: string): string;
942949
}
943950

944951

lib/definitions/platform.d.ts

+17
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@ interface IBuildPlatformAction {
1414
buildPlatform(platform: string, buildConfig: IBuildConfig, projectData: IProjectData): Promise<string>;
1515
}
1616

17+
interface IWorkflowService {
18+
handleLegacyWorkflow(options: IHandleLegacyWorkflowOptions): Promise<void>;
19+
}
20+
21+
interface IHandleLegacyWorkflowOptions {
22+
projectDir: string;
23+
settings: IWebpackWorkflowSettings;
24+
skipWarnings?: boolean;
25+
force?: boolean;
26+
}
27+
28+
interface IWebpackWorkflowSettings {
29+
bundle?: boolean | string;
30+
useHotModuleReload?: boolean;
31+
release?: boolean;
32+
}
33+
1734
interface IPlatformService extends IBuildPlatformAction, NodeJS.EventEmitter {
1835
cleanPlatforms(platforms: string[], platformTemplate: string, projectData: IProjectData, config: IPlatformOptions, framework?: string): Promise<void>;
1936

lib/definitions/project.d.ts

+9-1
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

+16-10
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,35 @@ export class BundleValidatorHelper extends VersionValidatorHelper implements IBu
77
webpack: "nativescript-dev-webpack"
88
};
99

10-
constructor(protected $projectData: IProjectData,
11-
protected $errors: IErrors,
10+
constructor(protected $errors: IErrors,
1211
protected $options: IOptions) {
1312
super();
14-
this.$projectData.initializeProjectData();
1513
}
1614

17-
public validate(minSupportedVersion?: string): void {
15+
public validate(projectData: IProjectData, minSupportedVersion?: string): void {
1816
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)) {
17+
const currentVersion = this.getBundlerDependencyVersion(projectData);
18+
if (!currentVersion) {
2319
this.$errors.failWithoutHelp(BundleValidatorMessages.MissingBundlePlugin);
2420
}
2521

26-
const currentVersion = bundlerVersionInDependencies || bundlerVersionInDevDependencies;
2722
const shouldThrowError = minSupportedVersion && this.isValidVersion(currentVersion) && this.isVersionLowerThan(currentVersion, minSupportedVersion);
2823
if (shouldThrowError) {
29-
this.$errors.failWithoutHelp(util.format(BundleValidatorMessages.NotSupportedVersion, minSupportedVersion));
24+
this.$errors.failWithoutHelp(util.format(BundleValidatorMessages.NotSupportedVersion, minSupportedVersion));
3025
}
3126
}
3227
}
28+
29+
public getBundlerDependencyVersion(projectData: IProjectData, bundlerName?: string): string {
30+
let dependencyVersion = null;
31+
const bundlePluginName = bundlerName || this.bundlersMap[this.$options.bundle];
32+
const bundlerVersionInDependencies = projectData.dependencies && projectData.dependencies[bundlePluginName];
33+
const bundlerVersionInDevDependencies = projectData.devDependencies && projectData.devDependencies[bundlePluginName];
34+
dependencyVersion = bundlerVersionInDependencies || bundlerVersionInDevDependencies;
35+
36+
return dependencyVersion;
37+
38+
}
3339
}
3440

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

lib/helpers/livesync-command-helper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
152152
}
153153

154154
const minSupportedWebpackVersion = this.$options.hmr ? LiveSyncCommandHelper.MIN_SUPPORTED_WEBPACK_VERSION_WITH_HMR : null;
155-
this.$bundleValidatorHelper.validate(minSupportedWebpackVersion);
155+
this.$bundleValidatorHelper.validate(this.$projectData, minSupportedWebpackVersion);
156156

157157
return result;
158158
}

0 commit comments

Comments
 (0)