Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Support for downloading for a platform other than the host platform. #7

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ grunt.loadNpmTasks('grunt-download-atom-shell');
* `symbols` - Download debugging symbols instead of binaries, default to `false`.
* `rebuild` - Whether to rebuild native modules after atom-shell is downloaded.
* `apm` - The path to apm.
* `platform` - What platform to download (`win32`, `darwin`, `linux`). default is the host platform.
* `addPlatformToOutputPath` - Whether to put the downloaded atom-shell in a platform specific directory within outputDir. (e.g., outputDir/darwin/) Defaults to `false` for backwards compatibility.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can remove the addPlatformToOutputPath option and assume that it is false. It would still work with Atom because it sets atomShellDownloadDir = path.join(os.tmpdir(), 'atom-cached-atom-shells').


### Example

Expand Down
40 changes: 23 additions & 17 deletions tasks/download-atom-shell-task.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ module.exports = (grunt) ->
else
null

isAtomShellVersionCached = (downloadDir, version) ->
grunt.file.isFile path.join(downloadDir, version, 'version')
isAtomShellVersionCached = (downloadDir, version, platform) ->
grunt.file.isFile path.join(downloadDir, version, platform, 'version')

installAtomShell = (outputDir, downloadDir, version) ->
wrench.copyDirSyncRecursive path.join(downloadDir, version), outputDir,
installAtomShell = (outputDir, downloadDir, version, platform) ->
wrench.copyDirSyncRecursive path.join(downloadDir, version, platform), outputDir,
forceDelete: true
excludeHiddenUnix: false
inflateSymlinks: false
Expand All @@ -62,9 +62,9 @@ module.exports = (grunt) ->
callback null
unzipper.extract(path: directoryPath)

saveAtomShellToCache = (inputStream, outputDir, downloadDir, version, callback) ->
wrench.mkdirSyncRecursive path.join downloadDir, version
cacheFile = path.join downloadDir, version, 'atom-shell.zip'
saveAtomShellToCache = (inputStream, outputDir, downloadDir, version, platform, callback) ->
wrench.mkdirSyncRecursive path.join downloadDir, version, platform
cacheFile = path.join downloadDir, version, platform, 'atom-shell.zip'

unless process.platform is 'win32'
len = parseInt(inputStream.headers['content-length'], 10)
Expand Down Expand Up @@ -94,55 +94,61 @@ module.exports = (grunt) ->
@requiresConfig "#{@name}.version", "#{@name}.outputDir"
done = @async()

{version, outputDir, downloadDir, symbols, rebuild, apm} = grunt.config @name
{version, outputDir, downloadDir, symbols, rebuild, apm, platform, addPlatformToOutputPath} = grunt.config @name
version = "v#{version}"
downloadDir ?= path.join os.tmpdir(), 'downloaded-atom-shell'
symbols ?= false
rebuild ?= false
platform ?= process.platform
addPlatformToOutputPath ?= false

if addPlatformToOutputPath
downloadDir = path.join downloadDir, platform

apm ?= getApmPath()

# Do nothing if it's the expected version.
currentAtomShellVersion = getCurrentAtomShellVersion outputDir
return done() if currentAtomShellVersion is version

# Try find the cached one.
if isAtomShellVersionCached downloadDir, version
if isAtomShellVersionCached downloadDir, version, platform
grunt.verbose.writeln("Installing cached atom-shell #{version}.")
installAtomShell outputDir, downloadDir, version
installAtomShell outputDir, downloadDir, version, platform
rebuildNativeModules apm, currentAtomShellVersion, version, done
else
# Request the assets.
github = new GitHub({repo: 'atom/atom-shell'})
github.getReleases tag_name: version, (error, releases) ->
unless releases?.length > 0
grunt.log.error "Cannot find atom-shell #{version} from GitHub", error
grunt.log.error "Cannot find atom-shell #{version} for #{platform} from GitHub", error
return done false

# Which file to download
filename =
if symbols
"atom-shell-#{version}-#{process.platform}-symbols.zip"
"atom-shell-#{version}-#{platform}-symbols.zip"
else
"atom-shell-#{version}-#{process.platform}.zip"
"atom-shell-#{version}-#{platform}.zip"

# Find the asset of current platform.
found = false
for asset in releases[0].assets when asset.name is filename
found = true
github.downloadAsset asset, (error, inputStream) ->
if error?
grunt.log.error "Cannot download atom-shell #{version}", error
grunt.log.error "Cannot download atom-shell #{version} for #{platform}", error
return done false

# Save file to cache.
grunt.verbose.writeln "Downloading atom-shell #{version}."
saveAtomShellToCache inputStream, outputDir, downloadDir, version, (error) ->
saveAtomShellToCache inputStream, outputDir, downloadDir, version, platform, (error) ->
if error?
grunt.log.error "Failed to download atom-shell #{version}", error
grunt.log.error "Failed to download atom-shell #{version} for #{platform}", error
return done false

grunt.verbose.writeln "Installing atom-shell #{version}."
installAtomShell outputDir, downloadDir, version
installAtomShell outputDir, downloadDir, version, platform
rebuildNativeModules apm, currentAtomShellVersion, version, done

if not found
Expand Down