Skip to content

Commit

Permalink
refactor: Unified and simplified package.json and version handling
Browse files Browse the repository at this point in the history
  • Loading branch information
honzajavorek committed Aug 18, 2016
1 parent bcb5234 commit 621bd4f
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 19 deletions.
5 changes: 2 additions & 3 deletions src/dredd-command.coffee
Expand Up @@ -5,13 +5,12 @@ fs = require 'fs'
spawnArgs = require 'spawn-args'
{spawn} = require('child_process')

parsePackageJson = require './parse-package-json'
Dredd = require './dredd'
interactiveConfig = require './interactive-config'
configUtils = require './config-utils'
logger = require './logger'

version = parsePackageJson path.join(__dirname, '../package.json')
packageData = require('../package.json')

TERM_TIMEOUT = 1000
TERM_RETRY = 500
Expand Down Expand Up @@ -178,7 +177,7 @@ class DreddCommand

# show version
else if @argv.version is true
console.log version
console.log("#{packageData.name} v#{packageData.version}")
return @_processExit(0)

loadDreddFile: ->
Expand Down
7 changes: 0 additions & 7 deletions src/parse-package-json.coffee

This file was deleted.

4 changes: 2 additions & 2 deletions src/reporters/apiary-reporter.coffee
Expand Up @@ -6,7 +6,7 @@ url = require 'url'
clone = require 'clone'
generateUuid = require('node-uuid').v4

packageConfig = require './../../package.json'
packageData = require './../../package.json'
logger = require './../logger'

CONNECTION_ERRORS = ['ECONNRESET', 'ENOTFOUND', 'ESOCKETTIMEDOUT', 'ETIMEDOUT', 'ECONNREFUSED', 'EHOSTUNREACH', 'EPIPE']
Expand Down Expand Up @@ -222,7 +222,7 @@ class ApiaryReporter
path: path
method: method
headers:
'User-Agent': "Dredd REST Reporter/" + packageConfig['version'] + " (" + system + ")"
'User-Agent': "Dredd REST Reporter/" + packageData.version + " (" + system + ")"
'Content-Type': 'application/json'
'Content-Length': Buffer.byteLength(postData, 'utf8')

Expand Down
5 changes: 2 additions & 3 deletions src/transaction-runner.coffee
Expand Up @@ -12,7 +12,7 @@ clone = require 'clone'
flattenHeaders = require './flatten-headers'
addHooks = require './add-hooks'
sortTransactions = require './sort-transactions'
packageConfig = require './../package.json'
packageData = require './../package.json'
logger = require './logger'


Expand Down Expand Up @@ -293,8 +293,7 @@ class TransactionRunner
if not flatHeaders['User-Agent']
system = os.type() + ' ' + os.release() + '; ' + os.arch()
flatHeaders['User-Agent'] = "Dredd/" + \
packageConfig.version + \
" (" + system + ")"
packageData.version + " (" + system + ")"

# Parse and add headers from the config to the transaction
if configuration.options.header.length > 0
Expand Down
1 change: 0 additions & 1 deletion test/integration/dredd-command-test.coffee
Expand Up @@ -7,7 +7,6 @@ bodyParser = require 'body-parser'

proxyquire = require('proxyquire').noCallThru()

packageJson = require '../../package.json'
loggerStub = require '../../src/logger'
configUtils = require '../../src/config-utils'

Expand Down
1 change: 0 additions & 1 deletion test/integration/dredd-test.coffee
Expand Up @@ -7,7 +7,6 @@ bodyParser = require 'body-parser'

proxyquire = require('proxyquire').noCallThru()

packageJson = require '../../package.json'
loggerStub = require '../../src/logger'

PORT = 9876
Expand Down
4 changes: 2 additions & 2 deletions test/unit/dredd-command-test.coffee
Expand Up @@ -4,7 +4,7 @@ express = require 'express'
proxyquire = require('proxyquire').noCallThru()

options = require '../../src/options'
packageJson = require '../../package.json'
packageData = require '../../package.json'

childProcessStub = require 'child_process'
loggerStub = require '../../src/logger'
Expand Down Expand Up @@ -253,7 +253,7 @@ describe "DreddCommand class", () ->
done()

it 'prints out version', ->
assert.include stdout, "#{packageJson.name} v#{packageJson.version}"
assert.include stdout, "#{packageData.name} v#{packageData.version}"

describe '"init" (nodejs)', ->
before (done) ->
Expand Down

0 comments on commit 621bd4f

Please sign in to comment.