-
-
Notifications
You must be signed in to change notification settings - Fork 197
Fix update #318
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
Fix update #318
Changes from 4 commits
0f5ae7b
df49daa
f46073f
2ad0926
d8ae20a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -310,7 +310,8 @@ export class PlatformService implements IPlatformService { | |
this.$errors.fail("No platform specified.") | ||
} | ||
|
||
platform = platform.toLowerCase(); | ||
var parts = platform.split("@"); | ||
platform = parts[0].toLowerCase(); | ||
|
||
if (!this.isValidPlatform(platform)) { | ||
this.$errors.fail("Invalid platform %s. Valid platforms are %s.", platform, helpers.formatListOfNames(this.$platformsData.platformsNames)); | ||
|
@@ -442,19 +443,28 @@ export class PlatformService implements IPlatformService { | |
var currentVersion = data && data.version ? data.version : "0.2.0"; | ||
var newVersion = version || this.$npm.getLatestVersion(platformData.frameworkPackageName).wait(); | ||
|
||
if(!semver.valid(newVersion)) { | ||
this.$errors.fail("The version %s is not valid. The version should consists from 3 parts seperated by dot.", newVersion); | ||
} | ||
if(platformData.platformProjectService.canUpdatePlatform(currentVersion, newVersion).wait()) { | ||
|
||
if(semver.gt(currentVersion, newVersion)) { // Downgrade | ||
var isUpdateConfirmed = this.$prompter.confirm("You are going to update to lower version. Are you sure?", () => "n").wait(); | ||
if(isUpdateConfirmed) { | ||
if(!semver.valid(newVersion)) { | ||
this.$errors.fail("The version %s is not valid. The version should consists from 3 parts separated by dot.", newVersion); | ||
} | ||
|
||
if(semver.gt(currentVersion, newVersion)) { // Downgrade | ||
var isUpdateConfirmed = this.$prompter.confirm("You are going to update to lower version. Are you sure?", () => "n").wait(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This message sounds weird to me. @ikoevska, any suggestions? |
||
if(isUpdateConfirmed) { | ||
this.updatePlatformCore(platformData, currentVersion, newVersion).wait(); | ||
} | ||
} else if(semver.eq(currentVersion, newVersion)) { | ||
this.$errors.fail("Current and new version are the same."); | ||
} else { | ||
this.updatePlatformCore(platformData, currentVersion, newVersion).wait(); | ||
} | ||
} else if(semver.eq(currentVersion, newVersion)) { | ||
this.$errors.fail("Current and new version are the same."); | ||
} else { | ||
this.updatePlatformCore(platformData, currentVersion, newVersion).wait(); | ||
var isUpdateConfirmed = this.$prompter.confirm(util.format("We need to override xcodeproj file. The old one will be saved at %s Are you sure?", options.profileDir), () => "y").wait(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing full stop after %s |
||
if(isUpdateConfirmed) { | ||
platformData.platformProjectService.updatePlatform(currentVersion, newVersion).wait(); | ||
this.updatePlatformCore(platformData, currentVersion, newVersion).wait(); | ||
} | ||
} | ||
|
||
}).future<void>()(); | ||
|
@@ -463,16 +473,36 @@ export class PlatformService implements IPlatformService { | |
private updatePlatformCore(platformData: IPlatformData, currentVersion: string, newVersion: string): IFuture<void> { | ||
return (() => { | ||
// Remove old framework files | ||
var oldFrameworkFiles = this.getFrameworkFiles(platformData, currentVersion).wait(); | ||
_.each(oldFrameworkFiles, file => { | ||
this.$fs.deleteFile(path.join(platformData.projectRoot, file)).wait(); | ||
var oldFrameworkData = this.getFrameworkFiles(platformData, currentVersion).wait(); | ||
|
||
_.each(oldFrameworkData.frameworkFiles, file => { | ||
var fileToDelete = path.join(platformData.projectRoot, file); | ||
this.$logger.trace("Deleting %s", fileToDelete); | ||
this.$fs.deleteFile(fileToDelete).wait(); | ||
}); | ||
|
||
_.each(oldFrameworkData.frameworkDirectories, dir => { | ||
var dirToDelete = path.join(platformData.projectRoot, dir); | ||
this.$logger.trace("Deleting %s", dirToDelete); | ||
this.$fs.deleteDirectory(dirToDelete).wait(); | ||
}); | ||
|
||
// Add new framework files | ||
var newFrameworkFiles = this.getFrameworkFiles(platformData, newVersion).wait(); | ||
var cacheDirectoryPath = this.getNpmCacheDirectoryCore(platformData.frameworkPackageName, newVersion); | ||
_.each(newFrameworkFiles, file => { | ||
shell.cp("-f", path.join(cacheDirectoryPath, file), path.join(platformData.projectRoot, file)); | ||
var newFrameworkData = this.getFrameworkFiles(platformData, newVersion).wait(); | ||
var cacheDirectoryPath = this.$npm.getCachedPackagePath(platformData.frameworkPackageName, newVersion); | ||
|
||
_.each(newFrameworkData.frameworkFiles, file => { | ||
var sourceFile = path.join(cacheDirectoryPath, constants.PROJECT_FRAMEWORK_FOLDER_NAME, file); | ||
var destinationFile = path.join(platformData.projectRoot, file); | ||
this.$logger.trace("Replacing %s with %s", sourceFile, destinationFile); | ||
shell.cp("-f", sourceFile, destinationFile); | ||
}); | ||
|
||
_.each(newFrameworkData.frameworkDirectories, dir => { | ||
var sourceDirectory = path.join(cacheDirectoryPath, constants.PROJECT_FRAMEWORK_FOLDER_NAME, dir); | ||
var destinationDirectory = path.join(platformData.projectRoot, dir); | ||
this.$logger.trace("Copying %s to %s", sourceDirectory, destinationDirectory); | ||
shell.cp("-fR", path.join(sourceDirectory, "*"), destinationDirectory); | ||
}); | ||
|
||
// Update .tnsproject file | ||
|
@@ -484,32 +514,35 @@ export class PlatformService implements IPlatformService { | |
}).future<void>()(); | ||
} | ||
|
||
private getFrameworkFiles(platformData: IPlatformData, version: string): IFuture<string[]> { | ||
private getFrameworkFiles(platformData: IPlatformData, version: string): IFuture<any> { | ||
return (() => { | ||
var npmCacheDirectoryPath = this.getNpmCacheDirectory(platformData.frameworkPackageName, version).wait(); | ||
var allFiles = this.$fs.enumerateFilesInDirectorySync(npmCacheDirectoryPath); | ||
var cachedPackagePath = this.$npm.getCachedPackagePath(platformData.frameworkPackageName, version); | ||
this.ensurePackageIsCached(cachedPackagePath, platformData.frameworkPackageName, version).wait(); | ||
|
||
var allFiles = this.$fs.enumerateFilesInDirectorySync(cachedPackagePath); | ||
var filteredFiles = _.filter(allFiles, file => _.contains(platformData.frameworkFilesExtensions, path.extname(file))); | ||
var relativeToCacheFiles = _.map(filteredFiles, file => file.substr(npmCacheDirectoryPath.length)); | ||
|
||
return relativeToCacheFiles; | ||
var allFrameworkDirectories = _.map(this.$fs.readDirectory(path.join(cachedPackagePath, constants.PROJECT_FRAMEWORK_FOLDER_NAME)).wait(), dir => path.join(cachedPackagePath, constants.PROJECT_FRAMEWORK_FOLDER_NAME, dir)); | ||
var filteredFrameworkDirectories = _.filter(allFrameworkDirectories, dir => this.$fs.getFsStats(dir).wait().isDirectory() && (_.contains(platformData.frameworkFilesExtensions, path.extname(dir)) || _.contains(platformData.frameworkDirectoriesNames, path.basename(dir)))); | ||
|
||
}).future<string[]>()(); | ||
return { | ||
frameworkFiles: this.mapFrameworkFiles(cachedPackagePath, filteredFiles), | ||
frameworkDirectories: this.mapFrameworkFiles(cachedPackagePath, filteredFrameworkDirectories) | ||
} | ||
|
||
}).future<any>()(); | ||
} | ||
|
||
private getNpmCacheDirectory(packageName: string, version: string): IFuture<string> { | ||
private ensurePackageIsCached(cachedPackagePath: string, packageName: string, version: string): IFuture<void> { | ||
return (() => { | ||
var npmCacheDirectoryPath = this.getNpmCacheDirectoryCore(packageName, version); | ||
|
||
if(!this.$fs.exists(npmCacheDirectoryPath).wait()) { | ||
if(!this.$fs.exists(cachedPackagePath).wait()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider removing this check. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking about it, but I can't figure out a better solution. I'm opened to any suggestions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After talking in person, we agreed on the current code. |
||
this.$npm.addToCache(packageName, version).wait(); | ||
} | ||
|
||
return npmCacheDirectoryPath; | ||
}).future<string>()(); | ||
}).future<void>()(); | ||
} | ||
|
||
private getNpmCacheDirectoryCore(packageName: string, version: string): string { | ||
return path.join(this.$npm.getCacheRootPath(), packageName, version, "package"); | ||
private mapFrameworkFiles(npmCacheDirectoryPath: string, files: string[]): string[] { | ||
return _.map(files, file => file.substr(npmCacheDirectoryPath.length + constants.PROJECT_FRAMEWORK_FOLDER_NAME.length + 1)) | ||
} | ||
} | ||
$injector.register("platformService", PlatformService); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commented code, consider removing it entirely