cli/src/build/repository/deploy.ts

46 lines
1.3 KiB
TypeScript

import fs from 'fs-extra';
import path from 'path';
import { sshDeploy } from './deployment/ssh';
import { developDeploy } from './deployment/develop';
/**
* Deploy according to configuration
* @param name Repository name
* @param location Repository path
* @param outDir Output directory
* @param deployment Deployment name
*/
export async function deploy(
name: string,
location: string,
outDir: string,
deployment: string): Promise<void> {
const deployFile = path.join(location, 'deployment.json');
if (!await fs.pathExists(deployFile)) {
throw new Error('deployment.json file is missing! Can\'t deploy!');
}
const meta = await fs.readJson(deployFile);
// If we have a path to a metadata file, we copy the output directory to
// the plugins directory, overwriting existing plugins with the same name!
if ((deployment.indexOf('dev') === 0 || deployment.indexOf('squee') === 0)
&& meta.devSqueebot) {
console.log('\n [!!!] DEPLOYING REPOSITORY FOR DEVELOPMENT [!!!]\n');
developDeploy(location, meta, outDir);
return;
}
// Other deployment methods come here
if (deployment in meta) {
console.log('\n [!!!] DEPLOYING REPOSITORY [!!!]\n');
const dpl = meta[deployment];
if (dpl.ssh) {
await sshDeploy(outDir, dpl);
}
}
}