Add dry run, mod scan.

This commit is contained in:
Aaron Suen 2020-03-27 23:43:56 -04:00
parent 86569d426b
commit 5795bef3a4
5 changed files with 109 additions and 2 deletions

View File

@ -11,7 +11,7 @@ const keepers = {};
module.exports = async () => {
const meta = {};
Object.keys(config)
.filter(k => keepers[k])
.filter(k => keepers[k] && config[k])
.forEach(k => meta[k] = config[k]);
if(!Object.keys(meta)
.length)
@ -48,6 +48,11 @@ module.exports = async () => {
.sort()
.forEach(k => body.push('tags=' + k));
if(config.dryrun) {
console.log('dry run; not saving details');
console.log(body);
return;
}
console.log('applying package detail changes...');
await cdblib.fetch(uri, 'post', body.join('&'));
console.log('package details updated');

View File

@ -31,6 +31,11 @@ async function makerelease() {
fields.vcsLabel = config.branch;
fields.uploadOpt = 'vcs';
fields.title = config.version;
if(config.dryrun) {
console.log('dry run; not submitting');
console.log(JSON.stringify(fields));
return;
}
console.log('submitting new release...');
$ = await cdblib.fetch(uri, 'post', fields, {
follow_max: 10
@ -51,7 +56,12 @@ module.exports = async () => {
console.log('version ' + config.version + ' already released');
return;
}
await makerelease();
if(config.dryrun) {
console.log('not waiting for release due to dry run');
return true;
}
console.log('waiting for new submission to be listed...');
for(let i = 0; i < config.timeout; i += config.poll) {
if(await checkalready()) {

View File

@ -7,7 +7,7 @@ const config = {};
module.exports = config;
const layers = {};
const layord = 'default fromfile fromgit frommeta cmdline'.split(' ');
const layord = 'default fromfile modscan fromgit cmdline'.split(' ');
function set(name, obj) {
if(!layord.find(x => x === name))

View File

@ -113,6 +113,9 @@ module.exports = async () => {
const spec = JSON.parse(buff);
config.set('fromgit', spec);
const scanned = require('./modscan')(outdir);
config.set('')
} finally {
await fsx.emptyDir(tmpdir.path);
await tmpdir.cleanup();

89
modscan.js Normal file
View File

@ -0,0 +1,89 @@
const fs = require('fs');
const path = require('path');
const config = require('./config');
async function readstr(...paths) {
return await new Promise((r, j) => fs.readFile(path.join(...paths), (e, x) => {
if(e && e.code === 'ENOENT') return r();
if(e) return j(e);
return r(x.toString());
}));
}
async function findmods(data, ...pathparts) {
const pathname = path.join(...pathparts);
const ents = {};
(await new Promise(r => fs.readdir(pathname, (e, x) => e ? r([]) : r(x))))
.filter(x => !x.startsWith('.'))
.forEach(x => ents[x] = true);
let recurse = Object.keys(ents);
if(ents['game.conf'])
recurse = recurse.filter(x => x === 'mods');
const tasks = recurse.map(x => findmods(data, ...pathparts, x));
let modname = (pathparts.length === 1) ? config.pkg : pathparts[pathparts.length - 1];
if(ents['depends.txt'])
(await readstr(pathname, 'depends.txt') || '')
.split('\n')
.filter(x => /\S/.test(x))
.map(x => x.replace(/#.*/, '')
.trim())
.forEach(x => {
if(x.endsWith('?'))
data.soft[x.replace('?', '')] = true;
else
data.hard[x] = true;
});
if(ents['mod.conf']) {
const conf = {};
(await readstr(pathname, 'mod.conf') || '')
.split('\n')
.map(x => x.replace(/#.*/, ''))
.forEach(x => {
const a = x.split('=', 2)
.map(x => x.trim());
conf[a[0]] = a[1];
});
if(conf.depends)
conf.depends
.split(',')
.map(x => x.trim())
.forEach(x => data.hard[x] = true);
if(conf.optional_depends)
conf.optional_depends
.split(',')
.map(x => x.trim())
.forEach(x => data.soft[x] = true);
if(conf.name)
modname = conf.name;
}
if(ents['init.lua'])
data.prov[modname] = true;
await Promise.all(tasks);
}
function apply(obj, key, src) {
if(!obj[key] && obj[key] !== '')
obj[key] = Object.keys(src)
.sort()
.join(',');
}
async function modscan(pathname) {
const data = {
prov: {},
hard: {},
soft: {}
};
await findmods(data, pathname);
const meta = {};
apply(meta, 'provides_str', data.prov);
apply(meta, 'harddep_str', data.hard);
apply(meta, 'softdep_str', data.soft);
return meta;
}
module.exports = modscan;