diff --git a/README.md b/README.md index 1c61c898..897348ef 100644 --- a/README.md +++ b/README.md @@ -148,11 +148,11 @@ deno run npm:poku --include='./a,./b' ## Documentation -> Documentation in Progress 🧑🏻‍🔧 +> Website in Progress 🧑🏻‍🔧 > > Initially, the documentation is based on **Node.js** usage, but you can use all the options normally for both **Bun** and **Deno**. -### `poku(string | string[])` +### `poku(targetDirs: string | string[])` #### Include directories @@ -174,11 +174,11 @@ npx poku --include='./targetDirA,./targetDirB' --- -### `poku(string | string[], configs: Configs)` +### `poku(targetDirs: string | string[], configs?: Configs)` #### `filter: RexExp` -By default, **Poku** searches for _`*.test.*`_ files, but you can customize it using the `filter` option. +By default, **Poku** searches for _`.test.`_ files, but you can customize it using the `filter` option. > Filter by path using **Regex** to match only the files that should be performed. @@ -375,6 +375,12 @@ npx poku --include='...' --exclude='some-file-or-dir|other-file-or-dir' --- -## Documentation in Progress... +### `listFiles(targetDir: string, configs?: ListFilesConfigs)` -> 🧑🏻‍🎓 Soon documenting all options and **Poku**'s usage variations. +Returns all files in a directory, independent of their depth. + +```ts +listFiles('some-dir'); +``` + +- You can use the `filter` and `exclude` options, as well as they are for **`poku`** method. diff --git a/src/@types/get-files.ts b/src/@types/list-files.ts similarity index 100% rename from src/@types/get-files.ts rename to src/@types/list-files.ts diff --git a/src/@types/poku.ts b/src/@types/poku.ts index 422b77bd..aa5cd71a 100644 --- a/src/@types/poku.ts +++ b/src/@types/poku.ts @@ -1,4 +1,4 @@ -import type { Configs as GetFileOptions } from './get-files.ts'; +import type { Configs as ListFilesConfigs } from './list-files.js'; export type Configs = { /** @@ -34,4 +34,4 @@ export type Configs = { * @default false */ parallel?: boolean; -} & GetFileOptions; +} & ListFilesConfigs; diff --git a/src/bin/index.ts b/src/bin/index.ts index b1ddf868..87d8d704 100644 --- a/src/bin/index.ts +++ b/src/bin/index.ts @@ -1,6 +1,6 @@ #! /usr/bin/env node -import { escapeRegExp } from '../modules/get-files.js'; +import { escapeRegExp } from '../modules/list-files.js'; import { getArg, hasArg } from '../helpers/get-arg.js'; import { poku } from '../index.js'; diff --git a/src/index.ts b/src/index.ts index d5f79387..1b3e3464 100755 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,6 @@ export { poku } from './modules/poku.js'; export { exit } from './modules/exit.js'; -export type { Code } from './@types/code.js'; -export type { Configs } from './@types/poku.js'; +export { publicListFiles as listFiles } from './modules/list-files.js'; +export type { Code } from './@types/code.ts'; +export type { Configs } from './@types/poku.ts'; +export type { Configs as ListFilesConfigs } from './@types/list-files.ts'; diff --git a/src/modules/get-files.ts b/src/modules/list-files.ts similarity index 78% rename from src/modules/get-files.ts rename to src/modules/list-files.ts index b5e0f698..d37afb50 100644 --- a/src/modules/get-files.ts +++ b/src/modules/list-files.ts @@ -1,7 +1,7 @@ import process from 'node:process'; import fs from 'node:fs'; import path from 'node:path'; -import type { Configs } from '../@types/get-files.ts'; +import type { Configs } from '../@types/list-files.js'; export const escapeRegExp = (string: string) => string.replace(/[.*+?^${}()[\]\\]/g, '\\$&'); @@ -10,7 +10,7 @@ const envFilter = process.env.FILTER?.trim() ? new RegExp(escapeRegExp(process.env.FILTER), 'i') : null; -export const getFiles = ( +export const listFiles = ( dirPath: string, files: string[] = [], configs?: Configs @@ -35,9 +35,13 @@ export const getFiles = ( if (exclude && exclude.some((regex) => regex.test(fullPath))) continue; - if (fs.statSync(fullPath).isDirectory()) getFiles(fullPath, files, configs); + if (fs.statSync(fullPath).isDirectory()) + listFiles(fullPath, files, configs); else if (filter.test(fullPath)) files.push(fullPath); } return files; }; + +export const publicListFiles = (targetDir: string, configs?: Configs) => + listFiles(targetDir, [], configs); diff --git a/src/services/run-tests.ts b/src/services/run-tests.ts index 9c409a6d..123c5512 100644 --- a/src/services/run-tests.ts +++ b/src/services/run-tests.ts @@ -3,7 +3,7 @@ import { EOL } from 'node:os'; import path from 'node:path'; import { runner } from '../helpers/runner.js'; import { indentation } from '../helpers/indentation.js'; -import { getFiles } from '../modules/get-files.js'; +import { listFiles } from '../modules/list-files.js'; import { hr } from '../helpers/hr.js'; import { format } from '../helpers/format.js'; import { runTestFile } from './run-test-file.js'; @@ -17,7 +17,7 @@ export const runTests = async ( const cwd = process.cwd(); const testDir = path.join(cwd, dir); const currentDir = path.relative(cwd, testDir); - const files = getFiles(testDir, undefined, configs); + const files = listFiles(testDir, undefined, configs); const totalTests = files.length; const showLogs = !isQuiet(configs); @@ -60,7 +60,7 @@ export const runTestsParallel = async ( ): Promise => { const cwd = process.cwd(); const testDir = path.join(cwd, dir); - const files = getFiles(testDir, undefined, configs); + const files = listFiles(testDir, undefined, configs); const showLogs = !isQuiet(configs); const promises = files.map(async (filePath) => { diff --git a/test/integration/import.test.ts b/test/integration/import.test.ts index 5b359dd6..07a0c020 100644 --- a/test/integration/import.test.ts +++ b/test/integration/import.test.ts @@ -3,3 +3,4 @@ import * as index from '../../src/index.js'; assert.ok(index.poku); assert.ok(index.exit); +assert.ok(index.listFiles); diff --git a/tools/compatibility/deno.ts b/tools/compatibility/deno.ts index c0c96c43..baa07a92 100644 --- a/tools/compatibility/deno.ts +++ b/tools/compatibility/deno.ts @@ -1,8 +1,8 @@ import { promises as fs } from 'node:fs'; -import { getFiles } from '../../src/modules/get-files.ts'; +import { listFiles } from '../../src/modules/list-files.ts'; const ensureDenoCompatibility = async (path: string) => { - const files = getFiles(path, [], { + const files = listFiles(path, [], { filter: /\.(m)?(t)?s$/, }); diff --git a/tools/compatibility/node.ts b/tools/compatibility/node.ts index 898b0c41..0dbdceb0 100644 --- a/tools/compatibility/node.ts +++ b/tools/compatibility/node.ts @@ -1,8 +1,8 @@ import { promises as fs } from 'node:fs'; -import { getFiles } from '../../src/modules/get-files.js'; +import { listFiles } from '../../src/modules/list-files.js'; const ensureNodeCompatibility = async (path: string) => { - const files = getFiles(path, [], { + const files = listFiles(path, [], { filter: /\.(m)?(j|t)?s$/, });