cdbrelease/cdbedit.js
Aaron Suen 8362e41b0e Metadata editing, releasing via the API
Left to do:
- test out including commit hash, when ruben
  finishes implementing this in the API.
- screenshot reconciliation.
2021-02-27 11:20:52 -05:00

34 lines
1006 B
JavaScript

'use strict';
const mylog = require('./mylog');
const config = require('./config');
const cdbfetch = require('./cdbfetch');
const sortser = obj => JSON.stringify(Array.isArray(obj) ? obj.sort() : obj);
module.exports = async () => {
const pkgurl = `/packages/${config.user}/${config.pkg}/`;
mylog('checking existing package metadata...');
const resp = await cdbfetch(pkgurl);
const edits = {};
Object.keys(resp.body)
.filter(k => k !== 'screenshots' && config[k] !== undefined)
.forEach(k => {
if(sortser(resp.body[k]) !== sortser(k === 'long_description' ?
config[k].replace(/\r/g, '')
.replace(/\n/g, '\r\n') : config[k]))
edits[k] = config[k];
});
if(!Object.keys(edits)
.length)
return mylog('package metadata already up to date');
if(config.dryrun)
return mylog(`DRY RUN: package metadata edits: ${JSON.stringify(edits)}`);
mylog('updating package metadata...');
await cdbfetch(pkgurl, 'post', edits, { json: true });
mylog('package metadata updated');
};