Skip to content

Commit 62d11ad

Browse files
authored
Merge pull request #87 from wp-blocks/1.6.6
Refactor PHP file parsing, time tracking, and logic enhancements
2 parents 60ab10e + 4c7e7c8 commit 62d11ad

14 files changed

Lines changed: 123 additions & 96 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ npx @wp-blocks/make-pot src languages --charset='utf-8' --include="src/**/*.{ts,
7070
- `--package-name <name>`: Specifies the package name.
7171
- `--location`: Includes location information in the `.pot` file.
7272
- `--ignore-domain`: Ignores text domain in the processing.
73+
- `--translation-domains`: Restrict to specific translation domains.
7374
- `--mergePaths <paths>`: Merges with existing POT file(s).
7475
- `--subtractPaths <paths>`: Subtracts strings from existing POT file(s).
7576
- `--subtractAndMerge`: Subtracts and merges strings from existing POT file(s).
7677
- `--include <files>`: Includes specific files for processing.
7778
- `--exclude <files>`: Excludes specific files from processing.
78-
- `--silent`: Suppresses output to stdout.
79+
- `--silent`: Suppresses verbose output to stdout.
7980
- `--json`: Outputs the JSON gettext data.
8081
- `--charset`: Defines the encoding charset of the pot file, you can choose "iso-8859-1" and "uft-8" (defaults to iso-8859-1)
81-
- `--translation-domains`: Restrict to specific translation domains.
8282
- `--output`: Outputs the gettext data.
8383

8484
### Example usage

package-lock.json

Lines changed: 2 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@wp-blocks/make-pot",
3-
"version": "1.6.5",
3+
"version": "1.6.6",
44
"license": "GPL-3.0-or-later",
55
"homepage": "https://wp-blocks.github.io/make-pot/",
66
"description": "A Node.js script for generating a POT file from source code",
@@ -68,7 +68,6 @@
6868
"gettext-merger": "^1.2.1",
6969
"gettext-parser": "^4.2.0",
7070
"glob": "^11.1.0",
71-
"tannin": "^1.2.0",
7271
"tree-sitter": "^0.21.1",
7372
"tree-sitter-javascript": "^0.23.1",
7473
"tree-sitter-php": "^0.23.12",

src/cli/getArgs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import { parseCliArgs } from "./parseCli.js";
1212
export function getArgs(userArgs = {}): Args | MakeJsonArgs {
1313
const args = yargs
1414
.default(hideBin(process.argv))
15-
.help("h")
16-
.alias("help", "help")
15+
.help("help")
16+
.alias("h", "help")
1717
.usage("Usage: $0 <source> [destination] [options]")
1818
.positional("sourceDirectory", {
1919
describe: "Source directory",

src/extractors/auditStrings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function audit(args: Args, translationsUnion: SetOfBlocks) {
99
auditor.auditStrings(translationsUnion.blocks);
1010

1111
/** Get and print the results of the audit process */
12-
console.log("\nAudit Complete!");
12+
console.log("Audit Complete!");
1313
if (auditor.getResults().length === 0) {
1414
console.log("No issues found! 🎉");
1515
// if there are no errors, we can remove the audit.log file

src/extractors/headers.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function validateRequiredFields(
4545

4646
if (missingFields.length > 0) {
4747
if (!silent) {
48-
console.error("\n! Missing required information for POT file header:\n");
48+
console.error("\n⚠️ Missing required information for POT file header:\n");
4949

5050
for (const field of missingFields) {
5151
console.error(
@@ -343,11 +343,13 @@ export function translationsHeaders(args: Args): SetOfBlocks {
343343
// the main file is the plugin main php file or the css file
344344
const fakePath = domain === "plugin" ? `${args.slug}.php` : "style.css";
345345

346-
return new SetOfBlocks([
347-
buildBlock(`Name of the ${domain}`, name, [fakePath]),
348-
buildBlock(`Url of the ${domain}`, url, [fakePath]),
349-
buildBlock(`Description of the ${domain}`, description, [fakePath]),
350-
buildBlock(`Author of the ${domain}`, author, [fakePath]),
351-
buildBlock(`Author URI of the ${domain}`, authorUri, [fakePath]),
352-
]);
346+
const blocks = [];
347+
348+
if (name) blocks.push(buildBlock(`Name of the ${domain}`, name, [fakePath]));
349+
if (url) blocks.push(buildBlock(`Url of the ${domain}`, url, [fakePath]));
350+
if (description) blocks.push(buildBlock(`Description of the ${domain}`, description, [fakePath]));
351+
if (author) blocks.push(buildBlock(`Author of the ${domain}`, author, [fakePath]));
352+
if (authorUri) blocks.push(buildBlock(`Author URI of the ${domain}`, authorUri, [fakePath]));
353+
354+
return new SetOfBlocks(blocks);
353355
}

src/extractors/php.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function extractPhpPluginData(args: Args): Record<string, string> {
3333
* @return {Record<string, string>} - A record containing the plugin information.
3434
*/
3535
export function parsePHPFile(phpContent: string): Record<string, string> {
36-
const match = phpContent.match(/\/\*\*([\s\S]*?)\*\//);
36+
const match = phpContent.match(/\/\*\*?([\s\S]*?)\*\//);
3737

3838
if (match?.[1] && match) {
3939
const commentBlock = match[1];
@@ -42,7 +42,7 @@ export function parsePHPFile(phpContent: string): Record<string, string> {
4242
const pluginInfo: Record<string, string> = {};
4343

4444
for (const line of lines) {
45-
const keyValueMatch = line.match(/^\s*\*\s*([^:]+):\s*(.*)/);
45+
const keyValueMatch = line.match(/^\s*(?:\*\s*)?([^:]+):\s*(.*)/);
4646

4747
if (!keyValueMatch) {
4848
continue;

src/parser/exec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export async function exec(args: Args): Promise<string> {
2727
/** The pot file header contains the data about the plugin or theme */
2828
const potHeader = await generateHeader(args);
2929

30+
/** Capture the start time */
31+
args.timeStart = new Date();
32+
3033
/** We need to find the main file data so that the definitions are extracted from the plugin or theme files */
3134
let translationsUnion = translationsHeaders(args);
3235

src/parser/taskRunner.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export async function taskRunner(
1818
args: Args,
1919
progressBar: SingleBar,
2020
) {
21-
const messages: string[] = [];
2221
// Create a new array of promises that update the bar when they finish.
2322
const tasksWithProgress = tasks.map((task) =>
2423
task.then((result) => {
@@ -48,16 +47,6 @@ export async function taskRunner(
4847
* Add the strings to the destination set
4948
*/
5049
destination.addArray(result.blocks);
51-
const strings = result.blocks.map((b) => b.msgid);
52-
53-
/* Log the results */
54-
if (args.options?.silent !== true) {
55-
messages.push(
56-
`✅ ${result.path} - ${strings.length} strings found [${strings.join(", ")}]`,
57-
);
58-
}
59-
} else if (args.options?.silent !== true) {
60-
messages.push(`❌ ${result.path} - has no strings`);
6150
}
6251
}
6352
})
@@ -67,12 +56,5 @@ export async function taskRunner(
6756

6857
progressBar.stop();
6958

70-
console.log("\n🎉 Done!");
71-
console.log(
72-
`📝 Found ${Object.values(destination.blocks).length} translation strings in ${path.resolve(args.paths.cwd)}.`,
73-
);
74-
75-
console.log(messages.join(os.EOL));
76-
7759
return destination;
7860
}

src/potCommand.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ import { printModuleInfo, printTimeElapsed } from "./utils/common.js";
66
export default function potCommand(args: Args) {
77
if (Object.keys(args).length > 0) {
88
printModuleInfo();
9-
/* capture the start time */
10-
const timeStart = new Date();
119
/** make the pot file */
1210
makePot(args)
1311
.then(() => {
1412
/* output the end time */
15-
printTimeElapsed("Make-Pot", timeStart);
13+
printTimeElapsed("Make-Pot", args.timeStart);
1614
})
1715
.catch((error) => {
1816
console.error(`🫤 Make-pot - ${error}`);

0 commit comments

Comments
 (0)