Skip to content

Process as platform specific files only these located in app folder #515

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 2 commits into from
Jun 2, 2015
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 5 additions & 4 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use let here. You may consider a whole file replace of vars with lets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm planning to replace all var usages with let in another PR.

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);
}
});

Expand Down
114 changes: 114 additions & 0 deletions test/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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());
});
});
});
4 changes: 1 addition & 3 deletions test/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down