Skip to content

Commit 69f54b0

Browse files
committed
Code review changes
1 parent d17afa9 commit 69f54b0

File tree

4 files changed

+41
-36
lines changed

4 files changed

+41
-36
lines changed

lib/common

lib/definitions/project.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ interface IProjectData {
2222

2323
interface IProjectTemplatesService {
2424
defaultTemplatePath: IFuture<string>;
25-
androidFrameworkPath: IFuture<string>;
25+
getAndroidFrameworkPath(whereToInstall: string): IFuture<string>
2626
}

lib/services/project-service.ts

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,21 @@ export class ProjectService implements IProjectService {
5454

5555
private getProjectData(): IFuture<IProjectData> {
5656
return(() => {
57-
var projectFilePath = path.join(this.projectDir, this.$config.PROJECT_FILE_NAME);
58-
var projectData:IProjectData = {
59-
projectDir: this.projectDir,
60-
platformsDir: path.join(this.projectDir, "platforms"),
61-
projectFilePath: path.join(this.projectDir, this.$config.PROJECT_FILE_NAME)
62-
};
63-
64-
if (this.$fs.exists(projectFilePath).wait()) {
65-
var fileContent = this.$fs.readJson(projectFilePath).wait();
66-
projectData.projectId = fileContent.id;
67-
projectData.projectName = path.basename(this.projectDir);
57+
var projectData: IProjectData = null;
58+
59+
if(this.projectDir) {
60+
projectData = {
61+
projectDir: this.projectDir,
62+
platformsDir: path.join(this.projectDir, "platforms"),
63+
projectFilePath: path.join(this.projectDir, this.$config.PROJECT_FILE_NAME)
64+
};
65+
var projectFilePath = path.join(this.projectDir, this.$config.PROJECT_FILE_NAME);
66+
67+
if (this.$fs.exists(projectFilePath).wait()) {
68+
var fileContent = this.$fs.readJson(projectFilePath).wait();
69+
projectData.projectId = fileContent.id;
70+
projectData.projectName = path.basename(this.projectDir);
71+
}
6872
}
6973

7074
return projectData;
@@ -239,7 +243,7 @@ export class ProjectService implements IProjectService {
239243
$injector.register("projectService", ProjectService);
240244

241245
class AndroidProjectService implements IPlatformProjectService {
242-
private cachedFrameworkDir: string = null;
246+
private frameworkDir: string = null;
243247

244248
constructor(private $fs: IFileSystem,
245249
private $errors: IErrors,
@@ -250,16 +254,18 @@ class AndroidProjectService implements IPlatformProjectService {
250254

251255
public createProject(projectData: IProjectData): IFuture<void> {
252256
return (() => {
257+
this.frameworkDir = this.getFrameworkDir(projectData).wait();
258+
253259
var packageName = projectData.projectId;
254260
var projectDir = path.join(projectData.projectDir, "platforms", "android");
255261

256262
this.validatePackageName(packageName);
257263
this.validateProjectName(projectData.projectName);
258264

259-
var targetApi = this.getTarget().wait();
260-
261265
this.checkRequirements().wait();
262266

267+
var targetApi = this.getTarget().wait();
268+
263269
// Log the values for project
264270
this.$logger.trace("Creating NativeScript project for the Android platform");
265271
this.$logger.trace("Path: %s", projectData.projectDir);
@@ -269,13 +275,15 @@ class AndroidProjectService implements IPlatformProjectService {
269275

270276
this.$logger.out("Copying template files...");
271277

272-
shell.cp("-r", path.join(this.frameworkDir.wait(), "assets"), projectDir);
273-
shell.cp("-r", path.join(this.frameworkDir.wait(), "gen"), projectDir);
274-
shell.cp("-r", path.join(this.frameworkDir.wait(), "libs"), projectDir);
275-
shell.cp("-r", path.join(this.frameworkDir.wait(), "res"), projectDir);
278+
shell.cp("-r", path.join(this.frameworkDir, "assets"), projectDir);
279+
shell.cp("-r", path.join(this.frameworkDir, "gen"), projectDir);
280+
shell.cp("-r", path.join(this.frameworkDir, "libs"), projectDir);
281+
shell.cp("-r", path.join(this.frameworkDir, "res"), projectDir);
282+
283+
shell.cp("-f", path.join(this.frameworkDir, ".project"), projectDir);
284+
shell.cp("-f", path.join(this.frameworkDir, "AndroidManifest.xml"), projectDir);
276285

277-
shell.cp("-f", path.join(this.frameworkDir.wait(), ".project"), projectDir);
278-
shell.cp("-f", path.join(this.frameworkDir.wait(), "AndroidManifest.xml"), projectDir);
286+
this.$fs.deleteDirectory(path.join(projectData.platformsDir, "android", "node_modules")).wait();
279287

280288
// Interpolate the activity name and package
281289
var stringsFilePath = path.join(projectDir, 'res', 'values', 'strings.xml');
@@ -327,21 +335,16 @@ class AndroidProjectService implements IPlatformProjectService {
327335
}
328336
}
329337

330-
private get frameworkDir(): IFuture<string> {
338+
private getFrameworkDir(projectData: IProjectData): IFuture<string> {
331339
return(() => {
332-
if(!this.cachedFrameworkDir) {
333-
var androidFrameworkPath = this.$projectTemplatesService.androidFrameworkPath.wait();
334-
this.cachedFrameworkDir = path.join(androidFrameworkPath, ProjectService.PROJECT_FRAMEWORK_DIR);
335-
}
336-
337-
return this.cachedFrameworkDir;
338-
340+
var androidFrameworkPath = this.$projectTemplatesService.getAndroidFrameworkPath(path.join(projectData.platformsDir, "android")).wait();
341+
return path.join(androidFrameworkPath, "framework");
339342
}).future<string>()();
340343
}
341344

342345
private getTarget(): IFuture<string> {
343346
return (() => {
344-
var projectPropertiesFilePath = path.join(this.frameworkDir.wait(), "project.properties");
347+
var projectPropertiesFilePath = path.join(this.frameworkDir, "project.properties");
345348

346349
if (this.$fs.exists(projectPropertiesFilePath).wait()) {
347350
var properties = this.$propertiesParser.createEditor(projectPropertiesFilePath).wait();

lib/services/project-templates-service.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,23 @@ export class ProjectTemplatesService implements IProjectTemplatesService {
2222
return this.downloadNpmPackage(ProjectTemplatesService.NPM_DEFAULT_TEMPLATE_NAME);
2323
}
2424

25-
public get androidFrameworkPath(): IFuture<string> {
26-
return this.downloadNpmPackage(ProjectTemplatesService.NPM_ANDROID_BRIDGE_NAME);
25+
public getAndroidFrameworkPath(where?: string): IFuture<string> {
26+
return this.downloadNpmPackage(ProjectTemplatesService.NPM_ANDROID_BRIDGE_NAME, where);
2727
}
2828

29-
private downloadNpmPackage(packageName: string): IFuture<string> {
29+
private downloadNpmPackage(packageName: string, where?: string): IFuture<string> {
3030
return (() => {
3131
try {
3232
this.$npm.load().wait();
33-
this.$npm.install(npm.cache, packageName).wait();
33+
var location = where || npm.cache;
34+
this.$npm.install(location, packageName).wait();
3435
} catch (error) {
3536
this.$logger.debug(error);
3637
this.$errors.fail(ProjectTemplatesService.NPM_LOAD_FAILED);
3738
}
3839

39-
return path.join(npm.cache, "node_modules", packageName);
40+
return path.join(location, "node_modules", packageName);
41+
4042
}).future<string>()();
4143
}
4244
}

0 commit comments

Comments
 (0)