Skip to content

Commit ecea6c4

Browse files
authored
Update deploy-ftp.js
1 parent b1c6d2f commit ecea6c4

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

bin/deploy-ftp.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@ const chalk = require("chalk");
44
const {execSync} = require("child_process");
55
const FtpDeploy = require("ftp-deploy");
66
const ftpDeploy = new FtpDeploy();
7-
const projectJson = require(process.cwd() + '/package.json');
7+
const cwd = process.cwd();
8+
const projectJson = require(cwd + '/package.json');
89

910
// load configuration from .env.local file
10-
require('dotenv').config({path: process.cwd() + '/.env.local'});
11+
require('dotenv').config({path: cwd + '/.env.local'});
1112

1213
console.log(chalk.bgYellow(chalk.black(`- DEPLOY PROJECT ${projectJson.name} -`)));
1314

15+
// set mail constants
1416
const FTP_USER = process.env.DSDEPLOY_FTP_USER;
1517
const FTP_HOST = process.env.DSDEPLOY_FTP_HOST;
1618
const FTP_PORT = process.env.DSDEPLOY_FTP_PORT || 21;
1719
const FTP_PASSWORD = process.env.DSDEPLOY_FTP_PASSWORD;
18-
const FTP_REMOTE_DIR = process.env.DSDEPLOY_FTP_REMOTE_DIR || __dirname.split('/').reverse()[0];
20+
const FTP_REMOTE_DIR = process.env.DSDEPLOY_FTP_REMOTE_DIR || cwd.split('/').reverse()[0];
1921

2022
// build project
2123
console.log(chalk.cyan('\nBuilding project...'));
@@ -25,8 +27,8 @@ execSync('npm run build');
2527
let localDir = null;
2628
const localDirs = ['dist', 'build'];
2729
for (let i = 0; i < localDirs.length; i++) {
28-
if (fs.existsSync(localDirs[i])) {
29-
localDir = localDirs[i];
30+
if (fs.existsSync(`${cwd}/${localDirs[i]}`)) {
31+
localDir = `${cwd}/${localDirs[i]}`;
3032
break;
3133
}
3234
}
@@ -45,7 +47,7 @@ const config = {
4547
user: FTP_USER,
4648
host: FTP_HOST,
4749
port: FTP_PORT,
48-
localRoot: __dirname + "/" + localDir,
50+
localRoot: localDir,
4951
remoteRoot: `/${FTP_REMOTE_DIR}/`,
5052
include: ["*", "**/*"], // this would upload everything except dot files
5153
deleteRemote: false, // delete ALL existing files at destination before uploading, if true

0 commit comments

Comments
 (0)