mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: install: save metadata
This commit is contained in:
1 parent
3c97ff74a9
commit
90528f15d1
1 file changed
+14
-2
@@ -127,11 +127,16 @@ if (!argv.args[0] || argv.args[0] === 'cli') {
|
||||
console.log('Current Addons: ', addons);
|
||||
fs.writeFileSync(addonPath, JSON.stringify(addons, null, 2));
|
||||
});
|
||||
cli.command('install [package]').action(async (src) => {
|
||||
cli.command('install [package]').action(async (_src) => {
|
||||
if (!_src) {
|
||||
cli.outputHelp();
|
||||
return;
|
||||
}
|
||||
if (yarnVersion !== 1) throw new Error('Yarn 1 is required.');
|
||||
const addonDir = path.join(hydroPath, 'addons');
|
||||
let newAddonPath: string = '';
|
||||
fs.ensureDirSync(addonDir);
|
||||
let src = _src;
|
||||
if (!src.startsWith('http')) {
|
||||
try {
|
||||
src = child.execSync(`yarn info ${src} dist.tarball`, { cwd: os.tmpdir() })
|
||||
@@ -164,8 +169,15 @@ if (!argv.args[0] || argv.args[0] === 'cli') {
|
||||
console.log('Installing depedencies');
|
||||
child.execSync('yarn --production', { stdio: 'inherit', cwd: newAddonPath });
|
||||
child.execSync(`hydrooj addon add '${newAddonPath}'`);
|
||||
fs.writeFileSync(path.join(newAddonPath, '__metadata__'), JSON.stringify({
|
||||
src: _src,
|
||||
lastUpdate: Date.now(),
|
||||
}));
|
||||
});
|
||||
cli.help();
|
||||
cli.parse();
|
||||
if (!cli.matchedCommand) console.log('Unknown command.');
|
||||
if (!cli.matchedCommand) {
|
||||
console.log('Unknown command.');
|
||||
cli.outputHelp();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user