Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add App_Resources from default template if missing #2513 #2609

Merged
merged 1 commit into from
Mar 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these could be const instead of let

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree const is the better approach. I'll leave it as let now, following the whole style of the file - where all other same-constructed paths are with let. I'll take care to use const in the future :)

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here - these could be const

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