Skip to content

Commit f2d59a7

Browse files
committed
fix: add the initial version of the Legacy Workflow warnings and recommendations
1 parent ace53e5 commit f2d59a7

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
lines changed

lib/common/helpers.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,31 @@ export function createTable(headers: string[], data: string[][]): any {
384384
return table;
385385
}
386386

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

lib/services/workflow-service.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import * as helpers from "../common/helpers";
22
import * as path from "path";
33
import * as semver from "semver";
4+
import { EOL } from "os";
45

56
export class WorkflowService implements IWorkflowService {
7+
private legacyWorkflowDeprecationMessage = `With the upcoming NativeScript 6.0 the Webpack workflow will become the only way of build apps.
8+
More info about the reason for this change and how to migrate your project can be found in the link below:
9+
<TODO: add link here>`;
10+
private webpackWorkflowConfirmMessage = `Do you want to switch your app to the Webpack workflow?`;
11+
612
constructor(private $bundleValidatorHelper: IBundleValidatorHelper,
713
private $fs: IFileSystem,
814
private $logger: ILogger,
@@ -37,9 +43,17 @@ export class WorkflowService implements IWorkflowService {
3743
}
3844

3945
private async handleWebpackWorkflowSwitch(projectData: IProjectData, skipWarnings: boolean, force: boolean): Promise<boolean> {
40-
let hasSwitched = false;
46+
let hasSwitched = force;
4147
if (force || helpers.isInteractive()) {
42-
hasSwitched = force || await this.$prompter.confirm("Please use webpack!", () => true);
48+
if (!force) {
49+
this.$logger.info();
50+
this.$logger.printMarkdown(`
51+
__Improve your project by switching to the Webpack workflow.__
52+
53+
\`${this.legacyWorkflowDeprecationMessage}\``);
54+
hasSwitched = await this.$prompter.confirm(this.webpackWorkflowConfirmMessage, () => true);
55+
}
56+
4357
if (hasSwitched) {
4458
this.$projectDataService.setUseLegacyWorkflow(projectData.projectDir, false);
4559
await this.ensureWebpackPluginInstalled(projectData);
@@ -54,11 +68,17 @@ export class WorkflowService implements IWorkflowService {
5468
}
5569

5670
private showLegacyWorkflowWarning() {
57-
this.$logger.warn("TODO: <Add a legacy workflow warning here>");
71+
const legacyWorkflowWarning = `You are using the Legacy Workflow.${EOL}${EOL}${this.legacyWorkflowDeprecationMessage}`;
72+
const warningWithBorders = helpers.getMessageWithBorders(legacyWorkflowWarning);
73+
74+
this.$logger.warn(warningWithBorders);
5875
}
5976

6077
private showNoBundleWarning() {
61-
this.$logger.warn("TODO: <Add a `--no-bundle` workflow warning here>");
78+
const legacyWorkflowWarning = `You are using the '--no-bundle' flag which is switching to the Legacy Workflow.${EOL}${EOL}${this.legacyWorkflowDeprecationMessage}`;
79+
const warningWithBorders = helpers.getMessageWithBorders(legacyWorkflowWarning);
80+
81+
this.$logger.warn(warningWithBorders);
6282
}
6383

6484
private async ensureWebpackPluginInstalled(projectData: IProjectData) {
@@ -81,8 +101,8 @@ export class WorkflowService implements IWorkflowService {
81101
if (!isInstalledVersionSupported) {
82102
const webpackConfigPath = path.join(projectData.projectDir, webpackConfigFileName);
83103
if (this.$fs.exists(webpackConfigPath)) {
84-
this.$logger.info(`<TODO: Add a webpack cofnig backup info here>`);
85104
this.$fs.rename(webpackConfigPath, `${webpackConfigPath}.bak`);
105+
this.$logger.warn(`The 'nativescript-dev-webpack' plugin was updated and your '${webpackConfigFileName}' was replaced. You can find your old '${webpackConfigPath}' in '${webpackConfigPath}.bak'.`);
86106
}
87107

88108
const installResult = await this.$packageManager.install(`${webpackPluginName}@latest`, projectData.projectDir, {

0 commit comments

Comments
 (0)