Archived
记录与数据处理
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import Client from 'ssh2-sftp-client';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const HOST = process.env.DEPLOY_HOST ?? '192.168.1.71';
|
||||
const USERNAME = process.env.DEPLOY_USER ?? 'feie9454';
|
||||
const REMOTE_DIR = process.env.DEPLOY_PATH ?? '/var/www/html';
|
||||
const PASSWORD = process.env.DEPLOY_PASSWORD;
|
||||
|
||||
if (!PASSWORD) {
|
||||
console.error('Missing DEPLOY_PASSWORD env var.');
|
||||
console.error('Example (PowerShell): $env:DEPLOY_PASSWORD="<your password>"; npm run deploy');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const localDist = path.resolve(__dirname, '..', 'dist');
|
||||
|
||||
const sftp = new Client();
|
||||
|
||||
try {
|
||||
console.log(`Deploying ${localDist} -> ${USERNAME}@${HOST}:${REMOTE_DIR}`);
|
||||
|
||||
await sftp.connect({
|
||||
host: HOST,
|
||||
username: USERNAME,
|
||||
password: PASSWORD,
|
||||
readyTimeout: 20000,
|
||||
});
|
||||
|
||||
// Ensure remote directory exists
|
||||
await sftp.mkdir(REMOTE_DIR, true);
|
||||
|
||||
// Upload dist contents into REMOTE_DIR
|
||||
await sftp.uploadDir(localDist, REMOTE_DIR);
|
||||
|
||||
console.log('Deploy complete.');
|
||||
} catch (err) {
|
||||
console.error('Deploy failed:', err?.message ?? err);
|
||||
process.exitCode = 1;
|
||||
} finally {
|
||||
try {
|
||||
await sftp.end();
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user