Skip to content

Commit

Permalink
catch non-existant packages
Browse files Browse the repository at this point in the history
  • Loading branch information
hobbyquaker committed Mar 6, 2021
1 parent 932af11 commit e77ca67
Showing 1 changed file with 37 additions and 29 deletions.
66 changes: 37 additions & 29 deletions update_dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,46 @@ async function compareVersions(dir) {
const pkgJson = pkgs[dir];
const dependencies = pkgJson.dependencies;
for (const pkg in dependencies) {
const json = await got(`https://registry.npmjs.org/${pkg}`, {
responseType: 'json'
});

const actual = dependencies[pkg];
const latest = json.body['dist-tags'].latest;
if (actual !== latest) {
const response = await prompts({
type: 'confirm',
name: 'confirmed',
message: `update ${pkg} ${actual} to ${latest}?`
let json;
try {
json = await got(`https://registry.npmjs.org/${pkg}`, {
responseType: 'json'
});
if (response.confirmed) {
dependencies[pkg] = latest;
pkgs.combined.dependencies[pkg] = `0.0.0 - ${latest}`;
const file = path.join('addon_files/redmatic', dir, 'package.json')
await fs.writeFile(path.join(__dirname, 'package.json'), JSON.stringify(pkgs.combined, null, ' '));
await fs.writeFile(path.join(__dirname, file), JSON.stringify(pkgs[dir], null, ' '));
let changelog = '';
switch (pkg) {
case 'node-red':
changelog = ' ([Changelog](https://github.com/node-red/node-red/blob/master/CHANGELOG.md))';
break;
case 'node-red-dashboard':
changelog = ' ([Changelog](https://github.com/node-red/node-red-dashboard/blob/master/CHANGELOG.md))';
break;
default:
} catch (error) {
console.error(pkg, error.message);
}

if (json) {
const actual = dependencies[pkg];
const latest = json.body['dist-tags'].latest;
if (actual !== latest) {
const response = await prompts({
type: 'confirm',
name: 'confirmed',
message: `update ${pkg} ${actual} to ${latest}?`
});
if (response.confirmed) {
dependencies[pkg] = latest;
pkgs.combined.dependencies[pkg] = `0.0.0 - ${latest}`;
const file = path.join('addon_files/redmatic', dir, 'package.json')
await fs.writeFile(path.join(__dirname, 'package.json'), JSON.stringify(pkgs.combined, null, ' '));
await fs.writeFile(path.join(__dirname, file), JSON.stringify(pkgs[dir], null, ' '));
let changelog = '';
switch (pkg) {
case 'node-red':
changelog = ' ([Changelog](https://github.com/node-red/node-red/blob/master/CHANGELOG.md))';
break;
case 'node-red-dashboard':
changelog = ' ([Changelog](https://github.com/node-red/node-red-dashboard/blob/master/CHANGELOG.md))';
break;
default:
}
const {stdout, stderr} = await exec(`git commit package.json ${file} -m 'update ${pkg} ${actual} to ${latest}${changelog}'`);
console.log(stderr, stdout);
updateCount += 1;
}
const {stdout, stderr} = await exec(`git commit package.json ${file} -m 'update ${pkg} ${actual} to ${latest}${changelog}'`);
console.log(stderr, stdout);
updateCount += 1;
}

}
}

Expand Down

0 comments on commit e77ca67

Please sign in to comment.