Skip to content

Commit

Permalink
improved dependency update script
Browse files Browse the repository at this point in the history
  • Loading branch information
hobbyquaker committed Aug 8, 2020
1 parent 92d4486 commit 1fab529
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@
"license": "Apache-2.0",
"devDependencies": {
"github-markdown-css": "^3.0.1",
"got": "^11.5.2",
"latest-semver": "^1.0.0",
"npm-check-updates": "^3.1.1",
"showdown": "^1.9.0",
"prompts": "^2.3.2",
"request": "^2.88.0",
"showdown": "^1.9.0",
"sync-request": "^6.1.0"
}
}
}
56 changes: 56 additions & 0 deletions update_dependencies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const fs = require('fs').promises;
const path = require('path');
const got = require('got');
const prompts = require('prompts');
const util = require('util');
const exec = util.promisify(require('child_process').exec);

const dirs = ['var', 'lib', 'www'];

const pkgs = {
combined: require(path.join(__dirname, 'package.json'))
};

dirs.forEach(dir => {
pkgs[dir] = require(path.join(__dirname, 'addon_files/redmatic', dir, 'package.json'));
console.log(dir)
});

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 (dependencies[pkg] !== latest) {
const response = await prompts({
type: 'confirm',
name: 'confirmed',
message: `update ${pkg} ${dependencies[pkg]} 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, ' '));
const {stdout, stderr} = await exec(`git commit package.json ${file} -m 'update ${pkg} to ${latest}'`);
console.log(stderr, stdout);
}
}
}
console.log(pkgs[dir].dependencies, pkgs.combined.dependencies);

}
async function checkDirs() {
for (dir of dirs) {
await compareVersions(dir);
}
}


checkDirs();

0 comments on commit 1fab529

Please sign in to comment.