Skip to content

Commit

Permalink
Merge pull request #23 from lisb/hotfix/daab-version-command
Browse files Browse the repository at this point in the history
Hotfix/daab version command
  • Loading branch information
krdlab authored Aug 13, 2024
2 parents 6d8bfdb + 29472d3 commit d66aa98
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 11 deletions.
60 changes: 50 additions & 10 deletions lib/daab-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,56 @@ console.info('node:', process.version);
console.info('arch:', process.arch);
console.info('platform:', process.platform);

const packages = [
'lisb-hubot',
'hubot-direct',
'direct-js',
];
const packages = {
'lisb-hubot': [],
'hubot-direct': ['direct-js'],
};

new Arborist().loadActual().then((tree) => {
const getVersion = (i) => i != null ? i.version : '';
const ps = packages.sort().map(name => ({ name, version: getVersion(tree.children.get(name)) }));
ps.forEach(p => {
console.info(`${p.name}:`, p.version);
});
Object.keys(packages)
.reduce((acc, key) => {
const node = tree.children.get(key);
if (!node) {
return acc;
}

acc.push(makePackageInfo(node));

if (packages[node.name].length === 0) {
return acc;
}

const children = packages[node.name].map((n) => ({
name: n,
node: node.children.get(n),
}));
const found = children.filter((c) => c.node != null);

acc.push(...found.map((c) => makePackageInfo(c.node)));
if (children.length > found.length) {
acc.push(...children.filter((c) => c.node == null).map((c) => tree.children.get(c.name)));
}

return acc;
}, [])
.sort(compareName)
.forEach(printPackageInfo);
});

const getValue = (n, k) => (n != null ? n[k] : undefined);

const makePackageInfo = (n) => {
return ['name', 'version'].reduce((acc, k) => Object.assign(acc, { [k]: getValue(n, k) }), {});
};

const compareName = (a, b) => {
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return +1;
}
return 0;
};

const printPackageInfo = (pi) => console.info(`${pi.name}: ${pi.version}`);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "daab",
"version": "0.5.0",
"version": "0.6.0",
"description": "daab (direct agent assist bot) commandline interface",
"main": "lib/daab.js",
"scripts": {
Expand Down

0 comments on commit d66aa98

Please sign in to comment.