cdbrelease/cdbedit.js
2020-03-27 23:24:33 -04:00

53 lines
1.4 KiB
JavaScript

'use strict';
const config = require('./config');
const cdblib = require('./cdblib');
const keepers = {};
`type title short_desc tags license media_license provides_str harddep_str
softdep_str repo website issueTracker forums desc`.match(/\S+/g)
.forEach(k => keepers[k] = true);
module.exports = async () => {
const meta = {};
Object.keys(config)
.filter(k => keepers[k])
.forEach(k => meta[k] = config[k]);
if(!Object.keys(meta)
.length)
return;
meta.name = config.pkg;
const uri = config.root + '/packages/' + config.user + '/' + config.pkg + '/edit/';
await cdblib.login();
console.log('fetching package edit page...');
const $ = await cdblib.fetch(uri);
const fields = cdblib.getfields($);
const tags = {};
meta.tags.split(',')
.filter(x => /\S/.test(x))
.map(x => x.trim())
.forEach(x => tags[cdblib.findopt($, 'select#tags option', x)] = true);
delete meta.tags;
'type license media_license'.split(' ')
.forEach(k => {
if(meta[k])
meta[k] = cdblib.findopt($, `select#${k} option`, meta[k]);
});
Object.assign(fields, meta);
let body = Object.keys(fields)
.sort()
.map(k => encodeURIComponent(k) + '=' + encodeURIComponent(fields[k]));
Object.keys(tags)
.map(k => Number(k))
.sort()
.forEach(k => body.push('tags=' + k));
console.log('applying package detail changes...');
await cdblib.fetch(uri, 'post', body.join('&'));
console.log('package details updated');
};