Skip to content

Commit

Permalink
add App_Resources from default template, if not found in the specifie…
Browse files Browse the repository at this point in the history
…d template #2513 (#2609)
  • Loading branch information
yyosifov authored Mar 15, 2017
1 parent 4cb7ebf commit 0d3e921
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/services/project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down Expand Up @@ -102,6 +104,27 @@ export class ProjectService implements IProjectService {
this.$fs.createDirectory(path.join(projectDir, "platforms"));
}

private async ensureAppResourcesExist(projectDir: string): Promise<void> {
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) {
Expand Down
29 changes: 29 additions & 0 deletions test/project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 0d3e921

Please sign in to comment.