Skip to content

Do not crash application after upgrade to 1.3.0 #992

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

Merged
merged 1 commit into from
Oct 1, 2015
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
1 change: 1 addition & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export let APP_RESOURCES_FOLDER_NAME = "App_Resources";
export let PROJECT_FRAMEWORK_FOLDER_NAME = "framework";
export let NATIVESCRIPT_KEY_NAME = "nativescript";
export let NODE_MODULES_FOLDER_NAME = "node_modules";
export let TNS_MODULES_FOLDER_NAME = "tns_modules";
export let TNS_CORE_MODULES_NAME = "tns-core-modules";
export let PACKAGE_JSON_FILE_NAME = "package.json";
export let NODE_MODULE_CACHE_PATH_KEY_NAME = "node-modules-cache-path";
Expand Down
1 change: 1 addition & 0 deletions lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface IProjectData {
platformsDir: string;
projectFilePath: string;
projectId?: string;
dependencies: any;
}

interface IProjectDataService {
Expand Down
5 changes: 4 additions & 1 deletion lib/project-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class ProjectData implements IProjectData {
public projectFilePath: string;
public projectId: string;
public projectName: string;
public dependencies: any;

constructor(private $fs: IFileSystem,
private $errors: IErrors,
Expand All @@ -31,8 +32,9 @@ export class ProjectData implements IProjectData {
let data: any = null;

if (this.$fs.exists(this.projectFilePath).wait()) {
let fileContent: any = null;
try {
let fileContent = this.$fs.readJson(this.projectFilePath).wait();
fileContent = this.$fs.readJson(this.projectFilePath).wait();
data = fileContent[this.$staticConfig.CLIENT_NAME_KEY_IN_PROJECT_FILE];
} catch (err) {
this.$errors.fail({formatStr: "The project file %s is corrupted." + os.EOL +
Expand All @@ -44,6 +46,7 @@ export class ProjectData implements IProjectData {

if(data) {
this.projectId = data.id;
this.dependencies = fileContent.dependencies;
} else { // This is the case when we have package.json file but nativescipt key is not presented in it
this.tryToUpgradeProject().wait();
}
Expand Down
16 changes: 9 additions & 7 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,20 +157,22 @@ export class PlatformService implements IPlatformService {
let contents = this.$fs.readDirectory(appDestinationDirectoryPath).wait();

_(contents)
.filter(directoryName => directoryName !== "tns_modules")
.filter(directoryName => directoryName !== constants.TNS_MODULES_FOLDER_NAME)
.each(directoryName => this.$fs.deleteDirectory(path.join(appDestinationDirectoryPath, directoryName)).wait())
.value();

// Copy all files from app dir, but make sure to exclude tns_modules
let sourceFiles = this.$fs.readDirectory(appSourceDirectoryPath).wait();
if(_.contains(sourceFiles, "tns_modules")) {
this.$logger.warn("You have tns_modules dir in your app folder. It will not be used and you can safely remove it.");
let hasTnsModulesInAppFolder = _.contains(sourceFiles, constants.TNS_MODULES_FOLDER_NAME);
if(hasTnsModulesInAppFolder && this.$projectData.dependencies && this.$projectData.dependencies[constants.TNS_CORE_MODULES_NAME]) {
this.$logger.warn("You have tns_modules dir in your app folder and tns-core-modules in your package.json file. Tns_modules dir in your app folder will not be used and you can safely remove it.");
sourceFiles.filter(source => source !== constants.TNS_MODULES_FOLDER_NAME)
.map(source => path.join(appSourceDirectoryPath, source))
.forEach(source => shell.cp("-Rf", source, appDestinationDirectoryPath));
} else {
shell.cp("-Rf", path.join(appSourceDirectoryPath, "*"), appDestinationDirectoryPath);
}

sourceFiles.filter(source => source !== "tns_modules")
.map(source => path.join(appSourceDirectoryPath, source))
.forEach(source => shell.cp("-Rf", source, appDestinationDirectoryPath));

// Copy App_Resources to project root folder
this.$fs.ensureDirectoryExists(platformData.platformProjectService.getAppResourcesDestinationDirectoryPath().wait()).wait(); // Should be deleted
let appResourcesDirectoryPath = path.join(appDestinationDirectoryPath, constants.APP_RESOURCES_FOLDER_NAME);
Expand Down
1 change: 1 addition & 0 deletions test/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ export class ProjectDataStub implements IProjectData {
}
projectFilePath: string;
projectId: string;
dependencies: any;
}

export class PlatformsDataStub implements IPlatformsData {
Expand Down