-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6494 from RocketChat/version-to-js
Convert Version Package to JS
- Loading branch information
Showing
3 changed files
with
76 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import {exec} from 'child_process'; | ||
import os from 'os'; | ||
import Future from 'fibers/future'; | ||
import async from 'async'; | ||
|
||
class VersionCompiler { | ||
processFilesForTarget(files) { | ||
const future = new Future; | ||
const processFile = function(file, cb) { | ||
if (!file.getDisplayPath().match(/rocketchat\.info$/)) { | ||
return cb(); | ||
} | ||
|
||
let output = JSON.parse(file.getContentsAsString()); | ||
output.build = { | ||
date: new Date().toISOString(), | ||
nodeVersion: process.version, | ||
arch: process.arch, | ||
platform: process.platform, | ||
osRelease: os.release(), | ||
totalMemory: os.totalmem(), | ||
freeMemory: os.freemem(), | ||
cpus: os.cpus().length | ||
}; | ||
|
||
if (process.env.TRAVIS_BUILD_NUMBER) { | ||
output.travis = { | ||
buildNumber: process.env.TRAVIS_BUILD_NUMBER, | ||
branch: process.env.TRAVIS_BRANCH, | ||
tag: process.env.TRAVIS_TAG | ||
}; | ||
} | ||
|
||
exec('git log --pretty=format:\'%H%n%ad%n%an%n%s\' -n 1', function(err, result) { | ||
if (err == null) { | ||
result = result.split('\n'); | ||
output.commit = { | ||
hash: result.shift(), | ||
date: result.shift(), | ||
author: result.shift(), | ||
subject: result.join('\n') | ||
}; | ||
} | ||
|
||
exec('git describe --abbrev=0 --tags', function(err, result) { | ||
if (err == null && output.commit != null) { | ||
output.commit.tag = result.replace('\n', ''); | ||
} | ||
|
||
exec('git rev-parse --abbrev-ref HEAD', function(err, result) { | ||
if (err == null && output.commit != null) { | ||
output.commit.branch = result.replace('\n', ''); | ||
} | ||
output = `RocketChat.Info = ${ JSON.stringify(output, null, 4) };`; | ||
file.addJavaScript({ | ||
data: output, | ||
path: `${ file.getPathInPackage() }.js` | ||
}); | ||
cb(); | ||
}); | ||
}); | ||
}); | ||
}; | ||
|
||
async.each(files, processFile, future.resolver()); | ||
return future.wait(); | ||
} | ||
} | ||
|
||
Plugin.registerCompiler({ | ||
extensions: ['info'] | ||
}, function() { | ||
return new VersionCompiler(); | ||
}); |