From f6b769b5a73a0b43239782f300efe31613c54f22 Mon Sep 17 00:00:00 2001 From: Matt Hernandez Date: Tue, 13 Sep 2016 16:41:52 -0400 Subject: [PATCH] Replace mod standard in favor of standard. No more mod-standard; just pure standard ASI goodness. --- .eslintrc | 7 --- lib/build.js | 40 ++++++------- lib/demeteorizer.js | 16 +++--- lib/exec.js | 2 +- lib/find-node-version.js | 30 +++++----- lib/update-package.js | 32 +++++------ package.json | 8 +-- test/build.js | 112 ++++++++++++++++++------------------- test/find-node-version.js | 102 +++++++++++++++++----------------- test/update-package.js | 114 +++++++++++++++++++------------------- 10 files changed, 227 insertions(+), 236 deletions(-) delete mode 100644 .eslintrc diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 42438cc..0000000 --- a/.eslintrc +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "modulus", - "rules": { - "no-sync": 0, - "no-undefined": 0 - } -} diff --git a/lib/build.js b/lib/build.js index f8c5bc1..9056efd 100644 --- a/lib/build.js +++ b/lib/build.js @@ -1,12 +1,12 @@ -const Hoek = require('hoek'); -const Util = require('util'); +const Hoek = require('hoek') +const Util = require('util') -const Exec = require('./exec'); +const Exec = require('./exec') const defaults = { server: 'localhost', directory: '.demeteorized' -}; +} // // Options include: @@ -15,38 +15,38 @@ const defaults = { // architecture - Architecture build target. // module.exports = function (options, done) { - var args, build; + var args, build - options = Hoek.applyToDefaults(defaults, options); + options = Hoek.applyToDefaults(defaults, options) args = [ 'build', '--server', options.server, '--directory', Util.format('%s', options.directory) - ]; + ] if (options.architecture) { - args.push('--architecture'); - args.push(options.architecture); + args.push('--architecture') + args.push(options.architecture) } - if (options.debug) args.push('--debug'); - if (options.serverOnly) args.push('--server-only'); + if (options.debug) args.push('--debug') + if (options.serverOnly) args.push('--server-only') - build = Exec.spawn('meteor', args, { cwd: options.input, stdio: 'inherit' }); + build = Exec.spawn('meteor', args, { cwd: options.input, stdio: 'inherit' }) build.on('error', function (err) { var message = [ 'Meteor not in $PATH.', 'Please make sure Meteor is installed properly.' - ].join(' '); + ].join(' ') - if (err.code === 'ENOENT') return done(new Error(message)); - done(err); - }); + if (err.code === 'ENOENT') return done(new Error(message)) + done(err) + }) build.on('close', function (code) { - if (code !== 0) return done(new Error('Conversion failed.')); - done(); - }); -}; + if (code !== 0) return done(new Error('Conversion failed.')) + done() + }) +} diff --git a/lib/demeteorizer.js b/lib/demeteorizer.js index 7d937ec..2583ddc 100644 --- a/lib/demeteorizer.js +++ b/lib/demeteorizer.js @@ -1,14 +1,14 @@ -const Hoek = require('hoek'); +const Hoek = require('hoek') -const Build = require('./build'); -const UpdatePackage = require('./update-package'); +const Build = require('./build') +const UpdatePackage = require('./update-package') module.exports = function (options, done) { - Hoek.assert(options !== undefined, 'You must provide a valid options object'); + Hoek.assert(options !== undefined, 'You must provide a valid options object') Build(options, function (err) { - if (err) return done(err); + if (err) return done(err) - UpdatePackage(options, done); - }); -}; + UpdatePackage(options, done) + }) +} diff --git a/lib/exec.js b/lib/exec.js index 688c5bf..d586280 100644 --- a/lib/exec.js +++ b/lib/exec.js @@ -1 +1 @@ -exports.spawn = require('cross-spawn'); +exports.spawn = require('cross-spawn') diff --git a/lib/find-node-version.js b/lib/find-node-version.js index a3f804a..482cba6 100644 --- a/lib/find-node-version.js +++ b/lib/find-node-version.js @@ -1,24 +1,24 @@ -const Fs = require('fs'); -const Path = require('path'); +const Fs = require('fs') +const Path = require('path') -const Hoek = require('hoek'); +const Hoek = require('hoek') -const DEFAULT_NODE_VERSION = '0.10.33'; +const DEFAULT_NODE_VERSION = '0.10.33' module.exports = function (options) { - var version, bootPath; + var version, bootPath - Hoek.assert(options !== undefined, 'options is required'); - Hoek.assert(Fs.existsSync(options.directory), 'Output directory not found'); + Hoek.assert(options !== undefined, 'options is required') + Hoek.assert(Fs.existsSync(options.directory), 'Output directory not found') - if (typeof options.nodeVersion !== 'undefined') return options.nodeVersion; + if (typeof options.nodeVersion !== 'undefined') return options.nodeVersion bootPath = Path.resolve( options.directory, 'bundle', 'programs', 'server', - 'boot.js'); + 'boot.js') try { // Read boot.js to find the MIN_NODE_VERSION; use that version as the node @@ -26,15 +26,15 @@ module.exports = function (options) { Fs.readFileSync(bootPath).toString().split('\n').some(function (line) { if (line.indexOf('MIN_NODE_VERSION') >= 0) { /* eslint-disable no-magic-numbers */ - version = line.split(' ')[3].replace(/[v;']/g, ''); + version = line.split(' ')[3].replace(/[v;']/g, '') /* eslint-enable no-magic-numbers */ - return true; + return true } - }); + }) } catch (err) { - version = DEFAULT_NODE_VERSION; + version = DEFAULT_NODE_VERSION } - return version || DEFAULT_NODE_VERSION; -}; + return version || DEFAULT_NODE_VERSION +} diff --git a/lib/update-package.js b/lib/update-package.js index 6f63872..29eabe4 100644 --- a/lib/update-package.js +++ b/lib/update-package.js @@ -1,38 +1,38 @@ -const Fs = require('fs'); -const Path = require('path'); +const Fs = require('fs') +const Path = require('path') -const Hoek = require('hoek'); +const Hoek = require('hoek') -const FindNodeVersion = require('./find-node-version'); +const FindNodeVersion = require('./find-node-version') module.exports = function (options, done) { - var packagePath, packageContents; + var packagePath, packageContents - Hoek.assert(options !== undefined, 'options is required'); - Hoek.assert(Fs.existsSync(options.directory), 'Output directory not found'); + Hoek.assert(options !== undefined, 'options is required') + Hoek.assert(Fs.existsSync(options.directory), 'Output directory not found') packagePath = Path.resolve( options.directory, 'bundle', 'programs', 'server', - 'package.json'); + 'package.json') // // Manual parsing of the package.json allows mocking of the read. // - packageContents = JSON.parse(Fs.readFileSync(packagePath)); + packageContents = JSON.parse(Fs.readFileSync(packagePath)) packageContents.engines = { node: FindNodeVersion(options), npm: options.npmVersion || 'latest' - }; + } - packageContents.main = '../../main.js'; - packageContents.scripts = { start: 'node ../../main' }; + packageContents.main = '../../main.js' + packageContents.scripts = { start: 'node ../../main' } - Hoek.merge(packageContents, options.json || {}); + Hoek.merge(packageContents, options.json || {}) - Fs.chmodSync(packagePath, '0644'); - Fs.writeFile(packagePath, JSON.stringify(packageContents, null, 2), done); -}; + Fs.chmodSync(packagePath, '0644') + Fs.writeFile(packagePath, JSON.stringify(packageContents, null, 2), done) +} diff --git a/package.json b/package.json index dc15978..a2e97f0 100644 --- a/package.json +++ b/package.json @@ -32,13 +32,11 @@ "lab": "10.x.x", "proxyquire": "1.7.10", "sinon": "1.17.5", - "eslint": "2.11.1", - "eslint-plugin-hapi": "4.0.0", - "eslint-plugin-promise": "1.1.0", - "eslint-config-modulus": "0.6.0" + "standard": "8.0.0" }, "scripts": { - "test": "lab --threshold 100 --lint", + "pretest": "standard", + "test": "lab --threshold 100", "gen-coverage": "lab --coverage --reporter lcov --output coverage/lcov.info" }, "main": "./lib/demeteorizer", diff --git a/test/build.js b/test/build.js index 23faa85..476d21b 100644 --- a/test/build.js +++ b/test/build.js @@ -1,35 +1,35 @@ -const EventEmitter = require('events').EventEmitter; +const EventEmitter = require('events').EventEmitter -const Code = require('code'); -const Lab = require('lab'); -const Proxyquire = require('proxyquire'); -const Sinon = require('sinon'); +const Code = require('code') +const Lab = require('lab') +const Proxyquire = require('proxyquire') +const Sinon = require('sinon') -var cpStub = {}; +var cpStub = {} var Build = Proxyquire('../lib/build', { './exec': cpStub -}); +}) -var lab = exports.lab = Lab.script(); +var lab = exports.lab = Lab.script() -var describe = lab.describe; -var beforeEach = lab.beforeEach; -var it = lab.it; -var expect = Code.expect; +var describe = lab.describe +var beforeEach = lab.beforeEach +var it = lab.it +var expect = Code.expect describe('build', function () { - var emitter; + var emitter beforeEach(function (done) { - emitter = new EventEmitter(); - cpStub.spawn = Sinon.stub().returns(emitter); - done(); - }); + emitter = new EventEmitter() + cpStub.spawn = Sinon.stub().returns(emitter) + done() + }) it('exports a function', function (done) { - expect(Build).to.be.a.function(); - done(); - }); + expect(Build).to.be.a.function() + done() + }) it('defaults options', function (done) { Build({}, function () { @@ -39,13 +39,13 @@ describe('build', function () { 'localhost', '--directory', '.demeteorized' - ])).to.be.true(); + ])).to.be.true() - done(); - }); + done() + }) - emitter.emit('close', 0); - }); + emitter.emit('close', 0) + }) it('overrides architecture when provided', function (done) { Build({ architecture: 'os.linux.x86_64' }, function () { @@ -57,13 +57,13 @@ describe('build', function () { '.demeteorized', '--architecture', 'os.linux.x86_64' - ])).to.be.true(); + ])).to.be.true() - done(); - }); + done() + }) - emitter.emit('close', 0); - }); + emitter.emit('close', 0) + }) it('includes debug when provided', function (done) { Build({ debug: true }, function () { @@ -74,13 +74,13 @@ describe('build', function () { '--directory', '.demeteorized', '--debug' - ])).to.be.true(); + ])).to.be.true() - done(); - }); + done() + }) - emitter.emit('close', 0); - }); + emitter.emit('close', 0) + }) it('includes server only when provided', function (done) { Build({ serverOnly: true }, function () { @@ -91,40 +91,40 @@ describe('build', function () { '--directory', '.demeteorized', '--server-only' - ])).to.be.true(); + ])).to.be.true() - done(); - }); + done() + }) - emitter.emit('close', 0); - }); + emitter.emit('close', 0) + }) it('returns an error on failed exit', function (done) { Build({}, function (err) { - expect(err.message).to.equal('Conversion failed.'); + expect(err.message).to.equal('Conversion failed.') - done(); - }); + done() + }) - emitter.emit('close', 1); - }); + emitter.emit('close', 1) + }) it('returns an error when the command fails', function (done) { Build({}, function (err) { - expect(err.message).to.equal('failed'); + expect(err.message).to.equal('failed') - done(); - }); + done() + }) - emitter.emit('error', new Error('failed')); - }); + emitter.emit('error', new Error('failed')) + }) it('return clear error message when Meteor not installed', function (done) { Build({}, function (err) { - expect(err.message).to.include('Meteor not in $PATH'); - done(); - }); + expect(err.message).to.include('Meteor not in $PATH') + done() + }) - emitter.emit('error', { code: 'ENOENT' }); - }); -}); + emitter.emit('error', { code: 'ENOENT' }) + }) +}) diff --git a/test/find-node-version.js b/test/find-node-version.js index acaf248..8574d84 100644 --- a/test/find-node-version.js +++ b/test/find-node-version.js @@ -1,47 +1,47 @@ -const Code = require('code'); -const Lab = require('lab'); -const Proxyquire = require('proxyquire'); -const Sinon = require('sinon'); +const Code = require('code') +const Lab = require('lab') +const Proxyquire = require('proxyquire') +const Sinon = require('sinon') -var fsStub = {}; +var fsStub = {} var FindVersion = Proxyquire('../lib/find-node-version', { fs: fsStub -}); +}) -var lab = exports.lab = Lab.script(); +var lab = exports.lab = Lab.script() -var describe = lab.describe; -var before = lab.beforeEach; -var it = lab.it; -var expect = Code.expect; +var describe = lab.describe +var before = lab.beforeEach +var it = lab.it +var expect = Code.expect describe('find-node-version', function () { describe('initialization', function () { it('fails if no options object is provided', function (done) { expect(function () { - FindVersion(); - }).to.throw(); + FindVersion() + }).to.throw() - done(); - }); + done() + }) before(function (done) { - fsStub.existsSync = Sinon.stub().returns(false); - done(); - }); + fsStub.existsSync = Sinon.stub().returns(false) + done() + }) it('fails if output directory does not exist', function (done) { expect(function () { - FindVersion({ directory: '' }); - }).to.throw(); + FindVersion({ directory: '' }) + }).to.throw() - done(); - }); - }); + done() + }) + }) describe('successfully', function () { before(function (done) { - fsStub.existsSync = Sinon.stub().returns(true); + fsStub.existsSync = Sinon.stub().returns(true) fsStub.readFileSync = Sinon.stub().returns([ 'var Fiber = require("fibers");', 'var fs = require("fs");', @@ -55,45 +55,45 @@ describe('find-node-version', function () { '', '// This code is duplicated in tools/main.js.', 'var MIN_NODE_VERSION = \'v0.10.36\';' - ].join('\n')); - done(); - }); + ].join('\n')) + done() + }) it('sets node version from --node-version', function (done) { expect(FindVersion({ directory: '', nodeVersion: '4.2.0' })) - .to.equal('4.2.0'); - done(); - }); + .to.equal('4.2.0') + done() + }) it('finds the node version from boot.js', function (done) { - expect(FindVersion({ directory: '' })).to.equal('0.10.36'); - done(); - }); - }); + expect(FindVersion({ directory: '' })).to.equal('0.10.36') + done() + }) + }) describe('unsuccessfully', function () { before(function (done) { - fsStub.existsSync = Sinon.stub().returns(true); - fsStub.readFileSync = Sinon.stub().returns(''); - done(); - }); + fsStub.existsSync = Sinon.stub().returns(true) + fsStub.readFileSync = Sinon.stub().returns('') + done() + }) it('finds the node version from boot.js', function (done) { - expect(FindVersion({ directory: '' })).to.equal('0.10.33'); - done(); - }); - }); + expect(FindVersion({ directory: '' })).to.equal('0.10.33') + done() + }) + }) describe('throws trying to', function () { before(function (done) { - fsStub.existsSync = Sinon.stub().returns(true); - fsStub.readFileSync = Sinon.stub().throws(); - done(); - }); + fsStub.existsSync = Sinon.stub().returns(true) + fsStub.readFileSync = Sinon.stub().throws() + done() + }) it('find the node version from boot.js', function (done) { - expect(FindVersion({ directory: '' })).to.equal('0.10.33'); - done(); - }); - }); -}); + expect(FindVersion({ directory: '' })).to.equal('0.10.33') + done() + }) + }) +}) diff --git a/test/update-package.js b/test/update-package.js index 32697bb..0329871 100644 --- a/test/update-package.js +++ b/test/update-package.js @@ -1,75 +1,75 @@ -const Path = require('path'); +const Path = require('path') -const Code = require('code'); -const Lab = require('lab'); -const Proxyquire = require('proxyquire'); -const Sinon = require('sinon'); +const Code = require('code') +const Lab = require('lab') +const Proxyquire = require('proxyquire') +const Sinon = require('sinon') -var fsStub = {}; +var fsStub = {} var UpdatePackage = Proxyquire('../lib/update-package', { fs: fsStub -}); +}) -var lab = exports.lab = Lab.script(); +var lab = exports.lab = Lab.script() -var describe = lab.describe; -var before = lab.beforeEach; -var it = lab.it; -var expect = Code.expect; +var describe = lab.describe +var before = lab.beforeEach +var it = lab.it +var expect = Code.expect describe('update-package', function () { describe('fails', function () { before(function (done) { - fsStub.existsSync = Sinon.stub().returns(false); - done(); - }); + fsStub.existsSync = Sinon.stub().returns(false) + done() + }) it('if no options object is provided', function (done) { expect(function () { - UpdatePackage(); - }).to.throw(); + UpdatePackage() + }).to.throw() - done(); - }); + done() + }) it('if output directory does not exist', function (done) { expect(function () { - UpdatePackage({ directory: '' }, function () {}); - }).to.throw(); + UpdatePackage({ directory: '' }, function () {}) + }).to.throw() - done(); - }); - }); + done() + }) + }) describe('successfully', function () { before(function (done) { - fsStub.existsSync = Sinon.stub().returns(true); - fsStub.readFileSync = Sinon.stub().returns('{}'); - fsStub.chmodSync = Sinon.stub(); - fsStub.writeFile = Sinon.stub().yields(null); - done(); - }); + fsStub.existsSync = Sinon.stub().returns(true) + fsStub.readFileSync = Sinon.stub().returns('{}') + fsStub.chmodSync = Sinon.stub() + fsStub.writeFile = Sinon.stub().yields(null) + done() + }) it('creates a valid package.json', function (done) { UpdatePackage({ directory: '' }, function () { - expect(fsStub.writeFile.called).to.be.true(); - done(); - }); - }); - }); + expect(fsStub.writeFile.called).to.be.true() + done() + }) + }) + }) describe('merges json from options into package.json', function () { before(function (done) { - fsStub.existsSync = Sinon.stub().returns(true); - fsStub.readFileSync = Sinon.stub().returns('{}'); - fsStub.chmodSync = Sinon.stub(); - fsStub.writeFile = Sinon.stub().yields(null); - done(); - }); + fsStub.existsSync = Sinon.stub().returns(true) + fsStub.readFileSync = Sinon.stub().returns('{}') + fsStub.chmodSync = Sinon.stub() + fsStub.writeFile = Sinon.stub().yields(null) + done() + }) it('creates a valid package.json', function (done) { UpdatePackage({ directory: '', json: { test: true } }, function () { - var path = Path.resolve('./bundle/programs/server/package.json'); + var path = Path.resolve('./bundle/programs/server/package.json') var json = [ '{', ' "engines": {', @@ -81,18 +81,18 @@ describe('update-package', function () { ' "start": "node ../../main"', ' },', ' "test": true', - '}'].join('\n'); + '}'].join('\n') - expect(fsStub.writeFile.calledWith(path, json)).to.be.true(); - done(); - }); - }); - }); + expect(fsStub.writeFile.calledWith(path, json)).to.be.true() + done() + }) + }) + }) describe('uses npm version specified from options', function () { it('sets npm version using options.npmVersion', function (done) { UpdatePackage({ directory: '', npmVersion: '3.9.0' }, function () { - var path = Path.resolve('./bundle/programs/server/package.json'); + var path = Path.resolve('./bundle/programs/server/package.json') var json = [ '{', ' "engines": {', @@ -103,11 +103,11 @@ describe('update-package', function () { ' "scripts": {', ' "start": "node ../../main"', ' }', - '}'].join('\n'); - - expect(fsStub.writeFile.calledWith(path, json)).to.be.true(); - done(); - }); - }); - }); -}); + '}'].join('\n') + + expect(fsStub.writeFile.calledWith(path, json)).to.be.true() + done() + }) + }) + }) +})