Skip to content

Commit 011a103

Browse files
committed
Respect configuration when preparing project files
1 parent 0166da3 commit 011a103

19 files changed

+77
-54
lines changed

lib/commands/debug.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export abstract class DebugPlatformCommand implements ICommand {
1+
import { Configurations } from "../common/constants";
2+
3+
export abstract class DebugPlatformCommand implements ICommand {
24
public allowedParameters: ICommandParameter[] = [];
35
public platform: string;
46

@@ -66,8 +68,10 @@
6668
skipWatcher: !this.$options.watch || this.$options.justlaunch,
6769
watchAllFiles: this.$options.syncAllFiles
6870
};
69-
70-
await this.$debugLiveSyncService.liveSync(deviceDescriptors, liveSyncInfo);
71+
const projectFilesConfig: IProjectFilesConfig = {
72+
configuration: this.$options.release ? Configurations.Release.toLowerCase() : Configurations.Debug.toLowerCase()
73+
};
74+
await this.$debugLiveSyncService.liveSync(deviceDescriptors, liveSyncInfo, projectFilesConfig);
7175
}
7276

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

lib/commands/run.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ERROR_NO_VALID_SUBCOMMAND_FORMAT } from "../common/constants";
1+
import { ERROR_NO_VALID_SUBCOMMAND_FORMAT, Configurations } from "../common/constants";
22

33
export class RunCommandBase implements ICommand {
44
protected platform: string;
@@ -116,8 +116,10 @@ export class RunCommandBase implements ICommand {
116116
watchAllFiles: this.$options.syncAllFiles,
117117
clean: this.$options.clean
118118
};
119-
120-
await this.$liveSyncService.liveSync(deviceDescriptors, liveSyncInfo);
119+
const projectFilesConfig: IProjectFilesConfig = {
120+
configuration: this.$options.release ? Configurations.Release.toLowerCase() : Configurations.Debug.toLowerCase()
121+
};
122+
await this.$liveSyncService.liveSync(deviceDescriptors, liveSyncInfo, projectFilesConfig);
121123
}
122124
}
123125

lib/commands/test.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
import { Configurations } from "../common/constants";
2+
13
function RunTestCommandFactory(platform: string) {
24
return function RunTestCommand(
5+
$options: IOptions,
36
$testExecutionService: ITestExecutionService,
47
$projectData: IProjectData) {
58
$projectData.initializeProjectData();
6-
this.execute = (args: string[]): Promise<void> => $testExecutionService.startTestRunner(platform, $projectData);
9+
const projectFilesConfig: IProjectFilesConfig = {
10+
configuration: this.$options.release ? Configurations.Release.toLowerCase() : Configurations.Debug.toLowerCase()
11+
};
12+
this.execute = (args: string[]): Promise<void> => $testExecutionService.startTestRunner(platform, $projectData, projectFilesConfig);
713
this.allowedParameters = [];
814
};
915
}
@@ -12,9 +18,12 @@ $injector.registerCommand("dev-test|android", RunTestCommandFactory('android'));
1218
$injector.registerCommand("dev-test|ios", RunTestCommandFactory('iOS'));
1319

1420
function RunKarmaTestCommandFactory(platform: string) {
15-
return function RunKarmaTestCommand($testExecutionService: ITestExecutionService, $projectData: IProjectData) {
21+
return function RunKarmaTestCommand($options: IOptions, $testExecutionService: ITestExecutionService, $projectData: IProjectData) {
1622
$projectData.initializeProjectData();
17-
this.execute = (args: string[]): Promise<void> => $testExecutionService.startKarmaServer(platform, $projectData);
23+
const projectFilesConfig: IProjectFilesConfig = {
24+
configuration: this.$options.release ? Configurations.Release.toLowerCase() : Configurations.Debug.toLowerCase()
25+
};
26+
this.execute = (args: string[]): Promise<void> => $testExecutionService.startKarmaServer(platform, $projectData, projectFilesConfig);
1827
this.allowedParameters = [];
1928
};
2029
}

lib/definitions/livesync.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ interface ILiveSyncService {
154154
* @param {ILiveSyncInfo} liveSyncData Describes the LiveSync operation - for which project directory is the operation and other settings.
155155
* @returns {Promise<void>}
156156
*/
157-
liveSync(deviceDescriptors: ILiveSyncDeviceInfo[], liveSyncData: ILiveSyncInfo): Promise<void>;
157+
liveSync(deviceDescriptors: ILiveSyncDeviceInfo[], liveSyncData: ILiveSyncInfo, projectFilesConfig: IProjectFilesConfig): Promise<void>;
158158

159159
/**
160160
* Stops LiveSync operation for specified directory.
@@ -203,7 +203,7 @@ interface IFullSyncInfo {
203203

204204
interface IPlatformLiveSyncService {
205205
fullSync(syncInfo: IFullSyncInfo): Promise<ILiveSyncResultInfo>;
206-
liveSyncWatchAction(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo): Promise<ILiveSyncResultInfo>;
206+
liveSyncWatchAction(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo, projectFilesConfig: IProjectFilesConfig): Promise<ILiveSyncResultInfo>;
207207
refreshApplication(projectData: IProjectData, liveSyncInfo: ILiveSyncResultInfo): Promise<void>;
208208
}
209209

lib/definitions/platform.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ interface IPlatformsData {
287287
}
288288

289289
interface INodeModulesBuilder {
290-
prepareNodeModules(absoluteOutputPath: string, platform: string, lastModifiedTime: Date, projectData: IProjectData): Promise<void>;
290+
prepareNodeModules(absoluteOutputPath: string, platform: string, lastModifiedTime: Date, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise<void>;
291291
cleanNodeModules(absoluteOutputPath: string, platform: string): void;
292292
}
293293

lib/definitions/plugins.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
interface IPluginsService {
22
add(plugin: string, projectData: IProjectData): Promise<void>; // adds plugin by name, github url, local path and et.
33
remove(pluginName: string, projectData: IProjectData): Promise<void>; // removes plugin only by name
4-
prepare(pluginData: IDependencyData, platform: string, projectData: IProjectData): Promise<void>;
4+
prepare(pluginData: IDependencyData, platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise<void>;
55
getAllInstalledPlugins(projectData: IProjectData): Promise<IPluginData[]>;
66
ensureAllDependenciesAreInstalled(projectData: IProjectData): Promise<void>;
77

lib/definitions/project.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ interface IAndroidProjectPropertiesManager {
275275
}
276276

277277
interface ITestExecutionService {
278-
startTestRunner(platform: string, projectData: IProjectData): Promise<void>;
279-
startKarmaServer(platform: string, projectData: IProjectData): Promise<void>;
278+
startTestRunner(platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise<void>;
279+
startKarmaServer(platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise<void>;
280280
}
281281

282282
/**

lib/providers/project-files-provider.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ export class ProjectFilesProvider extends ProjectFilesProviderBase {
1212

1313
private static INTERNAL_NONPROJECT_FILES = [ "**/*.ts" ];
1414

15-
public mapFilePath(filePath: string, platform: string, projectData: IProjectData): string {
15+
public mapFilePath(filePath: string, platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): string {
1616
let platformData = this.$platformsData.getPlatformData(platform.toLowerCase(), projectData);
17-
let parsedFilePath = this.getPreparedFilePath(filePath);
17+
let parsedFilePath = this.getPreparedFilePath(filePath, projectFilesConfig);
1818
let mappedFilePath = "";
1919
if (parsedFilePath.indexOf(constants.NODE_MODULES_FOLDER_NAME) > -1) {
2020
let relativePath = path.relative(path.join(projectData.projectDir, constants.NODE_MODULES_FOLDER_NAME), parsedFilePath);

lib/services/livesync/ios-livesync-service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ export class IOSLiveSyncService extends PlatformLiveSyncServiceBase implements I
5858
};
5959
}
6060

61-
public liveSyncWatchAction(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo): Promise<ILiveSyncResultInfo> {
61+
public liveSyncWatchAction(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo, projectFilesConfig: IProjectFilesConfig): Promise<ILiveSyncResultInfo> {
6262
if (liveSyncInfo.isRebuilt) {
6363
// In this case we should execute fullsync because iOS Runtime requires the full content of app dir to be extracted in the root of sync dir.
6464
return this.fullSync({ projectData: liveSyncInfo.projectData, device, syncAllFiles: liveSyncInfo.syncAllFiles, watch: true });
6565
} else {
66-
return super.liveSyncWatchAction(device, liveSyncInfo);
66+
return super.liveSyncWatchAction(device, liveSyncInfo, projectFilesConfig);
6767
}
6868
}
6969

lib/services/livesync/livesync-service.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
3434
}
3535

3636
public async liveSync(deviceDescriptors: ILiveSyncDeviceInfo[],
37-
liveSyncData: ILiveSyncInfo): Promise<void> {
37+
liveSyncData: ILiveSyncInfo, projectFilesConfig: IProjectFilesConfig): Promise<void> {
3838
const projectData = this.$projectDataService.getProjectData(liveSyncData.projectDir);
3939
await this.$pluginsService.ensureAllDependenciesAreInstalled(projectData);
40-
await this.liveSyncOperation(deviceDescriptors, liveSyncData, projectData);
40+
await this.liveSyncOperation(deviceDescriptors, liveSyncData, projectData, projectFilesConfig);
4141
}
4242

4343
public async stopLiveSync(projectDir: string, deviceIdentifiers?: string[]): Promise<void> {
@@ -117,7 +117,7 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
117117

118118
@hook("liveSync")
119119
private async liveSyncOperation(deviceDescriptors: ILiveSyncDeviceInfo[],
120-
liveSyncData: ILiveSyncInfo, projectData: IProjectData): Promise<void> {
120+
liveSyncData: ILiveSyncInfo, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise<void> {
121121
// In case liveSync is called for a second time for the same projectDir.
122122
const isAlreadyLiveSyncing = this.liveSyncProcessesInfo[projectData.projectDir] && !this.liveSyncProcessesInfo[projectData.projectDir].isStopped;
123123
this.setLiveSyncProcessInfo(liveSyncData.projectDir, deviceDescriptors);
@@ -130,7 +130,7 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
130130
// Should be set after prepare
131131
this.$injector.resolve<DeprecatedUsbLiveSyncService>("usbLiveSyncService").isInitialized = true;
132132

133-
await this.startWatcher(projectData, liveSyncData);
133+
await this.startWatcher(projectData, liveSyncData, projectFilesConfig);
134134
}
135135
}
136136

@@ -272,7 +272,7 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
272272
};
273273
}
274274

275-
private async startWatcher(projectData: IProjectData, liveSyncData: ILiveSyncInfo): Promise<void> {
275+
private async startWatcher(projectData: IProjectData, liveSyncData: ILiveSyncInfo, projectFilesConfig: IProjectFilesConfig): Promise<void> {
276276
let pattern = [APP_FOLDER_NAME];
277277

278278
if (liveSyncData.watchAllFiles) {
@@ -338,7 +338,7 @@ export class LiveSyncService extends EventEmitter implements ILiveSyncService {
338338
useLiveEdit: liveSyncData.useLiveEdit
339339
};
340340

341-
const liveSyncResultInfo = await service.liveSyncWatchAction(device, settings);
341+
const liveSyncResultInfo = await service.liveSyncWatchAction(device, settings, projectFilesConfig);
342342
await this.refreshApplication(projectData, liveSyncResultInfo);
343343
},
344344
(device: Mobile.IDevice) => {

lib/services/livesync/platform-livesync-service-base.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ export abstract class PlatformLiveSyncServiceBase {
5353
};
5454
}
5555

56-
public async liveSyncWatchAction(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo): Promise<ILiveSyncResultInfo> {
56+
public async liveSyncWatchAction(device: Mobile.IDevice, liveSyncInfo: ILiveSyncWatchInfo, projectFilesConfig: IProjectFilesConfig): Promise<ILiveSyncResultInfo> {
5757
const projectData = liveSyncInfo.projectData;
5858
const syncInfo = _.merge<IFullSyncInfo>({ device, watch: true }, liveSyncInfo);
5959
const deviceAppData = await this.getAppData(syncInfo);
6060

6161
let modifiedLocalToDevicePaths: Mobile.ILocalToDevicePathData[] = [];
6262
if (liveSyncInfo.filesToSync.length) {
6363
const filesToSync = liveSyncInfo.filesToSync;
64-
const mappedFiles = _.map(filesToSync, filePath => this.$projectFilesProvider.mapFilePath(filePath, device.deviceInfo.platform, projectData));
64+
const mappedFiles = _.map(filesToSync, filePath => this.$projectFilesProvider.mapFilePath(filePath, device.deviceInfo.platform, projectData, projectFilesConfig));
6565

6666
// Some plugins modify platforms dir on afterPrepare (check nativescript-dev-sass) - we want to sync only existing file.
6767
const existingFiles = mappedFiles.filter(m => this.$fs.exists(m));
@@ -85,7 +85,7 @@ export abstract class PlatformLiveSyncServiceBase {
8585
const filePaths = liveSyncInfo.filesToRemove;
8686
const platformData = this.$platformsData.getPlatformData(device.deviceInfo.platform, projectData);
8787

88-
const mappedFiles = _.map(filePaths, filePath => this.$projectFilesProvider.mapFilePath(filePath, device.deviceInfo.platform, projectData));
88+
const mappedFiles = _.map(filePaths, filePath => this.$projectFilesProvider.mapFilePath(filePath, device.deviceInfo.platform, projectData, projectFilesConfig));
8989
const projectFilesPath = path.join(platformData.appDestinationDirectoryPath, APP_FOLDER_NAME);
9090
const localToDevicePaths = await this.$projectFilesManager.createLocalToDevicePaths(deviceAppData, projectFilesPath, mappedFiles, []);
9191
modifiedLocalToDevicePaths.push(...localToDevicePaths);

lib/services/platform-service.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as semver from "semver";
66
import { EventEmitter } from "events";
77
import { AppFilesUpdater } from "./app-files-updater";
88
import { attachAwaitDetach } from "../common/helpers";
9+
import { Configurations } from "../common/constants";
910
import * as temp from "temp";
1011
temp.track();
1112
let clui = require("clui");
@@ -306,7 +307,10 @@ export class PlatformService extends EventEmitter implements IPlatformService {
306307
}
307308

308309
if (!changesInfo || changesInfo.modulesChanged) {
309-
await this.copyTnsModules(platform, projectData);
310+
const projectFilesConfig: IProjectFilesConfig = {
311+
configuration: appFilesUpdaterOptions.release ? Configurations.Release.toLowerCase() : Configurations.Debug.toLowerCase()
312+
};
313+
await this.copyTnsModules(platform, projectData, projectFilesConfig);
310314
} else if (appFilesUpdaterOptions.bundle) {
311315
let dependencies = this.$nodeModulesDependenciesBuilder.getProductionDependencies(projectData.projectDir);
312316
for (let dependencyKey in dependencies) {
@@ -325,7 +329,11 @@ export class PlatformService extends EventEmitter implements IPlatformService {
325329
excludedDirs.push(constants.TNS_MODULES_FOLDER_NAME);
326330
}
327331

328-
this.$projectFilesManager.processPlatformSpecificFiles(directoryPath, platform, excludedDirs);
332+
const projectFilesConfig: IProjectFilesConfig = {
333+
configuration: appFilesUpdaterOptions.release ? Configurations.Release.toLowerCase() : Configurations.Debug.toLowerCase()
334+
};
335+
336+
this.$projectFilesManager.processPlatformSpecificFiles(directoryPath, platform, projectFilesConfig, excludedDirs);
329337

330338
if (!changesInfo || changesInfo.configChanged || changesInfo.modulesChanged) {
331339
await platformData.platformProjectService.processConfigurationFilesFromAppResources(appFilesUpdaterOptions.release, projectData);
@@ -364,15 +372,15 @@ export class PlatformService extends EventEmitter implements IPlatformService {
364372
}
365373
}
366374

367-
private async copyTnsModules(platform: string, projectData: IProjectData): Promise<void> {
375+
private async copyTnsModules(platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise<void> {
368376
let platformData = this.$platformsData.getPlatformData(platform, projectData);
369377
let appDestinationDirectoryPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME);
370378
let lastModifiedTime = this.$fs.exists(appDestinationDirectoryPath) ? this.$fs.getFsStats(appDestinationDirectoryPath).mtime : null;
371379

372380
try {
373381
let tnsModulesDestinationPath = path.join(appDestinationDirectoryPath, constants.TNS_MODULES_FOLDER_NAME);
374382
// Process node_modules folder
375-
await this.$nodeModulesBuilder.prepareNodeModules(tnsModulesDestinationPath, platform, lastModifiedTime, projectData);
383+
await this.$nodeModulesBuilder.prepareNodeModules(tnsModulesDestinationPath, platform, lastModifiedTime, projectData, projectFilesConfig);
376384
} catch (error) {
377385
this.$logger.debug(error);
378386
shell.rm("-rf", appDestinationDirectoryPath);

lib/services/plugins-service.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,22 @@ export class PluginsService implements IPluginsService {
107107
return await platformData.platformProjectService.validatePlugins(projectData);
108108
}
109109

110-
public async prepare(dependencyData: IDependencyData, platform: string, projectData: IProjectData): Promise<void> {
110+
public async prepare(dependencyData: IDependencyData, platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise<void> {
111111
platform = platform.toLowerCase();
112112
let platformData = this.$platformsData.getPlatformData(platform, projectData);
113113
let pluginData = this.convertToPluginData(dependencyData, projectData.projectDir);
114114

115115
let appFolderExists = this.$fs.exists(path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME));
116116
if (appFolderExists) {
117-
this.preparePluginScripts(pluginData, platform, projectData);
117+
this.preparePluginScripts(pluginData, platform, projectData, projectFilesConfig);
118118
await this.preparePluginNativeCode(pluginData, platform, projectData);
119119

120120
// Show message
121121
this.$logger.out(`Successfully prepared plugin ${pluginData.name} for ${platform}.`);
122122
}
123123
}
124124

125-
private preparePluginScripts(pluginData: IPluginData, platform: string, projectData: IProjectData): void {
125+
private preparePluginScripts(pluginData: IPluginData, platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): void {
126126
let platformData = this.$platformsData.getPlatformData(platform, projectData);
127127
let pluginScriptsDestinationPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME, "tns_modules");
128128
let scriptsDestinationExists = this.$fs.exists(pluginScriptsDestinationPath);
@@ -136,7 +136,7 @@ export class PluginsService implements IPluginsService {
136136
}
137137

138138
//prepare platform speciffic files, .map and .ts files
139-
this.$projectFilesManager.processPlatformSpecificFiles(pluginScriptsDestinationPath, platform);
139+
this.$projectFilesManager.processPlatformSpecificFiles(pluginScriptsDestinationPath, platform, projectFilesConfig);
140140
}
141141

142142
public async preparePluginNativeCode(pluginData: IPluginData, platform: string, projectData: IProjectData): Promise<void> {

lib/services/test-execution-service.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class TestExecutionService implements ITestExecutionService {
3333

3434
public platform: string;
3535

36-
public async startTestRunner(platform: string, projectData: IProjectData): Promise<void> {
36+
public async startTestRunner(platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise<void> {
3737
this.platform = platform;
3838
this.$options.justlaunch = true;
3939
await new Promise<void>((resolve, reject) => {
@@ -114,7 +114,7 @@ class TestExecutionService implements ITestExecutionService {
114114

115115
const liveSyncInfo: ILiveSyncInfo = { projectDir: projectData.projectDir, skipWatcher: !this.$options.watch || this.$options.justlaunch, watchAllFiles: this.$options.syncAllFiles };
116116

117-
await this.$liveSyncService.liveSync(deviceDescriptors, liveSyncInfo);
117+
await this.$liveSyncService.liveSync(deviceDescriptors, liveSyncInfo, projectFilesConfig);
118118

119119
if (this.$options.debugBrk) {
120120
this.$logger.info('Starting debugger...');
@@ -133,7 +133,7 @@ class TestExecutionService implements ITestExecutionService {
133133
});
134134
}
135135

136-
public async startKarmaServer(platform: string, projectData: IProjectData): Promise<void> {
136+
public async startKarmaServer(platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise<void> {
137137
platform = platform.toLowerCase();
138138
this.platform = platform;
139139

@@ -224,7 +224,7 @@ class TestExecutionService implements ITestExecutionService {
224224
});
225225

226226
const liveSyncInfo: ILiveSyncInfo = { projectDir: projectData.projectDir, skipWatcher: !this.$options.watch || this.$options.justlaunch, watchAllFiles: this.$options.syncAllFiles };
227-
await this.$liveSyncService.liveSync(deviceDescriptors, liveSyncInfo);
227+
await this.$liveSyncService.liveSync(deviceDescriptors, liveSyncInfo, projectFilesConfig);
228228
}
229229
};
230230

0 commit comments

Comments
 (0)