diff --git a/README.md b/README.md index d7b04b6..108d299 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,9 @@ This will look for files in the `app` and `resources` directories and will creat - [x] Blade support - [x] Support all WordPress translation functions - [x] POT file header is customizable +- [ ] Read info from style.css - [ ] Option to select output type (POT or JSON) +- [ ] JSON / JS support See the [open issues](https://github.com/freave/make-pot/issues) for a full list of proposed features (and known issues). diff --git a/src/cli/index.ts b/src/cli/index.ts index 5ac3ebf..0b197d5 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -10,7 +10,11 @@ const args = initArgs(); export const makePot = async () => { console.log(c.black.bgGreen("Freave make-pot " + getVersion())); - const results: any[] = await walkDirectories(args.source); + let results: any[] = await walkDirectories(args.source); + + results = results.filter((result) => { + return result !== undefined; + }); if (results.length === 0) { console.log(c.red("No matches found.")); diff --git a/src/helpers/walkDirectories.ts b/src/helpers/walkDirectories.ts index eaca8c7..b1c325c 100644 --- a/src/helpers/walkDirectories.ts +++ b/src/helpers/walkDirectories.ts @@ -1,5 +1,5 @@ import {readdir} from "node:fs/promises"; -import {resolve} from "node:path"; +import {resolve, extname} from "node:path"; import c from "ansi-colors"; // https://stackoverflow.com/a/45130990/8678755 @@ -16,7 +16,12 @@ async function getFiles(dir: string): Promise { const files = await Promise.all(dirents.map((dirent) => { const res = resolve(dir, dirent.name); - return dirent.isDirectory() ? getFiles(res) : res; + + if (!dirent.isDirectory() && extname(res) === '.php') { + return res; + } + + return dirent.isDirectory() ? getFiles(res) : undefined; })); return Array.prototype.concat(...files); } diff --git a/test/nested/a-folder/test.txt b/test/nested/a-folder/test.txt new file mode 100644 index 0000000..16b14f5 --- /dev/null +++ b/test/nested/a-folder/test.txt @@ -0,0 +1 @@ +test file