From 237bd2e40294d15062f5e40ba94788cd01074e38 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Fri, 4 Jun 2021 16:01:15 +0200 Subject: [PATCH] fix: properly handle missing App_Resources --- lib/project-data.ts | 9 ++--- lib/services/project-config-service.ts | 47 ++++++++++++++------------ lib/services/project-service.ts | 8 ++++- 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/lib/project-data.ts b/lib/project-data.ts index cb1794fb07..b72a9c6b32 100644 --- a/lib/project-data.ts +++ b/lib/project-data.ts @@ -257,10 +257,11 @@ export class ProjectData implements IProjectData { return this.nsConfig[constants.CONFIG_NS_APP_RESOURCES_ENTRY]; } - return path.join( - this.getAppDirectoryRelativePath(), - constants.APP_RESOURCES_FOLDER_NAME - ); + return constants.APP_RESOURCES_FOLDER_NAME; + // return path.join( + // this.getAppDirectoryRelativePath(), + // constants.APP_RESOURCES_FOLDER_NAME + // ); } public getAppDirectoryPath(projectDir?: string): string { diff --git a/lib/services/project-config-service.ts b/lib/services/project-config-service.ts index e17d926260..b44aa0b8bd 100644 --- a/lib/services/project-config-service.ts +++ b/lib/services/project-config-service.ts @@ -140,7 +140,7 @@ export default { this.$logger.trace( "Project Config Service using legacy configuration..." ); - if (!this.forceUsingLegacyConfig) { + if (!this.forceUsingLegacyConfig && info.hasNSConfig) { this.warnUsingLegacyNSConfig(); } return this.fallbackToLegacyNSConfig(info); @@ -329,31 +329,36 @@ export default { // ignore if the file doesn't exist } - const packageJson = this.$fs.readJson( - path.join(this.projectHelper.projectDir, "package.json") - ); + try { + const packageJson = this.$fs.readJson( + path.join(this.projectHelper.projectDir, "package.json") + ); - // add app id to additionalData for backwards compatibility - if ( - !NSConfig.id && - packageJson && - packageJson.nativescript && - packageJson.nativescript.id - ) { - const ids = packageJson.nativescript.id; - if (typeof ids === "string") { - additionalData.push({ - id: packageJson.nativescript.id, - }); - } else if (typeof ids === "object") { - for (const platform of Object.keys(ids)) { + // add app id to additionalData for backwards compatibility + if ( + !NSConfig.id && + packageJson && + packageJson.nativescript && + packageJson.nativescript.id + ) { + const ids = packageJson.nativescript.id; + if (typeof ids === "string") { additionalData.push({ - [platform]: { - id: packageJson.nativescript.id[platform], - }, + id: packageJson.nativescript.id, }); + } else if (typeof ids === "object") { + for (const platform of Object.keys(ids)) { + additionalData.push({ + [platform]: { + id: packageJson.nativescript.id[platform], + }, + }); + } } } + } catch (err) { + this.$logger.trace("failed to read package.json data for config", err); + // ignore if the file doesn't exist } return _.defaultsDeep({}, ...additionalData, NSConfig); diff --git a/lib/services/project-service.ts b/lib/services/project-service.ts index 3c24ece6f7..76307a95d2 100644 --- a/lib/services/project-service.ts +++ b/lib/services/project-service.ts @@ -108,7 +108,9 @@ export class ProjectService implements IProjectService { try { await this.$childProcess.exec(`git init ${projectDir}`); await this.$childProcess.exec(`git -C ${projectDir} add --all`); - await this.$childProcess.exec(`git -C ${projectDir} commit --no-verify -m "init"`); + await this.$childProcess.exec( + `git -C ${projectDir} commit --no-verify -m "init"` + ); } catch (err) { this.$logger.trace( "Unable to initialize git repository. Error is: ", @@ -218,6 +220,9 @@ export class ProjectService implements IProjectService { ); if (!this.$fs.exists(appResourcesDestinationPath)) { + this.$logger.trace( + "Project does not have App_Resources - fetching from default template." + ); this.$fs.createDirectory(appResourcesDestinationPath); const tempDir = await this.$tempService.mkdirSync("ns-default-template"); // the template installed doesn't have App_Resources -> get from a default template @@ -265,4 +270,5 @@ export class ProjectService implements IProjectService { }; } } + injector.register("projectService", ProjectService);