Skip to content

Commit 681512a

Browse files
author
Dimitar Kerezov
committed
Introduce prepareJSApp hook
* Extract all code that webpack needs to replace into a single method * Introduce a hook (`prepareJSApp`) for that method so it can be replaced * Add additional check for when not to delete `App_Resources` directory when preparing JS so that whenever preparing natively we don't copy all the files twice
1 parent db04d3b commit 681512a

25 files changed

+369
-149
lines changed

lib/commands/appstore-upload.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ export class PublishIOS implements ICommand {
5757
const platform = this.$devicePlatformsConstants.iOS;
5858
// No .ipa path provided, build .ipa on out own.
5959
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
60+
const platformInfo: IPreparePlatformInfo = {
61+
platform,
62+
appFilesUpdaterOptions,
63+
platformTemplate: this.$options.platformTemplate,
64+
projectData: this.$projectData,
65+
config: this.$options,
66+
env: this.$options.env
67+
};
68+
6069
if (mobileProvisionIdentifier || codeSignIdentity) {
6170
const iOSBuildConfig: IBuildConfig = {
6271
projectDir: this.$options.path,
@@ -70,12 +79,12 @@ export class PublishIOS implements ICommand {
7079
};
7180
this.$logger.info("Building .ipa with the selected mobile provision and/or certificate.");
7281
// This is not very correct as if we build multiple targets we will try to sign all of them using the signing identity here.
73-
await this.$platformService.preparePlatform(platform, appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData, this.$options);
82+
await this.$platformService.preparePlatform(platformInfo);
7483
await this.$platformService.buildPlatform(platform, iOSBuildConfig, this.$projectData);
7584
ipaFilePath = this.$platformService.lastOutputPath(platform, iOSBuildConfig, this.$projectData);
7685
} else {
7786
this.$logger.info("No .ipa, mobile provision or certificate set. Perfect! Now we'll build .xcarchive and let Xcode pick the distribution certificate and provisioning profile for you when exporting .ipa for AppStore submission.");
78-
await this.$platformService.preparePlatform(platform, appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData, this.$options);
87+
await this.$platformService.preparePlatform(platformInfo);
7988

8089
const platformData = this.$platformsData.getPlatformData(platform, this.$projectData);
8190
const iOSProjectService = <IOSProjectService>platformData.platformProjectService;

lib/commands/build.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,16 @@ export class BuildCommandBase {
1313
public async executeCore(args: string[]): Promise<void> {
1414
const platform = args[0].toLowerCase();
1515
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
16-
await this.$platformService.preparePlatform(platform, appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData, this.$options);
16+
const platformInfo: IPreparePlatformInfo = {
17+
platform,
18+
appFilesUpdaterOptions,
19+
platformTemplate: this.$options.platformTemplate,
20+
projectData: this.$projectData,
21+
config: this.$options,
22+
env: this.$options.env
23+
};
24+
25+
await this.$platformService.preparePlatform(platformInfo);
1726
this.$options.clean = true;
1827
const buildConfig: IBuildConfig = {
1928
buildForDevice: this.$options.forDevice,

lib/commands/deploy.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,17 @@ export class DeployOnDeviceCommand implements ICommand {
3030
keyStorePassword: this.$options.keyStorePassword,
3131
keyStorePath: this.$options.keyStorePath
3232
};
33-
return this.$platformService.deployPlatform(args[0], appFilesUpdaterOptions, deployOptions, this.$projectData, this.$options);
33+
34+
const deployPlatformInfo: IDeployPlatformInfo = {
35+
platform: args[0],
36+
appFilesUpdaterOptions,
37+
deployOptions,
38+
projectData: this.$projectData,
39+
config: this.$options,
40+
env: this.$options.env
41+
};
42+
43+
return this.$platformService.deployPlatform(deployPlatformInfo);
3444
}
3545

3646
public async canExecute(args: string[]): Promise<boolean> {

lib/commands/prepare.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,16 @@ export class PrepareCommand implements ICommand {
1111

1212
public async execute(args: string[]): Promise<void> {
1313
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
14-
await this.$platformService.preparePlatform(args[0], appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData, this.$options);
14+
const platformInfo: IPreparePlatformInfo = {
15+
platform: args[0],
16+
appFilesUpdaterOptions,
17+
platformTemplate: this.$options.platformTemplate,
18+
projectData: this.$projectData,
19+
config: this.$options,
20+
env: this.$options.env
21+
};
22+
23+
await this.$platformService.preparePlatform(platformInfo);
1524
}
1625

1726
public async canExecute(args: string[]): Promise<boolean> {

lib/declarations.d.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ interface IPort {
374374
port: Number;
375375
}
376376

377-
interface IOptions extends ICommonOptions, IBundle, IPlatformTemplate, IEmulator, IClean, IProvision, ITeamIdentifier, IAndroidReleaseOptions, INpmInstallConfigurationOptions, IPort {
377+
interface IOptions extends ICommonOptions, IBundle, IPlatformTemplate, IEmulator, IClean, IProvision, ITeamIdentifier, IAndroidReleaseOptions, INpmInstallConfigurationOptions, IPort, IEnvOptions {
378378
all: boolean;
379379
client: boolean;
380380
compileSdk: number;
@@ -395,11 +395,15 @@ interface IOptions extends ICommonOptions, IBundle, IPlatformTemplate, IEmulator
395395
chrome: boolean;
396396
}
397397

398+
interface IEnvOptions {
399+
env: Object;
400+
}
401+
398402
interface IAndroidBuildOptionsSettings extends IAndroidReleaseOptions, IRelease { }
399403

400404
interface IAppFilesUpdaterOptions extends IBundle, IRelease { }
401405

402-
interface IPlatformBuildData extends IAppFilesUpdaterOptions, IBuildConfig { }
406+
interface IPlatformBuildData extends IAppFilesUpdaterOptions, IBuildConfig, IEnvOptions { }
403407

404408
interface IDeviceEmulator extends IEmulator, IDeviceIdentifier { }
405409

lib/definitions/livesync.d.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ interface ILiveSyncDeviceInfo extends IOptionalOutputPath, IOptionalDebuggingOpt
111111
/**
112112
* Describes a LiveSync operation.
113113
*/
114-
interface ILiveSyncInfo extends IProjectDir {
114+
interface ILiveSyncInfo extends IProjectDir, IEnvOptions {
115115
/**
116116
* Defines if the watcher should be skipped. If not passed, fs.Watcher will be started.
117117
*/
@@ -145,14 +145,17 @@ interface ILiveSyncBuildInfo extends IIsEmulator, IPlatform {
145145
pathToBuildItem: string;
146146
}
147147

148+
interface IProjectDataComposition {
149+
projectData: IProjectData;
150+
}
151+
148152
/**
149153
* Desribes object that can be passed to ensureLatestAppPackageIsInstalledOnDevice method.
150154
*/
151-
interface IEnsureLatestAppPackageIsInstalledOnDeviceOptions {
155+
interface IEnsureLatestAppPackageIsInstalledOnDeviceOptions extends IProjectDataComposition, IEnvOptions {
152156
device: Mobile.IDevice;
153157
preparedPlatforms: string[];
154158
rebuiltInformation: ILiveSyncBuildInfo[];
155-
projectData: IProjectData;
156159
deviceBuildInfoDescriptor: ILiveSyncDeviceInfo;
157160
settings: ILatestAppPackageInstalledSettings;
158161
liveSyncData?: ILiveSyncInfo;
@@ -273,8 +276,7 @@ interface IShouldSkipEmitLiveSyncNotification {
273276
interface IAttachDebuggerOptions extends IDebuggingAdditionalOptions, IEnableDebuggingDeviceOptions, IIsEmulator, IPlatform, IOptionalOutputPath {
274277
}
275278

276-
interface ILiveSyncWatchInfo {
277-
projectData: IProjectData;
279+
interface ILiveSyncWatchInfo extends IProjectDataComposition {
278280
filesToRemove: string[];
279281
filesToSync: string[];
280282
isReinstalled: boolean;
@@ -289,8 +291,7 @@ interface ILiveSyncResultInfo {
289291
useLiveEdit?: boolean;
290292
}
291293

292-
interface IFullSyncInfo {
293-
projectData: IProjectData;
294+
interface IFullSyncInfo extends IProjectDataComposition {
294295
device: Mobile.IDevice;
295296
watch: boolean;
296297
syncAllFiles: boolean;

lib/definitions/platform.d.ts

+50-20
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,10 @@ interface IPlatformService extends NodeJS.EventEmitter {
3939
* When there are changes to be prepared, it prepares the native project for the specified platform.
4040
* When finishes, prepare saves the .nsprepareinfo file in platform folder.
4141
* This file contains information about current project configuration and allows skipping unnecessary build, deploy and livesync steps.
42-
* @param {string} platform The platform to be prepared.
43-
* @param {IAppFilesUpdaterOptions} appFilesUpdaterOptions Options needed to instantiate AppFilesUpdater class.
44-
* @param {string} platformTemplate The name of the platform template.
45-
* @param {IProjectData} projectData DTO with information about the project.
46-
* @param {IAddPlatformCoreOptions} config Options required for project preparation/creation.
47-
* @param {Array} filesToSync Files about to be synced to device.
42+
* @param {IPreparePlatformInfo} platformInfo Options to control the preparation.
4843
* @returns {boolean} true indicates that the platform was prepared.
4944
*/
50-
preparePlatform(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, platformTemplate: string, projectData: IProjectData, config: IPlatformOptions, filesToSync?: Array<String>, nativePrepare?: INativePrepare): Promise<boolean>;
45+
preparePlatform(platformInfo: IPreparePlatformInfo): Promise<boolean>;
5146

5247
/**
5348
* Determines whether a build is necessary. A build is necessary when one of the following is true:
@@ -106,14 +101,10 @@ interface IPlatformService extends NodeJS.EventEmitter {
106101
/**
107102
* Executes prepare, build and installOnPlatform when necessary to ensure that the latest version of the app is installed on specified platform.
108103
* - When --clean option is specified it builds the app on every change. If not, build is executed only when there are native changes.
109-
* @param {string} platform The platform to deploy.
110-
* @param {IAppFilesUpdaterOptions} appFilesUpdaterOptions Options needed to instantiate AppFilesUpdater class.
111-
* @param {IDeployPlatformOptions} deployOptions Various options that can manage the deploy operation.
112-
* @param {IProjectData} projectData DTO with information about the project.
113-
* @param {IAddPlatformCoreOptions} config Options required for project preparation/creation.
104+
* @param {IDeployPlatformInfo} deployInfo Options required for project preparation and deployment.
114105
* @returns {void}
115106
*/
116-
deployPlatform(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, deployOptions: IDeployPlatformOptions, projectData: IProjectData, config: IPlatformOptions): Promise<void>;
107+
deployPlatform(deployInfo: IDeployPlatformInfo): Promise<void>;
117108

118109
/**
119110
* Runs the application on specified platform. Assumes that the application is already build and installed. Fails if this is not true.
@@ -276,9 +267,19 @@ interface IPlatformsData {
276267
getPlatformData(platform: string, projectData: IProjectData): IPlatformData;
277268
}
278269

270+
interface IAppFilesUpdaterOptionsComposition {
271+
appFilesUpdaterOptions: IAppFilesUpdaterOptions;
272+
}
273+
274+
interface IJsNodeModulesData extends IPlatform, IProjectDataComposition, IAppFilesUpdaterOptionsComposition {
275+
absoluteOutputPath: string;
276+
lastModifiedTime: Date;
277+
projectFilesConfig: IProjectFilesConfig;
278+
}
279+
279280
interface INodeModulesBuilder {
280281
prepareNodeModules(absoluteOutputPath: string, platform: string, lastModifiedTime: Date, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise<void>;
281-
prepareJSNodeModules(absoluteOutputPath: string, platform: string, lastModifiedTime: Date, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise<void>;
282+
prepareJSNodeModules(jsNodeModulesData: IJsNodeModulesData): Promise<void>;
282283
cleanNodeModules(absoluteOutputPath: string, platform: string): void;
283284
}
284285

@@ -291,15 +292,44 @@ interface IBuildInfo {
291292
buildTime: string;
292293
}
293294

294-
interface IPreparePlatformService extends NodeJS.EventEmitter {
295-
addPlatform(platformData: IPlatformData, frameworkDir: string, installedVersion: string, projectData: IProjectData, config: IPlatformOptions, platformTemplate?: string, ): Promise<void>;
296-
preparePlatform(platform: string, platformData: IPlatformData, appFilesUpdaterOptions: IAppFilesUpdaterOptions, projectData: IProjectData, platformSpecificData: IPlatformSpecificData, changesInfo?: IProjectChangesInfo, filesToSync?: Array<String>, projectFilesConfig?: IProjectFilesConfig): Promise<void>;
295+
interface IPlatformDataComposition {
296+
platformData: IPlatformData;
297297
}
298298

299-
interface IPreparePlatformJSService extends IPreparePlatformService {
299+
interface ICopyAppFilesData extends IProjectDataComposition, IAppFilesUpdaterOptionsComposition, IPlatformDataComposition { }
300+
301+
interface IPreparePlatformService {
302+
addPlatform(info: IAddPlatformInfo): Promise<void>;
303+
preparePlatform(config: IPreparePlatformJSInfo): Promise<void>;
304+
}
300305

306+
interface IAddPlatformInfo extends IProjectDataComposition, IPlatformDataComposition {
307+
frameworkDir: string;
308+
installedVersion: string;
309+
config: IPlatformOptions;
310+
platformTemplate?: string;
301311
}
302312

303-
interface IPreparePlatformNativeService extends IPreparePlatformService {
313+
interface IPreparePlatformJSInfo extends IPreparePlatformCoreInfo, ICopyAppFilesData {
314+
projectFilesConfig?: IProjectFilesConfig;
315+
}
304316

305-
}
317+
interface IPreparePlatformCoreInfo extends IPreparePlatformInfoBase {
318+
platformSpecificData: IPlatformSpecificData
319+
changesInfo?: IProjectChangesInfo;
320+
}
321+
322+
interface IPreparePlatformInfo extends IPreparePlatformInfoBase, IPlatformConfig, IPlatformTemplate { }
323+
324+
interface IPlatformConfig {
325+
config: IPlatformOptions;
326+
}
327+
328+
interface IPreparePlatformInfoBase extends IPlatform, IAppFilesUpdaterOptionsComposition, IProjectDataComposition, IEnvOptions {
329+
filesToSync?: string[];
330+
nativePrepare?: INativePrepare;
331+
}
332+
333+
interface IDeployPlatformInfo extends IPlatform, IAppFilesUpdaterOptionsComposition, IProjectDataComposition, IPlatformConfig, IEnvOptions {
334+
deployOptions: IDeployPlatformOptions
335+
}

lib/options.ts

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export class Options extends commonOptionsLibPath.OptionsBase {
1515
forDevice: { type: OptionType.Boolean },
1616
provision: { type: OptionType.Object },
1717
client: { type: OptionType.Boolean, default: true },
18+
env: { type: OptionType.Object },
1819
production: { type: OptionType.Boolean },
1920
debugTransport: { type: OptionType.Boolean },
2021
keyStorePath: { type: OptionType.String },

lib/services/analytics/analytics-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ export class AnalyticsService extends AnalyticsServiceBase {
1111

1212
constructor(protected $logger: ILogger,
1313
protected $options: IOptions,
14+
protected $processService: IProcessService,
1415
$staticConfig: Config.IStaticConfig,
1516
$prompter: IPrompter,
1617
$userSettingsService: UserSettings.IUserSettingsService,
1718
$analyticsSettingsService: IAnalyticsSettingsService,
1819
$osInfo: IOsInfo,
1920
private $childProcess: IChildProcess,
20-
protected $processService: IProcessService,
2121
private $projectDataService: IProjectDataService,
2222
private $mobileHelper: Mobile.IMobileHelper) {
2323
super($logger, $options, $staticConfig, $processService, $prompter, $userSettingsService, $analyticsSettingsService, $osInfo);

lib/services/livesync/livesync-command-helper.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
99
private $platformsData: IPlatformsData,
1010
private $analyticsService: IAnalyticsService,
1111
private $errors: IErrors) {
12-
this.$analyticsService.setShouldDispose(this.$options.justlaunch || !this.$options.watch);
12+
this.$analyticsService.setShouldDispose(this.$options.justlaunch || !this.$options.watch);
1313
}
1414

1515
public getPlatformsForOperation(platform: string): string[] {
@@ -74,7 +74,8 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
7474
projectDir: this.$projectData.projectDir,
7575
skipWatcher: !this.$options.watch,
7676
watchAllFiles: this.$options.syncAllFiles,
77-
clean: this.$options.clean
77+
clean: this.$options.clean,
78+
env: this.$options.env
7879
};
7980

8081
await this.$liveSyncService.liveSync(deviceDescriptors, liveSyncInfo);
@@ -95,7 +96,16 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
9596

9697
const availablePlatforms = this.getPlatformsForOperation(platform);
9798
for (const currentPlatform of availablePlatforms) {
98-
await this.$platformService.deployPlatform(currentPlatform, this.$options, deployOptions, this.$projectData, this.$options);
99+
const deployPlatformInfo: IDeployPlatformInfo = {
100+
platform: currentPlatform,
101+
appFilesUpdaterOptions: this.$options,
102+
deployOptions,
103+
projectData: this.$projectData,
104+
config: this.$options,
105+
env: this.$options.env
106+
};
107+
108+
await this.$platformService.deployPlatform(deployPlatformInfo);
99109
await this.$platformService.startApplication(currentPlatform, runPlatformOptions, this.$projectData.projectId);
100110
this.$platformService.trackProjectType(this.$projectData);
101111
}

lib/services/livesync/livesync-service.ts

+19-6
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,21 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
359359
options.preparedPlatforms.push(platform);
360360

361361
const platformSpecificOptions = options.deviceBuildInfoDescriptor.platformSpecificOptions || <IPlatformOptions>{};
362-
await this.$platformService.preparePlatform(platform, {
363-
bundle: false,
364-
release: false,
365-
}, null, options.projectData, platformSpecificOptions, options.modifiedFiles, nativePrepare);
362+
const prepareInfo: IPreparePlatformInfo = {
363+
platform,
364+
appFilesUpdaterOptions: {
365+
bundle: false,
366+
release: false,
367+
},
368+
projectData: options.projectData,
369+
env: options.env,
370+
nativePrepare: nativePrepare,
371+
filesToSync: options.modifiedFiles,
372+
platformTemplate: null,
373+
config: platformSpecificOptions
374+
};
375+
376+
await this.$platformService.preparePlatform(prepareInfo);
366377
}
367378

368379
const buildResult = await this.installedCachedAppPackage(platform, options);
@@ -447,7 +458,8 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
447458
projectData,
448459
deviceBuildInfoDescriptor,
449460
liveSyncData,
450-
settings
461+
settings,
462+
env: liveSyncData.env
451463
}, { skipNativePrepare: deviceBuildInfoDescriptor.skipNativePrepare });
452464

453465
const liveSyncResultInfo = await this.getLiveSyncService(platform).fullSync({
@@ -551,7 +563,8 @@ export class LiveSyncService extends EventEmitter implements IDebugLiveSyncServi
551563
projectData,
552564
deviceBuildInfoDescriptor,
553565
settings: latestAppPackageInstalledSettings,
554-
modifiedFiles: allModifiedFiles
566+
modifiedFiles: allModifiedFiles,
567+
env: liveSyncData.env
555568
}, { skipNativePrepare: deviceBuildInfoDescriptor.skipNativePrepare });
556569

557570
const service = this.getLiveSyncService(device.deviceInfo.platform);

0 commit comments

Comments
 (0)