From 680720e23b25a41f68447a26c887a4b5dc4c21d7 Mon Sep 17 00:00:00 2001 From: Fatme Havaluova Date: Tue, 2 Jun 2015 08:46:58 +0300 Subject: [PATCH 1/2] Process as platform specific files only these located in app folder https://github.com/NativeScript/nativescript-cli/issues/514 --- lib/services/platform-service.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index 4fda8de1ae..63583e769f 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -157,15 +157,16 @@ export class PlatformService implements IPlatformService { } // Process platform specific files - var contents = this.$fs.readDirectory(platformData.appDestinationDirectoryPath).wait(); + var contents = this.$fs.readDirectory(path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME)).wait(); var files: string[] = []; _.each(contents, d => { - var fsStat = this.$fs.getFsStats(path.join(platformData.appDestinationDirectoryPath, d)).wait(); + let filePath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME, d); + let fsStat = this.$fs.getFsStats(filePath).wait(); if(fsStat.isDirectory() && d !== constants.APP_RESOURCES_FOLDER_NAME) { - this.processPlatformSpecificFiles(platform, this.$fs.enumerateFilesInDirectorySync(path.join(platformData.appDestinationDirectoryPath, d))).wait(); + this.processPlatformSpecificFiles(platform, this.$fs.enumerateFilesInDirectorySync(filePath)).wait(); } else if(fsStat.isFile()) { - files.push(path.join(platformData.appDestinationDirectoryPath, d)); + files.push(filePath); } }); From 2f79b4de452dd984403f0a00b1fc66c642cb8ee9 Mon Sep 17 00:00:00 2001 From: Fatme Havaluova Date: Tue, 2 Jun 2015 09:45:44 +0300 Subject: [PATCH 2/2] Add unit tests to ensure that only the files in app folder will be process on prepare step. --- test/platform-service.ts | 114 +++++++++++++++++++++++++++++++++++++++ test/stubs.ts | 4 +- 2 files changed, 115 insertions(+), 3 deletions(-) diff --git a/test/platform-service.ts b/test/platform-service.ts index 0ed596c258..bd5a72f326 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -25,6 +25,9 @@ import Future = require("fibers/future"); var assert = require("chai").assert; require('should'); +let temp = require("temp"); +temp.track(); + function createTestInjector() { var testInjector = new yok.Yok(); @@ -165,4 +168,115 @@ describe('Platform Service Tests', () => { }); }); }); + + describe("prepare platform unit tests", () => { + let testInjector: IInjector, fs: IFileSystem; + beforeEach(() => { + testInjector = createTestInjector(); + testInjector.register("fs", fsLib.FileSystem); + fs = testInjector.resolve("fs"); + }); + it("should process only files in app folder when preparing for iOS platform", () => { + let tempFolder = temp.mkdirSync("prepare platform"); + + let appFolderPath = path.join(tempFolder, "app"); + fs.createDirectory(appFolderPath).wait(); + + let app1FolderPath = path.join(tempFolder, "app1"); + fs.createDirectory(app1FolderPath).wait(); + + let appDestFolderPath = path.join(tempFolder, "appDest"); + let appResourcesFolderPath = path.join(appDestFolderPath, "App_Resources"); + + // Add platform specific files to app and app1 folders + let platformSpecificFiles = [ + "test1.ios.js", "test1-ios-js", "test2.android.js", "test2-android-js" + ]; + + let destinationDirectories = [appFolderPath, app1FolderPath]; + + _.each(destinationDirectories, directoryPath => { + _.each(platformSpecificFiles, filePath => { + let fileFullPath = path.join(directoryPath, filePath); + fs.writeFile(fileFullPath, "testData").wait(); + }); + }); + + let platformsData = testInjector.resolve("platformsData"); + platformsData.platformsNames = ["ios", "android"]; + platformsData.getPlatformData = (platform: string) => { + return { + appDestinationDirectoryPath: appDestFolderPath, + appResourcesDestinationDirectoryPath: appResourcesFolderPath, + normalizedPlatformName: "iOS" + } + }; + + let projectData = testInjector.resolve("projectData"); + projectData.projectDir = tempFolder; + + let platformService = testInjector.resolve("platformService"); + platformService.preparePlatform("ios").wait(); + + // Asserts that the files in app folder are process as platform specific + assert.isTrue(fs.exists(path.join(appDestFolderPath, "app" , "test1.js")).wait()); + assert.isTrue(fs.exists(path.join(appDestFolderPath, "app", "test1-js")).wait()); + assert.isFalse(fs.exists(path.join(appDestFolderPath, "app", "test2.js")).wait()); + assert.isFalse(fs.exists(path.join(appDestFolderPath, "app", "test2-js")).wait()); + + // Asserts that the files in app1 folder aren't process as platform specific + assert.isFalse(fs.exists(path.join(appDestFolderPath, "app1")).wait()); + }); + it("should process only files in app folder when preparing for Android platform", () => { + let tempFolder = temp.mkdirSync("prepare platform"); + + let appFolderPath = path.join(tempFolder, "app"); + fs.createDirectory(appFolderPath).wait(); + + let app1FolderPath = path.join(tempFolder, "app1"); + fs.createDirectory(app1FolderPath).wait(); + + let appDestFolderPath = path.join(tempFolder, "appDest"); + let appResourcesFolderPath = path.join(appDestFolderPath, "App_Resources"); + + // Add platform specific files to app and app1 folders + let platformSpecificFiles = [ + "test1.ios.js", "test1-ios-js", "test2.android.js", "test2-android-js" + ]; + + let destinationDirectories = [appFolderPath, app1FolderPath]; + + _.each(destinationDirectories, directoryPath => { + _.each(platformSpecificFiles, filePath => { + let fileFullPath = path.join(directoryPath, filePath); + fs.writeFile(fileFullPath, "testData").wait(); + }); + }); + + let platformsData = testInjector.resolve("platformsData"); + platformsData.platformsNames = ["ios", "android"]; + platformsData.getPlatformData = (platform: string) => { + return { + appDestinationDirectoryPath: appDestFolderPath, + appResourcesDestinationDirectoryPath: appResourcesFolderPath, + normalizedPlatformName: "Android" + } + }; + + let projectData = testInjector.resolve("projectData"); + projectData.projectDir = tempFolder; + + let platformService = testInjector.resolve("platformService"); + platformService.preparePlatform("android").wait(); + + // Asserts that the files in app folder are process as platform specific + assert.isTrue(fs.exists(path.join(appDestFolderPath, "app" , "test2.js")).wait()); + assert.isTrue(fs.exists(path.join(appDestFolderPath, "app", "test2-js")).wait()); + assert.isFalse(fs.exists(path.join(appDestFolderPath, "app", "test1.js")).wait()); + assert.isFalse(fs.exists(path.join(appDestFolderPath, "app", "test1-js")).wait()); + + // Asserts that the files in app1 folder aren't process as platform specific + assert.isFalse(fs.exists(path.join(appDestFolderPath, "app1")).wait()); + }); + }); }); diff --git a/test/stubs.ts b/test/stubs.ts index 9fb439a3b0..7909889b0a 100644 --- a/test/stubs.ts +++ b/test/stubs.ts @@ -227,9 +227,7 @@ export class ProjectDataStub implements IProjectData { } export class PlatformsDataStub implements IPlatformsData { - public get platformsNames(): string[] { - return undefined; - } + public platformsNames: string[]; public getPlatformData(platform: string): IPlatformData { return {