Created
November 21, 2016 21:04
-
-
Save phillipskevin/5fd84033a8d5be628ae54a20c58aec57 to your computer and use it in GitHub Desktop.
List when the dependencies of your project were published
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const npm = require('npm'); | |
const publishTimes = {}; | |
function getInfo(name, version) { | |
return new Promise((resolve) => { | |
npm.info(name, (err, info) => { | |
const times = typeof info[version] === 'object' ? info[version].time : {}; | |
resolve(`${name}@${version}|${times[version]}`);; | |
}); | |
}); | |
} | |
npm.load(__dirname + 'package.json', () => { | |
npm.ls((err, { dependencies: deps }) => { | |
var promises = [] | |
for (let dep in deps) { | |
const name = "" + deps[dep].name; | |
const version = "" + deps[dep].version; | |
promises.push(getInfo(name, version)); | |
} | |
Promise.all(promises) | |
.then((results) => { | |
results = results.sort((a, b) => { | |
return new Date(a.split('|')[1]) - new Date(b.split('|')[1]); | |
}); | |
console.log(results); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment