-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d59a63
commit 95b5293
Showing
3 changed files
with
151 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { deleteDirectoryAndFiles, dirPath, names, coolText } from './test.js'; | ||
|
||
export async function createDirectoryWithFiles() { | ||
await deleteDirectoryAndFiles(); | ||
// Create directory | ||
await fs.promises.mkdir(dirPath); | ||
|
||
const getRandomNames = (num = 1) => { | ||
let nameArr = []; | ||
for (let i = 0; i < num; i++) { | ||
nameArr.push(names[Math.floor(Math.random() * names.length)]); | ||
} | ||
return nameArr.join(' '); | ||
}; | ||
let arr = Array.from({ length: 20 }, (_, i) => i); | ||
let testFilesMade = 0; | ||
let oneFilePath = ''; | ||
for await (let i of arr) { | ||
const num = Math.floor(Math.random() * 5) + 1; | ||
let ext = '.txt'; | ||
if (i === 0) { | ||
ext = '.md'; | ||
} | ||
|
||
let filePath = path.join(dirPath, `${getRandomNames(num)}${ext}`); | ||
await fs.promises.writeFile(filePath, 'Test content'); | ||
testFilesMade++; | ||
if (i === 19) { | ||
oneFilePath = filePath; | ||
} | ||
} | ||
console.log(coolText(`created ${testFilesMade} test files`)); | ||
return oneFilePath; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters