mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
模块管理器
This commit is contained in:
1 parent
04941936bc
commit
3e9b074e77
22 files changed
+191
-59
No files matched your search
@@ -0,0 +1,39 @@
|
||||
/* 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-module')) {
|
||||
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-module`));
|
||||
}
|
||||
|
||||
async function install(id, url) {
|
||||
await download(url, root(`module/${id}.hydro-module`));
|
||||
}
|
||||
|
||||
module.exports = { getInstalled, del, install };
|
||||
Reference in new issue
Block a user