#!/usr/bin/env node
// Copyright IBM Corp. 2016. All Rights Reserved.
// Node module: apiconnect
// US Government Users Restricted Rights - Use, duplication or disclosure
// restricted by GSA ADP Schedule Contract with IBM Corp.
var fs = require('fs');
var getConfigDir = require('./util').getConfigDir;
var rmdir = require('./util').rmdir;

if (process.env.npm_config_config_clear === undefined || process.env.npm_config_config_clear === 'true') {
  try {
    var configDir = getConfigDir(false);
    var stats = fs.statSync(configDir);
    if (stats.isDirectory()) {
      rmdir(configDir);
    }
  } catch (err) {
    if (err.code !== 'ENOENT') {
      console.error('IBM API Connect developer toolkit was unable to remove the global configuration directory "'
        + configDir + '".');
    }
  }
}
