mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2025-05-18 12:02:53 +02:00
@ -1,38 +0,0 @@
|
||||
import fs from 'node:fs'
|
||||
|
||||
import fsMock from 'mock-fs'
|
||||
import tap from 'tap'
|
||||
|
||||
import {
|
||||
TEMPORARY_PATH,
|
||||
createTemporaryEmptyFolder
|
||||
} from '../createTemporaryEmptyFolder.js'
|
||||
import { isExistingPath } from '../isExistingPath.js'
|
||||
|
||||
await tap.test('utils/createTemporaryEmptyFolder', async (t) => {
|
||||
t.afterEach(() => {
|
||||
fsMock.restore()
|
||||
})
|
||||
|
||||
await t.test('should create the temporary folder', async (t) => {
|
||||
fsMock({})
|
||||
t.equal(await isExistingPath(TEMPORARY_PATH), false)
|
||||
await createTemporaryEmptyFolder()
|
||||
t.equal(await isExistingPath(TEMPORARY_PATH), true)
|
||||
})
|
||||
|
||||
await t.test(
|
||||
'should remove and create again the temporary folder',
|
||||
async (t) => {
|
||||
fsMock({
|
||||
[TEMPORARY_PATH]: {
|
||||
'file.txt': ''
|
||||
}
|
||||
})
|
||||
t.equal(await isExistingPath(TEMPORARY_PATH), true)
|
||||
t.equal((await fs.promises.readdir(TEMPORARY_PATH)).length, 1)
|
||||
await createTemporaryEmptyFolder()
|
||||
t.equal((await fs.promises.readdir(TEMPORARY_PATH)).length, 0)
|
||||
}
|
||||
)
|
||||
})
|
@ -1,10 +1,10 @@
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
|
||||
export async function copyDirectory(
|
||||
export const copyDirectory = async (
|
||||
source: string,
|
||||
destination: string
|
||||
): Promise<void> {
|
||||
): Promise<void> => {
|
||||
const filesToCreate = await fs.promises.readdir(source)
|
||||
for (const file of filesToCreate) {
|
||||
const originalFilePath = path.join(source, file)
|
||||
|
@ -1,14 +0,0 @@
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import fs from 'node:fs'
|
||||
|
||||
import { isExistingPath } from '../utils/isExistingPath.js'
|
||||
|
||||
export const TEMPORARY_URL = new URL('../../temp', import.meta.url)
|
||||
export const TEMPORARY_PATH = fileURLToPath(TEMPORARY_URL)
|
||||
|
||||
export const createTemporaryEmptyFolder = async (): Promise<void> => {
|
||||
if (await isExistingPath(TEMPORARY_PATH)) {
|
||||
await fs.promises.rm(TEMPORARY_URL, { recursive: true, force: true })
|
||||
}
|
||||
await fs.promises.mkdir(TEMPORARY_URL)
|
||||
}
|
10
cli/utils/parseCommandOutput.ts
Normal file
10
cli/utils/parseCommandOutput.ts
Normal file
@ -0,0 +1,10 @@
|
||||
export const parseCommandOutput = (output: string): string[] => {
|
||||
return output
|
||||
.split('\n')
|
||||
.map((line) => {
|
||||
return line.trim()
|
||||
})
|
||||
.filter((line) => {
|
||||
return line.length > 0
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user