Use new runas API for grunt install on Windows.

This commit is contained in:
Cheng Zhao
2014-02-12 22:23:14 +08:00
parent d8737ba4a1
commit 0419ae8712

View File

@@ -1,24 +1,20 @@
path = require 'path'
runas = null
module.exports = (grunt) ->
{cp, mkdir, rm, spawn} = require('./task-helpers')(grunt)
{cp, mkdir, rm} = require('./task-helpers')(grunt)
grunt.registerTask 'install', 'Install the built application', ->
installDir = grunt.config.get('atom.installDir')
shellAppDir = grunt.config.get('atom.shellAppDir')
if process.platform is 'win32'
done = @async()
runas = require 'runas'
runas ?= require 'runas'
copyFolder = path.resolve 'script', 'copy-folder.cmd'
# cmd /c ""script" "source" "destination""
arg = "/c \"\"#{copyFolder}\" \"#{shellAppDir}\" \"#{installDir}\"\""
if runas('cmd', [arg], hide: true) isnt 0
done("Failed to copy #{shellAppDir} to #{installDir}")
if runas('cmd', ['/c', copyFolder, shellAppDir, installDir], admin: true) isnt 0
grunt.log.error("Failed to copy #{shellAppDir} to #{installDir}")
createShortcut = path.resolve 'script', 'create-shortcut.cmd'
args = ['/c', createShortcut, path.join(installDir, 'atom.exe'), 'Atom']
spawn {cmd: 'cmd', args}, done
runas('cmd', ['/c', createShortcut, path.join(installDir, 'atom.exe'), 'Atom'])
else
rm installDir
mkdir path.dirname(installDir)