Skip to content

Commit e0321db

Browse files
FatmeFatme
authored andcommitted
Merge pull request #377 from NativeScript/famte/chage-app-structure
Change app structure - move tns_modules inside app folder
2 parents 7dac90c + 03ea16c commit e0321db

File tree

8 files changed

+38
-53
lines changed

8 files changed

+38
-53
lines changed

lib/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
///<reference path=".d.ts"/>
22

33
export var APP_FOLDER_NAME = "app";
4-
export var TNS_MODULES_FOLDER_NAME = "tns_modules";
54
export var APP_RESOURCES_FOLDER_NAME = "App_Resources";
65
export var PROJECT_FRAMEWORK_FOLDER_NAME = "framework";
76

lib/definitions/platform.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ interface IPlatformData {
2424
emulatorServices: Mobile.IEmulatorPlatformServices;
2525
projectRoot: string;
2626
normalizedPlatformName: string;
27+
appDestinationDirectoryPath: string;
28+
appResourcesDestinationDirectoryPath: string;
2729
deviceBuildOutputPath: string;
2830
emulatorBuildOutputPath?: string;
2931
validPackageNamesForDevice: string[];

lib/definitions/project.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ interface IPlatformProjectService {
2626
createProject(projectRoot: string, frameworkDir: string): IFuture<void>;
2727
interpolateData(projectRoot: string): IFuture<void>;
2828
afterCreateProject(projectRoot: string): IFuture<void>;
29-
prepareProject(platformData: IPlatformData): IFuture<string>;
3029
buildProject(projectRoot: string): IFuture<void>;
3130
isPlatformPrepared(projectRoot: string): IFuture<boolean>;
3231
addLibrary(platformData: IPlatformData, libraryPath: string): IFuture<void>;

lib/services/android-project-service.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,16 @@ class AndroidProjectService implements IPlatformProjectService {
3030
}
3131

3232
public get platformData(): IPlatformData {
33+
var projectRoot = path.join(this.$projectData.platformsDir, "android");
34+
3335
return {
3436
frameworkPackageName: "tns-android",
3537
normalizedPlatformName: "Android",
38+
appDestinationDirectoryPath: path.join(projectRoot, "assets"),
39+
appResourcesDestinationDirectoryPath: path.join(projectRoot, "res"),
3640
platformProjectService: this,
3741
emulatorServices: this.$androidEmulatorServices,
38-
projectRoot: path.join(this.$projectData.platformsDir, "android"),
42+
projectRoot: projectRoot,
3943
deviceBuildOutputPath: path.join(this.$projectData.platformsDir, "android", "bin"),
4044
validPackageNamesForDevice: [
4145
util.format("%s-%s.%s", this.$projectData.projectName, "debug", "apk"),
@@ -123,25 +127,6 @@ class AndroidProjectService implements IPlatformProjectService {
123127
}).future<void>()();
124128
}
125129

126-
public prepareProject(platformData: IPlatformData): IFuture<string> {
127-
return (() => {
128-
var appSourceDirectory = path.join(this.$projectData.projectDir, constants.APP_FOLDER_NAME);
129-
var assetsDirectory = path.join(platformData.projectRoot, "assets");
130-
var resDirectory = path.join(platformData.projectRoot, "res");
131-
132-
shell.cp("-Rf", path.join(appSourceDirectory, "*"), assetsDirectory);
133-
134-
var appResourcesDirectoryPath = path.join(assetsDirectory, constants.APP_RESOURCES_FOLDER_NAME);
135-
if (this.$fs.exists(appResourcesDirectoryPath).wait()) {
136-
shell.cp("-Rf", path.join(appResourcesDirectoryPath, platformData.normalizedPlatformName, "*"), resDirectory);
137-
this.$fs.deleteDirectory(appResourcesDirectoryPath).wait();
138-
}
139-
140-
return assetsDirectory;
141-
142-
}).future<string>()();
143-
}
144-
145130
public getDebugOnDeviceSetup(): Mobile.IDebugOnDeviceSetup {
146131
return { };
147132
}

lib/services/ios-project-service.ts

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,18 @@ class IOSProjectService implements IPlatformProjectService {
2424
private $npm: INodePackageManager) { }
2525

2626
public get platformData(): IPlatformData {
27+
var projectRoot = path.join(this.$projectData.platformsDir, "ios");
28+
2729
return {
2830
frameworkPackageName: "tns-ios",
2931
normalizedPlatformName: "iOS",
32+
appDestinationDirectoryPath: path.join(projectRoot, this.$projectData.projectName),
33+
appResourcesDestinationDirectoryPath: path.join(projectRoot, this.$projectData.projectName, "Resources", "icons"),
3034
platformProjectService: this,
3135
emulatorServices: this.$iOSEmulatorServices,
32-
projectRoot: path.join(this.$projectData.platformsDir, "ios"),
33-
deviceBuildOutputPath: path.join(this.$projectData.platformsDir, "ios", "build", "device"),
34-
emulatorBuildOutputPath: path.join(this.$projectData.platformsDir, "ios", "build", "emulator"),
36+
projectRoot: projectRoot,
37+
deviceBuildOutputPath: path.join(projectRoot, "build", "device"),
38+
emulatorBuildOutputPath: path.join(projectRoot, "build", "emulator"),
3539
validPackageNamesForDevice: [
3640
this.$projectData.projectName + ".ipa"
3741
],
@@ -109,25 +113,6 @@ class IOSProjectService implements IPlatformProjectService {
109113
}).future<void>()();
110114
}
111115

112-
public prepareProject(platformData: IPlatformData): IFuture<string> {
113-
return (() => {
114-
var appSourceDirectory = path.join(this.$projectData.projectDir, constants.APP_FOLDER_NAME);
115-
var appDestinationDirectory = path.join(platformData.projectRoot, this.$projectData.projectName);
116-
var resDirectory = path.join(platformData.projectRoot, this.$projectData.projectName, "Resources", "icons");
117-
this.$fs.ensureDirectoryExists(resDirectory).wait();
118-
119-
shell.cp("-Rf", path.join(appSourceDirectory, "*"), appDestinationDirectory);
120-
121-
var appResourcesDirectoryPath = path.join(appDestinationDirectory, constants.APP_RESOURCES_FOLDER_NAME);
122-
if (this.$fs.exists(appResourcesDirectoryPath).wait()) {
123-
shell.cp("-Rf", path.join(appResourcesDirectoryPath, platformData.normalizedPlatformName, "*"), resDirectory);
124-
this.$fs.deleteDirectory(appResourcesDirectoryPath).wait();
125-
}
126-
127-
return appDestinationDirectory;
128-
}).future<string>()();
129-
}
130-
131116
public buildProject(projectRoot: string): IFuture<void> {
132117
return (() => {
133118
var basicArgs = [

lib/services/platform-service.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,29 @@ export class PlatformService implements IPlatformService {
139139
platform = platform.toLowerCase();
140140

141141
var platformData = this.$platformsData.getPlatformData(platform);
142-
var platformProjectService = platformData.platformProjectService;
143142

144-
var appFilesLocation = platformProjectService.prepareProject(platformData).wait();
143+
// Copy app folder to native project
144+
var appSourceDirectoryPath = path.join(this.$projectData.projectDir, constants.APP_FOLDER_NAME);
145+
shell.cp("-R", appSourceDirectoryPath, platformData.appDestinationDirectoryPath);
146+
147+
// Copy App_Resources to project root folder
148+
this.$fs.ensureDirectoryExists(platformData.appResourcesDestinationDirectoryPath).wait(); // Should be deleted
149+
var appResourcesDirectoryPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME, constants.APP_RESOURCES_FOLDER_NAME);
150+
if (this.$fs.exists(appResourcesDirectoryPath).wait()) {
151+
shell.cp("-Rf", path.join(appResourcesDirectoryPath, platformData.normalizedPlatformName, "*"), platformData.appResourcesDestinationDirectoryPath);
152+
this.$fs.deleteDirectory(appResourcesDirectoryPath).wait();
153+
}
145154

146-
var appDirectoryPath = path.join(this.$projectData.projectDir, constants.APP_FOLDER_NAME);
147-
var contents = this.$fs.readDirectory(appDirectoryPath).wait();
155+
// Process platform specific files
156+
var contents = this.$fs.readDirectory(platformData.appDestinationDirectoryPath).wait();
148157
var files: string[] = [];
149158

150159
_.each(contents, d => {
151-
var fsStat = this.$fs.getFsStats(path.join(appDirectoryPath, d)).wait();
160+
var fsStat = this.$fs.getFsStats(path.join(platformData.appDestinationDirectoryPath, d)).wait();
152161
if(fsStat.isDirectory() && d !== constants.APP_RESOURCES_FOLDER_NAME) {
153-
this.processPlatformSpecificFiles(platform, this.$fs.enumerateFilesInDirectorySync(path.join(appFilesLocation, d))).wait();
162+
this.processPlatformSpecificFiles(platform, this.$fs.enumerateFilesInDirectorySync(path.join(platformData.appDestinationDirectoryPath, d))).wait();
154163
} else if(fsStat.isFile()) {
155-
files.push(path.join(appFilesLocation,d));
164+
files.push(path.join(platformData.appDestinationDirectoryPath, d));
156165
}
157166
});
158167

test/platform-commands.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class PlatformData implements IPlatformData {
2424
deviceBuildOutputPath = "";
2525
validPackageNamesForDevice: string[] = [];
2626
frameworkFilesExtensions = [".jar", ".dat"];
27+
appDestinationDirectoryPath = "";
28+
appResourcesDestinationDirectoryPath = "";
2729
}
2830

2931
class ErrorsNoFailStub implements IErrors {

test/stubs.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,9 @@ export class PlatformsDataStub implements IPlatformsData {
235235
projectRoot: "",
236236
deviceBuildOutputPath: "",
237237
validPackageNamesForDevice: [],
238-
frameworkFilesExtensions: []
238+
frameworkFilesExtensions: [],
239+
appDestinationDirectoryPath: "",
240+
appResourcesDestinationDirectoryPath: ""
239241
};
240242
}
241243

@@ -254,7 +256,9 @@ export class PlatformProjectServiceStub implements IPlatformProjectService {
254256
projectRoot: "",
255257
deviceBuildOutputPath: "",
256258
validPackageNamesForDevice: [],
257-
frameworkFilesExtensions: []
259+
frameworkFilesExtensions: [],
260+
appDestinationDirectoryPath: "",
261+
appResourcesDestinationDirectoryPath: ""
258262
};
259263
}
260264
validate(): IFuture<void> {

0 commit comments

Comments
 (0)