cli/src/build/repository/deployment/develop.ts

48 lines
1.3 KiB
TypeScript

import fs from 'fs-extra';
import path from 'path';
import { loadEnvironment } from '@squeebot/core/lib/core';
/**
* Deploy to a local environment
* @param location Repository location
* @param meta Deployment metadata
* @param outDir Repository output files
*/
export async function developDeploy(
location: string,
meta: Record<string, string | number>,
outDir: string,
): Promise<void> {
console.log('Deploying to a configured Squeebot development environment');
const devbotPath = path.resolve(location, meta.devSqueebot as string);
console.log('Path:', devbotPath);
if (!await fs.pathExists(devbotPath)) {
throw new Error('Development Squeebot environment file doesn\'t exist!');
}
const devEnv = await loadEnvironment(devbotPath);
if (!devEnv.pluginsPath) {
throw new Error('Bad development Squeebot environment file!');
}
const pluginsPath = path.resolve(devEnv.path, devEnv.pluginsPath);
console.log('Copying plugins to', pluginsPath);
const listAllFiles = await fs.readdir(outDir);
for (const f of listAllFiles) {
if (f === 'repository' || f.endsWith('.tgz') || f.endsWith('.json')) {
continue;
}
const dst = path.join(pluginsPath, f);
await fs.copy(path.join(outDir, f), dst, {
overwrite: true,
});
}
console.log('Done!');
}