Skip to content

Commit

Permalink
Merge pull request #6494 from RocketChat/version-to-js
Browse files Browse the repository at this point in the history
Convert Version Package to JS
  • Loading branch information
engelgabriel authored Mar 29, 2017
2 parents 55b14e3 + 3d01b25 commit f379571
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 64 deletions.
4 changes: 2 additions & 2 deletions packages/rocketchat-version/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Package.describe({

Package.registerBuildPlugin({
name: 'compileVersion',
use: ['coffeescript'],
sources: ['plugin/compile-version.coffee']
use: ['ecmascript'],
sources: ['plugin/compile-version.js']
});

Package.onUse(function(api) {
Expand Down
62 changes: 0 additions & 62 deletions packages/rocketchat-version/plugin/compile-version.coffee

This file was deleted.

74 changes: 74 additions & 0 deletions packages/rocketchat-version/plugin/compile-version.js
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();
});

0 comments on commit f379571

Please sign in to comment.