From a1916997f1c567373935fa2510d3fb210269aa29 Mon Sep 17 00:00:00 2001 From: Nadya Atanasova Date: Thu, 6 Jul 2017 18:04:57 +0300 Subject: [PATCH] Respect configuration when preparing project files --- lib/commands/test.ts | 11 ++++++++--- lib/common | 2 +- lib/definitions/platform.d.ts | 4 ++-- lib/definitions/plugins.d.ts | 4 ++-- lib/definitions/project.d.ts | 4 ++-- lib/providers/project-files-provider.ts | 4 ++-- lib/services/platform-service.ts | 19 ++++++++++--------- lib/services/plugins-service.ts | 8 ++++---- lib/services/test-execution-service.ts | 4 ++-- .../node-modules/node-modules-builder.ts | 8 ++++---- .../node-modules/node-modules-dest-copy.ts | 8 ++++---- test/plugin-prepare.ts | 6 +++--- test/plugins-service.ts | 2 +- test/project-files-provider.ts | 12 ++++++------ 14 files changed, 51 insertions(+), 45 deletions(-) diff --git a/lib/commands/test.ts b/lib/commands/test.ts index 9e6f197120..774d028ffc 100644 --- a/lib/commands/test.ts +++ b/lib/commands/test.ts @@ -1,9 +1,13 @@ +import * as helpers from "../common/helpers"; + function RunTestCommandFactory(platform: string) { return function RunTestCommand( + $options: IOptions, $testExecutionService: ITestExecutionService, $projectData: IProjectData) { $projectData.initializeProjectData(); - this.execute = (args: string[]): Promise => $testExecutionService.startTestRunner(platform, $projectData); + const projectFilesConfig = helpers.getProjectFilesConfig({ isReleaseBuild: this.$options.release }); + this.execute = (args: string[]): Promise => $testExecutionService.startTestRunner(platform, $projectData, projectFilesConfig); this.allowedParameters = []; }; } @@ -12,9 +16,10 @@ $injector.registerCommand("dev-test|android", RunTestCommandFactory('android')); $injector.registerCommand("dev-test|ios", RunTestCommandFactory('iOS')); function RunKarmaTestCommandFactory(platform: string) { - return function RunKarmaTestCommand($testExecutionService: ITestExecutionService, $projectData: IProjectData) { + return function RunKarmaTestCommand($options: IOptions, $testExecutionService: ITestExecutionService, $projectData: IProjectData) { $projectData.initializeProjectData(); - this.execute = (args: string[]): Promise => $testExecutionService.startKarmaServer(platform, $projectData); + const projectFilesConfig = helpers.getProjectFilesConfig({ isReleaseBuild: this.$options.release }); + this.execute = (args: string[]): Promise => $testExecutionService.startKarmaServer(platform, $projectData, projectFilesConfig); this.allowedParameters = []; }; } diff --git a/lib/common b/lib/common index 359f7508cb..fa89ea0c2d 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit 359f7508cbf174452c5afa213337805e1ab50860 +Subproject commit fa89ea0c2d5eb555e703f878ce20edeccd4706c7 diff --git a/lib/definitions/platform.d.ts b/lib/definitions/platform.d.ts index 5645e49f21..fed7c2fd15 100644 --- a/lib/definitions/platform.d.ts +++ b/lib/definitions/platform.d.ts @@ -287,8 +287,8 @@ interface IPlatformsData { } interface INodeModulesBuilder { - prepareNodeModules(absoluteOutputPath: string, platform: string, lastModifiedTime: Date, projectData: IProjectData): Promise; - prepareJSNodeModules(absoluteOutputPath: string, platform: string, lastModifiedTime: Date, projectData: IProjectData): Promise; + prepareNodeModules(absoluteOutputPath: string, platform: string, lastModifiedTime: Date, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise; + prepareJSNodeModules(absoluteOutputPath: string, platform: string, lastModifiedTime: Date, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise; cleanNodeModules(absoluteOutputPath: string, platform: string): void; } diff --git a/lib/definitions/plugins.d.ts b/lib/definitions/plugins.d.ts index 7feb3d5bc6..ded728e3cb 100644 --- a/lib/definitions/plugins.d.ts +++ b/lib/definitions/plugins.d.ts @@ -1,10 +1,10 @@ interface IPluginsService { add(plugin: string, projectData: IProjectData): Promise; // adds plugin by name, github url, local path and et. remove(pluginName: string, projectData: IProjectData): Promise; // removes plugin only by name - prepare(pluginData: IDependencyData, platform: string, projectData: IProjectData): Promise; + prepare(pluginData: IDependencyData, platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise; getAllInstalledPlugins(projectData: IProjectData): Promise; ensureAllDependenciesAreInstalled(projectData: IProjectData): Promise; - preparePluginScripts(pluginData: IPluginData, platform: string, projectData: IProjectData): void + preparePluginScripts(pluginData: IPluginData, platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): void /** * Returns all dependencies and devDependencies from pacakge.json file. diff --git a/lib/definitions/project.d.ts b/lib/definitions/project.d.ts index 2656ddf251..b8a73670af 100644 --- a/lib/definitions/project.d.ts +++ b/lib/definitions/project.d.ts @@ -279,8 +279,8 @@ interface IAndroidProjectPropertiesManager { } interface ITestExecutionService { - startTestRunner(platform: string, projectData: IProjectData): Promise; - startKarmaServer(platform: string, projectData: IProjectData): Promise; + startTestRunner(platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise; + startKarmaServer(platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise; } /** diff --git a/lib/providers/project-files-provider.ts b/lib/providers/project-files-provider.ts index afe422d537..6a70fb2592 100644 --- a/lib/providers/project-files-provider.ts +++ b/lib/providers/project-files-provider.ts @@ -12,9 +12,9 @@ export class ProjectFilesProvider extends ProjectFilesProviderBase { private static INTERNAL_NONPROJECT_FILES = [ "**/*.ts" ]; - public mapFilePath(filePath: string, platform: string, projectData: IProjectData): string { + public mapFilePath(filePath: string, platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): string { let platformData = this.$platformsData.getPlatformData(platform.toLowerCase(), projectData); - let parsedFilePath = this.getPreparedFilePath(filePath); + let parsedFilePath = this.getPreparedFilePath(filePath, projectFilesConfig); let mappedFilePath = ""; if (parsedFilePath.indexOf(constants.NODE_MODULES_FOLDER_NAME) > -1) { let relativePath = path.relative(path.join(projectData.projectDir, constants.NODE_MODULES_FOLDER_NAME), parsedFilePath); diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index 976c2a5e78..c829e1b02c 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -294,10 +294,11 @@ export class PlatformService extends EventEmitter implements IPlatformService { this.$logger.out("Preparing project..."); let platformData = this.$platformsData.getPlatformData(platform, projectData); - await this.preparePlatformCoreJS(platform, platformData, appFilesUpdaterOptions, projectData, platformSpecificData, changesInfo); + const projectFilesConfig = helpers.getProjectFilesConfig({ isReleaseBuild: appFilesUpdaterOptions.release }); + await this.preparePlatformCoreJS(platform, platformData, appFilesUpdaterOptions, projectData, platformSpecificData, changesInfo, filesToSync, projectFilesConfig); if (!nativePrepare || !nativePrepare.skipNativePrepare) { - await this.preparePlatformCoreNative(platform, platformData, appFilesUpdaterOptions, projectData, platformSpecificData, changesInfo); + await this.preparePlatformCoreNative(platform, platformData, appFilesUpdaterOptions, projectData, platformSpecificData, changesInfo, projectFilesConfig); } let directoryPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME); @@ -306,12 +307,12 @@ export class PlatformService extends EventEmitter implements IPlatformService { excludedDirs.push(constants.TNS_MODULES_FOLDER_NAME); } - this.$projectFilesManager.processPlatformSpecificFiles(directoryPath, platform, excludedDirs); + this.$projectFilesManager.processPlatformSpecificFiles(directoryPath, platform, projectFilesConfig, excludedDirs); this.$logger.out(`Project successfully prepared (${platform})`); } - private async preparePlatformCoreJS(platform: string, platformData: IPlatformData, appFilesUpdaterOptions: IAppFilesUpdaterOptions, projectData: IProjectData, platformSpecificData: IPlatformSpecificData, changesInfo?: IProjectChangesInfo, filesToSync?: Array, ): Promise { + private async preparePlatformCoreJS(platform: string, platformData: IPlatformData, appFilesUpdaterOptions: IAppFilesUpdaterOptions, projectData: IProjectData, platformSpecificData: IPlatformSpecificData, changesInfo?: IProjectChangesInfo, filesToSync?: Array, projectFilesConfig?: IProjectFilesConfig): Promise { if (!changesInfo || changesInfo.appFilesChanged) { await this.copyAppFiles(platformData, appFilesUpdaterOptions, projectData); @@ -324,11 +325,11 @@ export class PlatformService extends EventEmitter implements IPlatformService { } if (!changesInfo || changesInfo.modulesChanged) { - await this.copyTnsModules(platform, platformData, projectData); + await this.copyTnsModules(platform, platformData, projectData, projectFilesConfig); } } - public async preparePlatformCoreNative(platform: string, platformData: IPlatformData, appFilesUpdaterOptions: IAppFilesUpdaterOptions, projectData: IProjectData, platformSpecificData: IPlatformSpecificData, changesInfo?: IProjectChangesInfo): Promise { + public async preparePlatformCoreNative(platform: string, platformData: IPlatformData, appFilesUpdaterOptions: IAppFilesUpdaterOptions, projectData: IProjectData, platformSpecificData: IPlatformSpecificData, changesInfo?: IProjectChangesInfo, projectFilesConfig?: IProjectFilesConfig): Promise { if (changesInfo.hasChanges) { await this.cleanProject(platform, appFilesUpdaterOptions, platformData, projectData); } @@ -347,7 +348,7 @@ export class PlatformService extends EventEmitter implements IPlatformService { let tnsModulesDestinationPath = path.join(appDestinationDirectoryPath, constants.TNS_MODULES_FOLDER_NAME); // Process node_modules folder - await this.$nodeModulesBuilder.prepareNodeModules(tnsModulesDestinationPath, platform, lastModifiedTime, projectData); + await this.$nodeModulesBuilder.prepareNodeModules(tnsModulesDestinationPath, platform, lastModifiedTime, projectData, projectFilesConfig); } if (!changesInfo || changesInfo.configChanged || changesInfo.modulesChanged) { @@ -385,14 +386,14 @@ export class PlatformService extends EventEmitter implements IPlatformService { } } - private async copyTnsModules(platform: string, platformData: IPlatformData, projectData: IProjectData): Promise { + private async copyTnsModules(platform: string, platformData: IPlatformData, projectData: IProjectData, projectFilesConfig?: IProjectFilesConfig): Promise { let appDestinationDirectoryPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME); let lastModifiedTime = this.$fs.exists(appDestinationDirectoryPath) ? this.$fs.getFsStats(appDestinationDirectoryPath).mtime : null; try { let tnsModulesDestinationPath = path.join(appDestinationDirectoryPath, constants.TNS_MODULES_FOLDER_NAME); // Process node_modules folder - await this.$nodeModulesBuilder.prepareJSNodeModules(tnsModulesDestinationPath, platform, lastModifiedTime, projectData); + await this.$nodeModulesBuilder.prepareJSNodeModules(tnsModulesDestinationPath, platform, lastModifiedTime, projectData, projectFilesConfig); } catch (error) { this.$logger.debug(error); shell.rm("-rf", appDestinationDirectoryPath); diff --git a/lib/services/plugins-service.ts b/lib/services/plugins-service.ts index 57d07d132b..0b460da5db 100644 --- a/lib/services/plugins-service.ts +++ b/lib/services/plugins-service.ts @@ -107,14 +107,14 @@ export class PluginsService implements IPluginsService { return await platformData.platformProjectService.validatePlugins(projectData); } - public async prepare(dependencyData: IDependencyData, platform: string, projectData: IProjectData): Promise { + public async prepare(dependencyData: IDependencyData, platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise { platform = platform.toLowerCase(); let platformData = this.$platformsData.getPlatformData(platform, projectData); let pluginData = this.convertToPluginData(dependencyData, projectData.projectDir); let appFolderExists = this.$fs.exists(path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME)); if (appFolderExists) { - this.preparePluginScripts(pluginData, platform, projectData); + this.preparePluginScripts(pluginData, platform, projectData, projectFilesConfig); await this.preparePluginNativeCode(pluginData, platform, projectData); // Show message @@ -122,7 +122,7 @@ export class PluginsService implements IPluginsService { } } - public preparePluginScripts(pluginData: IPluginData, platform: string, projectData: IProjectData): void { + public preparePluginScripts(pluginData: IPluginData, platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): void { let platformData = this.$platformsData.getPlatformData(platform, projectData); let pluginScriptsDestinationPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME, "tns_modules"); let scriptsDestinationExists = this.$fs.exists(pluginScriptsDestinationPath); @@ -136,7 +136,7 @@ export class PluginsService implements IPluginsService { } //prepare platform speciffic files, .map and .ts files - this.$projectFilesManager.processPlatformSpecificFiles(pluginScriptsDestinationPath, platform); + this.$projectFilesManager.processPlatformSpecificFiles(pluginScriptsDestinationPath, platform, projectFilesConfig); } public async preparePluginNativeCode(pluginData: IPluginData, platform: string, projectData: IProjectData): Promise { diff --git a/lib/services/test-execution-service.ts b/lib/services/test-execution-service.ts index f6bcc41a45..376490882c 100644 --- a/lib/services/test-execution-service.ts +++ b/lib/services/test-execution-service.ts @@ -33,7 +33,7 @@ class TestExecutionService implements ITestExecutionService { public platform: string; - public async startTestRunner(platform: string, projectData: IProjectData): Promise { + public async startTestRunner(platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise { this.platform = platform; this.$options.justlaunch = true; await new Promise((resolve, reject) => { @@ -133,7 +133,7 @@ class TestExecutionService implements ITestExecutionService { }); } - public async startKarmaServer(platform: string, projectData: IProjectData): Promise { + public async startKarmaServer(platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise { platform = platform.toLowerCase(); this.platform = platform; diff --git a/lib/tools/node-modules/node-modules-builder.ts b/lib/tools/node-modules/node-modules-builder.ts index 0143d437ab..8e84bb8031 100644 --- a/lib/tools/node-modules/node-modules-builder.ts +++ b/lib/tools/node-modules/node-modules-builder.ts @@ -8,16 +8,16 @@ export class NodeModulesBuilder implements INodeModulesBuilder { private $nodeModulesDependenciesBuilder: INodeModulesDependenciesBuilder ) { } - public async prepareNodeModules(absoluteOutputPath: string, platform: string, lastModifiedTime: Date, projectData: IProjectData): Promise { + public async prepareNodeModules(absoluteOutputPath: string, platform: string, lastModifiedTime: Date, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise { const productionDependencies = this.initialPrepareNodeModules(absoluteOutputPath, platform, lastModifiedTime, projectData); const npmPluginPrepare: NpmPluginPrepare = this.$injector.resolve(NpmPluginPrepare); - await npmPluginPrepare.preparePlugins(productionDependencies, platform, projectData); + await npmPluginPrepare.preparePlugins(productionDependencies, platform, projectData, projectFilesConfig); } - public async prepareJSNodeModules(absoluteOutputPath: string, platform: string, lastModifiedTime: Date, projectData: IProjectData): Promise { + public async prepareJSNodeModules(absoluteOutputPath: string, platform: string, lastModifiedTime: Date, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise { const productionDependencies = this.initialPrepareNodeModules(absoluteOutputPath, platform, lastModifiedTime, projectData); const npmPluginPrepare: NpmPluginPrepare = this.$injector.resolve(NpmPluginPrepare); - await npmPluginPrepare.prepareJSPlugins(productionDependencies, platform, projectData); + await npmPluginPrepare.prepareJSPlugins(productionDependencies, platform, projectData, projectFilesConfig); } public cleanNodeModules(absoluteOutputPath: string, platform: string): void { diff --git a/lib/tools/node-modules/node-modules-dest-copy.ts b/lib/tools/node-modules/node-modules-dest-copy.ts index 78d19c607c..f80b0f175b 100644 --- a/lib/tools/node-modules/node-modules-dest-copy.ts +++ b/lib/tools/node-modules/node-modules-dest-copy.ts @@ -137,7 +137,7 @@ export class NpmPluginPrepare { return result; } - public async preparePlugins(dependencies: IDependencyData[], platform: string, projectData: IProjectData): Promise { + public async preparePlugins(dependencies: IDependencyData[], platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise { if (_.isEmpty(dependencies) || this.allPrepared(dependencies, platform, projectData)) { return; } @@ -155,10 +155,10 @@ export class NpmPluginPrepare { await this.afterPrepare(dependencies, platform, projectData); } - public async prepareJSPlugins(dependencies: IDependencyData[], platform: string, projectData: IProjectData): Promise { + public async prepareJSPlugins(dependencies: IDependencyData[], platform: string, projectData: IProjectData, projectFilesConfig: IProjectFilesConfig): Promise { if (_.isEmpty(dependencies) || this.allPrepared(dependencies, platform, projectData)) { return; - } +} for (let dependencyKey in dependencies) { const dependency = dependencies[dependencyKey]; @@ -169,7 +169,7 @@ export class NpmPluginPrepare { let platformData = this.$platformsData.getPlatformData(platform, projectData); let appFolderExists = this.$fs.exists(path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME)); if (appFolderExists) { - this.$pluginsService.preparePluginScripts(pluginData, platform, projectData); + this.$pluginsService.preparePluginScripts(pluginData, platform, projectData, projectFilesConfig); // Show message this.$logger.out(`Successfully prepared plugin ${pluginData.name} for ${platform}.`); } diff --git a/test/plugin-prepare.ts b/test/plugin-prepare.ts index 6c07491663..bca777f0c8 100644 --- a/test/plugin-prepare.ts +++ b/test/plugin-prepare.ts @@ -28,7 +28,7 @@ class TestNpmPluginPrepare extends NpmPluginPrepare { describe("Plugin preparation", () => { it("skips prepare if no plugins", async () => { const pluginPrepare = new TestNpmPluginPrepare({}); - await pluginPrepare.preparePlugins([], "android", null); + await pluginPrepare.preparePlugins([], "android", null, {}); assert.deepEqual({}, pluginPrepare.preparedDependencies); }); @@ -42,7 +42,7 @@ describe("Plugin preparation", () => { nativescript: null, } ]; - await pluginPrepare.preparePlugins(testDependencies, "android", null); + await pluginPrepare.preparePlugins(testDependencies, "android", null, {}); assert.deepEqual({}, pluginPrepare.preparedDependencies); }); @@ -62,7 +62,7 @@ describe("Plugin preparation", () => { nativescript: null, } ]; - await pluginPrepare.preparePlugins(testDependencies, "android", null); + await pluginPrepare.preparePlugins(testDependencies, "android", null, {}); const prepareData = { "tns-core-modules-widgets": true, "nativescript-calendar": true }; assert.deepEqual(prepareData, pluginPrepare.preparedDependencies); }); diff --git a/test/plugins-service.ts b/test/plugins-service.ts index 4cad62b65b..2744d5f055 100644 --- a/test/plugins-service.ts +++ b/test/plugins-service.ts @@ -516,7 +516,7 @@ describe("Plugins service", () => { `\n@#[line:1,col:39].` + `\n@#[line:1,col:39].`; mockBeginCommand(testInjector, expectedErrorMessage); - await pluginsService.prepare(pluginJsonData, "android", projectData); + await pluginsService.prepare(pluginJsonData, "android", projectData, {}); }); }); }); diff --git a/test/project-files-provider.ts b/test/project-files-provider.ts index 8d21a50966..2c910275e7 100644 --- a/test/project-files-provider.ts +++ b/test/project-files-provider.ts @@ -57,37 +57,37 @@ describe("project-files-provider", () => { describe("mapFilePath", () => { it("returns file path from prepared project when path from app dir is passed", () => { let projectData: IProjectData = testInjector.resolve("projectData"); - let mappedFilePath = projectFilesProvider.mapFilePath(path.join(appSourceDir, "test.js"), "android", projectData); + let mappedFilePath = projectFilesProvider.mapFilePath(path.join(appSourceDir, "test.js"), "android", projectData, {}); assert.deepEqual(mappedFilePath, path.join(appDestinationDirectoryPath, "app", "test.js")); }); it("returns file path from prepared project when path from app/App_Resources/platform dir is passed", () => { let projectData: IProjectData = testInjector.resolve("projectData"); - let mappedFilePath = projectFilesProvider.mapFilePath(path.join(appSourceDir, "App_Resources", "android", "test.js"), "android", projectData); + let mappedFilePath = projectFilesProvider.mapFilePath(path.join(appSourceDir, "App_Resources", "android", "test.js"), "android", projectData, {}); assert.deepEqual(mappedFilePath, path.join(appResourcesDestinationDirectoryPath, "test.js")); }); it("returns null when path from app/App_Resources/android dir is passed and iOS platform is specified", () => { let projectData: IProjectData = testInjector.resolve("projectData"); - let mappedFilePath = projectFilesProvider.mapFilePath(path.join(appSourceDir, "App_Resources", "android", "test.js"), "iOS", projectData); + let mappedFilePath = projectFilesProvider.mapFilePath(path.join(appSourceDir, "App_Resources", "android", "test.js"), "iOS", projectData, {}); assert.deepEqual(mappedFilePath, null); }); it("returns null when path from app/App_Resources/ dir (not platform specific) is passed", () => { let projectData: IProjectData = testInjector.resolve("projectData"); - let mappedFilePath = projectFilesProvider.mapFilePath(path.join(appSourceDir, "App_Resources", "test.js"), "android", projectData); + let mappedFilePath = projectFilesProvider.mapFilePath(path.join(appSourceDir, "App_Resources", "test.js"), "android", projectData, {}); assert.deepEqual(mappedFilePath, null); }); it("returns file path from prepared project when path from app dir is passed and it contains platform in its name", () => { let projectData: IProjectData = testInjector.resolve("projectData"); - let mappedFilePath = projectFilesProvider.mapFilePath(path.join(appSourceDir, "test.android.js"), "android", projectData); + let mappedFilePath = projectFilesProvider.mapFilePath(path.join(appSourceDir, "test.android.js"), "android", projectData, {}); assert.deepEqual(mappedFilePath, path.join(appDestinationDirectoryPath, "app", "test.js")); }); it("returns file path from prepared project when path from app dir is passed and it contains configuration in its name", () => { let projectData: IProjectData = testInjector.resolve("projectData"); - let mappedFilePath = projectFilesProvider.mapFilePath(path.join(appSourceDir, "test.debug.js"), "android", projectData); + let mappedFilePath = projectFilesProvider.mapFilePath(path.join(appSourceDir, "test.debug.js"), "android", projectData, {}); assert.deepEqual(mappedFilePath, path.join(appDestinationDirectoryPath, "app", "test.js")); }); });