Skip to content

Commit

Permalink
fix: correct bug in single file rename
Browse files Browse the repository at this point in the history
Add test to check for name change
  • Loading branch information
nerdoza committed Oct 31, 2023
1 parent 6140a36 commit 81f9b4c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/ftp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default async function (options: Options) {
await ftpClient.ensureDir(path)
} catch (error) {
if (shouldBeVerbose) {
console.error(`Could not create directory ${path}`)
console.error(`Could not create directory '${path}'`)
}
throw error
}
Expand All @@ -57,20 +57,23 @@ export default async function (options: Options) {
try {
for (const fileSource of fileSources) {
const parsedFileSource = parse(fileSource)
const parsedFileDest = parse(options.dest)
const remoteDir = srcIsDynamic
? join(options.dest, parsedFileSource.dir.replace(parse(options.src).dir, ''))
: parse(options.dest).dir
: parsedFileDest.dir

if (shouldBeVerbose) {
console.log(`Ensuring directory ${remoteDir} exists`)
console.log(`Ensuring directory '${remoteDir}' exists`)
}
await ftpClient.cd('/')
await ensureDir(remoteDir)

const remoteFile = join(remoteDir, parsedFileSource.base)
const remoteFile = srcIsDynamic
? join(remoteDir, parsedFileSource.base)
: join(remoteDir, parsedFileDest.base)

if (shouldBeVerbose) {
console.log(`Uploading ${fileSource} to ${remoteFile}`)
console.log(`Uploading '${fileSource}' to '${remoteFile}'`)
}
await ftpClient.uploadFrom(fileSource, remoteFile)
}
Expand Down
12 changes: 12 additions & 0 deletions test/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ describe('Upload File', function () {
this.timeout(10000)

it('can upload test file using FTP', async function () {
const config = {
...defaultConfig,
src: 'test/fixtures/index.html',
dest: 'upload/index.html'
}

const uploadedFiles = await UploadFile(config)
expect(uploadedFiles).to.be.an('array')
expect(uploadedFiles).to.have.lengthOf(1)
})

it('can upload renamed test file using FTP', async function () {
const config = {
...defaultConfig,
src: 'test/fixtures/index.html',
Expand Down

0 comments on commit 81f9b4c

Please sign in to comment.