Skip to content

Commit

Permalink
use local install of spike if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
jescalan committed Jul 27, 2017
1 parent 6d90a7c commit e1a4063
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ const GA = require('universal-analytics')
const ArgumentParser = require('argparse').ArgumentParser
const reduce = require('lodash.reduce')
const pkg = require('../package.json')
let Spike = require('spike-core') // mocked in tests
const path = require('path')
const fs = require('fs')
let analytics
let Spike

/**
* @class CLI
Expand All @@ -19,9 +21,6 @@ module.exports = class CLI extends EventEmitter {
constructor () {
super()

const uid = Spike.globalConfig().id // mocked in tests
analytics = new GA('UA-79663181-1', uid, { strictCidFormat: false })

this.parser = new ArgumentParser({
version: pkg.version,
description: pkg.description,
Expand Down Expand Up @@ -50,6 +49,20 @@ module.exports = class CLI extends EventEmitter {
// null values here
args = reduce(args, (m, v, k) => { if (v) m[k] = v; return m }, {})

// try to load up a local spike instance first
let spikePath = args.path && path.join(args.path, 'node_modules/spike-core')
try {
fs.accessSync(spikePath)
} catch (_) {
spikePath = 'spike-core'
}

if (!Spike) { Spike = require(spikePath) }

// set up analytics
const uid = Spike.globalConfig().id // mocked in tests
analytics = new GA('UA-79663181-1', uid, { strictCidFormat: false })

// anonymous analytics for usage data
analytics.event({ ec: 'cmd', ea: args.fn, ev: JSON.stringify(args) }).send()

Expand Down

0 comments on commit e1a4063

Please sign in to comment.