2017-06-28 20:33:27 +00:00
|
|
|
const cp = require('child_process');
|
|
|
|
const tmp = require('tmp');
|
|
|
|
const root = require('root-require');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
detectVersions,
|
|
|
|
};
|
|
|
|
|
|
|
|
function detectVersions(config) {
|
|
|
|
config.logger.debug('Detecting versions');
|
|
|
|
const versions = {};
|
|
|
|
try {
|
|
|
|
versions.renovate = root('package.json').version;
|
|
|
|
const tmpDir = tmp.dirSync({ unsafeCleanup: true });
|
2017-07-21 06:47:05 +00:00
|
|
|
const result = cp.spawnSync('npm', ['--version'], {
|
2017-06-28 20:33:27 +00:00
|
|
|
cwd: tmpDir.name,
|
|
|
|
shell: true,
|
|
|
|
});
|
|
|
|
versions.npm = result.stdout.toString().split('\n')[0];
|
|
|
|
} catch (err) {
|
2017-07-19 06:05:26 +00:00
|
|
|
config.logger.error({ err }, 'Error detecting versions');
|
2017-06-28 20:33:27 +00:00
|
|
|
}
|
|
|
|
config.logger.debug({ versions }, 'Detected versions');
|
|
|
|
return versions;
|
|
|
|
}
|