Skip to content

Commit

Permalink
fix: Fix f.path sometimes being undefined (#533)
Browse files Browse the repository at this point in the history
* fix: Append `.gitattributes` file as well

* fix: Fix `f.path` sometimes being undefined

* Update createGitAttributes.ts
  • Loading branch information
mrousavy authored Feb 10, 2025
1 parent ff9d709 commit 4907639
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/nitrogen/src/createGitAttributes.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import fs from 'fs/promises'
import path from 'path'

const GIT_ATTRIBUTES_CONTENT = `
* linguist-generated
`

export async function createGitAttributes(folder: string): Promise<string> {
const file = path.join(folder, '.gitattributes')
// Marks all files in this current folder as "generated"
await fs.writeFile(file, `* linguist-generated`)
await fs.writeFile(file, GIT_ATTRIBUTES_CONTENT.trim() + '\n', 'utf-8')
return file
}
9 changes: 7 additions & 2 deletions packages/nitrogen/src/getFiles.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { promises as fs } from 'fs'
import { Dirent, promises as fs } from 'fs'
import path from 'path'

function getFilePath(file: Dirent, rootDir: string): string {
const dir = file.parentPath ?? file.path ?? rootDir
return path.join(dir, file.name)
}

export async function getFiles(directory: string): Promise<string[]> {
try {
const files = await fs.readdir(directory, {
recursive: true,
withFileTypes: true,
})

return files.filter((f) => f.isFile()).map((f) => path.join(f.path, f.name))
return files.filter((f) => f.isFile()).map((f) => getFilePath(f, directory))
} catch (error) {
if (
typeof error === 'object' &&
Expand Down

0 comments on commit 4907639

Please sign in to comment.