@@ -4,18 +4,20 @@ const chalk = require("chalk");
44const { execSync} = require ( "child_process" ) ;
55const FtpDeploy = require ( "ftp-deploy" ) ;
66const 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
1213console . log ( chalk . bgYellow ( chalk . black ( `- DEPLOY PROJECT ${ projectJson . name } -` ) ) ) ;
1314
15+ // set mail constants
1416const FTP_USER = process . env . DSDEPLOY_FTP_USER ;
1517const FTP_HOST = process . env . DSDEPLOY_FTP_HOST ;
1618const FTP_PORT = process . env . DSDEPLOY_FTP_PORT || 21 ;
1719const 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
2123console . log ( chalk . cyan ( '\nBuilding project...' ) ) ;
@@ -25,8 +27,8 @@ execSync('npm run build');
2527let localDir = null ;
2628const localDirs = [ 'dist' , 'build' ] ;
2729for ( 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