Skip to content

Commit

Permalink
WIP Deps sync script
Browse files Browse the repository at this point in the history
  • Loading branch information
sneridagh committed Nov 25, 2023
1 parent be34424 commit 797a655
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions packages/scripts/depsSync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env node
/* eslint no-console: 0 */
import fs from 'fs';
import https from 'https';

// if (process.argv.length < 3) {
// console.log(process.argv.length);
// process.exit(1);
// }

const pkg = process.argv[2];
const version = process.argv[3];

function loadPackageJSON(pkg = '.') {
return JSON.parse(fs.readFileSync(`${pkg}/package.json`, 'utf8'));
}

async function getVoltoPackageJSON(tag) {
const url = `https://raw.githubusercontent.com/plone/volto/${tag}/package.json`;
const requestContent = await new Promise((resolve, reject) => {
https
.get(url, {}, (resp) => {
let data = '';
resp.on('data', (chunk) => {
data += chunk;
});
resp.on('end', () => {
resolve(data);
});
})
.on('error', (err) => {
reject(err);
});
});
return JSON.parse(requestContent);
}

function updatePackageJSON(path = '.', packageJSON) {
fs.writeFileSync(
`${path}/package.json`,
`${JSON.stringify(packageJSON, null, 2)}`,
);
}

async function main() {
const packageJSON = loadPackageJSON();
const currentVoltoVersion = packageJSON.dependencies['@plone/volto'];
const VoltoDependencies = (await getVoltoPackageJSON(currentVoltoVersion))
.dependencies;

Object.entries(VoltoDependencies).forEach(([pkg, version]) => {
console.log(`${pkg} @ ${version}`);
if (packageJSON.dependencies[pkg]) {
packageJSON.dependencies[pkg] = version;
}
});

updatePackageJSON(packageJSON);
}

main();

0 comments on commit 797a655

Please sign in to comment.