deploy.sh -> deploy.js
This commit is contained in:
parent
42573afb62
commit
2bee1f5d79
@ -6,7 +6,8 @@
|
||||
"build": "nuxt generate",
|
||||
"dev": "nuxt dev --host",
|
||||
"preview": "nuxt preview",
|
||||
"postinstall": "nuxt prepare"
|
||||
"postinstall": "nuxt prepare",
|
||||
"deploy": "node ./scripts/deploy.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@floating-ui/vue": "^1.1.5",
|
||||
@ -38,6 +39,7 @@
|
||||
"nuxt": "^4.0.3",
|
||||
"nuxt-svgo": "^4.0.9",
|
||||
"sass": "^1.81.0",
|
||||
"ssh2-sftp-client": "^12.0.1",
|
||||
"typescript": "^5.7.2",
|
||||
"unenv": "^1.10.0",
|
||||
"unplugin-icons": "^0.20.1",
|
||||
|
||||
84
scripts/deploy.js
Normal file
84
scripts/deploy.js
Normal file
@ -0,0 +1,84 @@
|
||||
import { execSync } from 'node:child_process'
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
import readline from 'node:readline'
|
||||
import SftpClient from 'ssh2-sftp-client'
|
||||
|
||||
const HOST = '92.53.106.114'
|
||||
const USERNAME = 'cs21601'
|
||||
const REMOTE_BASE = '/home/c/cs21601/quantum'
|
||||
const LOCAL_DIST = path.resolve('./dist')
|
||||
const LOCAL_SRC_ARCHIVE = path.resolve('./src.zip')
|
||||
const DATE = new Date().toISOString().replace(/[-:]/g, '').replace(/\..+/, '');
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const password = await ask(`Введите пароль для ${USERNAME}@${HOST}: `)
|
||||
|
||||
// 1) yarn build
|
||||
execSync('yarn build', { stdio: 'inherit' })
|
||||
|
||||
// 2) git archive
|
||||
execSync(`git archive --format=zip --output=${LOCAL_SRC_ARCHIVE} main`, { stdio: 'inherit' })
|
||||
|
||||
const sftp = new SftpClient()
|
||||
await sftp.connect({
|
||||
host: HOST,
|
||||
port: 22,
|
||||
username: USERNAME,
|
||||
password,
|
||||
})
|
||||
|
||||
// 3) Переименование public_html
|
||||
try {
|
||||
await sftp.rename(`${REMOTE_BASE}/public_html`, `${REMOTE_BASE}/public_html_${DATE}`)
|
||||
console.log('✅ Папка public_html переименована')
|
||||
}
|
||||
catch {
|
||||
console.log('⚠️ public_html не найдена, пропускаю переименование')
|
||||
}
|
||||
|
||||
// 4) Загрузка dist
|
||||
await sftp.mkdir(`${REMOTE_BASE}/public_html`, true)
|
||||
await uploadDir(sftp, LOCAL_DIST, `${REMOTE_BASE}/public_html`)
|
||||
|
||||
// 5) Загрузка src.zip
|
||||
await sftp.mkdir(`${REMOTE_BASE}/src`, true)
|
||||
await sftp.put(LOCAL_SRC_ARCHIVE, `${REMOTE_BASE}/src.zip`)
|
||||
|
||||
await sftp.end()
|
||||
console.log('🎉 Деплой завершён успешно!')
|
||||
}
|
||||
catch (err) {
|
||||
console.error('❌ Ошибка деплоя:', err.message)
|
||||
process.exit(1)
|
||||
}
|
||||
})()
|
||||
|
||||
function ask(query) {
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
})
|
||||
return new Promise((resolve) => {
|
||||
rl.question(query, (value) => {
|
||||
rl.close()
|
||||
resolve(value)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
async function uploadDir(sftp, localDir, remoteDir) {
|
||||
const items = fs.readdirSync(localDir)
|
||||
for (const item of items) {
|
||||
const localPath = path.join(localDir, item)
|
||||
const remotePath = `${remoteDir}/${item}`
|
||||
if (fs.lstatSync(localPath).isDirectory()) {
|
||||
await sftp.mkdir(remotePath, true)
|
||||
await uploadDir(sftp, localPath, remotePath)
|
||||
}
|
||||
else {
|
||||
await sftp.put(localPath, remotePath)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
HOST="92.53.106.114"
|
||||
USER="cs21601"
|
||||
REMOTE_BASE="/home/c/cs21601/quantum"
|
||||
DATE=$(date +%Y%m%d_%H%M%S)
|
||||
|
||||
# 1) yarn build
|
||||
yarn build
|
||||
|
||||
# 2) git archive
|
||||
git archive --format=zip --output=src.zip main
|
||||
|
||||
# 3) Переименовать public_html
|
||||
ssh ${USER}@${HOST} "mv ${REMOTE_BASE}/public_html ${REMOTE_BASE}/public_html_${DATE} || echo 'public_html не найдена'"
|
||||
|
||||
# 4) Загрузка dist
|
||||
scp -r dist/* ${USER}@${HOST}:${REMOTE_BASE}/public_html/
|
||||
|
||||
# 5) Загрузка src.zip
|
||||
scp src.zip ${USER}@${HOST}:${REMOTE_BASE}/
|
||||
|
||||
echo "✅ Деплой завершён"
|
||||
103
yarn.lock
103
yarn.lock
@ -4488,6 +4488,15 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"asn1@npm:^0.2.6":
|
||||
version: 0.2.6
|
||||
resolution: "asn1@npm:0.2.6"
|
||||
dependencies:
|
||||
safer-buffer: "npm:~2.1.0"
|
||||
checksum: 10c0/00c8a06c37e548762306bcb1488388d2f76c74c36f70c803f0c081a01d3bdf26090fc088cd812afc5e56a6d49e33765d451a5f8a68ab9c2b087eba65d2e980e0
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"ast-kit@npm:^2.0.0, ast-kit@npm:^2.1.1":
|
||||
version: 2.1.2
|
||||
resolution: "ast-kit@npm:2.1.2"
|
||||
@ -4642,6 +4651,15 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"bcrypt-pbkdf@npm:^1.0.2":
|
||||
version: 1.0.2
|
||||
resolution: "bcrypt-pbkdf@npm:1.0.2"
|
||||
dependencies:
|
||||
tweetnacl: "npm:^0.14.3"
|
||||
checksum: 10c0/ddfe85230b32df25aeebfdccfbc61d3bc493ace49c884c9c68575de1f5dcf733a5d7de9def3b0f318b786616b8d85bad50a28b1da1750c43e0012c93badcc148
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"binary-extensions@npm:^2.0.0":
|
||||
version: 2.3.0
|
||||
resolution: "binary-extensions@npm:2.3.0"
|
||||
@ -4766,6 +4784,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"buildcheck@npm:~0.0.6":
|
||||
version: 0.0.6
|
||||
resolution: "buildcheck@npm:0.0.6"
|
||||
checksum: 10c0/8cbdb89f41bc484b8325f4828db4135b206a0dffb641eb6cdb2b7022483c45dd0e5aac6d820c9a67bdd2caab3a02c76d7ceec7bd9ec494b5a2270d2806b01a76
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"builtin-modules@npm:^3.3.0":
|
||||
version: 3.3.0
|
||||
resolution: "builtin-modules@npm:3.3.0"
|
||||
@ -5257,6 +5282,18 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"concat-stream@npm:^2.0.0":
|
||||
version: 2.0.0
|
||||
resolution: "concat-stream@npm:2.0.0"
|
||||
dependencies:
|
||||
buffer-from: "npm:^1.0.0"
|
||||
inherits: "npm:^2.0.3"
|
||||
readable-stream: "npm:^3.0.2"
|
||||
typedarray: "npm:^0.0.6"
|
||||
checksum: 10c0/29565dd9198fe1d8cf57f6cc71527dbc6ad67e12e4ac9401feb389c53042b2dceedf47034cbe702dfc4fd8df3ae7e6bfeeebe732cc4fa2674e484c13f04c219a
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"confbox@npm:^0.1.8":
|
||||
version: 0.1.8
|
||||
resolution: "confbox@npm:0.1.8"
|
||||
@ -5348,6 +5385,17 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"cpu-features@npm:~0.0.10":
|
||||
version: 0.0.10
|
||||
resolution: "cpu-features@npm:0.0.10"
|
||||
dependencies:
|
||||
buildcheck: "npm:~0.0.6"
|
||||
nan: "npm:^2.19.0"
|
||||
node-gyp: "npm:latest"
|
||||
checksum: 10c0/0c4a12904657b22477ffbcfd2b4b2bdd45b174f283616b18d9e1ade495083f9f6098493feb09f4ae2d0b36b240f9ecd32cfb4afe210cf0d0f8f0cc257bd58e54
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"crc-32@npm:^1.2.0":
|
||||
version: 1.2.2
|
||||
resolution: "crc-32@npm:1.2.2"
|
||||
@ -9654,6 +9702,15 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"nan@npm:^2.19.0, nan@npm:^2.20.0":
|
||||
version: 2.23.0
|
||||
resolution: "nan@npm:2.23.0"
|
||||
dependencies:
|
||||
node-gyp: "npm:latest"
|
||||
checksum: 10c0/b986dd257dca53ab43a3b6ca6d0eafde697b69e1d63b242fa4aece50ce97eb169f9c4a5d8eb0eb5f58d118a9595fee11f3198fa210f023440053bb6f54109e73
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"nanoid@npm:^3.3.11":
|
||||
version: 3.3.11
|
||||
resolution: "nanoid@npm:3.3.11"
|
||||
@ -10063,6 +10120,7 @@ __metadata:
|
||||
nuxt: "npm:^4.0.3"
|
||||
nuxt-svgo: "npm:^4.0.9"
|
||||
sass: "npm:^1.81.0"
|
||||
ssh2-sftp-client: "npm:^12.0.1"
|
||||
swiper: "npm:^11.1.15"
|
||||
typescript: "npm:^5.7.2"
|
||||
unenv: "npm:^1.10.0"
|
||||
@ -11511,7 +11569,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"readable-stream@npm:^3.1.1, readable-stream@npm:^3.4.0, readable-stream@npm:^3.6.2":
|
||||
"readable-stream@npm:^3.0.2, readable-stream@npm:^3.1.1, readable-stream@npm:^3.4.0, readable-stream@npm:^3.6.2":
|
||||
version: 3.6.2
|
||||
resolution: "readable-stream@npm:3.6.2"
|
||||
dependencies:
|
||||
@ -11871,7 +11929,7 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"safer-buffer@npm:>= 2.1.2 < 3.0.0":
|
||||
"safer-buffer@npm:>= 2.1.2 < 3.0.0, safer-buffer@npm:~2.1.0":
|
||||
version: 2.1.2
|
||||
resolution: "safer-buffer@npm:2.1.2"
|
||||
checksum: 10c0/7e3c8b2e88a1841c9671094bbaeebd94448111dd90a81a1f606f3f67708a6ec57763b3b47f06da09fc6054193e0e6709e77325415dc8422b04497a8070fa02d4
|
||||
@ -12315,6 +12373,33 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"ssh2-sftp-client@npm:^12.0.1":
|
||||
version: 12.0.1
|
||||
resolution: "ssh2-sftp-client@npm:12.0.1"
|
||||
dependencies:
|
||||
concat-stream: "npm:^2.0.0"
|
||||
ssh2: "npm:^1.16.0"
|
||||
checksum: 10c0/38017b7ff5a935873be99e17ce401b426cf4c78dad6b4cd29ae18ba12ec418bda72b336b451e7ba4d5a1e1c4ccb029ded49fd6ff7398f3804e52084fbf0d3df1
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"ssh2@npm:^1.16.0":
|
||||
version: 1.16.0
|
||||
resolution: "ssh2@npm:1.16.0"
|
||||
dependencies:
|
||||
asn1: "npm:^0.2.6"
|
||||
bcrypt-pbkdf: "npm:^1.0.2"
|
||||
cpu-features: "npm:~0.0.10"
|
||||
nan: "npm:^2.20.0"
|
||||
dependenciesMeta:
|
||||
cpu-features:
|
||||
optional: true
|
||||
nan:
|
||||
optional: true
|
||||
checksum: 10c0/d336a85d87501c64ba230b6c1a2901a9b0e376fe7f7a1640a7f8dbdafe674b2e1a5dc6236ffd1329969dc0cf03cd57759b28743075e61229a984065ee1d56bed
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"ssri@npm:^12.0.0":
|
||||
version: 12.0.0
|
||||
resolution: "ssri@npm:12.0.0"
|
||||
@ -12923,6 +13008,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"tweetnacl@npm:^0.14.3":
|
||||
version: 0.14.5
|
||||
resolution: "tweetnacl@npm:0.14.5"
|
||||
checksum: 10c0/4612772653512c7bc19e61923fbf42903f5e0389ec76a4a1f17195859d114671ea4aa3b734c2029ce7e1fa7e5cc8b80580f67b071ecf0b46b5636d030a0102a2
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"type-check@npm:^0.4.0, type-check@npm:~0.4.0":
|
||||
version: 0.4.0
|
||||
resolution: "type-check@npm:0.4.0"
|
||||
@ -12967,6 +13059,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"typedarray@npm:^0.0.6":
|
||||
version: 0.0.6
|
||||
resolution: "typedarray@npm:0.0.6"
|
||||
checksum: 10c0/6005cb31df50eef8b1f3c780eb71a17925f3038a100d82f9406ac2ad1de5eb59f8e6decbdc145b3a1f8e5836e17b0c0002fb698b9fe2516b8f9f9ff602d36412
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"typescript@npm:^5.7.2, typescript@npm:^5.7.3":
|
||||
version: 5.9.2
|
||||
resolution: "typescript@npm:5.9.2"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user