Skip to content

Commit b52b225

Browse files
author
Matt Hernandez
committed
Merge pull request #108 from onmodulus/feature/use-meteor-version
Feature/use meteor version
2 parents d8574b9 + f83c660 commit b52b225

File tree

3 files changed

+67
-21
lines changed

3 files changed

+67
-21
lines changed

lib/cli.js

+9-16
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,21 @@ program
1111
.option('-d, --debug', 'Bundle in debug mode (don\'t minify, etc).', false)
1212
.parse(process.argv);
1313

14-
var appName = program.app_name;
15-
var debug = program.debug;
16-
var input = process.cwd();
17-
var output = program.output;
18-
var release = program.release;
19-
var tarball = program.tarball;
14+
program.output = program.output || path.join(process.cwd(), '.demeteorized');
2015

21-
output = output || path.join(process.cwd(), '.demeteorized');
22-
23-
if (release) {
24-
console.log('Release:', release);
16+
if (program.release) {
17+
console.log('Release:', program.release);
2518
}
2619

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

2922
var options = {
30-
appName : appName,
31-
debug : debug,
32-
input : input,
33-
output : output,
34-
release : release,
35-
tarball : tarball
23+
appName : program.app_name,
24+
debug : program.debug,
25+
input : process.cwd(),
26+
output : program.output,
27+
release : program.release,
28+
tarball : program.tarball
3629
};
3730

3831
demeteorizer.convert(

lib/demeteorizer.js

+26-3
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ Demeteorizer.prototype.createPackageJSON = function (context, callback) {
352352

353353
var input = context.options.input;
354354
var appName = context.options.appName;
355+
var bootPath = path.resolve(
356+
context.options.output, 'programs', 'server', 'boot.js');
355357

356358
// Set the app name to the name of the input folder.
357359
var name = path.basename(input);
@@ -370,9 +372,30 @@ Demeteorizer.prototype.createPackageJSON = function (context, callback) {
370372
packageJSON.scripts = {
371373
start: 'node main.js'
372374
};
373-
// FIXME: this is a hack to avoid defaulting to [email protected] which breaks some
374-
// timer code.
375-
packageJSON.engines = { node: '0.10.33' };
375+
376+
try {
377+
// Read boot.js to find the MIN_NODE_VERSION; use that version as the node
378+
// version of the project.
379+
fs.readFileSync(bootPath).toString().split('\n').some(function (line) {
380+
if (line.indexOf('MIN_NODE_VERSION') >= 0) {
381+
packageJSON.engines = {
382+
node: line.split(' ')[3].replace(/[v;']/g, '')
383+
};
384+
385+
return true;
386+
}
387+
});
388+
} catch (err) {
389+
this.emit('progress', 'failed to parse node version, defaulting to 0.10.33');
390+
packageJSON.engines = { node: '0.10.33' };
391+
}
392+
393+
// This happens if boot.js is parsed successfully, but the version wasn't
394+
// found in the file.
395+
if (!packageJSON.engines) {
396+
packageJSON.engines = { node: '0.10.33' };
397+
}
398+
376399
packageJSON.dependencies = context.dependencies;
377400

378401
fs.writeFileSync(context.paths.package_json, JSON.stringify(packageJSON, null, 2));

spec/demeteorizer-spec.js

+32-2
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,47 @@ describe('demeteorizer lib', function () {
151151
});
152152

153153
describe('#createPackageJSON', function () {
154-
it('should create package.json with the correct fields', function () {
154+
before(function () {
155155
context.paths = {};
156156
context.paths.package_json = './package.json';
157+
});
158+
159+
it('should create package.json with the correct node version', function () {
160+
fsStub.readFileSync =
161+
sinon.stub().returns('var MIN_NODE_VERSION = \'v0.12.0\';');
157162

158163
fsStub.writeFileSync = function (path, data) {
159164
path.should.equal('./package.json');
160165
JSON.parse(data).engines.node.should.exist;
166+
JSON.parse(data).engines.node.should.equal('0.12.0');
161167
};
162168

163169
demeteorizer.createPackageJSON(context, new Function());
164170
});
165-
});
166171

172+
it('should default the node version if version not found boot.js', function () {
173+
fsStub.readFileSync =
174+
sinon.stub().returns('');
175+
176+
fsStub.writeFileSync = function (path, data) {
177+
path.should.equal('./package.json');
178+
JSON.parse(data).engines.node.should.exist;
179+
JSON.parse(data).engines.node.should.equal('0.10.33');
180+
};
181+
182+
demeteorizer.createPackageJSON(context, new Function());
183+
});
184+
185+
it('should default the node version if boot.js parse fails', function () {
186+
fsStub.readFileSync = function () { throw new Error('ENOENT'); };
187+
188+
fsStub.writeFileSync = function (path, data) {
189+
path.should.equal('./package.json');
190+
JSON.parse(data).engines.node.should.exist;
191+
JSON.parse(data).engines.node.should.equal('0.10.33');
192+
};
193+
194+
demeteorizer.createPackageJSON(context, new Function());
195+
});
196+
});
167197
});

0 commit comments

Comments
 (0)