mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-09 23:48:36 +01:00
add email service deploy
This commit is contained in:
36
scripts/helpers/deploy-helper.ts
Normal file
36
scripts/helpers/deploy-helper.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
import { Client, ScpClient } from 'node-scp';
|
||||
import { NodeSSH } from 'node-ssh'
|
||||
import fs from 'fs-extra';
|
||||
import { REMOTE_HOST, IDENTITY_FILE } from '../.config'
|
||||
|
||||
export class DeployHelper {
|
||||
|
||||
private static scpClient: ScpClient;
|
||||
private static sshClient: NodeSSH;
|
||||
|
||||
static async connect() {
|
||||
this.scpClient = await Client({
|
||||
host: REMOTE_HOST,
|
||||
username: 'root',
|
||||
privateKey: fs.readFileSync(IDENTITY_FILE)
|
||||
})
|
||||
this.sshClient = new NodeSSH();
|
||||
await this.sshClient.connect({
|
||||
host: REMOTE_HOST,
|
||||
username: 'root',
|
||||
privateKeyPath: IDENTITY_FILE
|
||||
});
|
||||
}
|
||||
|
||||
static async execute(command: string) {
|
||||
const res = await this.sshClient.execCommand(command);
|
||||
console.log(res);
|
||||
}
|
||||
|
||||
static instances() {
|
||||
return { scp: this.scpClient, ssh: this.sshClient }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
35
scripts/helpers/zip-helper.ts
Normal file
35
scripts/helpers/zip-helper.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
import fs from 'fs-extra';
|
||||
import archiver from 'archiver';
|
||||
|
||||
|
||||
function handleEvents(archive: archiver.Archiver, output: fs.WriteStream) {
|
||||
|
||||
output.on('close', function () {
|
||||
console.log(archive.pointer() + ' total bytes');
|
||||
});
|
||||
|
||||
output.on('end', function () {
|
||||
console.log('Data has been drained');
|
||||
});
|
||||
|
||||
archive.on('warning', function (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
console.error(err);
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
|
||||
archive.on('error', function (err) {
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
|
||||
export function createZip(outPath: string) {
|
||||
const output = fs.createWriteStream(outPath);
|
||||
const archive = archiver('zip', { zlib: { level: 2 } });
|
||||
handleEvents(archive, output);
|
||||
archive.pipe(output);
|
||||
return archive;
|
||||
}
|
||||
Reference in New Issue
Block a user