Created
December 15, 2022 15:25
-
-
Save troZee/d8346fe4558b6f2d2177283f73c24413 to your computer and use it in GitHub Desktop.
Check npm last publish date for each dependency inside a package.json file
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 fs = require('fs'); | |
const { exec } = require('child_process'); | |
function execute(command, callback) { | |
exec(command, function (error, stdout, stderr) { | |
if (stderr || error) { | |
// console.log(`ππππππππ ${stderr} ${error}`); | |
} else { | |
callback(stdout); | |
} | |
}); | |
} | |
// Read the contents of the package.json file | |
const packageJson = fs.readFileSync('package.json', 'utf8'); | |
// Parse the JSON to get the dependencies object | |
const dependencies = JSON.parse(packageJson).dependencies; | |
// Print the dependencies | |
Object.entries(dependencies).forEach((element) => { | |
const depName = element[0]; | |
execute(`npm view ${depName} version`, (version) => { | |
execute(`npm view ${depName} time --json`, (data) => { | |
const parse = JSON.parse(data); | |
const trimVersion = version.trim(); | |
const date = parse[trimVersion]; | |
if (new Date(date).getFullYear() < new Date().getFullYear()) { | |
console.log(`${depName} ${trimVersion} ${date}`); | |
} | |
}); | |
}); | |
}); |
Author
troZee
commented
Jan 12, 2024
const fs = require('fs');
const { exec } = require('child_process');
function execute(command, callback) {
exec(command, function (error, stdout, stderr) {
if (stderr || error) {
// console.log(`ππππππππ ${stderr} ${error}`);
} else {
callback(stdout);
}
});
}
// Read the contents of the package.json file
const packageJson = fs.readFileSync('package.json', 'utf8');
// Parse the JSON to get the dependencies object
const dependencies = JSON.parse(packageJson).dependencies;
const dependenciesList = Object.entries(dependencies)
const array = [];
let counter = 0;
// Print the dependencies
dependenciesList.forEach((element,index) => {
const depName = element[0];
execute(`npm view ${depName} version`, (version) => {
execute(`npm view ${depName} time --json`, (data) => {
const parse = JSON.parse(data);
const currentVersion = version.trim();
const theLatestVersion = Object.keys(parse).pop()
const theLatestDate = parse[theLatestVersion]
const date = parse[currentVersion];
const isMoreThanYear = (new Date().getTime() - new Date(date).getTime()) / (1000 * 3600 * 24 * 365) > 1
if (isMoreThanYear) {
console.log(`${depName} ${currentVersion} ${date}`);
array.push({depName, currentVersion, theLatestVersion, date, theLatestDate})
}
counter = counter + 1
if (counter === dependenciesList.length) {
console.table(array, ["depName", "currentVersion", "date", "theLatestVersion", "theLatestDate"]);
}
});
});
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment