diff --git a/lib/services/project-service.ts b/lib/services/project-service.ts index 681b74fd8d..e0c63728a4 100644 --- a/lib/services/project-service.ts +++ b/lib/services/project-service.ts @@ -48,6 +48,8 @@ export class ProjectService implements IProjectService { let templatePath = await this.$projectTemplatesService.prepareTemplate(selectedTemplate, projectDir); await this.extractTemplate(projectDir, templatePath); + await this.ensureAppResourcesExist(projectDir); + let packageName = constants.TNS_CORE_MODULES_NAME; await this.$npm.install(packageName, projectDir, { save: true, "save-exact": true }); @@ -102,6 +104,27 @@ export class ProjectService implements IProjectService { this.$fs.createDirectory(path.join(projectDir, "platforms")); } + private async ensureAppResourcesExist(projectDir: string): Promise { + let appPath = path.join(projectDir, constants.APP_FOLDER_NAME), + appResourcesDestinationPath = path.join(appPath, constants.APP_RESOURCES_FOLDER_NAME); + + if (!this.$fs.exists(appResourcesDestinationPath)) { + this.$fs.createDirectory(appResourcesDestinationPath); + + // the template installed doesn't have App_Resources -> get from a default template + let defaultTemplateName = constants.RESERVED_TEMPLATE_NAMES["default"]; + await this.$npm.install(defaultTemplateName, projectDir, { save: true, }); + let defaultTemplateAppResourcesPath = path.join(projectDir, constants.NODE_MODULES_FOLDER_NAME, + defaultTemplateName, constants.APP_RESOURCES_FOLDER_NAME); + + if (this.$fs.exists(defaultTemplateAppResourcesPath)) { + shelljs.cp('-R', defaultTemplateAppResourcesPath, appPath); + } + + await this.$npm.uninstall(defaultTemplateName, { save: true }, projectDir); + } + } + private removeMergedDependencies(projectDir: string, templatePackageJsonData: any): void { let extractedTemplatePackageJsonPath = path.join(projectDir, constants.APP_FOLDER_NAME, constants.PACKAGE_JSON_FILE_NAME); for (let key in templatePackageJsonData) { diff --git a/test/project-service.ts b/test/project-service.ts index 2136fc5f8f..bb2421bfc6 100644 --- a/test/project-service.ts +++ b/test/project-service.ts @@ -138,9 +138,12 @@ describe("Project Service Tests", () => { describe("project service integration tests", () => { let defaultTemplatePath: string; let defaultSpecificVersionTemplatePath: string; + let noAppResourcesTemplatePath: string; let angularTemplatePath: string; let typescriptTemplatePath: string; + const noAppResourcesTemplateName = "tns-template-hello-world-ts"; + before(async () => { let projectIntegrationTest = new ProjectIntegrationTest(); let fs: IFileSystem = projectIntegrationTest.testInjector.resolve("fs"); @@ -205,6 +208,23 @@ describe("Project Service Tests", () => { typescriptTemplatePath = path.join(typescriptTemplateDir, "node_modules", constants.RESERVED_TEMPLATE_NAMES["typescript"]); fs.deleteDirectory(path.join(typescriptTemplatePath, "node_modules")); + let noAppResourcesTemplateDir = temp.mkdirSync("noAppResources"); + fs.writeJson(path.join(noAppResourcesTemplateDir, "package.json"), { + "name": "blankTemplate", + "version": "1.0.0", + "description": "dummy", + "license": "MIT", + "readme": "dummy", + "repository": "dummy" + }); + + await npmInstallationManager.install(noAppResourcesTemplateName, noAppResourcesTemplateDir, { + dependencyType: "save", + version: "2.0.0" + }); + noAppResourcesTemplatePath = path.join(noAppResourcesTemplateDir, "node_modules", noAppResourcesTemplateName); + + fs.deleteDirectory(path.join(noAppResourcesTemplatePath, "node_modules")); }); it("creates valid project from default template", async () => { @@ -234,6 +254,15 @@ describe("Project Service Tests", () => { await projectIntegrationTest.assertProject(tempFolder, projectName, "org.nativescript.myapp", defaultSpecificVersionTemplatePath); }); + it("creates valid project from a template without App_Resources", async () => { + let projectIntegrationTest = new ProjectIntegrationTest(); + let tempFolder = temp.mkdirSync("project"); + let projectName = "myapp"; + + await projectIntegrationTest.createProject({ projectName: projectName, template: noAppResourcesTemplateName + "@2.0.0", pathToProject: tempFolder }); + await projectIntegrationTest.assertProject(tempFolder, projectName, "org.nativescript.myapp", noAppResourcesTemplatePath); + }); + it("creates valid project from typescript template", async () => { let projectIntegrationTest = new ProjectIntegrationTest(); let tempFolder = temp.mkdirSync("projectTypescript");