Skip to content

feat: deprecate the legacy workflow and recommend the new one #4546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ $injector.require("hmrStatusService", "./services/hmr-status-service");
$injector.require("pacoteService", "./services/pacote-service");
$injector.require("qrCodeTerminalService", "./services/qr-code-terminal-service");
$injector.require("testInitializationService", "./services/test-initialization-service");
$injector.require("workflowService", "./services/workflow-service");

$injector.require("networkConnectivityValidator", "./helpers/network-connectivity-validator");
$injector.requirePublic("cleanupService", "./services/cleanup-service");
24 changes: 14 additions & 10 deletions lib/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
$platformService: IPlatformService,
private $bundleValidatorHelper: IBundleValidatorHelper,
protected $logger: ILogger) {
super($options, $platformsData, $platformService, $projectData);
this.$projectData.initializeProjectData();
protected $logger: ILogger,
protected $workflowService: IWorkflowService) {
super($options, $platformsData, $platformService, $projectData);
this.$projectData.initializeProjectData();
}

public async executeCore(args: string[]): Promise<string> {
await this.$workflowService.handleLegacyWorkflow(this.$projectData.projectDir, this.$options, true);
const platform = args[0].toLowerCase();
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = {
bundle: !!this.$options.bundle,
Expand Down Expand Up @@ -63,7 +65,7 @@ export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
this.$errors.fail(`Applications for platform ${platform} can not be built on this OS`);
}

this.$bundleValidatorHelper.validate();
this.$bundleValidatorHelper.validate(this.$projectData);
}

protected async validateArgs(args: string[], platform: string): Promise<ICanExecuteCommandOutput> {
Expand Down Expand Up @@ -94,8 +96,9 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
$platformService: IPlatformService,
$bundleValidatorHelper: IBundleValidatorHelper,
$logger: ILogger) {
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService, $bundleValidatorHelper, $logger);
$logger: ILogger,
$workflowService: IWorkflowService) {
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService, $bundleValidatorHelper, $logger, $workflowService);
}

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

super.validatePlatform(platform);

let result = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true }});
let result = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true } });
if (result.canExecute) {
result = await super.validateArgs(args, platform);
}
Expand All @@ -129,8 +132,9 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
$platformService: IPlatformService,
$bundleValidatorHelper: IBundleValidatorHelper,
protected $androidBundleValidatorHelper: IAndroidBundleValidatorHelper,
protected $logger: ILogger) {
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService, $bundleValidatorHelper, $logger);
protected $logger: ILogger,
$workflowService: IWorkflowService) {
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService, $bundleValidatorHelper, $logger, $workflowService);
}

public async execute(args: string[]): Promise<void> {
Expand All @@ -149,7 +153,7 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
const platform = this.$devicePlatformsConstants.Android;
super.validatePlatform(platform);
this.$androidBundleValidatorHelper.validateRuntimeVersion(this.$projectData);
let result = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true }});
let result = await super.canExecuteCommandBase(platform, { notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true } });
if (result.canExecute) {
if (this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
this.$errors.fail(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
Expand Down
6 changes: 4 additions & 2 deletions lib/commands/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ export class DebugPlatformCommand extends ValidatePlatformCommandBase implements
private $debugDataService: IDebugDataService,
private $liveSyncService: IDebugLiveSyncService,
private $liveSyncCommandHelper: ILiveSyncCommandHelper,
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper) {
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper,
private $workflowService: IWorkflowService) {
super($options, $platformsData, $platformService, $projectData);
}

public async execute(args: string[]): Promise<void> {
await this.$workflowService.handleLegacyWorkflow(this.$projectData.projectDir, this.$options, true);
await this.$devicesService.initialize({
platform: this.platform,
deviceId: this.$options.device,
Expand Down Expand Up @@ -67,7 +69,7 @@ export class DebugPlatformCommand extends ValidatePlatformCommandBase implements
}

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

const result = await super.canExecuteCommandBase(this.platform, { validateOptions: true, notConfiguredEnvOptions: { hideCloudBuildOption: true, hideSyncToPreviewAppOption: true } });
return result;
Expand Down
6 changes: 3 additions & 3 deletions lib/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export class DeployOnDeviceCommand extends ValidatePlatformCommandBase implement
$platformsData: IPlatformsData,
private $bundleValidatorHelper: IBundleValidatorHelper,
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper) {
super($options, $platformsData, $platformService, $projectData);
this.$projectData.initializeProjectData();
super($options, $platformsData, $platformService, $projectData);
this.$projectData.initializeProjectData();
}

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

public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
this.$androidBundleValidatorHelper.validateNoAab();
this.$bundleValidatorHelper.validate();
this.$bundleValidatorHelper.validate(this.$projectData);
if (!args || !args.length || args.length > 1) {
return false;
}
Expand Down
8 changes: 5 additions & 3 deletions lib/commands/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ export class PrepareCommand extends ValidatePlatformCommandBase implements IComm
$platformService: IPlatformService,
$projectData: IProjectData,
private $platformCommandParameter: ICommandParameter,
$platformsData: IPlatformsData) {
super($options, $platformsData, $platformService, $projectData);
this.$projectData.initializeProjectData();
$platformsData: IPlatformsData,
private $workflowService: IWorkflowService) {
super($options, $platformsData, $platformService, $projectData);
this.$projectData.initializeProjectData();
}

public async execute(args: string[]): Promise<void> {
await this.$workflowService.handleLegacyWorkflow(this.$projectData.projectDir, this.$options, true);
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = {
bundle: !!this.$options.bundle,
release: this.$options.release,
Expand Down
10 changes: 6 additions & 4 deletions lib/commands/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ export class PreviewCommand implements ICommand {
private $options: IOptions,
private $previewAppLogProvider: IPreviewAppLogProvider,
private $previewQrCodeService: IPreviewQrCodeService,
protected $workflowService: IWorkflowService,
$cleanupService: ICleanupService) {
this.$analyticsService.setShouldDispose(false);
$cleanupService.setShouldDispose(false);
}
this.$analyticsService.setShouldDispose(false);
$cleanupService.setShouldDispose(false);
}

public async execute(): Promise<void> {
await this.$workflowService.handleLegacyWorkflow(this.$projectData.projectDir, this.$options, true);
this.$previewAppLogProvider.on(DEVICE_LOG_EVENT_NAME, (deviceId: string, message: string) => {
this.$logger.info(message);
});
Expand All @@ -44,7 +46,7 @@ export class PreviewCommand implements ICommand {
}

await this.$networkConnectivityValidator.validate();
this.$bundleValidatorHelper.validate(PreviewCommand.MIN_SUPPORTED_WEBPACK_VERSION);
this.$bundleValidatorHelper.validate(this.$projectData, PreviewCommand.MIN_SUPPORTED_WEBPACK_VERSION);
return true;
}
}
Expand Down
5 changes: 4 additions & 1 deletion lib/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ export class RunCommandBase implements ICommand {
private $errors: IErrors,
private $hostInfo: IHostInfo,
private $liveSyncCommandHelper: ILiveSyncCommandHelper,
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper) { }
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper,
private $options: IOptions,
private $workflowService: IWorkflowService) { }

public allowedParameters: ICommandParameter[] = [];
public async execute(args: string[]): Promise<void> {
await this.$workflowService.handleLegacyWorkflow(this.$projectData.projectDir, this.$options, true);
await this.$analyticsService.trackPreviewAppData(this.platform, this.$projectData.projectDir);
return this.$liveSyncCommandHelper.executeCommandLiveSync(this.platform, this.liveSyncCommandHelperAdditionalOptions);
}
Expand Down
8 changes: 6 additions & 2 deletions lib/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ abstract class TestCommandBase {
protected abstract $platformEnvironmentRequirements: IPlatformEnvironmentRequirements;
protected abstract $errors: IErrors;
protected abstract $cleanupService: ICleanupService;
protected abstract $workflowService: IWorkflowService;

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

Expand Down Expand Up @@ -54,7 +56,8 @@ class TestAndroidCommand extends TestCommandBase implements ICommand {
protected $options: IOptions,
protected $platformEnvironmentRequirements: IPlatformEnvironmentRequirements,
protected $errors: IErrors,
protected $cleanupService: ICleanupService) {
protected $cleanupService: ICleanupService,
protected $workflowService: IWorkflowService) {
super();
}

Expand All @@ -69,7 +72,8 @@ class TestIosCommand extends TestCommandBase implements ICommand {
protected $options: IOptions,
protected $platformEnvironmentRequirements: IPlatformEnvironmentRequirements,
protected $errors: IErrors,
protected $cleanupService: ICleanupService) {
protected $cleanupService: ICleanupService,
protected $workflowService: IWorkflowService) {
super();
}

Expand Down
9 changes: 8 additions & 1 deletion lib/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export class UpdateCommand extends ValidatePlatformCommandBase implements IComma
private $pluginsService: IPluginsService,
private $projectDataService: IProjectDataService,
private $fs: IFileSystem,
private $logger: ILogger) {
private $logger: ILogger,
private $workflowService: IWorkflowService) {
super($options, $platformsData, $platformService, $projectData);
this.$projectData.initializeProjectData();
}
Expand All @@ -28,6 +29,12 @@ export class UpdateCommand extends ValidatePlatformCommandBase implements IComma
static readonly backupFailMessage: string = "Could not backup project folders!";

public async execute(args: string[]): Promise<void> {
if (this.$options.workflow) {
const forceWebpackWorkflow = true;
await this.$workflowService.handleLegacyWorkflow(this.$projectData.projectDir, this.$options, forceWebpackWorkflow);
return;
}

const tmpDir = path.join(this.$projectData.projectDir, UpdateCommand.tempFolder);

try {
Expand Down
25 changes: 25 additions & 0 deletions lib/common/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,31 @@ export function createTable(headers: string[], data: string[][]): any {
return table;
}

export function getMessageWithBorders(message: string, spanLength = 3): string {
const longestRowLength = message.split(EOL).sort(function (a, b) { return b.length - a.length; })[0].length;
let border = "*".repeat(longestRowLength + 2 * spanLength); // * 2 for both sides
if (border.length % 2 === 0) {
border += "*"; // the * should always be an odd number in order to get * in each edge (we will remove the even *s below)
}
border = border.replace(/\*\*/g, "* "); // ***** => * * * in order to have similar padding to the side borders
const formatRow = function (row: string) {
return _.padEnd("*", spanLength) + _.padEnd(row, border.length - (2 * spanLength)) + _.padStart("*", spanLength) + EOL;
};
const emptyRow = formatRow("");

const messageWithBorders = [];
messageWithBorders.push(
EOL,
border + EOL,
emptyRow,
...message.split(EOL).map(row => formatRow(row)),
emptyRow,
border + EOL,
EOL
);
return messageWithBorders.join("");
}

export function remove<T>(array: T[], predicate: (element: T) => boolean, numberOfElements?: number): T[] {
numberOfElements = numberOfElements || 1;
const index = _.findIndex(array, predicate);
Expand Down
9 changes: 8 additions & 1 deletion lib/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ interface IOptions extends IRelease, IDeviceIdentifier, IJustLaunch, IAvd, IAvai
performance: Object;
setupOptions(projectData: IProjectData): void;
cleanupLogFile: string;
workflow: boolean;
}

interface IEnvOptions {
Expand Down Expand Up @@ -939,7 +940,13 @@ interface IBundleValidatorHelper {
* @param {string} minSupportedVersion the minimum supported version of nativescript-dev-webpack
* @return {void}
*/
validate(minSupportedVersion?: string): void;
validate(projectData: IProjectData, minSupportedVersion?: string): void;

/**
* Returns the installed bundler version.
* @return {string}
*/
getBundlerDependencyVersion(projectData: IProjectData, bundlerName?: string): string;
}


Expand Down
10 changes: 10 additions & 0 deletions lib/definitions/platform.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ interface IBuildPlatformAction {
buildPlatform(platform: string, buildConfig: IBuildConfig, projectData: IProjectData): Promise<string>;
}

interface IWorkflowService {
handleLegacyWorkflow(projectDir: string, settings: IWebpackWorkflowSettings, skipWarnings?: boolean, force?: boolean): Promise<void>;
}

interface IWebpackWorkflowSettings {
bundle?: boolean | string;
useHotModuleReload?: boolean;
release?: boolean;
}

interface IPlatformService extends IBuildPlatformAction, NodeJS.EventEmitter {
cleanPlatforms(platforms: string[], platformTemplate: string, projectData: IProjectData, config: IPlatformOptions, framework?: string): Promise<void>;

Expand Down
10 changes: 9 additions & 1 deletion lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ interface IProjectDataService {
*/
setNSValue(projectDir: string, key: string, value: any): void;

/**
* Sets a value in the `useLegacyWorkflow` key in a project's nsconfig.json.
* @param {string} projectDir The project directory - the place where the root package.json is located.
* @param {any} value Value of the key to be set to `useLegacyWorkflow` key in project's nsconfig.json.
* @returns {void}
*/
setUseLegacyWorkflow(projectDir: string, value: any): void;

/**
* Removes a property from `nativescript` key in project's package.json.
* @param {string} projectDir The project directory - the place where the root package.json is located.
Expand Down Expand Up @@ -584,7 +592,7 @@ interface IIOSExtensionsService {
removeExtensions(options: IRemoveExtensionsOptions): void;
}

interface IAddExtensionsFromPathOptions{
interface IAddExtensionsFromPathOptions {
extensionsFolderPath: string;
projectData: IProjectData;
platformData: IPlatformData;
Expand Down
26 changes: 16 additions & 10 deletions lib/helpers/bundle-validator-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,35 @@ export class BundleValidatorHelper extends VersionValidatorHelper implements IBu
webpack: "nativescript-dev-webpack"
};

constructor(protected $projectData: IProjectData,
protected $errors: IErrors,
constructor(protected $errors: IErrors,
protected $options: IOptions) {
super();
this.$projectData.initializeProjectData();
}

public validate(minSupportedVersion?: string): void {
public validate(projectData: IProjectData, minSupportedVersion?: string): void {
if (this.$options.bundle) {
const bundlePluginName = this.bundlersMap[this.$options.bundle];
const bundlerVersionInDependencies = this.$projectData.dependencies && this.$projectData.dependencies[bundlePluginName];
const bundlerVersionInDevDependencies = this.$projectData.devDependencies && this.$projectData.devDependencies[bundlePluginName];
if (!bundlePluginName || (!bundlerVersionInDependencies && !bundlerVersionInDevDependencies)) {
const currentVersion = this.getBundlerDependencyVersion(projectData);
if (!currentVersion) {
this.$errors.failWithoutHelp(BundleValidatorMessages.MissingBundlePlugin);
}

const currentVersion = bundlerVersionInDependencies || bundlerVersionInDevDependencies;
const shouldThrowError = minSupportedVersion && this.isValidVersion(currentVersion) && this.isVersionLowerThan(currentVersion, minSupportedVersion);
if (shouldThrowError) {
this.$errors.failWithoutHelp(util.format(BundleValidatorMessages.NotSupportedVersion, minSupportedVersion));
this.$errors.failWithoutHelp(util.format(BundleValidatorMessages.NotSupportedVersion, minSupportedVersion));
}
}
}

public getBundlerDependencyVersion(projectData: IProjectData, bundlerName?: string): string {
let dependencyVersion = null;
const bundlePluginName = bundlerName || this.bundlersMap[this.$options.bundle];
const bundlerVersionInDependencies = projectData.dependencies && projectData.dependencies[bundlePluginName];
const bundlerVersionInDevDependencies = projectData.devDependencies && projectData.devDependencies[bundlePluginName];
dependencyVersion = bundlerVersionInDependencies || bundlerVersionInDevDependencies;

return dependencyVersion;

}
}

$injector.register("bundleValidatorHelper", BundleValidatorHelper);
2 changes: 1 addition & 1 deletion lib/helpers/livesync-command-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
}

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

return result;
}
Expand Down
1 change: 1 addition & 0 deletions lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export class Options {
file: { type: OptionType.String, hasSensitiveValue: true },
force: { type: OptionType.Boolean, alias: "f", hasSensitiveValue: false },
// remove legacy
workflow: { type: OptionType.Boolean, hasSensitiveValue: false },
companion: { type: OptionType.Boolean, hasSensitiveValue: false },
emulator: { type: OptionType.Boolean, hasSensitiveValue: false },
sdk: { type: OptionType.String, hasSensitiveValue: false },
Expand Down
2 changes: 1 addition & 1 deletion lib/project-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,4 @@ export class ProjectData implements IProjectData {
this.$logger.warnWithLabel("IProjectData.projectId is deprecated. Please use IProjectData.projectIdentifiers[platform].");
}
}
$injector.register("projectData", ProjectData);
$injector.register("projectData", ProjectData, true);
Loading