Skip to content

Commit

Permalink
Show upload precess
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekotora committed Aug 1, 2023
1 parent cc78558 commit 20814fa
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions deploy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { Client } = require('node-scp')
const fs = require('fs')
const path = require('path')
require('dotenv').config()

const config = {
Expand All @@ -11,6 +12,45 @@ const config = {
remoteDir: '/data/wwwroot/docs.warudo.app'
}

function joinRemote(client, ...args) {
if (client.remotePathSep === path.win32.sep) {
return path.win32.join(...args)
}
return path.posix.join(...args)
}

async function uploadDir(src, dest) {
try {
const isExist = await this.exists(dest)

if (!isExist) {
console.log(`mkdir: ${dest}`);
await this.mkdir(dest)
}

const dirEntries = fs.readdirSync(src, {
encoding: 'utf8',
withFileTypes: true,
})

for (const e of dirEntries) {
if (e.isDirectory()) {
const newSrc = path.join(src, e.name)
const newDst = joinRemote(this, dest, e.name)
console.log(`upload dir: ${newDst}`);
await this.uploadDir(newSrc, newDst)
} else if (e.isFile()) {
const newSrc = path.join(src, e.name)
const newDst = joinRemote(this, dest, e.name)
console.log(`upload file: ${newDst}`);
await this.uploadFile(newSrc, newDst)
}
}
} catch (error) {
throw error
}
}

async function submit() {
if(!await fs.existsSync('./build')) {
throw Error('Build file not exists, run `yarn build` first.')
Expand All @@ -27,6 +67,7 @@ async function submit() {
});
console.log('Uploading files...')
await scpClient.emptyDir(config.remoteDir)
scpClient.uploadDir = uploadDir;
await scpClient.uploadDir(config.localDir, config.remoteDir);
await scpClient.close();
}catch(e) {
Expand Down

0 comments on commit 20814fa

Please sign in to comment.