2015-10-16 08:54:09 +08:00
|
|
|
fs = require 'fs'
|
|
|
|
path = require 'path'
|
|
|
|
|
|
|
|
module.exports = (grunt) ->
|
|
|
|
{spawn} = require('./task-helpers')(grunt)
|
|
|
|
|
|
|
|
getVersion = (callback) ->
|
2015-10-17 05:01:29 +08:00
|
|
|
onBuildMachine = process.env.JANKY_SHA1 and process.env.JANKY_BRANCH is 'master'
|
|
|
|
onWindows = process.platform is 'win32'
|
2015-10-16 08:54:09 +08:00
|
|
|
inRepository = fs.existsSync(path.resolve(__dirname, '..', '..', '.git'))
|
2015-11-12 02:25:11 +08:00
|
|
|
{version} = require(path.join(grunt.config.get('nylasGruntConfig.appDir'), 'package.json'))
|
2015-10-17 05:01:29 +08:00
|
|
|
if onBuildMachine or onWindows or not inRepository
|
2015-10-16 08:54:09 +08:00
|
|
|
callback(null, version)
|
|
|
|
else
|
|
|
|
cmd = 'git'
|
|
|
|
args = ['rev-parse', '--short', 'HEAD']
|
|
|
|
spawn {cmd, args}, (error, {stdout}={}, code) ->
|
|
|
|
commitHash = stdout?.trim?()
|
|
|
|
combinedVersion = "#{version}-#{commitHash}"
|
|
|
|
callback(error, combinedVersion)
|
|
|
|
|
|
|
|
grunt.registerTask 'set-version', 'Set the version in the plist and package.json', ->
|
|
|
|
done = @async()
|
|
|
|
|
|
|
|
getVersion (error, version) ->
|
|
|
|
if error?
|
|
|
|
done(error)
|
|
|
|
return
|
|
|
|
|
2015-11-12 02:25:11 +08:00
|
|
|
appDir = grunt.config.get('nylasGruntConfig.appDir')
|
2015-10-16 08:54:09 +08:00
|
|
|
|
|
|
|
# Replace version field of package.json.
|
|
|
|
packageJsonPath = path.join(appDir, 'package.json')
|
|
|
|
packageJson = require(packageJsonPath)
|
|
|
|
packageJson.version = version
|
|
|
|
packageJsonString = JSON.stringify(packageJson)
|
|
|
|
fs.writeFileSync(packageJsonPath, packageJsonString)
|
|
|
|
|
|
|
|
if process.platform is 'darwin'
|
|
|
|
cmd = 'script/set-version'
|
2015-11-12 02:25:11 +08:00
|
|
|
args = [grunt.config.get('nylasGruntConfig.buildDir'), version]
|
2015-10-16 08:54:09 +08:00
|
|
|
spawn {cmd, args}, (error, result, code) -> done(error)
|
|
|
|
|
|
|
|
else if process.platform is 'win32'
|
2015-11-12 02:25:11 +08:00
|
|
|
shellAppDir = grunt.config.get('nylasGruntConfig.shellAppDir')
|
2015-10-16 08:54:09 +08:00
|
|
|
shellExePath = path.join(shellAppDir, 'nylas.exe')
|
|
|
|
|
|
|
|
strings =
|
|
|
|
CompanyName: 'Nylas, Inc.'
|
|
|
|
FileDescription: 'Nylas'
|
|
|
|
LegalCopyright: 'Copyright (C) 2014-2015 Nylas, Inc. All rights reserved'
|
|
|
|
ProductName: 'Nylas'
|
|
|
|
ProductVersion: version
|
|
|
|
|
|
|
|
rcedit = require('rcedit')
|
|
|
|
rcedit(shellExePath, {'version-string': strings}, done)
|
|
|
|
else
|
|
|
|
done()
|