Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Version Package to JS #6494

Merged
merged 7 commits into from
Mar 29, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

76 changes: 76 additions & 0 deletions packages/rocketchat-version/plugin/compile-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//let Future, VersionCompiler, async, exec, os;
Copy link
Member

Choose a reason for hiding this comment

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

Can you remove this?


let VersionCompiler = undefined;
const exec = Npm.require('child_process').exec;
Copy link
Member

Choose a reason for hiding this comment

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

Here you can improve with const {exec} = Npm.require('child_process');

const os = Npm.require('os');
const Future = Npm.require('fibers/future');
const async = Npm.require('async');
Copy link
Member

Choose a reason for hiding this comment

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

You probably can use imports here:

import {exec} from 'child_process';
import os from 'os';
import Future from 'fibers/future';
import async from 'async');

Can you test this?


Plugin.registerCompiler({
Copy link
Member

Choose a reason for hiding this comment

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

Move this to after the class declaration

extensions: ['info']
}, function() {
return new VersionCompiler();
});

VersionCompiler = (function() {
function VersionCompiler() {}

VersionCompiler.prototype.processFilesForTarget = function(files) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you change this to the ES6 class format?

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
};
}
return 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')
};
}
return exec('git describe --abbrev=0 --tags', function(err, result) {
if (err == null && output.commit != null) {
output.commit.tag = result.replace('\n', '');
}
return 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`
});
return cb();
});
});
});
};
async.each(files, processFile, future.resolver());
return future.wait();
};

return VersionCompiler;

}());