Skip to content

Commit

Permalink
Merge pull request #41 from AthennaIO/develop
Browse files Browse the repository at this point in the history
Fix file extension
  • Loading branch information
jlenon7 authored Mar 23, 2023
2 parents 4a0bdc8 + 1e6bf66 commit 74002a7
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/common",
"version": "3.4.6",
"version": "3.4.7",
"description": "The Athenna common helpers to use in any Node.js ESM project.",
"license": "MIT",
"author": "João Lenon <[email protected]>",
Expand Down
15 changes: 10 additions & 5 deletions src/Helpers/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,19 @@ export class File {
filePath = Path.this(filePath, 3)
}

const { base, dir, root } = parse(filePath)
let { name, base, dir, root, ext } = parse(filePath)

const baseArray = base.split('.')

const name = baseArray.splice(0, 1)[0]
const ext = baseArray.reduce((accumulator, current) => {
return accumulator.concat('.').concat(current)
}, '')
if (base.endsWith('.d.ts')) {
ext = '.d.ts'
name = baseArray.splice(0, 1)[0]
}

if (base.endsWith('.js.map')) {
ext = '.js.map'
name = baseArray.splice(0, 1)[0]
}

const mime = lookup(dir + sep + base)

Expand Down
Empty file.
Empty file.
33 changes: 33 additions & 0 deletions tests/Unit/FileTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,39 @@ test.group('FileTest', group => {
assert.equal(relativePathFile.base, 'package.json')
})

test('should be able to generate instance of files that has dots in the path and the extension should be the last', async ({
assert,
}) => {
const file = new File(Path.stubs('controllers/app.controller.ts'))

assert.isTrue(file.fileExists)
assert.equal(file.extension, '.ts')
assert.equal(file.name, 'app.controller')
assert.equal(file.base, 'app.controller.ts')
})

test('should be able to generate instance of files with .js.map extension and the extension should be .js.map', async ({
assert,
}) => {
const file = new File(Path.stubs('extensions/file.js.map'))

assert.isTrue(file.fileExists)
assert.equal(file.name, 'file')
assert.equal(file.base, 'file.js.map')
assert.equal(file.extension, '.js.map')
})

test('should be able to generate instance of files with .d.ts extension and the extension should be .d.ts', async ({
assert,
}) => {
const file = new File(Path.stubs('extensions/file.d.ts'))

assert.isTrue(file.fileExists)
assert.equal(file.name, 'file')
assert.equal(file.base, 'file.d.ts')
assert.equal(file.extension, '.d.ts')
})

test('should generate an instance of a file, it existing or not', async ({ assert }) => {
assert.equal(bigFile.path, bigFilePath)
assert.equal(bigFile.mime, 'text/plain')
Expand Down

0 comments on commit 74002a7

Please sign in to comment.