Skip to content

Commit

Permalink
Merge pull request #108 from onmodulus/feature/use-meteor-version
Browse files Browse the repository at this point in the history
Feature/use meteor version
  • Loading branch information
Matt Hernandez committed Feb 11, 2015
2 parents d8574b9 + f83c660 commit b52b225
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 21 deletions.
25 changes: 9 additions & 16 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,21 @@ program
.option('-d, --debug', 'Bundle in debug mode (don\'t minify, etc).', false)
.parse(process.argv);

var appName = program.app_name;
var debug = program.debug;
var input = process.cwd();
var output = program.output;
var release = program.release;
var tarball = program.tarball;
program.output = program.output || path.join(process.cwd(), '.demeteorized');

output = output || path.join(process.cwd(), '.demeteorized');

if (release) {
console.log('Release:', release);
if (program.release) {
console.log('Release:', program.release);
}

demeteorizer.on('progress', console.log.bind(console));

var options = {
appName : appName,
debug : debug,
input : input,
output : output,
release : release,
tarball : tarball
appName : program.app_name,
debug : program.debug,
input : process.cwd(),
output : program.output,
release : program.release,
tarball : program.tarball
};

demeteorizer.convert(
Expand Down
29 changes: 26 additions & 3 deletions lib/demeteorizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ Demeteorizer.prototype.createPackageJSON = function (context, callback) {

var input = context.options.input;
var appName = context.options.appName;
var bootPath = path.resolve(
context.options.output, 'programs', 'server', 'boot.js');

// Set the app name to the name of the input folder.
var name = path.basename(input);
Expand All @@ -370,9 +372,30 @@ Demeteorizer.prototype.createPackageJSON = function (context, callback) {
packageJSON.scripts = {
start: 'node main.js'
};
// FIXME: this is a hack to avoid defaulting to node@0.10.34 which breaks some
// timer code.
packageJSON.engines = { node: '0.10.33' };

try {
// Read boot.js to find the MIN_NODE_VERSION; use that version as the node
// version of the project.
fs.readFileSync(bootPath).toString().split('\n').some(function (line) {
if (line.indexOf('MIN_NODE_VERSION') >= 0) {
packageJSON.engines = {
node: line.split(' ')[3].replace(/[v;']/g, '')
};

return true;
}
});
} catch (err) {
this.emit('progress', 'failed to parse node version, defaulting to 0.10.33');
packageJSON.engines = { node: '0.10.33' };
}

// This happens if boot.js is parsed successfully, but the version wasn't
// found in the file.
if (!packageJSON.engines) {
packageJSON.engines = { node: '0.10.33' };
}

packageJSON.dependencies = context.dependencies;

fs.writeFileSync(context.paths.package_json, JSON.stringify(packageJSON, null, 2));
Expand Down
34 changes: 32 additions & 2 deletions spec/demeteorizer-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,47 @@ describe('demeteorizer lib', function () {
});

describe('#createPackageJSON', function () {
it('should create package.json with the correct fields', function () {
before(function () {
context.paths = {};
context.paths.package_json = './package.json';
});

it('should create package.json with the correct node version', function () {
fsStub.readFileSync =
sinon.stub().returns('var MIN_NODE_VERSION = \'v0.12.0\';');

fsStub.writeFileSync = function (path, data) {
path.should.equal('./package.json');
JSON.parse(data).engines.node.should.exist;
JSON.parse(data).engines.node.should.equal('0.12.0');
};

demeteorizer.createPackageJSON(context, new Function());
});
});

it('should default the node version if version not found boot.js', function () {
fsStub.readFileSync =
sinon.stub().returns('');

fsStub.writeFileSync = function (path, data) {
path.should.equal('./package.json');
JSON.parse(data).engines.node.should.exist;
JSON.parse(data).engines.node.should.equal('0.10.33');
};

demeteorizer.createPackageJSON(context, new Function());
});

it('should default the node version if boot.js parse fails', function () {
fsStub.readFileSync = function () { throw new Error('ENOENT'); };

fsStub.writeFileSync = function (path, data) {
path.should.equal('./package.json');
JSON.parse(data).engines.node.should.exist;
JSON.parse(data).engines.node.should.equal('0.10.33');
};

demeteorizer.createPackageJSON(context, new Function());
});
});
});

0 comments on commit b52b225

Please sign in to comment.