@wp-blocks/make-pot 1.4.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +79 -11
  2. package/lib/assets/block-i18n.js.map +7 -0
  3. package/lib/assets/package-i18n.js +1 -1
  4. package/lib/assets/package-i18n.js.map +7 -0
  5. package/lib/assets/theme-i18n.js.map +7 -0
  6. package/lib/assets/wp-plugin-i18n.js.map +7 -0
  7. package/lib/assets/wp-theme-i18n.js.map +7 -0
  8. package/lib/cli/getArgs.js +1 -1
  9. package/lib/cli/getArgs.js.map +7 -0
  10. package/lib/cli/getJsonArgs.js +1 -1
  11. package/lib/cli/getJsonArgs.js.map +7 -0
  12. package/lib/cli/parseCli.js +1 -1
  13. package/lib/cli/parseCli.js.map +7 -0
  14. package/lib/cli.js +2 -0
  15. package/lib/cli.js.map +7 -0
  16. package/lib/const.js +1 -1
  17. package/lib/const.js.map +7 -0
  18. package/lib/extractors/css.js +1 -1
  19. package/lib/extractors/css.js.map +7 -0
  20. package/lib/extractors/headers.js +6 -1
  21. package/lib/extractors/headers.js.map +7 -0
  22. package/lib/extractors/json.js +1 -1
  23. package/lib/extractors/json.js.map +7 -0
  24. package/lib/extractors/packageJson.js +1 -0
  25. package/lib/extractors/packageJson.js.map +7 -0
  26. package/lib/extractors/php.js +2 -2
  27. package/lib/extractors/php.js.map +7 -0
  28. package/lib/extractors/schema.js +4 -1
  29. package/lib/extractors/schema.js.map +7 -0
  30. package/lib/extractors/text.js +1 -1
  31. package/lib/extractors/text.js.map +7 -0
  32. package/lib/fs/fs.js +2 -1
  33. package/lib/fs/fs.js.map +7 -0
  34. package/lib/fs/glob.js +1 -3
  35. package/lib/fs/glob.js.map +7 -0
  36. package/lib/index.js +1 -2
  37. package/lib/index.js.map +7 -0
  38. package/lib/jsonCommand.js +1 -2
  39. package/lib/jsonCommand.js.map +7 -0
  40. package/lib/makeJson.js +2 -0
  41. package/lib/makeJson.js.map +7 -0
  42. package/lib/makePot.js +2 -0
  43. package/lib/makePot.js.map +7 -0
  44. package/lib/parser/exec.js +7 -3
  45. package/lib/parser/exec.js.map +7 -0
  46. package/lib/parser/makeJson.js +1 -3
  47. package/lib/parser/makeJson.js.map +7 -0
  48. package/lib/parser/makePot.js +1 -1
  49. package/lib/parser/makePot.js.map +7 -0
  50. package/lib/parser/patterns.js +1 -1
  51. package/lib/parser/patterns.js.map +7 -0
  52. package/lib/parser/process.js +1 -1
  53. package/lib/parser/process.js.map +7 -0
  54. package/lib/parser/progress.js +1 -1
  55. package/lib/parser/progress.js.map +7 -0
  56. package/lib/parser/taskRunner.js +2 -1
  57. package/lib/parser/taskRunner.js.map +7 -0
  58. package/lib/parser/tree.js +1 -1
  59. package/lib/parser/tree.js.map +7 -0
  60. package/lib/potCommand.js +1 -1
  61. package/lib/potCommand.js.map +7 -0
  62. package/lib/types.js +1 -1
  63. package/lib/types.js.map +7 -0
  64. package/lib/utils/common.js +4 -2
  65. package/lib/utils/common.js.map +7 -0
  66. package/lib/utils/extractors.js +1 -0
  67. package/lib/utils/extractors.js.map +7 -0
  68. package/package.json +22 -22
  69. package/tests/extract-headers.test.js +54 -0
  70. package/tests/extract.test.js +381 -381
  71. package/tests/jsonParse.test.js +167 -0
  72. package/tests/parse-headers.test.js +74 -0
  73. package/tests/tree.test.js +158 -158
  74. package/tsconfig.json +2 -0
  75. package/lib/extractors/utils.js +0 -1
  76. package/tests/getFiles.test.no.js +0 -85
  77. package/tests/jsonParse.no.js +0 -49
  78. package/tests/wpcliCompare.no.js +0 -32
@@ -1,2 +1,4 @@
1
- "use strict";var g=Object.create;var i=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,d=Object.prototype.hasOwnProperty;var k=(n,t)=>{for(var e in t)i(n,e,{get:t[e],enumerable:!0})},c=(n,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of p(t))!d.call(n,r)&&r!==e&&i(n,r,{get:()=>t[r],enumerable:!(o=f(t,r))||o.enumerable});return n};var a=(n,t,e)=>(e=n!=null?g(m(n)):{},c(t||!n||!n.__esModule?i(e,"default",{value:n,enumerable:!0}):e,n)),x=n=>c(i({},"__esModule",{value:!0}),n);var S={};k(S,{detectPatternType:()=>$,getCommentBlock:()=>h,getCopyright:()=>D,getPkgJsonData:()=>l,printHeader:()=>w,printTimeElapsed:()=>C,removeCommentMarkup:()=>y,reverseSlashes:()=>P,stringstring:()=>T,stripTranslationMarkup:()=>v});module.exports=x(S);var u=a(require("node:fs")),s=a(require("node:path"));function h(n){const t=n.match(/\/\*\*?[\s\S]*?\*\//);return t!==null?t[0]:n}function y(n){return n.match(/[a-zA-Z].*/gm)}function v(n){const t=/\/\*\*?\s*(?:translators:)\s*([\s\S]*?)\s*\*\/|\/\/\s*(?:translators:)\s*(.*)$/i,e=n.match(t);return e?e[1]:n}function T(n){return typeof n=="string"?n.includes(",")?n.split(","):[n]:null}function $(n){const t=n.includes("."),e=n.includes(s.default.sep);return n.includes("*")?"glob":!t&&!e?"directory":t&&!e?"file":"glob"}function D(n,t="GPL v2 or later"){return`# Copyright (C) ${new Date().getFullYear()} ${n}
2
- # This file is distributed under the ${t} license.`}function P(n){return n.replace(/\\/g,"/")}function l(...n){const t={},e=s.default.join(__dirname,"..","..","package.json"),o=u.default.existsSync(e)?require(e):{name:"makepot",version:""};for(const r of n)o[r]&&(t[r]=o[r]);return t}function w(){const{version:n,name:t}=l("name","version");console.log(`${t} version: ${n}`)}function C(n,t=new Date){console.log(`\u{1F680} Translation Pot file created in ${t.getTime()-n.getTime()}ms`)}0&&(module.exports={detectPatternType,getCommentBlock,getCopyright,getPkgJsonData,printHeader,printTimeElapsed,removeCommentMarkup,reverseSlashes,stringstring,stripTranslationMarkup});
1
+ "use strict";var f=Object.create;var s=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var y=(e,t)=>{for(var n in t)s(e,n,{get:t[n],enumerable:!0})},a=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of x(t))!k.call(e,r)&&r!==n&&s(e,r,{get:()=>t[r],enumerable:!(o=d(t,r))||o.enumerable});return e};var g=(e,t,n)=>(n=e!=null?f(h(e)):{},a(t||!e||!e.__esModule?s(n,"default",{value:e,enumerable:!0}):n,e)),$=e=>a(s({},"__esModule",{value:!0}),e);var J={};y(J,{detectPatternType:()=>S,getCommentBlock:()=>M,getCopyright:()=>v,getPkgJsonData:()=>m,printMakePotModuleInfo:()=>D,printStats:()=>b,printTimeElapsed:()=>T,removeCommentMarkup:()=>P,reverseSlashes:()=>w,stringstring:()=>F,stripTranslationMarkup:()=>C});module.exports=$(J);var l=g(require("node:fs")),i=require("node:os"),u=g(require("node:path")),p=require("../const.js");function M(e){const t=e.match(/\/\*\*?[\s\S]*?\*\//);return t!==null?t[0]:e}function P(e){return e.match(/[a-zA-Z].*/gm)}function C(e){const t=/\/\*\*?\s*(?:translators:)\s*([\s\S]*?)\s*\*\/|\/\/\s*(?:translators:)\s*(.*)$/i,n=e.match(t);return n?n[1]:e}function F(e){return typeof e=="string"?e.includes(",")?e.split(","):[e]:[]}function S(e){const t=e.includes("."),n=e.includes(u.default.sep);return e.includes("*")?"glob":!t&&!n?"directory":t&&!n?"file":"glob"}function v(e,t="GPL v2 or later"){return`# Copyright (C) ${new Date().getFullYear()} ${e}
2
+ # This file is distributed under the ${t} license.`}function w(e){return e.replace(/\\/g,"/")}function m(e,...t){const n={},o=u.default.join(e||process.cwd(),"package.json"),r=l.default.existsSync(o)?require(o):{};for(const c of t)r[c]&&(n[c]=r[c]);return n}function D(){const{version:e,name:t}=m(p.modulePath,"name","version");console.log(`${t} version: ${e}`)}function T(e,t,n=new Date){console.log(`
3
+ \u{1F680} ${e}: Job completed! ${e.split("-")[1]} file created in ${n.getTime()-t.getTime()}ms`)}function b(){console.log("Memory usage:",(process.memoryUsage().heapUsed/1024/1024).toFixed(2),"MB (Free:",((0,i.totalmem)()/1024/1024/1024).toFixed(2),`GB)
4
+ Cpu User:`,(process.cpuUsage().user/1e6).toFixed(2),"ms Cpu System:",(process.cpuUsage().system/1e6).toFixed(2),"ms of",(0,i.cpus)().length,"cores")}0&&(module.exports={detectPatternType,getCommentBlock,getCopyright,getPkgJsonData,printMakePotModuleInfo,printStats,printTimeElapsed,removeCommentMarkup,reverseSlashes,stringstring,stripTranslationMarkup});
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/common.ts"],
4
+ "sourcesContent": ["import fs from \"node:fs\";\nimport { cpus, totalmem } from \"node:os\";\nimport path from \"node:path\";\nimport { modulePath } from \"../const.js\";\n\n/**\n * A function that removes comment markup from a given string.\n *\n * @param {string} input - The input string with comment markup.\n * @return {string} - The input string without comment markup.\n */\nexport function getCommentBlock(input: string): string {\n\tconst commentBlock = input.match(/\\/\\*\\*?[\\s\\S]*?\\*\\//);\n\treturn commentBlock !== null ? commentBlock[0] : input;\n}\n\n/**\n * A function that starts to capture the text after the first letter.\n *\n * @param {string} input - The input string with comment markup.\n * @return {string} - The input string without comment markup.\n */\nexport function removeCommentMarkup(input: string): string[] | null {\n\treturn input.match(/[a-zA-Z].*/gm);\n}\n\n/**\n * Removes the markup from a comment string.\n *\n * @param {string} comment - The comment string to remove markup from.\n * @return {string} The comment text without the markers.\n */\nexport function stripTranslationMarkup(comment: string): string {\n\tconst commentPattern =\n\t\t/\\/\\*\\*?\\s*(?:translators:)\\s*([\\s\\S]*?)\\s*\\*\\/|\\/\\/\\s*(?:translators:)\\s*(.*)$/i;\n\tconst matches = comment.match(commentPattern);\n\treturn matches ? matches[1] : comment;\n}\n\n/**\n * Splits a string into an array of strings based on the presence of a comma.\n *\n * @param {string} string - The string to be split.\n * @return {string[]} An array of strings after splitting the input string.\n */\nexport function stringstring(string: string | string[] | undefined): string[] {\n\tif (typeof string === \"string\") {\n\t\tif (string.includes(\",\")) {\n\t\t\treturn string.split(\",\");\n\t\t}\n\t\treturn [string];\n\t}\n\treturn [];\n}\n\n/**\n * Determines if a pattern represents a file, a directory, or a glob pattern.\n * @param pattern - The pattern string to evaluate.\n * @returns 'file', 'directory', or 'glob'.\n */\nexport function detectPatternType(\n\tpattern: string,\n): \"file\" | \"directory\" | \"glob\" {\n\tconst containsFileExtension = pattern.includes(\".\");\n\tconst containsDirectorySeparator = pattern.includes(path.sep);\n\n\tif (pattern.includes(\"*\")) {\n\t\treturn \"glob\";\n\t}\n\tif (!containsFileExtension && !containsDirectorySeparator) {\n\t\treturn \"directory\";\n\t}\n\tif (containsFileExtension && !containsDirectorySeparator) {\n\t\treturn \"file\";\n\t}\n\treturn \"glob\";\n}\n\n/**\n * Generates a copyright comment for the specified slug and license.\n *\n * @param slug - The slug to include in the copyright comment\n * @param [license='GPL v2 or later'] - The license to use in the copyright comment\n * @return The generated copyright comment\n */\nexport function getCopyright(\n\tslug: string,\n\tlicense = \"GPL v2 or later\",\n): string {\n\treturn (\n\t\t`# Copyright (C) ${new Date().getFullYear()} ${slug}\\n` +\n\t\t`# This file is distributed under the ${license} license.`\n\t);\n}\n\n/**\n * Reverse slashes in a path, and replace backward slashes with forward slashes\n *\n * @param filePath - The path to be reversed.\n * @return {string} The reversed path.\n */\nexport function reverseSlashes(filePath: string): string {\n\t// Replace backward slashes with forward slashes\n\treturn filePath.replace(/\\\\/g, \"/\");\n}\n\n/**\n * The makepot package.json file data\n * @arguments {string[]} fields - The fields to extract\n * @return {Record<string, unknown>} - The package.json data\n */\nexport function getPkgJsonData(\n\tlocation?: string,\n\t...fields: string[]\n): Record<string, unknown> {\n\tconst requested: Record<string, unknown> = {};\n\t// read the package.json file the is in the root directory\n\tconst pkgJsonPath = path.join(location || process.cwd(), \"package.json\");\n\t// read the package.json file or return an empty object\n\tconst pkgJson: Record<string, unknown> = fs.existsSync(pkgJsonPath)\n\t\t? require(pkgJsonPath)\n\t\t: {};\n\t// extract the requested fields from the package.json\n\tfor (const field of fields) {\n\t\tif (pkgJson[field]) {\n\t\t\trequested[field] = pkgJson[field];\n\t\t}\n\t}\n\treturn requested;\n}\n\n/**\n * Print the module header with the current version and name\n */\nexport function printMakePotModuleInfo() {\n\tconst { version, name } = getPkgJsonData(modulePath, \"name\", \"version\");\n\t/* print the version */\n\tconsole.log(`${name} version: ${version}`);\n}\n\n/**\n * Output to the console the time elapsed in milliseconds between two dates\n * @param scriptName the name of the script\n * @param timeStart the start time\n * @param timeEnd the end time\n */\nexport function printTimeElapsed(\n\tscriptName: \"Make-Pot\" | \"Make-Json\",\n\ttimeStart: Date,\n\ttimeEnd: Date = new Date(),\n) {\n\tconsole.log(\n\t\t`\\n\uD83D\uDE80 ${scriptName}: Job completed! ${scriptName.split(\"-\")[1]} file created in ${\n\t\t\ttimeEnd.getTime() - timeStart.getTime()\n\t\t}ms`,\n\t);\n}\n\n/**\n/**\n* Prints the memory usage and cpu usage of the system\n */\nexport function printStats() {\n\tconsole.log(\n\t\t\"Memory usage:\",\n\t\t(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2),\n\t\t\"MB (Free:\",\n\t\t(totalmem() / 1024 / 1024 / 1024).toFixed(2),\n\t\t\"GB)\\nCpu User:\",\n\t\t(process.cpuUsage().user / 1000000).toFixed(2),\n\t\t\"ms Cpu System:\",\n\t\t(process.cpuUsage().system / 1000000).toFixed(2),\n\t\t\"ms of\",\n\t\tcpus().length,\n\t\t\"cores\",\n\t);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAe;AACf,qBAA+B;AAC/B,uBAAiB;AACjB,mBAA2B;AAQpB,SAAS,gBAAgB,OAAuB;AACtD,QAAM,eAAe,MAAM,MAAM,qBAAqB;AACtD,SAAO,iBAAiB,OAAO,aAAa,CAAC,IAAI;AAClD;AAQO,SAAS,oBAAoB,OAAgC;AACnE,SAAO,MAAM,MAAM,cAAc;AAClC;AAQO,SAAS,uBAAuB,SAAyB;AAC/D,QAAM,iBACL;AACD,QAAM,UAAU,QAAQ,MAAM,cAAc;AAC5C,SAAO,UAAU,QAAQ,CAAC,IAAI;AAC/B;AAQO,SAAS,aAAa,QAAiD;AAC7E,MAAI,OAAO,WAAW,UAAU;AAC/B,QAAI,OAAO,SAAS,GAAG,GAAG;AACzB,aAAO,OAAO,MAAM,GAAG;AAAA,IACxB;AACA,WAAO,CAAC,MAAM;AAAA,EACf;AACA,SAAO,CAAC;AACT;AAOO,SAAS,kBACf,SACgC;AAChC,QAAM,wBAAwB,QAAQ,SAAS,GAAG;AAClD,QAAM,6BAA6B,QAAQ,SAAS,iBAAAA,QAAK,GAAG;AAE5D,MAAI,QAAQ,SAAS,GAAG,GAAG;AAC1B,WAAO;AAAA,EACR;AACA,MAAI,CAAC,yBAAyB,CAAC,4BAA4B;AAC1D,WAAO;AAAA,EACR;AACA,MAAI,yBAAyB,CAAC,4BAA4B;AACzD,WAAO;AAAA,EACR;AACA,SAAO;AACR;AASO,SAAS,aACf,MACA,UAAU,mBACD;AACT,SACC,oBAAmB,oBAAI,KAAK,GAAE,YAAY,CAAC,IAAI,IAAI;AAAA,uCACX,OAAO;AAEjD;AAQO,SAAS,eAAe,UAA0B;AAExD,SAAO,SAAS,QAAQ,OAAO,GAAG;AACnC;AAOO,SAAS,eACf,aACG,QACuB;AAC1B,QAAM,YAAqC,CAAC;AAE5C,QAAM,cAAc,iBAAAA,QAAK,KAAK,YAAY,QAAQ,IAAI,GAAG,cAAc;AAEvE,QAAM,UAAmC,eAAAC,QAAG,WAAW,WAAW,IAC/D,QAAQ,WAAW,IACnB,CAAC;AAEJ,aAAW,SAAS,QAAQ;AAC3B,QAAI,QAAQ,KAAK,GAAG;AACnB,gBAAU,KAAK,IAAI,QAAQ,KAAK;AAAA,IACjC;AAAA,EACD;AACA,SAAO;AACR;AAKO,SAAS,yBAAyB;AACxC,QAAM,EAAE,SAAS,KAAK,IAAI,eAAe,yBAAY,QAAQ,SAAS;AAEtE,UAAQ,IAAI,GAAG,IAAI,aAAa,OAAO,EAAE;AAC1C;AAQO,SAAS,iBACf,YACA,WACA,UAAgB,oBAAI,KAAK,GACxB;AACD,UAAQ;AAAA,IACP;AAAA,YAAQ,UAAU,oBAAoB,WAAW,MAAM,GAAG,EAAE,CAAC,CAAC,oBAC7D,QAAQ,QAAQ,IAAI,UAAU,QAAQ,CACvC;AAAA,EACD;AACD;AAMO,SAAS,aAAa;AAC5B,UAAQ;AAAA,IACP;AAAA,KACC,QAAQ,YAAY,EAAE,WAAW,OAAO,MAAM,QAAQ,CAAC;AAAA,IACxD;AAAA,SACC,yBAAS,IAAI,OAAO,OAAO,MAAM,QAAQ,CAAC;AAAA,IAC3C;AAAA,KACC,QAAQ,SAAS,EAAE,OAAO,KAAS,QAAQ,CAAC;AAAA,IAC7C;AAAA,KACC,QAAQ,SAAS,EAAE,SAAS,KAAS,QAAQ,CAAC;AAAA,IAC/C;AAAA,QACA,qBAAK,EAAE;AAAA,IACP;AAAA,EACD;AACD;",
6
+ "names": ["path", "fs"]
7
+ }
@@ -0,0 +1 @@
1
+ "use strict";var c=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var l=(n,t)=>{for(var s in t)c(n,s,{get:t[s],enumerable:!0})},u=(n,t,s,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of d(t))!g.call(n,o)&&o!==s&&c(n,o,{get:()=>t[o],enumerable:!(e=m(t,o))||e.enumerable});return n};var k=n=>u(c({},"__esModule",{value:!0}),n);var x={};l(x,{buildBlock:()=>f,getKeyByValue:()=>B,yieldParsedData:()=>a});module.exports=k(x);var r=require("gettext-merger");function B(n,t){return Object.keys(n).find(s=>n[s]===t)??void 0}const f=(n,t,s=void 0)=>{const e=new r.Block([]);return e.msgctxt=void 0,e.msgid=t,e.msgid_plural="",e.msgstr=[],e.comments={},n&&(e.comments.extracted=[n]),s?.length&&(e.comments.reference=s),e};function a(n,t,s){const e=new r.SetOfBlocks([],s);if(n.length===0)return e;e.path=s;for(const o of n){const i=f(o.msgid,o.msgctxt,o.comments?.reference);i&&e.blocks.push(i)}return e}0&&(module.exports={buildBlock,getKeyByValue,yieldParsedData});
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/extractors.ts"],
4
+ "sourcesContent": ["import { Block, SetOfBlocks } from \"gettext-merger\";\n\n/**\n * Returns the key of an object based on its value\n *\n * @param object the object that contains the key\n * @param value the key that we want to get\n * @return {Record<string, string>} the filtered keys\n */\nexport function getKeyByValue(\n\tobject: Record<string, unknown>,\n\tvalue: string,\n): string | undefined {\n\treturn Object.keys(object).find((key) => object[key] === value) ?? undefined;\n}\n\n/**\n * Returns a gettext translation object\n *\n * @param label the label of the translation\n * @param string the string of the translation\n * @param filePath the file path of the translation\n */\nexport const buildBlock = (\n\tlabel: string,\n\tstring: string,\n\tfilePath: string[] | undefined = undefined,\n): Block => {\n\tconst block = new Block([]);\n\tblock.msgctxt = undefined;\n\tblock.msgid = string;\n\tblock.msgid_plural = \"\";\n\tblock.msgstr = [];\n\tblock.comments = {};\n\tif (label) {\n\t\tblock.comments.extracted = [label];\n\t}\n\tif (filePath?.length) {\n\t\tblock.comments.reference = filePath;\n\t}\n\treturn block;\n};\n\n/**\n * Extracts strings from parsed JSON data.\n *\n * @param {Record<string, any> | Parser.SyntaxNode} parsed - The parsed JSON data or syntax node.\n * @param {string | Parser} filename - The filename or parser.\n * @param filepath - the path to the file being parsed\n * @return {SetOfBlocks} An array of translation strings.\n */\nexport function yieldParsedData(\n\tparsed: Block[],\n\tfilename: \"block.json\" | \"theme.json\",\n\tfilepath: string,\n): SetOfBlocks {\n\tconst gettextTranslations: SetOfBlocks = new SetOfBlocks([], filepath);\n\n\tif (parsed.length === 0) {\n\t\treturn gettextTranslations;\n\t}\n\n\t// set the path of the translation\n\tgettextTranslations.path = filepath;\n\n\tfor (const item of parsed) {\n\t\tconst block = buildBlock(\n\t\t\titem.msgid,\n\t\t\titem.msgctxt as string,\n\t\t\titem.comments?.reference,\n\t\t);\n\n\t\tif (block) {\n\t\t\tgettextTranslations.blocks.push(block);\n\t\t}\n\t}\n\n\treturn gettextTranslations;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAmC;AAS5B,SAAS,cACf,QACA,OACqB;AACrB,SAAO,OAAO,KAAK,MAAM,EAAE,KAAK,CAAC,QAAQ,OAAO,GAAG,MAAM,KAAK,KAAK;AACpE;AASO,MAAM,aAAa,CACzB,OACA,QACA,WAAiC,WACtB;AACX,QAAM,QAAQ,IAAI,4BAAM,CAAC,CAAC;AAC1B,QAAM,UAAU;AAChB,QAAM,QAAQ;AACd,QAAM,eAAe;AACrB,QAAM,SAAS,CAAC;AAChB,QAAM,WAAW,CAAC;AAClB,MAAI,OAAO;AACV,UAAM,SAAS,YAAY,CAAC,KAAK;AAAA,EAClC;AACA,MAAI,UAAU,QAAQ;AACrB,UAAM,SAAS,YAAY;AAAA,EAC5B;AACA,SAAO;AACR;AAUO,SAAS,gBACf,QACA,UACA,UACc;AACd,QAAM,sBAAmC,IAAI,kCAAY,CAAC,GAAG,QAAQ;AAErE,MAAI,OAAO,WAAW,GAAG;AACxB,WAAO;AAAA,EACR;AAGA,sBAAoB,OAAO;AAE3B,aAAW,QAAQ,QAAQ;AAC1B,UAAM,QAAQ;AAAA,MACb,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK,UAAU;AAAA,IAChB;AAEA,QAAI,OAAO;AACV,0BAAoB,OAAO,KAAK,KAAK;AAAA,IACtC;AAAA,EACD;AAEA,SAAO;AACR;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-blocks/make-pot",
3
- "version": "1.4.0",
3
+ "version": "1.5.1",
4
4
  "license": "GPL-3.0-or-later",
5
5
  "homepage": "https://wp-blocks.github.io/make-pot/",
6
6
  "description": "A Node.js script for generating a POT file from source code",
@@ -9,13 +9,13 @@
9
9
  "John Hooks <bitmachina@outlook.com> (https://johnhooks.io/)"
10
10
  ],
11
11
  "type": "commonjs",
12
- "main": "lib/potCommand.js",
12
+ "main": "lib/index.js",
13
13
  "bin": {
14
- "default": "lib/index.js",
15
- "make-pot": "lib/index.js",
16
- "makepot": "lib/index.js",
17
- "make-json": "lib/jsonCommand.js",
18
- "makejson": "lib/jsonCommand.js"
14
+ "default": "./lib/cli.js",
15
+ "make-pot": "./lib/makePot.js",
16
+ "makepot": "./lib/makePot.js",
17
+ "make-json": "./lib/makeJson.js",
18
+ "makejson": "./lib/makeJson.js"
19
19
  },
20
20
  "engines": {
21
21
  "node": ">=16.0.0"
@@ -49,21 +49,21 @@
49
49
  "postinstall": "npm rebuild tree-sitter tree-sitter-typescript tree-sitter-php tree-sitter-javascript --force",
50
50
  "build": "npx esbuild ./src/**/* --format=cjs --minify --outdir=lib --platform=node",
51
51
  "watch": "tsc --watch",
52
- "lint": "npx @biomejs/biome check --apply src",
53
- "test": "node --test",
54
- "ci:bundle": "npx esbuild ./src/index.ts --format=cjs --outdir=lib --bundle --external:tree-sitter --external:tree-sitter-typescript --external:tree-sitter-php --external:tree-sitter-javascript --platform=node",
55
- "test:ci": "npm run ci:bundle && node --test",
52
+ "lint": "npx @biomejs/biome check --write src",
53
+ "rm": "rmdir /s /q lib",
54
+ "test:build": "npx esbuild ./src/**/* --format=cjs --sourcemap --outdir=lib --platform=node",
55
+ "test": "npm run test:build && node --test",
56
+ "build:build-ci": "npx esbuild ./src/index.ts --format=cjs --outdir=lib --bundle --external:tree-sitter --external:tree-sitter-typescript --external:tree-sitter-php --external:tree-sitter-javascript --platform=node",
57
+ "test:ci": "npm run build:build-ci && npm run test",
56
58
  "test:watch": "node --test --watch",
57
- "test:coverage": "node --test --experimental-test-coverage",
58
- "run": "node ./lib/index.js tests/fixtures/vinyl/",
59
- "runJson": "node ./lib/jsonCommand.js tests/fixtures/vinyl/"
59
+ "test:coverage": "node --test --experimental-test-coverage"
60
60
  },
61
61
  "dependencies": {
62
- "axios": "^1.7.2",
63
62
  "cli-progress": "^3.12.0",
64
63
  "gettext-merger": "^1.2.1",
65
64
  "gettext-parser": "^4.0.4",
66
- "glob": "^10.4.2",
65
+ "glob": "^11.0.2",
66
+ "tannin": "^1.2.0",
67
67
  "tree-sitter": "^0.20.6",
68
68
  "tree-sitter-javascript": "^0.20.4",
69
69
  "tree-sitter-php": "^0.20.0",
@@ -71,12 +71,12 @@
71
71
  "yargs": "^17.7.1"
72
72
  },
73
73
  "devDependencies": {
74
- "@biomejs/biome": "1.8.3",
75
- "@types/cli-progress": "^3.11.5",
74
+ "@biomejs/biome": "1.9.4",
75
+ "@types/cli-progress": "^3.11.6",
76
76
  "@types/gettext-parser": "^4.0.4",
77
- "@types/node": "^20.14.9",
78
- "@types/yargs": "^17.0.32",
79
- "esbuild": "0.23.0",
80
- "typescript": "^5.5.3"
77
+ "@types/node": "^22.15.17",
78
+ "@types/yargs": "^17.0.33",
79
+ "esbuild": "0.25.4",
80
+ "typescript": "^5.8.3"
81
81
  }
82
82
  }
@@ -0,0 +1,54 @@
1
+ const { describe, it } = require("node:test");
2
+ const { join } = require("node:path");
3
+ const assert = require("node:assert");
4
+ const { extractMainFileData } = require("../lib");
5
+
6
+ describe("should parse plugin main file", () => {
7
+ describe("should parse plugin.php", () => {
8
+ it("correctly extracts plugin headers", async () => {
9
+ const fileParsed = extractMainFileData({
10
+ domain: "plugin",
11
+ paths: {
12
+ cwd: join(process.cwd(), "tests/fixtures/plugin"),
13
+ },
14
+ slug: "plugin",
15
+ });
16
+ assert.deepStrictEqual(fileParsed, {
17
+ author: "Erik yo",
18
+ authorUri: "https://codekraft.it",
19
+ description:
20
+ "An example plugin to demo how to do internationalization in a WordPress plugin.",
21
+ domainPath: "/languages",
22
+ license: "GPL3+",
23
+ licenseUri: "http://www.gnu.org/licenses/gpl-3.0.html",
24
+ name: "plugin",
25
+ textDomain: "i18n-example",
26
+ version: "1.0.0",
27
+ });
28
+ });
29
+ });
30
+ });
31
+
32
+ describe("should parse theme main file", () => {
33
+ describe("should parse style.css", () => {
34
+ it("correctly extracts theme headers", async () => {
35
+ const fileParsed = extractMainFileData({
36
+ domain: "theme",
37
+ paths: {
38
+ cwd: join(process.cwd(), "tests/fixtures/theme"),
39
+ },
40
+ slug: "fabled-sunset",
41
+ });
42
+ assert.deepStrictEqual(fileParsed, {
43
+ name: "Theme name",
44
+ description: "Custom theme description...",
45
+ version: "1.0.0",
46
+ author: "Author Name",
47
+ tags: "block-patterns, full-site-editing",
48
+ textDomain: "fabled-sunset",
49
+ domainPath: "/assets/lang",
50
+ license: "GNU General Public License v2.0 or later",
51
+ });
52
+ });
53
+ });
54
+ });