Skip to content

Commit 60ee551

Browse files
fix: incorrect project is created when template does not have App_Resources
In case the project does not have App_Resources dir, CLI tries to extract the content of the default template's App_Resources. However, as the structure of the default template has changed (to v2), CLI extracts the resources to incorrect location. This makes the newly created project unbuildable. In order to fix this behavior and allow the default template to specify where App_Resources are located (via nsconfig.json file), change the logic in CLI to extract the default template to a temp location, read where the App_Resources is located and after that copy the content to the new project.
1 parent 7ea0239 commit 60ee551

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/services/project-service.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as shelljs from "shelljs";
44
import { format } from "util";
55
import { exported } from "../common/decorators";
66
import { Hooks, TemplatesV2PackageJsonKeysToRemove } from "../constants";
7+
import * as temp from "temp";
78

89
export class ProjectService implements IProjectService {
910

@@ -131,14 +132,16 @@ export class ProjectService implements IProjectService {
131132

132133
private async ensureAppResourcesExist(projectDir: string): Promise<void> {
133134
const projectData = this.$projectDataService.getProjectData(projectDir);
134-
const appPath = projectData.getAppDirectoryPath(projectDir);
135135
const appResourcesDestinationPath = projectData.getAppResourcesDirectoryPath(projectDir);
136136

137137
if (!this.$fs.exists(appResourcesDestinationPath)) {
138138
this.$fs.createDirectory(appResourcesDestinationPath);
139-
139+
const tempDir = temp.mkdirSync("ns-default-template");
140140
// the template installed doesn't have App_Resources -> get from a default template
141-
await this.$pacoteService.extractPackage(constants.RESERVED_TEMPLATE_NAMES["default"], appPath, { filter: (name: string, entry: any) => entry.path.indexOf(constants.APP_RESOURCES_FOLDER_NAME) !== -1 });
141+
await this.$pacoteService.extractPackage(constants.RESERVED_TEMPLATE_NAMES["default"], tempDir);
142+
const templateProjectData = this.$projectDataService.getProjectData(tempDir);
143+
const templateAppResourcesDir = templateProjectData.getAppResourcesDirectoryPath(tempDir);
144+
this.$fs.copyFile(path.join(templateAppResourcesDir, "*"), appResourcesDestinationPath);
142145
}
143146
}
144147

0 commit comments

Comments
 (0)