Skip to content

Commit a86d116

Browse files
author
Matt Hernandez
committed
adds json option
Adds the `--json` option and tests.
1 parent dc352b0 commit a86d116

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

bin/demeteorizer

-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ Program
1818

1919
Program.output = Program.output || Path.join(process.cwd(), '.demeteorized');
2020

21-
if (Program.release) {
22-
console.log('Release:', Program.release);
23-
}
24-
2521
try {
2622
Program.json = JSON.parse(Program.json);
2723
} catch(e) {

lib/update-package.js

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ module.exports = function (options, done) {
2525
packageContents.main = '../../main.js';
2626
packageContents.scripts = { start: 'node ../../main' };
2727

28+
Hoek.merge(packageContents, options.json || {});
29+
2830
//
2931
// The generated package.json is read-only, but removing it prior to writing
3032
// will allow updates.

test/update-package.js

+32
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const Path = require('path');
2+
13
const Code = require('code');
24
const Lab = require('lab');
35
const Proxyquire = require('proxyquire');
@@ -55,4 +57,34 @@ describe('update-package', function () {
5557
});
5658
});
5759
});
60+
61+
describe('merges json from options into package.json', function () {
62+
before(function (done) {
63+
fsStub.existsSync = Sinon.stub().returns(true);
64+
fsStub.readFileSync = Sinon.stub().returns('{}');
65+
fsStub.unlinkSync = Sinon.stub();
66+
fsStub.writeFile = Sinon.stub().yields(null);
67+
done();
68+
});
69+
70+
it('creates a valid package.json', function (done) {
71+
UpdatePackage({ directory: '', json: { test: true } }, function () {
72+
var path = Path.resolve('./bundle/programs/server/package.json');
73+
var json = [
74+
'{',
75+
' "engines": {',
76+
' "node": "0.10.33"',
77+
' },',
78+
' "main": "../../main.js",',
79+
' "scripts": {',
80+
' "start": "node ../../main"',
81+
' },',
82+
' "test": true',
83+
'}'].join('\n');
84+
85+
expect(fsStub.writeFile.calledWith(path, json)).to.be.true();
86+
done();
87+
});
88+
});
89+
});
5890
});

0 commit comments

Comments
 (0)