Skip to content

Commit

Permalink
Merge pull request #18 from freave/only-php-signed
Browse files Browse the repository at this point in the history
Now only reads files ending in .php, signed commit
  • Loading branch information
mve authored Aug 25, 2022
2 parents d8822c9 + 8fecc23 commit 31ddac7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
6 changes: 5 additions & 1 deletion src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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."));
Expand Down
9 changes: 7 additions & 2 deletions src/helpers/walkDirectories.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,7 +16,12 @@ async function getFiles(dir: string): Promise<any> {

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);
}
Expand Down
1 change: 1 addition & 0 deletions test/nested/a-folder/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test file

0 comments on commit 31ddac7

Please sign in to comment.