You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
/* eslint-disable import/no-dynamic-require */
|
|
|
|
/* eslint-disable no-await-in-loop */
|
|
|
|
/* eslint-disable no-eval */
|
|
|
|
const fs = require('fs');
|
|
|
|
const zlib = require('zlib');
|
|
|
|
const path = require('path');
|
|
|
|
const yaml = require('js-yaml');
|
|
|
|
const download = require('./download');
|
|
|
|
|
|
|
|
function root(name) {
|
|
|
|
return path.resolve(process.cwd(), name);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getInstalled() {
|
|
|
|
const files = fs.readdirSync(root('.build/module'));
|
|
|
|
const installed = [];
|
|
|
|
for (const file of files) {
|
|
|
|
if (file.endsWith('.hydro')) {
|
|
|
|
const f = fs.readFileSync(root(`.build/module/${file}`));
|
|
|
|
const s = fs.statSync(root(`.build/module/${file}`));
|
|
|
|
installed.push({
|
|
|
|
...yaml.safeLoad(zlib.gunzipSync(f)),
|
|
|
|
id: file.split('.')[0],
|
|
|
|
size: s.size,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return installed;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function del(id) {
|
|
|
|
fs.unlinkSync(root(`.build/module/${id}.hydro`));
|
|
|
|
}
|
|
|
|
|
|
|
|
async function install(id, url) {
|
|
|
|
await download(url, root(`module/${id}.hydro`));
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { getInstalled, del, install };
|