• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2/* eslint-disable camelcase */
3module.exports = launchSendMetrics
4var fs = require('graceful-fs')
5var child_process = require('child_process')
6
7if (require.main === module) main()
8
9function launchSendMetrics () {
10  var path = require('path')
11  var npm = require('../npm.js')
12  try {
13    if (!npm.config.get('send-metrics')) return
14    var cliMetrics = path.join(npm.config.get('cache'), 'anonymous-cli-metrics.json')
15    var targetRegistry = npm.config.get('metrics-registry')
16    fs.statSync(cliMetrics)
17    return runInBackground(__filename, [cliMetrics, targetRegistry])
18  } catch (ex) {
19    // if the metrics file doesn't exist, don't run
20  }
21}
22
23function runInBackground (js, args, opts) {
24  if (!args) args = []
25  args.unshift(js)
26  if (!opts) opts = {}
27  opts.stdio = 'ignore'
28  opts.detached = true
29  var child = child_process.spawn(process.execPath, args, opts)
30  child.unref()
31  return child
32}
33
34function main () {
35  var sendMetrics = require('./metrics.js').send
36  var metricsFile = process.argv[2]
37  var metricsRegistry = process.argv[3]
38
39  sendMetrics(metricsFile, metricsRegistry)
40}
41