@wp-blocks/make-pot 1.5.1 → 1.6.0

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 (57) hide show
  1. package/README.md +2 -1
  2. package/lib/cli/getArgs.js +1 -1
  3. package/lib/cli/getJsonArgs.js +1 -1
  4. package/lib/cli/parseCli.js +1 -1
  5. package/lib/const.js +1 -1
  6. package/lib/extractors/auditStrings.js +5 -0
  7. package/lib/extractors/css.js +1 -1
  8. package/lib/extractors/headers.js +12 -4
  9. package/lib/fs/fs.js +1 -1
  10. package/lib/index.js +1 -1
  11. package/lib/jsonCommand.js +1 -1
  12. package/lib/parser/exec.js +3 -7
  13. package/lib/parser/makeJson.js +1 -1
  14. package/lib/parser/makePot.js +1 -1
  15. package/lib/parser/process.js +1 -1
  16. package/lib/potCommand.js +1 -1
  17. package/lib/utils/common.js +8 -4
  18. package/lib/utils/output.js +1 -0
  19. package/package.json +4 -2
  20. package/tests/audit.test.js +50 -0
  21. package/tests/compare-json.test.js +81 -0
  22. package/tests/parse-headers.test.js +7 -6
  23. package/lib/assets/block-i18n.js.map +0 -7
  24. package/lib/assets/package-i18n.js.map +0 -7
  25. package/lib/assets/theme-i18n.js.map +0 -7
  26. package/lib/assets/wp-plugin-i18n.js.map +0 -7
  27. package/lib/assets/wp-theme-i18n.js.map +0 -7
  28. package/lib/cli/getArgs.js.map +0 -7
  29. package/lib/cli/getJsonArgs.js.map +0 -7
  30. package/lib/cli/parseCli.js.map +0 -7
  31. package/lib/cli.js.map +0 -7
  32. package/lib/const.js.map +0 -7
  33. package/lib/extractors/css.js.map +0 -7
  34. package/lib/extractors/headers.js.map +0 -7
  35. package/lib/extractors/json.js.map +0 -7
  36. package/lib/extractors/packageJson.js.map +0 -7
  37. package/lib/extractors/php.js.map +0 -7
  38. package/lib/extractors/schema.js.map +0 -7
  39. package/lib/extractors/text.js.map +0 -7
  40. package/lib/fs/fs.js.map +0 -7
  41. package/lib/fs/glob.js.map +0 -7
  42. package/lib/index.js.map +0 -7
  43. package/lib/jsonCommand.js.map +0 -7
  44. package/lib/makeJson.js.map +0 -7
  45. package/lib/makePot.js.map +0 -7
  46. package/lib/parser/exec.js.map +0 -7
  47. package/lib/parser/makeJson.js.map +0 -7
  48. package/lib/parser/makePot.js.map +0 -7
  49. package/lib/parser/patterns.js.map +0 -7
  50. package/lib/parser/process.js.map +0 -7
  51. package/lib/parser/progress.js.map +0 -7
  52. package/lib/parser/taskRunner.js.map +0 -7
  53. package/lib/parser/tree.js.map +0 -7
  54. package/lib/potCommand.js.map +0 -7
  55. package/lib/types.js.map +0 -7
  56. package/lib/utils/common.js.map +0 -7
  57. package/lib/utils/extractors.js.map +0 -7
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/cli/parseCli.ts"],
4
- "sourcesContent": ["import fs, { accessSync } from \"node:fs\";\nimport * as path from \"node:path\";\nimport * as process from \"node:process\";\nimport type * as yargs from \"yargs\";\nimport { DEFAULT_EXCLUDED_PATH } from \"../const.js\";\nimport { getEncodingCharset } from \"../fs/fs\";\nimport type { Args, DomainType, MakeJsonArgs } from \"../types.js\";\nimport { stringstring } from \"../utils/common.js\";\n\n/**\n * This function checks if the current working directory is a theme or plugin\n * @param currentPath The current working directory\n * @param slug The slug of the theme or plugin\n */\nfunction isThemeOrPlugin(currentPath = \"/\", slug = \"default\"): DomainType {\n\tconst currentWorkingDirectory = currentPath;\n\n\t/**\n\t * Checks if the current working directory contains a plugin file\n\t */\n\ttry {\n\t\taccessSync(\n\t\t\tpath.join(currentWorkingDirectory, `${slug}.php`),\n\t\t\tfs.constants.R_OK,\n\t\t);\n\t\treturn \"plugin\";\n\t} catch (err) {\n\t\t// do nothing\n\t\tconsole.log(\n\t\t\t`the current working directory ${currentWorkingDirectory} does not contain a ${slug}.php file`,\n\t\t);\n\t}\n\n\t/**\n\t * Checks if the current working directory contains a style.css file and is a theme\n\t */\n\ttry {\n\t\taccessSync(\n\t\t\tpath.join(currentWorkingDirectory, \"style.css\"),\n\t\t\tfs.constants.R_OK,\n\t\t);\n\t\treturn \"theme\";\n\t} catch (err) {\n\t\t// do nothing\n\t\tconsole.log(\n\t\t\t`the current working directory ${currentWorkingDirectory} does not contain a style.css file`,\n\t\t);\n\t}\n\n\t// If none of the above conditions are met, return \"generic\"\n\treturn \"generic\";\n}\n\n/**\n * Parses the command line arguments and returns an object with the parsed values.\n *\n * @param {{_: string[]}} args - The command line arguments to be parsed.\n * @return {object} - An object with the parsed values from the command line arguments.\n */\nexport function parseCliArgs(\n\targs: yargs.PositionalOptions & yargs.Options & yargs.Arguments,\n): Args {\n\t// Get the input and output paths\n\tconst pos1: string | undefined = args._[0]?.toString();\n\tconst pos2: string = args._[1]?.toString() || \"languages\";\n\n\tconst inputPath: string | undefined = pos1 ?? \".\";\n\t// remove \"/\" if the output path starts with it\n\tconst outputPath: string = pos2.startsWith(\"/\") ? pos2.slice(1) : pos2;\n\n\t// Store the current working directory\n\tconst currentWorkingDirectory = process.cwd();\n\n\t// Get the slug or use the basename of the current working directory\n\t// the slug is the plugin or theme slug. Defaults to the source directory\u2019s basename\n\tconst slug =\n\t\targs.slug && typeof args.slug === \"string\"\n\t\t\t? args.slug\n\t\t\t: path.basename(path.resolve(currentWorkingDirectory, inputPath));\n\n\t// Get the relative paths\n\tconst cwd = path.relative(currentWorkingDirectory, inputPath);\n\tconst out = path.relative(currentWorkingDirectory, outputPath);\n\n\t/** get the domain to look for (plugin, theme, etc) */\n\tif (!(args?.domain as DomainType)) {\n\t\targs.domain = isThemeOrPlugin(path.resolve(cwd), slug);\n\t} else {\n\t\tswitch (args.domain) {\n\t\t\tcase \"plugin\":\n\t\t\tcase \"theme\":\n\t\t\tcase \"block\":\n\t\t\tcase \"theme-block\":\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tconsole.error(\n\t\t\t\t\t`Invalid domain: ${args.domain}. Valid domains are: plugin, theme, block, theme-block, generic`,\n\t\t\t\t);\n\t\t\t\t// fallback to generic if the domain is invalid\n\t\t\t\targs.domain = \"generic\";\n\t\t}\n\t}\n\n\tconst parsedArgs: Args = {\n\t\tslug: slug,\n\t\tdomain: args.domain as DomainType,\n\t\tpaths: { cwd: cwd, out: out },\n\t\toptions: {\n\t\t\tignoreDomain: !!args?.ignoreDomain,\n\t\t\tpackageName: String(args.packageName),\n\t\t\tsilent: args.silent === true, // default is false\n\t\t\tjson: !!args.json,\n\t\t\tlocation: !!args?.location,\n\t\t\toutput: !!args?.output,\n\t\t\tfileComment: args.fileComment ? String(args.fileComment) : undefined,\n\t\t\tcharset: getEncodingCharset(args?.charset as string | undefined),\n\t\t\tskip: {\n\t\t\t\tjs: !!args.skipJs,\n\t\t\t\tphp: !!args.skipPhp,\n\t\t\t\tblade: !!args.skipBlade,\n\t\t\t\tblockJson: !!args.skipBlockJson,\n\t\t\t\tthemeJson: !!args.skipThemeJson,\n\t\t\t\taudit: !!args.skipAudit,\n\t\t\t},\n\t\t},\n\t\t// Patterns\n\t\tpatterns: {\n\t\t\tmergePaths: stringstring(args.mergePaths as string),\n\t\t\tsubtractPaths: stringstring(args.subtractPaths as string),\n\t\t\tsubtractAndMerge: !!args.subtractAndMerge,\n\t\t\tinclude: stringstring(args.include as string),\n\t\t\texclude: [\n\t\t\t\t...stringstring(args.exclude as string),\n\t\t\t\t...DEFAULT_EXCLUDED_PATH,\n\t\t\t],\n\t\t},\n\t};\n\n\tparsedArgs.paths.root = args.root ? String(args.root) : undefined;\n\n\treturn parsedArgs;\n}\n\n/**\n * Parses the command line arguments for the JSON command.\n * @param args - The command line arguments to be parsed.\n */\nexport function parseJsonArgs(\n\targs: yargs.PositionalOptions & yargs.Options & yargs.Arguments,\n): MakeJsonArgs {\n\t// Get the input and output paths\n\tconst inputPath: string = (args._[0] as string) || \"build\";\n\tconst outputPath: string = (args._[1] as string) || \"languages\";\n\tconst currentWorkingDirectory = process.cwd();\n\tconst slug = path.basename(path.resolve(currentWorkingDirectory));\n\n\tlet scriptName = undefined;\n\tif (args.scriptName) {\n\t\tscriptName = args.scriptName.split(\",\").map((s) => s.trim());\n\t\tif (scriptName.length === 1) {\n\t\t\tscriptName = scriptName[0];\n\t\t}\n\t}\n\n\treturn {\n\t\ttimeStart: Date.now(),\n\t\tslug,\n\t\tsource: inputPath,\n\t\tdestination: outputPath,\n\t\tscriptName,\n\t\tallowedFormats: args.allowedFormats as string[],\n\t\tpurge: !!args.purge,\n\t\tprettyPrint: !!args.prettyPrint,\n\t\tdebug: !!args.debug,\n\t\tpaths: {\n\t\t\tcwd: currentWorkingDirectory,\n\t\t\tout: path.join(currentWorkingDirectory, outputPath),\n\t\t},\n\t};\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA+B;AAC/B,WAAsB;AACtB,cAAyB;AAEzB,mBAAsC;AACtC,gBAAmC;AAEnC,oBAA6B;AAO7B,SAAS,gBAAgB,cAAc,KAAK,OAAO,WAAuB;AACzE,QAAM,0BAA0B;AAKhC,MAAI;AACH;AAAA,MACC,KAAK,KAAK,yBAAyB,GAAG,IAAI,MAAM;AAAA,MAChD,eAAAA,QAAG,UAAU;AAAA,IACd;AACA,WAAO;AAAA,EACR,SAAS,KAAK;AAEb,YAAQ;AAAA,MACP,iCAAiC,uBAAuB,uBAAuB,IAAI;AAAA,IACpF;AAAA,EACD;AAKA,MAAI;AACH;AAAA,MACC,KAAK,KAAK,yBAAyB,WAAW;AAAA,MAC9C,eAAAA,QAAG,UAAU;AAAA,IACd;AACA,WAAO;AAAA,EACR,SAAS,KAAK;AAEb,YAAQ;AAAA,MACP,iCAAiC,uBAAuB;AAAA,IACzD;AAAA,EACD;AAGA,SAAO;AACR;AAQO,SAAS,aACf,MACO;AAEP,QAAM,OAA2B,KAAK,EAAE,CAAC,GAAG,SAAS;AACrD,QAAM,OAAe,KAAK,EAAE,CAAC,GAAG,SAAS,KAAK;AAE9C,QAAM,YAA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@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/cli.ts"],
4
- "sourcesContent": ["#!/usr/bin/env node\n\nimport process from \"node:process\";\nimport * as yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\nimport { getArgs } from \"./cli/getArgs.js\";\nimport { getJsonArgs } from \"./cli/getJsonArgs.js\";\nimport makeJsonCommand from \"./jsonCommand.js\";\nimport makepotCommand from \"./potCommand.js\";\nimport type { Args, MakeJsonArgs } from \"./types.js\";\n\n/** Main execution */\n// Get the selected command\nconst r = yargs\n\t.default(hideBin(process.argv))\n\t.options({\n\t\tmakejson: {\n\t\t\tdescribe: \"Make JSON file\",\n\t\t\ttype: \"boolean\",\n\t\t\tdefault: false,\n\t\t},\n\t})\n\t.parseSync() as { makejson: boolean };\n\n// Execute the command\nif (!r.makejson) {\n\tmakepotCommand(getArgs() as Args);\n} else {\n\tmakeJsonCommand(getJsonArgs() as MakeJsonArgs);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAEA,0BAAoB;AACpB,YAAuB;AACvB,qBAAwB;AACxB,qBAAwB;AACxB,yBAA4B;AAC5B,yBAA4B;AAC5B,wBAA2B;AAK3B,MAAM,IAAI,MACR,YAAQ,wBAAQ,oBAAAA,QAAQ,IAAI,CAAC,EAC7B,QAAQ;AAAA,EACR,UAAU;AAAA,IACT,UAAU;AAAA,IACV,MAAM;AAAA,IACN,SAAS;AAAA,EACV;AACD,CAAC,EACA,UAAU;AAGZ,IAAI,CAAC,EAAE,UAAU;AAChB,wBAAAC,aAAe,wBAAQ,CAAS;AACjC,OAAO;AACN,yBAAAC,aAAgB,gCAAY,CAAiB;AAC9C;",
6
- "names": ["process", "makepotCommand", "makeJsonCommand"]
7
- }
package/lib/const.js.map DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/const.ts"],
4
- "sourcesContent": ["import path from \"node:path\";\nimport packagei18n from \"./assets/package-i18n.js\";\nimport wpPlugini18n from \"./assets/wp-plugin-i18n.js\";\nimport wpThemei18n from \"./assets/wp-theme-i18n.js\";\n\n/**\n * Theme Json metadata headers\n *\n */\nexport const pkgJsonHeaders = packagei18n;\n/**\n * The Plugin metadata headers\n * @link https://codex.wordpress.org/File_Header\n */\nexport const pluginHeaders = wpPlugini18n;\n/**\n * The Theme metadata headers\n * @link https://developer.wordpress.org/plugins/plugin-basics/header-requirements/\n */\nexport const themeHeaders = wpThemei18n;\n\n/**\n * The default list of paths to exclude from the pot file.\n * @link https://www.npmjs.com/package/glob#glob-primer\n */\nexport const DEFAULT_EXCLUDED_PATH = [\n\t\".git\",\n\t\"node_modules\",\n\t\"vendor\",\n\t\"build\",\n\t\"dist\",\n\t\"uploads\",\n\t\"Gruntfile.js\",\n\t\"webpack.config.js\",\n\t\"**/*.min.js\",\n\t\"tsconfig.js\",\n\t\"**.test.**\",\n\t\"tests\",\n];\n\n/**\n * The regex used to find the locale in the source code\n */\nexport const IsoCodeRegex = /-([a-z]{2}_[A-Z]{2})\\.po$/;\n\n/**\n * The regex used to find the filename in the source code\n */\nexport const fileRegex = /#:\\s*(.*?)(?::\\d+)?$/;\n\nexport const defaultLocale = \"en_US\";\n\n/**\n * The files that are allowed to be parsed using tree sitter\n *\n * Json and text files are parsed in a different way\n */\nexport const allowedFormats = [\"php\", \"js\", \"jsx\", \"ts\", \"tsx\", \"mjs\", \"cjs\"];\n\n/**\n * The default functions to use for i18n.\n */\nexport const i18nFunctions = {\n\t__: [\"msgid\", \"text_domain\"],\n\tesc_attr__: [\"msgid\", \"text_domain\"],\n\tesc_html__: [\"msgid\", \"text_domain\"],\n\tesc_xml__: [\"msgid\", \"text_domain\"],\n\t_e: [\"msgid\", \"text_domain\"],\n\tesc_attr_e: [\"msgid\", \"text_domain\"],\n\tesc_html_e: [\"msgid\", \"text_domain\"],\n\tesc_xml_e: [\"msgid\", \"text_domain\"],\n\t_x: [\"msgid\", \"msgctxt\", \"text_domain\"],\n\t_ex: [\"msgid\", \"msgctxt\", \"text_domain\"],\n\tesc_attr_x: [\"msgid\", \"msgctxt\", \"text_domain\"],\n\tesc_html_x: [\"msgid\", \"msgctxt\", \"text_domain\"],\n\tesc_xml_x: [\"msgid\", \"msgctxt\", \"text_domain\"],\n\t_n: [\"msgid\", \"msgid_plural\", \"number\", \"text_domain\"],\n\t_nx: [\"msgid\", \"msgid_plural\", \"number\", \"msgctxt\", \"text_domain\"],\n\t_n_noop: [\"msgid\", \"msgid_plural\", \"text_domain\"],\n\t_nx_noop: [\"msgid\", \"msgid_plural\", \"msgctxt\", \"text_domain\"],\n\n\t// Compat.\n\t_: [\"msgid\", \"text_domain\"],\n\n\t// Deprecated.\n\t_c: [\"msgid\", \"text_domain\"],\n\t_nc: [\"msgid\", \"msgid_plural\", \"number\", \"text_domain\"],\n\t__ngettext: [\"msgid\", \"msgid_plural\", \"number\", \"text_domain\"],\n\t__ngettext_noop: [\"msgid\", \"msgid_plural\", \"text_domain\"],\n};\n\n/**\n * @var modulePath The path to the module folder containing this file\n */\nexport const modulePath = path.resolve(__dirname, \"..\");\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AACjB,0BAAwB;AACxB,4BAAyB;AACzB,2BAAwB;AAMjB,MAAM,iBAAiB,oBAAAA;AAKvB,MAAM,gBAAgB,sBAAAC;AAKtB,MAAM,eAAe,qBAAAC;AAMrB,MAAM,wBAAwB;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAKO,MAAM,eAAe;AAKrB,MAAM,YAAY;AAElB,MAAM,gBAAgB;AAOtB,MAAM,iBAAiB,CAAC,OAAO,MAAM,OAAO,MAAM,OAAO,OAAO,KAAK;AAKrE,MAAM,gBAAgB;AAAA,EAC5B,IAAI,CAAC,SAAS,aAAa;AAAA,EAC3B,YAAY,CAAC,SAAS,aAAa;AAAA,EACnC,YAAY,CAAC,SAAS,aAAa;AAAA,EACnC,WAAW,CAAC,SAAS,aAAa;AAAA,EAClC,IAAI,CAAC,SAAS,aAAa;AAAA,EAC3B,YAAY,CAAC,SAAS,aAAa;AAAA,EACnC,YAAY,CAAC,SAAS,aAAa;AAAA,EACnC,WAAW,CAAC,SAAS,aAAa;AAAA,EAClC,IAAI,CAAC,SAAS,WAAW,aAAa;AAAA,EACtC,KAAK,CAAC,SAAS,WAAW,aAAa;AAAA,EACvC,YAAY,CAAC,SAAS,WAAW,aAAa;AAAA,EAC9C,YAAY,CAAC,SAAS,WAAW,aAAa;AAAA,EAC9C,WAAW,CAAC,SAAS,WAAW,aAAa;AAAA,EAC7C,IAAI,CAAC,SAAS,gBAAgB,UAAU,aAAa;AAAA,EACrD,KAAK,CAAC,SAAS,gBAAgB,UAAU,WAAW,aAAa;AAAA,EACjE,SAAS,CAAC,SAAS,gBAAgB,aAAa;AAAA,EAChD,UAAU,CAAC,SAAS,gBAAgB,WAAW,aAAa;AAAA;AAAA,EAG5D,GAAG,CAAC,SAAS,aAAa;AAAA;AAAA,EAG1B,IAAI,CAAC,SAAS,aAAa;AAAA,EAC3B,KAAK,CAAC,SAAS,gBAAgB,UAAU,aAAa;AAAA,EACtD,YAAY,CAAC,SAAS,gBAAgB,UAAU,aAAa;AAAA,EAC7D,iBAAiB,CAAC,SAAS,gBAAgB,aAAa;AACzD;AAKO,MAAM,aAAa,iBAAAC,QAAK,QAAQ,WAAW,IAAI;",
6
- "names": ["packagei18n", "wpPlugini18n", "wpThemei18n", "path"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/extractors/css.ts"],
4
- "sourcesContent": ["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { themeHeaders } from \"../const.js\";\nimport type { Args } from \"../types.js\";\nimport { getCommentBlock } from \"../utils/common.js\";\nimport { getKeyByValue } from \"../utils/extractors.js\";\nimport { extractFileData } from \"./text.js\";\n\n/**\n * Extracts the theme data from the style.css file.\n * @param args - The command line arguments.\n * @param filename - The name of the style.css file.\n */\nexport function extractCssThemeData(\n\targs: Args,\n\tfilename = \"style.css\",\n): Record<string, string> {\n\tlet fileData: Record<string, string> = {};\n\tconst styleCssFile = path.join(args.paths.cwd, filename);\n\n\tif (fs.existsSync(styleCssFile)) {\n\t\tconst fileContent = fs.readFileSync(styleCssFile, \"utf8\");\n\t\tconst commentBlock = getCommentBlock(fileContent);\n\t\tfileData = extractFileData(commentBlock);\n\n\t\tif (\"Theme Name\" in fileData) {\n\t\t\tconsole.log(`\uD83D\uDD35 Theme stylesheet detected. ${styleCssFile}`);\n\t\t\targs.domain = \"theme\";\n\n\t\t\tconst themeInfo: Record<string, string> = {};\n\n\t\t\t// Loop through the theme headers and extract the values with the required format\n\t\t\tfor (const keyValueMatch of Object.entries(fileData)) {\n\t\t\t\t// Check if the line matches the expected format\n\t\t\t\tif (keyValueMatch?.[0] && keyValueMatch[1]) {\n\t\t\t\t\t// filter the retrieved headers\n\t\t\t\t\tconst header = getKeyByValue(themeHeaders, keyValueMatch[0].trim());\n\t\t\t\t\tif (header === undefined) continue;\n\t\t\t\t\tthemeInfo[header] = keyValueMatch[1].trim();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn themeInfo;\n\t\t}\n\t} else {\n\t\tconsole.log(`Theme stylesheet not found in ${styleCssFile}`);\n\t}\n\treturn {};\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAe;AACf,uBAAiB;AACjB,mBAA6B;AAE7B,oBAAgC;AAChC,wBAA8B;AAC9B,kBAAgC;AAOzB,SAAS,oBACf,MACA,WAAW,aACc;AACzB,MAAI,WAAmC,CAAC;AACxC,QAAM,eAAe,iBAAAA,QAAK,KAAK,KAAK,MAAM,KAAK,QAAQ;AAEvD,MAAI,eAAAC,QAAG,WAAW,YAAY,GAAG;AAChC,UAAM,cAAc,eAAAA,QAAG,aAAa,cAAc,MAAM;AACxD,UAAM,mBAAe,+BAAgB,WAAW;AAChD,mBAAW,6BAAgB,YAAY;AAEvC,QAAI,gBAAgB,UAAU;AAC7B,cAAQ,IAAI,wCAAiC,YAAY,EAAE;AAC3D,WAAK,SAAS;AAEd,YAAM,YAAoC,CAAC;AAG3C,iBAAW,iBAAiB,OAAO,QAAQ,QAAQ,GAAG;AAErD,YAAI,gBAAgB,CAAC,KAAK,cAAc,CAAC,GAAG;AAE3C,gBAAM,aAAS,iCAAc,2BAAc,cAAc,CAAC,EAAE,KAAK,CAAC;AAClE,cAAI,WAAW,OAAW;AAC1B,oBAAU,MAAM,IAAI,cAAc,CAAC,EAAE,KAAK;AAAA,QAC3C;AAAA,MACD;AAEA,aAAO;AAAA,IACR;AAAA,EACD,OAAO;AACN,YAAQ,IAAI,iCAAiC,YAAY,EAAE;AAAA,EAC5D;AACA,SAAO,CAAC;AACT;",
6
- "names": ["path", "fs"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/extractors/headers.ts"],
4
- "sourcesContent": ["import path from \"node:path\";\nimport { SetOfBlocks } from \"gettext-merger\";\nimport { boolean } from \"yargs\";\nimport type PackageI18n from \"../assets/package-i18n.js\";\nimport { modulePath } from \"../const.js\";\nimport { getEncodingCharset } from \"../fs/fs.js\";\nimport type { Args, I18nHeaders, PotHeaders } from \"../types.js\";\nimport { getPkgJsonData } from \"../utils/common.js\";\nimport { buildBlock } from \"../utils/extractors.js\";\nimport { extractCssThemeData } from \"./css.js\";\nimport { extractPhpPluginData } from \"./php.js\";\n\n/**\n * Checks if required fields are missing and logs a clear error message\n * @param {object} headerData - The header data to validate\n * @returns {boolean} - true if all required fields are present, false otherwise\n */\nfunction validateRequiredFields(headerData: I18nHeaders): boolean {\n\tconst requiredFields = [\n\t\t{ key: \"slug\", name: \"Plugin/Theme slug\", placeholder: \"PLUGIN NAME\" },\n\t\t{ key: \"author\", name: \"Author name\", placeholder: \"AUTHOR\" },\n\t\t{ key: \"version\", name: \"Version\", placeholder: \"\" },\n\t\t{ key: \"email\", name: \"Author email\", placeholder: \"AUTHOR EMAIL\" },\n\t\t{ key: \"xDomain\", name: \"Text domain\", placeholder: \"PLUGIN TEXTDOMAIN\" },\n\t];\n\n\tconst missingFields = requiredFields.filter(\n\t\t(field) =>\n\t\t\t!headerData[field.key] ||\n\t\t\theaderData[field.key] === field.placeholder ||\n\t\t\t(field.key === \"version\" && headerData[field.key] === \"0.0.1\"),\n\t);\n\n\tif (missingFields.length > 0) {\n\t\tconsole.error(\"\\n! Missing required information for POT file header:\\n\");\n\n\t\tfor (const field of missingFields) {\n\t\t\tconsole.error(\n\t\t\t\t` - ${field.name} is missing or has a default value (eg. version: 0.0.1, author: \"AUTHOR <EMAIL>\")`,\n\t\t\t);\n\t\t}\n\n\t\tconsole.error(\n\t\t\t\"\\nPlease provide this information adding the missing fields inside the headers object of the plugin/theme declaration or to the package.json file.\",\n\t\t\t\"\\nFor more information check the documentation at https://github.com/wp-blocks/makePot\",\n\t\t);\n\n\t\tconsole.error(\"\\n\");\n\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\n/**\n * Extract author data from package.json author field and return an array of strings\n * the original field is a string and it's longer form is \"Your Name <email@example.com> (https://example.com)\"\n *\n * @returns an object with name, email, and website\n * @param authorData\n */\nfunction extractAuthorData(authorData: string | object): {\n\tname: string;\n\temail?: string;\n\twebsite?: string;\n} {\n\t// Default result with placeholder values\n\tconst defaultResult = { name: \"AUTHOR\", email: \"AUTHOR EMAIL\" };\n\n\t// Return default if no author data\n\tif (!authorData) {\n\t\treturn defaultResult;\n\t}\n\n\t// Handle string format: \"Barney Rubble <barney@npmjs.com> (http://barnyrubble.npmjs.com/)\"\n\tif (typeof authorData === \"string\") {\n\t\t// Try to extract email with regex\n\t\tconst emailMatch = authorData.match(/<([^>]+)>/);\n\t\tconst email = emailMatch ? emailMatch[1].trim() : undefined;\n\n\t\t// Try to extract website with regex\n\t\tconst websiteMatch = authorData.match(/\\(([^)]+)\\)/);\n\t\tconst website = websiteMatch ? websiteMatch[1].trim() : undefined;\n\n\t\t// Extract name by removing email and website parts if present\n\t\tlet name = authorData.trim();\n\t\tif (emailMatch) name = name.replace(emailMatch[0], \"\").trim();\n\t\tif (websiteMatch) name = name.replace(websiteMatch[0], \"\").trim();\n\n\t\treturn { name, email, website };\n\t}\n\tif (typeof authorData === \"object\") {\n\t\t// Handle object format: { name: \"Barney Rubble\", email: \"barney@npmjs.com\", website: \"http://barnyrubble.npmjs.com/\" }\n\t\treturn {\n\t\t\tname: authorData.name,\n\t\t\temail: authorData.email,\n\t\t\twebsite: authorData.website,\n\t\t};\n\t}\n}\n\n/**\n * Gets author data by checking multiple possible locations in package.json\n *\n * @param pkgJsonData The package.json data object\n * @returns Author data with name, email and website\n */\nexport function getAuthorFromPackage(pkgJsonData: PackageI18n): {\n\tname: string;\n\temail?: string;\n\twebsite?: string;\n} {\n\t// Check multiple possible locations for author information\n\tconst locations = [\n\t\t\"author\", // Standard author field\n\t\t\"authors\", // Some packages use authors (plural)\n\t\t\"contributors\", // Try contributors if no author\n\t\t\"maintainers\", // Try maintainers as last resort\n\t];\n\n\t// Try each location in order\n\tfor (const location of locations) {\n\t\tif (pkgJsonData[location]) {\n\t\t\tlet authorData: {\n\t\t\t\tname: string;\n\t\t\t\temail?: string;\n\t\t\t\twebsite?: string;\n\t\t\t};\n\t\t\tif (typeof pkgJsonData[location] === \"string\") {\n\t\t\t\tauthorData = extractAuthorData(pkgJsonData[location]);\n\t\t\t} else if (typeof pkgJsonData[location] === \"object\") {\n\t\t\t\tfor (const author of pkgJsonData[location]) {\n\t\t\t\t\tif (!author) continue;\n\t\t\t\t\tauthorData = extractAuthorData(author);\n\t\t\t\t\tif (authorData) break;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (\n\t\t\t\tauthorData?.name !== \"AUTHOR\" ||\n\t\t\t\tauthorData?.email !== \"AUTHOR EMAIL\"\n\t\t\t) {\n\t\t\t\treturn authorData;\n\t\t\t}\n\t\t}\n\t}\n\n\t// If no valid author data found in any location\n\treturn { name: \"AUTHOR\", email: \"AUTHOR EMAIL\" };\n}\n\n/**\n * This function consolidates the user headers data into a single object\n *\n * @param args the command line arguments\n * @return {Record<string, string>} the consolidated headers data object\n */\nfunction consolidateUserHeaderData(args: Args): I18nHeaders {\n\tconst pkgJsonData = getPkgJsonData(\n\t\targs.paths?.cwd,\n\t\t\"name\",\n\t\t\"version\",\n\t\t\"author\",\n\t\t\"authors\",\n\t\t\"contributors\",\n\t\t\"maintainers\",\n\t) as Record<[keyof PackageI18n], string>;\n\n\tconst bugs = `https://wordpress.org/support/${args.domain === \"theme\" ? \"themes\" : \"plugins\"}/${args.slug}`;\n\n\t// get author data from package.json\n\tconst pkgAuthor = getAuthorFromPackage(pkgJsonData);\n\t// Use command line author name if provided, fallback to package.json\n\tconst authorName = args?.headers?.author || pkgAuthor?.name;\n\tconst email = pkgAuthor?.email;\n\t// this is the author with email address in this format: author <email>\n\tconst authorString = `${authorName} <${email}>`;\n\t// get the current directory name as slug\n\tconst currentDir = path\n\t\t.basename(args.paths?.cwd || process.cwd())\n\t\t?.toLowerCase()\n\t\t.replace(\" \", \"-\");\n\tconst slug =\n\t\targs.slug ||\n\t\tcurrentDir ||\n\t\t(args.domain === \"theme\" ? \"THEME NAME\" : \"PLUGIN NAME\");\n\n\treturn {\n\t\t...args.headers,\n\t\tauthor: authorName,\n\t\tauthorString: authorString, // this is the author with email address in this format: author <email>\n\t\tslug,\n\t\temail,\n\t\tbugs,\n\t\tlicense: args.headers?.license || \"gpl-2.0 or later\",\n\t\tversion: args.headers?.version || pkgJsonData.version || \"0.0.1\",\n\t\tlanguage: \"en\",\n\t\txDomain: args.headers?.textDomain || slug,\n\t};\n}\n\n/**\n * Generates a POT header for a given set of arguments.\n * https://developer.wordpress.org/cli/commands/i18n/make-pot/\n * String that should be added as a comment to the top of the resulting POT file.\n * By default, a copyright comment is added for WordPress plugins and themes in the following manner:\n * `\n * Copyright (C) 2018 Example Plugin Author\n * This file is distributed under the same license as the Example Plugin package.\n * `\n * If a plugin or theme specifies a license in their main plugin file or stylesheet,\n * the comment looks like this: Copyright (C) 2018 Example Plugin Author This file is distributed under the GPLv2.\n *\n * @param args - The argument object containing the headers and their values.\n * @return The generated POT header.\n */\nexport async function generateHeader(args: Args) {\n\t// Consolidate the user headers data into a single object\n\tconst headerData = consolidateUserHeaderData(args);\n\n\t// the makepot module name and version\n\tconst { name, version } = getPkgJsonData(modulePath, \"name\", \"version\");\n\n\t// Validate required fields - exit early if validation fails\n\tif (!validateRequiredFields(headerData)) {\n\t\tprocess.exit(1); // Exit with error code\n\t\treturn null; // This is never reached but helps with TypeScript\n\t}\n\n\tconst header = {\n\t\t\"Project-Id-Version\": `${headerData.slug} ${headerData.version}`,\n\t\t\"Report-Msgid-Bugs-To\": headerData.authorString,\n\t\t\"MIME-Version\": \"1.0\",\n\t\t\"Content-Transfer-Encoding\": \"8bit\",\n\t\t\"content-type\": `text/plain; charset=${getEncodingCharset(args.options?.charset)}`,\n\t\t\"plural-forms\": \"nplurals=2; plural=(n!=1);\",\n\t\t\"POT-Creation-Date\": `${new Date().toISOString()}`,\n\t\t\"PO-Revision-Date\": `${new Date().getFullYear()}-MO-DA HO:MI+ZONE`,\n\t\t\"Last-Translator\": headerData.authorString,\n\t\t\"Language-Team\": headerData.authorString,\n\t\t\"X-Generator\": `${name} ${version}`,\n\t\tLanguage: `${headerData.language}`,\n\t\t\"X-Domain\": headerData.xDomain,\n\t};\n\n\treturn header;\n}\n\n/**\n * Extracts main file data based on the given arguments.\n *\n * @param {Args} args - The arguments for extracting the main file data.\n * @return {Record<string, string>} The extracted main file data.\n */\nexport function extractMainFileData(args: Args): Record<string, string> {\n\tlet extractedData = {};\n\tif ([\"plugin\", \"block\", \"generic\"].includes(args.domain)) {\n\t\textractedData = extractPhpPluginData(args);\n\t} else if ([\"theme\", \"theme-block\"].includes(args.domain)) {\n\t\textractedData = extractCssThemeData(args);\n\t} else {\n\t\tconsole.log(\"No main file detected.\");\n\t}\n\n\treturn extractedData;\n}\n\n/**\n * Generate translation strings based on the given type and headers.\n *\n * @return {Record<string, string>} the generated translation strings\n * @param args\n */\nexport function translationsHeaders(args: Args): SetOfBlocks {\n\tconst { domain, headers } = args as Args;\n\tconst { name, description, author, authorUri, url } = headers as {\n\t\t[key in PotHeaders]: string;\n\t};\n\n\t// the main file is the plugin main php file or the css file\n\tconst fakePath = domain === \"plugin\" ? `${args.slug}.php` : \"style.css\";\n\n\treturn new SetOfBlocks([\n\t\tbuildBlock(`Name of the ${domain}`, name, [fakePath]),\n\t\tbuildBlock(`Url of the ${domain}`, url, [fakePath]),\n\t\tbuildBlock(`Description of the ${domain}`, description, [fakePath]),\n\t\tbuildBlock(`Author of the ${domain}`, author, [fakePath]),\n\t\tbuildBlock(`Author URI of the ${domain}`, authorUri, [fakePath]),\n\t]);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AACjB,4BAA4B;AAG5B,mBAA2B;AAC3B,gBAAmC;AAEnC,oBAA+B;AAC/B,wBAA2B;AAC3B,iBAAoC;AACpC,iBAAqC;AAOrC,SAAS,uBAAuB,YAAkC;AACjE,QAAM,iBAAiB;AAAA,IACtB,EAAE,KAAK,QAAQ,MAAM,qBAAqB,aAAa,cAAc;AAAA,IACrE,EAAE,KAAK,UAAU,MAAM,eAAe,aAAa,SAAS;AAAA,IAC5D,EAAE,KAAK,WAAW,MAAM,WAAW,aAAa,GAAG;AAAA,IACnD,EAAE,KAAK,SAAS,MAAM,gBAAgB,aAAa,eAAe;AAAA,IAClE,EAAE,KAAK,WAAW,MAAM,eAAe,aAAa,oBAAoB;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,MAAM,aAAa,QAAQ,WAAW,IAAI,IAAI;AAKtD,QAAM,WAAW,WAAW,WAAW,GAAG,KAAK,IAAI,SAAS;AAE5D,SAAO,IAAI,kCAAY;AAAA,QACtB,8BAAW,eAAe,MAAM,IAAI,MAAM,CAAC,QAAQ,CAAC;AAAA,QACpD,8BAAW,cAAc,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC;AAAA,QAClD,8BAAW,sBAAsB,MAAM,IAAI,aAAa,CAAC,QAAQ,CAAC;AAAA,QAClE,8BAAW,iBAAiB,MAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC;AAAA,QACxD,8BAAW,qBAAqB,MAAM,IAAI,WAAW,CAAC,QAAQ,CAAC;AAAA,EAChE,CAAC;AACF;",
6
- "names": ["path"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/extractors/json.ts"],
4
- "sourcesContent": ["import path from \"node:path\";\nimport type { Block, SetOfBlocks } from \"gettext-merger\";\nimport type { I18nSchema } from \"../types.js\";\nimport { yieldParsedData } from \"../utils/extractors.js\";\nimport { JsonSchemaExtractor } from \"./schema.js\";\n\n/**\n * Parses a JSON file and returns an array of parsed data.\n *\n * @param {Object} opts - The arguments for parsing the JSON file.\n * @param {string} opts.filepath - The filepath of the JSON file to parse.\n * @param {Object} [opts.stats] - Optional statistics object.\n * @param {number} opts.stats.index - The index of the progress bar.\n * @return {Promise<TranslationStrings>} A promise that resolves to an object containing the parsed data.\n */\nexport async function parseJsonFile(opts: {\n\tfileContent: string;\n\tfilename: \"block.json\" | \"theme.json\";\n}): Promise<Block[]> {\n\tconst isTheme = opts.filename === \"theme.json\";\n\tconst schema: { url: string; fallback: I18nSchema } = {\n\t\turl: isTheme\n\t\t\t? JsonSchemaExtractor.themeJsonSource\n\t\t\t: JsonSchemaExtractor.blockJsonSource,\n\t\tfallback: isTheme\n\t\t\t? (JsonSchemaExtractor.themeJsonFallback as I18nSchema)\n\t\t\t: (JsonSchemaExtractor.blockJsonFallback as I18nSchema),\n\t};\n\n\tif (!schema.url || !schema.fallback) {\n\t\tconsole.error(\"Schema URL or fallback not provided\");\n\t\treturn;\n\t}\n\n\t// Get the JSON translations from the schema\n\tconst jsonTranslations = await JsonSchemaExtractor.parse(\n\t\topts.fileContent,\n\t\tschema,\n\t\t{\n\t\t\tfile: opts.filename,\n\t\t\taddReferences: true,\n\t\t},\n\t);\n\n\treturn jsonTranslations ?? [];\n}\n\n/**\n * Parses the JSON content of a file based on the filename and file content.\n *\n * @param {string} fileContent - The content of the file to parse.\n * @param {string} filePath - The path of the file being parsed.\n * @param {'block.json' | 'theme.json'} filename - The type of JSON file being parsed.\n * @return {Promise<TranslationStrings>} The parsed translation strings.\n */\nexport async function parseJsonCallback(\n\tfileContent: string,\n\tfilePath: string,\n\tfilename: \"block.json\" | \"theme.json\",\n): Promise<SetOfBlocks> {\n\tconst data = await parseJsonFile({\n\t\tfileContent: fileContent,\n\t\tfilename: filename,\n\t});\n\n\treturn yieldParsedData(data, filename, path.join(filePath, filename));\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AAGjB,wBAAgC;AAChC,oBAAoC;AAWpC,eAAsB,cAAc,MAGf;AACpB,QAAM,UAAU,KAAK,aAAa;AAClC,QAAM,SAAgD;AAAA,IACrD,KAAK,UACF,kCAAoB,kBACpB,kCAAoB;AAAA,IACvB,UAAU,UACN,kCAAoB,oBACpB,kCAAoB;AAAA,EACzB;AAEA,MAAI,CAAC,OAAO,OAAO,CAAC,OAAO,UAAU;AACpC,YAAQ,MAAM,qCAAqC;AACnD;AAAA,EACD;AAGA,QAAM,mBAAmB,MAAM,kCAAoB;AAAA,IAClD,KAAK;AAAA,IACL;AAAA,IACA;AAAA,MACC,MAAM,KAAK;AAAA,MACX,eAAe;AAAA,IAChB;AAAA,EACD;AAEA,SAAO,oBAAoB,CAAC;AAC7B;AAUA,eAAsB,kBACrB,aACA,UACA,UACuB;AACvB,QAAM,OAAO,MAAM,cAAc;AAAA,IAChC;AAAA,IACA;AAAA,EACD,CAAC;AAED,aAAO,mCAAgB,MAAM,UAAU,iBAAAA,QAAK,KAAK,UAAU,QAAQ,CAAC;AACrE;",
6
- "names": ["path"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/extractors/packageJson.ts"],
4
- "sourcesContent": ["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { pkgJsonHeaders } from \"../const.js\";\nimport type { Args } from \"../types.js\";\n\n/**\n * Extracts package data from the given arguments and returns a record\n * containing the specified fields from the package.json file.\n *\n * @param {Args} args - The arguments for extracting package data.\n *\n * @return {Record<string, string>} - A record containing the extracted package data.\n */\nexport function extractPackageJson(args: Args): Record<string, string> {\n\tconst fields = pkgJsonHeaders;\n\tconst pkgJsonMeta: Record<string, string> = {};\n\t// read the package.json file\n\tconst packageJsonPath = args.paths.cwd\n\t\t? path.join(args.paths.cwd, \"package.json\")\n\t\t: \"package.json\";\n\n\t/**\n\t * check if the package.json extract the fields from the package.json file\n\t */\n\tif (fs.existsSync(packageJsonPath)) {\n\t\tconst packageJson = JSON.parse(fs.readFileSync(packageJsonPath, \"utf8\"));\n\t\tfor (const field of Object.keys(fields)) {\n\t\t\t// if the field exists in the package.json\n\t\t\tif (field in packageJson) {\n\t\t\t\tpkgJsonMeta[field] = `${packageJson[field]}` as string;\n\t\t\t}\n\t\t}\n\t}\n\treturn pkgJsonMeta;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAe;AACf,uBAAiB;AACjB,mBAA+B;AAWxB,SAAS,mBAAmB,MAAoC;AACtE,QAAM,SAAS;AACf,QAAM,cAAsC,CAAC;AAE7C,QAAM,kBAAkB,KAAK,MAAM,MAChC,iBAAAA,QAAK,KAAK,KAAK,MAAM,KAAK,cAAc,IACxC;AAKH,MAAI,eAAAC,QAAG,WAAW,eAAe,GAAG;AACnC,UAAM,cAAc,KAAK,MAAM,eAAAA,QAAG,aAAa,iBAAiB,MAAM,CAAC;AACvE,eAAW,SAAS,OAAO,KAAK,MAAM,GAAG;AAExC,UAAI,SAAS,aAAa;AACzB,oBAAY,KAAK,IAAI,GAAG,YAAY,KAAK,CAAC;AAAA,MAC3C;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;",
6
- "names": ["path", "fs"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/extractors/php.ts"],
4
- "sourcesContent": ["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { pluginHeaders } from \"../const.js\";\nimport type { Args } from \"../types.js\";\nimport { getKeyByValue } from \"../utils/extractors.js\";\n\nexport function extractPhpPluginData(args: Args): Record<string, string> {\n\tlet fileData: Record<string, string> = {};\n\tconst folderPhpFile = path.join(args.paths.cwd, `${args.slug}.php`);\n\n\tif (fs.existsSync(folderPhpFile)) {\n\t\tconst fileContent = fs.readFileSync(folderPhpFile, \"utf8\");\n\t\tfileData = parsePHPFile(fileContent);\n\n\t\tconsole.log(`\uD83D\uDD35 Plugin file detected. (${folderPhpFile})`);\n\n\t\t// Set the domain\n\t\targs.domain = \"plugin\";\n\n\t\treturn fileData;\n\t}\n\n\tconsole.log(\"Plugin file not found.\");\n\tconsole.log(`Missing Plugin filename: ${folderPhpFile}`);\n\n\treturn {};\n}\n\n/**\n * Parses a PHP file and extracts the plugin information from the comment block.\n *\n * @param {string} phpContent - The content of the PHP file.\n * @return {Record<string, string>} - A record containing the plugin information.\n */\nexport function parsePHPFile(phpContent: string): Record<string, string> {\n\tconst match = phpContent.match(/\\/\\*\\*([\\s\\S]*?)\\*\\//);\n\n\tif (match?.[1] && match) {\n\t\tconst commentBlock = match[1];\n\t\tconst lines = commentBlock.split(\"\\n\");\n\n\t\tconst pluginInfo: Record<string, string> = {};\n\n\t\tfor (const line of lines) {\n\t\t\tconst keyValueMatch = line.match(/^\\s*\\*\\s*([^:]+):\\s*(.*)/);\n\n\t\t\tif (!keyValueMatch) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Check if the line matches the expected format\n\t\t\tif (keyValueMatch?.[1] && keyValueMatch[2]) {\n\t\t\t\t// filter the retrieved headers\n\t\t\t\tconst header = getKeyByValue(pluginHeaders, keyValueMatch[1].trim());\n\t\t\t\tif (header === undefined) continue;\n\t\t\t\tpluginInfo[header] = keyValueMatch[2].trim();\n\t\t\t}\n\t\t}\n\n\t\treturn pluginInfo;\n\t}\n\treturn {};\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAe;AACf,uBAAiB;AACjB,mBAA8B;AAE9B,wBAA8B;AAEvB,SAAS,qBAAqB,MAAoC;AACxE,MAAI,WAAmC,CAAC;AACxC,QAAM,gBAAgB,iBAAAA,QAAK,KAAK,KAAK,MAAM,KAAK,GAAG,KAAK,IAAI,MAAM;AAElE,MAAI,eAAAC,QAAG,WAAW,aAAa,GAAG;AACjC,UAAM,cAAc,eAAAA,QAAG,aAAa,eAAe,MAAM;AACzD,eAAW,aAAa,WAAW;AAEnC,YAAQ,IAAI,oCAA6B,aAAa,GAAG;AAGzD,SAAK,SAAS;AAEd,WAAO;AAAA,EACR;AAEA,UAAQ,IAAI,wBAAwB;AACpC,UAAQ,IAAI,4BAA4B,aAAa,EAAE;AAEvD,SAAO,CAAC;AACT;AAQO,SAAS,aAAa,YAA4C;AACxE,QAAM,QAAQ,WAAW,MAAM,sBAAsB;AAErD,MAAI,QAAQ,CAAC,KAAK,OAAO;AACxB,UAAM,eAAe,MAAM,CAAC;AAC5B,UAAM,QAAQ,aAAa,MAAM,IAAI;AAErC,UAAM,aAAqC,CAAC;AAE5C,eAAW,QAAQ,OAAO;AACzB,YAAM,gBAAgB,KAAK,MAAM,0BAA0B;AAE3D,UAAI,CAAC,eAAe;AACnB;AAAA,MACD;AAGA,UAAI,gBAAgB,CAAC,KAAK,cAAc,CAAC,GAAG;AAE3C,cAAM,aAAS,iCAAc,4BAAe,cAAc,CAAC,EAAE,KAAK,CAAC;AACnE,YAAI,WAAW,OAAW;AAC1B,mBAAW,MAAM,IAAI,cAAc,CAAC,EAAE,KAAK;AAAA,MAC5C;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AACA,SAAO,CAAC;AACT;",
6
- "names": ["path", "fs"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/extractors/schema.ts"],
4
- "sourcesContent": ["import type { Block } from \"gettext-merger\";\nimport * as blocki18n from \"../assets/block-i18n.js\";\nimport type BlockI18n from \"../assets/block-i18n.js\";\nimport * as themei18n from \"../assets/theme-i18n.js\";\nimport type ThemeI18n from \"../assets/theme-i18n.js\";\nimport type { I18nSchema } from \"../types.js\";\n\n/**\n * Extracts strings from JSON files using the I18n schema.\n */\n\n// biome-ignore lint/complexity/noStaticOnlyClass: <explanation>\nexport class JsonSchemaExtractor {\n\tprivate static schemaCache: { [url: string]: I18nSchema } = {};\n\n\t/** Theme */\n\tstatic themeJsonSource =\n\t\t\"http://develop.svn.wordpress.org/trunk/src/wp-includes/theme-i18n.json\";\n\tstatic themeJsonFallback = themei18n as ThemeI18n;\n\t/** Block */\n\tstatic blockJsonSource =\n\t\t\"http://develop.svn.wordpress.org/trunk/src/wp-includes/block-i18n.json\";\n\tstatic blockJsonFallback = blocki18n as BlockI18n;\n\n\t/**\n\t * Load the schema from the specified URL, with a fallback URL if needed.\n\t *\n\t * @param {string} url - The URL to load the schema from.\n\t * @param {I18nSchema} fallback - The fallback schema to use if the main URL fails.\n\t * @return {Promise<I18nSchema>} The loaded schema.\n\t */\n\tprivate static async loadSchema(\n\t\turl: string,\n\t\tfallback: I18nSchema,\n\t): Promise<I18nSchema> {\n\t\tif (JsonSchemaExtractor.schemaCache[url]) {\n\t\t\treturn JsonSchemaExtractor.schemaCache[url];\n\t\t}\n\n\t\ttry {\n\t\t\tconsole.log(`\\n[i] Loading schema from ${url}`);\n\t\t\tconst response = await fetch(url, {\n\t\t\t\tresponseType: \"json\",\n\t\t\t\taccept: \"application/json\",\n\t\t\t\theaders: {\n\t\t\t\t\t\"Access-Control-Allow-Origin\": \"*\",\n\t\t\t\t},\n\t\t\t})\n\t\t\t\t.then((response) => response.json())\n\t\t\t\t.catch((error: Error) => {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`\\nFailed to load schema from ${url}. Error: ${error.message}`,\n\t\t\t\t\t);\n\t\t\t\t});\n\n\t\t\t// Verify if the response is valid\n\t\t\tif (!response) {\n\t\t\t\treturn fallback;\n\t\t\t}\n\n\t\t\tconsole.log(\"Schema loaded successfully\");\n\t\t\tJsonSchemaExtractor.schemaCache[url] = response;\n\t\t\treturn response;\n\t\t} catch (error) {\n\t\t\tconsole.error(\n\t\t\t\t`\\nFailed to load schema from ${url}. Using fallback. Error: ${error.message}`,\n\t\t\t);\n\t\t\tJsonSchemaExtractor.schemaCache[url] = fallback;\n\t\t\treturn fallback;\n\t\t}\n\t}\n\n\t/**\n\t * Parses a string and extracts translations using the specified schema.\n\t *\n\t * @param {string} text - the input string to be parsed\n\t * @param {object} schema - the schema to use for parsing the input string\n\t * @param {string} schema.url - the URL of the schema to use for parsing the input string\n\t * @param {object} schema.schemaFallback - the fallback schema to use if the main schema fails\n\t * @param {object} options - the options for parsing the input string\n\t * @param {string} options.file - the name of the file being parsed\n\t * @param {boolean} options.addReferences - whether to add references to the extracted strings\n\t *\n\t * @return {Promise<I18nSchema | undefined>} a promise that resolves with the extracted schema\n\t */\n\tpublic static async parse(\n\t\ttext: string,\n\t\tschema: {\n\t\t\turl: string;\n\t\t\tfallback: I18nSchema;\n\t\t},\n\t\toptions: {\n\t\t\tfile: \"block.json\" | \"theme.json\";\n\t\t\taddReferences: boolean;\n\t\t},\n\t): Promise<Block[] | undefined> {\n\t\tconst parsedSchema = await JsonSchemaExtractor.loadSchema(\n\t\t\tschema.url,\n\t\t\tschema.fallback,\n\t\t);\n\n\t\ttry {\n\t\t\tconst json = JSON.parse(text) as Record<string, unknown>;\n\t\t\tif (!json) {\n\t\t\t\tconsole.error(\"Could not parse JSON.\");\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\treturn JsonSchemaExtractor.extractFromJsonSchema(\n\t\t\t\tjson,\n\t\t\t\tparsedSchema,\n\t\t\t\toptions,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tconsole.error(`Error parsing JSON: ${error.message}`);\n\t\t\treturn;\n\t\t}\n\t}\n\n\t/**\n\t * Extracts translatable strings from a JSON file by comparing it with a schema\n\t *\n\t * @param {Object} json - The JSON object to extract strings from\n\t * @param {Object} schema - The schema that defines which fields contain translatable strings\n\t * @param {Object} options - Options for extraction\n\t * @param {string} options.filename - The name of the file being extracted (for references)\n\t * @param {boolean} options.addReferences - Whether to add file references in comments\n\t * @return {Array} - An array of objects with translatable strings in gettext format\n\t */\n\tprivate static extractFromJsonSchema(\n\t\tjson: Record<string, unknown>,\n\t\tschema: I18nSchema,\n\t\toptions: { filename?: string; addReferences?: boolean } = {\n\t\t\tfilename: undefined,\n\t\t\taddReferences: false,\n\t\t},\n\t): Block[] | undefined {\n\t\tconst { filename = \"block.json\", addReferences = false } = options;\n\t\tconst translations = [];\n\n\t\t/**\n\t\t * Recursive function to extract translatable strings\n\t\t * @param {*} currentJson - The current node in the JSON\n\t\t * @param {*} currentSchema - The current node in the schema\n\t\t * @param {Array} path - The current path in the JSON\n\t\t */\n\t\tfunction extract(currentJson, currentSchema, path = []) {\n\t\t\t// If either is null or undefined, there's nothing to do\n\t\t\tif (!currentJson || !currentSchema) return;\n\n\t\t\t// Handles the case where both are objects\n\t\t\tif (\n\t\t\t\ttypeof currentJson === \"object\" &&\n\t\t\t\t!Array.isArray(currentJson) &&\n\t\t\t\ttypeof currentSchema === \"object\" &&\n\t\t\t\t!Array.isArray(currentSchema)\n\t\t\t) {\n\t\t\t\t// Iterate over the schema keys\n\t\t\t\tfor (const key of Object.keys(currentSchema)) {\n\t\t\t\t\tif (key in currentJson) {\n\t\t\t\t\t\t// If the key exists in the JSON, check the type\n\t\t\t\t\t\tif (typeof currentJson[key] === \"string\") {\n\t\t\t\t\t\t\t// It's a string - add it to translations\n\t\t\t\t\t\t\taddTranslation(\n\t\t\t\t\t\t\t\tcurrentJson[key],\n\t\t\t\t\t\t\t\tcurrentSchema[key],\n\t\t\t\t\t\t\t\tfilename,\n\t\t\t\t\t\t\t\taddReferences,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\tArray.isArray(currentJson[key]) &&\n\t\t\t\t\t\t\tArray.isArray(currentSchema[key])\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// It's an array - handle each element\n\t\t\t\t\t\t\thandleArrays(\n\t\t\t\t\t\t\t\tcurrentJson[key],\n\t\t\t\t\t\t\t\tcurrentSchema[key],\n\t\t\t\t\t\t\t\t[...path, key],\n\t\t\t\t\t\t\t\tfilename,\n\t\t\t\t\t\t\t\taddReferences,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else if (\n\t\t\t\t\t\t\ttypeof currentJson[key] === \"object\" &&\n\t\t\t\t\t\t\ttypeof currentSchema[key] === \"object\"\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t// It's an object - recurse\n\t\t\t\t\t\t\textract(currentJson[key], currentSchema[key], [...path, key]);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Handles arrays in JSON and schema\n\t\t * @param {Array} jsonArray - The JSON array\n\t\t * @param {Array} schemaArray - The schema array\n\t\t * @param {Array} path - The current path\n\t\t * @param {string} filename - The name of the file\n\t\t * @param {boolean} addReferences - whenever to add references\n\t\t */\n\t\tfunction handleArrays(\n\t\t\tjsonArray,\n\t\t\tschemaArray,\n\t\t\tpath,\n\t\t\tfilename,\n\t\t\taddReferences,\n\t\t) {\n\t\t\t// If the schema has at least one element, use it as a template\n\t\t\tif (schemaArray.length > 0) {\n\t\t\t\tconst schemaTemplate = schemaArray[0];\n\n\t\t\t\t// For each element in the JSON array\n\t\t\t\tfor (const jsonItem of jsonArray) {\n\t\t\t\t\tif (typeof jsonItem === \"string\") {\n\t\t\t\t\t\t// If the JSON element is a string, add it directly\n\t\t\t\t\t\taddTranslation(jsonItem, schemaTemplate, filename, addReferences);\n\t\t\t\t\t} else if (typeof jsonItem === \"object\") {\n\t\t\t\t\t\t// If it's an object, recurse\n\t\t\t\t\t\tif (typeof schemaTemplate === \"object\") {\n\t\t\t\t\t\t\textract(jsonItem, schemaTemplate, path);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// Edge case: handles cases like keywords: [\"string1\", \"string2\"]\n\t\t\t\t\t\t\t// when the schema has keywords: [\"keyword context\"]\n\t\t\t\t\t\t\tfor (const key of Object.keys(jsonItem)) {\n\t\t\t\t\t\t\t\tif (typeof jsonItem[key] === \"string\") {\n\t\t\t\t\t\t\t\t\taddTranslation(\n\t\t\t\t\t\t\t\t\t\tjsonItem[key],\n\t\t\t\t\t\t\t\t\t\tschemaTemplate,\n\t\t\t\t\t\t\t\t\t\tfilename,\n\t\t\t\t\t\t\t\t\t\taddReferences,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Adds a translation to the translations array\n\t\t * @param {string} msgctxt - The context of the text to be translated\n\t\t * @param {string} msgid - The text to be translated\n\t\t * @param {string} filename - The name of the file for references\n\t\t * @param {boolean} addReferences - Whether to add references\n\t\t */\n\t\tfunction addTranslation(msgctxt, msgid, filename, addReferences) {\n\t\t\tif (!msgctxt) return; // Do not add empty strings\n\n\t\t\tconst translation = {\n\t\t\t\tmsgid,\n\t\t\t\tmsgctxt,\n\t\t\t} as Block;\n\n\t\t\tif (addReferences) {\n\t\t\t\ttranslation.comments = {\n\t\t\t\t\treference: [filename],\n\t\t\t\t};\n\t\t\t}\n\n\t\t\ttranslations.push(translation);\n\t\t}\n\n\t\t// Start extraction from the root\n\t\textract(json, schema);\n\n\t\treturn translations;\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,gBAA2B;AAE3B,gBAA2B;AASpB,MAAM,oBAAoB;AAAA,EAChC,OAAe,cAA6C,CAAC;AAAA;AAAA,EAG7D,OAAO,kBACN;AAAA,EACD,OAAO,oBAAoB;AAAA;AAAA,EAE3B,OAAO,kBACN;AAAA,EACD,OAAO,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAS3B,aAAqB,WACpB,KACA,UACsB;AACtB,QAAI,oBAAoB,YAAY,GAAG,GAAG;AACzC,aAAO,oBAAoB,YAAY,GAAG;AAAA,IAC3C;AAEA,QAAI;AACH,cAAQ,IAAI;AAAA,0BAA6B,GAAG,EAAE;AAC9C,YAAM,WAAW,MAAM,MAAM,KAAK;AAAA,QACjC,cAAc;AAAA,QACd,QAAQ;AAAA,QACR,SAAS;AAAA,UACR,+BAA+B;AAAA,QAChC;AAAA,MACD,CAAC,EACC,KAAK,CAACA,cAAaA,UAAS,KAAK,CAAC,EAClC,MAAM,CAAC,UAAiB;AACxB,cAAM,IAAI;AAAA,UACT;AAAA,6BAAgC,GAAG,YAAY,MAAM,OAAO;AAAA,QAC7D;AAAA,MACD,CAAC;AAGF,UAAI,CAAC,UAAU;AACd,eAAO;AAAA,MACR;AAEA,cAAQ,IAAI,4BAA4B;AACxC,0BAAoB,YAAY,GAAG,IAAI;AACvC,aAAO;AAAA,IACR,SAAS,OAAO;AACf,cAAQ;AAAA,QACP;AAAA,6BAAgC,GAAG,4BAA4B,MAAM,OAAO;AAAA,MAC7E;AACA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M;AAEpB,WAAO;AAAA,EACR;AACD;",
6
- "names": ["response", "filename", "addReferences"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/extractors/text.ts"],
4
- "sourcesContent": ["import { removeCommentMarkup } from \"../utils/common.js\";\n\n/**\n * Extracts file data from the given file content.\n *\n * @param {string} fileContent - The content of the file.\n * @param {string} separator - The separator used in the file.\n * @return {Record<string, string>} An object containing the extracted file data.\n */\nexport function extractFileData(\n\tfileContent: string,\n\tseparator = \":\",\n): Record<string, string> {\n\tconst data: Record<string, string> = {};\n\n\t// split by lines and trim every line\n\tconst text = removeCommentMarkup(fileContent) ?? [];\n\t// split each line by break line and trim each part and add to data\n\tfor (const line of text) {\n\t\tconst parts = line.split(separator);\n\t\t/* Check if the parser has already collected the data from the previous line\n\t\t\t and the current line is empty.\n\t\t\t If so, skip this line */\n\t\tif (parts.length !== 2 && Object.values(data).length > 0 && parts[1]) {\n\t\t\tcontinue;\n\t\t}\n\t\tdata[parts[0]?.trim()] = parts[1].trim();\n\t}\n\n\treturn data;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAoC;AAS7B,SAAS,gBACf,aACA,YAAY,KACa;AACzB,QAAM,OAA+B,CAAC;AAGtC,QAAM,WAAO,mCAAoB,WAAW,KAAK,CAAC;AAElD,aAAW,QAAQ,MAAM;AACxB,UAAM,QAAQ,KAAK,MAAM,SAAS;AAIlC,QAAI,MAAM,WAAW,KAAK,OAAO,OAAO,IAAI,EAAE,SAAS,KAAK,MAAM,CAAC,GAAG;AACrE;AAAA,IACD;AACA,SAAK,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,MAAM,CAAC,EAAE,KAAK;AAAA,EACxC;AAEA,SAAO;AACR;",
6
- "names": []
7
- }
package/lib/fs/fs.js.map DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/fs/fs.ts"],
4
- "sourcesContent": ["import fs, { writeFileSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { Args } from \"../types.js\";\n\n/**\n * Ensures that a folder exists at the specified path.\n *\n * @param {string | undefined} folderPath - The path of the folder to ensure existence for.\n * @return {string} - The path of the folder, or '.' if folderPath is undefined.\n */\nfunction ensureFolderExists(folderPath: string | undefined): string {\n\tif (folderPath === undefined) {\n\t\treturn \".\";\n\t}\n\ttry {\n\t\t// Check if the folder exists\n\t\tfs.accessSync(\n\t\t\tpath.resolve(folderPath),\n\t\t\tfs.constants.R_OK | fs.constants.W_OK,\n\t\t);\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") {\n\t\t\t// The Folder does not exist, so create it\n\t\t\tfs.mkdirSync(folderPath, { recursive: true });\n\t\t\tconsole.log(`Folder created: ${folderPath}`);\n\t\t\treturn folderPath;\n\t\t}\n\t}\n\treturn folderPath;\n}\n\n/**\n * Gets the charset of the .pot file\n *\n * @param charset the charset of the .pot file\n * @return the charset of the .pot file\n */\nexport function getCharset(charset: string | undefined): BufferEncoding {\n\tif (!charset) {\n\t\treturn \"latin1\";\n\t}\n\t// we need to check if the charset is valid otherwise we return latin1 that is a common alias for ISO-8859-1 and the default charset for pot files\n\tswitch (charset.toLowerCase()) {\n\t\tcase \"utf-8\":\n\t\tcase \"utf8\":\n\t\t\treturn \"utf-8\";\n\t\tdefault:\n\t\t\treturn \"latin1\";\n\t}\n}\n\nexport function getEncodingCharset(charset: string | undefined): string {\n\tif (!charset) {\n\t\treturn \"iso-8859-1\";\n\t}\n\t// we need to check if the charset is valid otherwise we return utf-8 that is a common alias for ISO-8859-1 and the default charset for pot files\n\tswitch (charset.toLowerCase()) {\n\t\tcase \"utf-8\":\n\t\tcase \"utf8\":\n\t\t\treturn \"utf-8\";\n\t\tdefault:\n\t\t\treturn \"iso-8859-1\";\n\t}\n}\n\n/**\n * The output path for the pot file.\n * @param outpath - the output path for the pot/json files\n * @return {string} - the output path\n */\nexport function getOutputPath(outpath?: string): string {\n\treturn path.join(process.cwd(), outpath ?? \"languages\");\n}\n\n/**\n * The output path for the pot file.\n * @param args - the command line arguments\n */\nfunction getOutputFilePath(args: Args): string {\n\tconst { out, headers, options } = args.paths;\n\tlet i18nFolder = out ?? headers?.domainPath ?? \"languages\";\n\n\t// Remove leading and trailing slashes\n\ti18nFolder = i18nFolder.replace(/^\\/+|\\/+$/g, \"\");\n\n\tconst extension = options?.json ? \"json\" : \"pot\";\n\n\treturn path.join(process.cwd(), i18nFolder, `${args.slug}.${extension}`);\n}\n\n/**\n * Writes the .pot file to disk\n *\n * @param fileContent the content of the .pot file\n * @param args the command line arguments passed to the program\n */\nexport function writeFile(fileContent: string, args: Args): void {\n\tconst dest = getOutputFilePath(args);\n\n\tif (ensureFolderExists(path.dirname(dest))) {\n\t\t// get the encoding charset\n\t\tconst encodingCharset = getCharset(args.options?.charset);\n\t\tconsole.log(`\\nFile created at ${dest}`);\n\n\t\t// write the file\n\t\tconst potBuffer = Buffer.from(fileContent);\n\t\twriteFileSync(dest, potBuffer.toString(encodingCharset), {\n\t\t\tencoding: encodingCharset,\n\t\t});\n\t} else {\n\t\tconsole.log(`Folder ${dest} does not exist and cannot be created`);\n\t}\n}\n\n/**\n * The async version of fs.readFile method\n * @param path the path of the file to read\n * @return the content of the file as a string\n */\nexport async function readFileAsync(path: string): Promise<string> {\n\treturn readFile(path, \"utf-8\");\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAkC;AAClC,sBAAyB;AACzB,uBAAiB;AASjB,SAAS,mBAAmB,YAAwC;AACnE,MAAI,eAAe,QAAW;AAC7B,WAAO;AAAA,EACR;AACA,MAAI;AAEH,mBAAAA,QAAG;AAAA,MACF,iBAAAC,QAAK,QAAQ,UAAU;AAAA,MACvB,eAAAD,QAAG,UAAU,O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AM,YAAY,OAAO,KAAK,WAAW;AACzC,sCAAc,MAAM,UAAU,SAAS,eAAe,GAAG;AAAA,MACxD,UAAU;AAAA,IACX,CAAC;AAAA,EACF,OAAO;AACN,YAAQ,IAAI,UAAU,IAAI,uCAAuC;AAAA,EAClE;AACD;AAOA,eAAsB,cAAcA,OAA+B;AAClE,aAAO,0BAASA,OAAM,OAAO;AAC9B;",
6
- "names": ["fs", "path"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/fs/glob.ts"],
4
- "sourcesContent": ["import path from \"node:path\";\nimport { Glob, type Path } from \"glob\";\nimport { minimatch } from \"minimatch\";\n// @ts-ignore\nimport * as Javascript from \"tree-sitter-javascript\";\n// @ts-ignore\nimport * as php from \"tree-sitter-php\";\n// @ts-ignore\nimport * as ts from \"tree-sitter-typescript\";\nimport type { Args, Patterns } from \"../types.js\";\nimport { detectPatternType } from \"../utils/common.js\";\n\n/**\n * Return the parser based on the file extension\n *\n * @param file - Path to the file\n * @return {Parser|null} - the parser to be used with the file or null if no parser is found\n */\nexport function getParser(\n\tfile: string,\n): string | { name: string; language: unknown } | null {\n\tconst ext = file.split(\".\").pop();\n\tswitch (ext) {\n\t\tcase \"ts\":\n\t\t\treturn ts.typescript;\n\t\tcase \"tsx\":\n\t\t\treturn ts.tsx;\n\t\tcase \"js\":\n\t\tcase \"jsx\":\n\t\tcase \"mjs\":\n\t\tcase \"cjs\":\n\t\t\treturn Javascript.default;\n\t\tcase \"php\":\n\t\t\treturn php.default;\n\t\tdefault:\n\t\t\treturn null;\n\t}\n}\n\n// Build the ignore function for Glob\nexport const ignoreFunc = (\n\tfilePath: Path,\n\texcludedPatterns: string[],\n): boolean => {\n\treturn excludedPatterns.some((exclude) => {\n\t\tconst type = detectPatternType(exclude);\n\t\t// return true to ignore\n\t\tswitch (type) {\n\t\t\tcase \"file\":\n\t\t\t\treturn filePath.isNamed(exclude);\n\t\t\tcase \"directory\":\n\t\t\t\treturn filePath.relative().includes(exclude);\n\t\t\tdefault:\n\t\t\t\t// Handle glob patterns using minimatch\n\t\t\t\treturn minimatch(filePath.relative(), exclude);\n\t\t}\n\t}) as boolean;\n};\n\n/**\n * Retrieves a list of files based on the provided arguments and patterns.\n *\n * @param {Args} args - The argument object containing the source directory and other options.\n * @param {Patterns} pattern - The pattern object containing the included and excluded file patterns.\n * @return A promise that resolves to an array of file paths.\n */\nexport function getFiles(args: Args, pattern: Patterns) {\n\t// Execute the glob search with the built patterns\n\treturn new Glob(pattern.include, {\n\t\tignore: {\n\t\t\tignored: (p: Path) => ignoreFunc(p, pattern.exclude),\n\t\t},\n\t\tnodir: true,\n\t\tcwd: args.paths.cwd,\n\t\troot: args.paths.root ? path.resolve(args.paths.root) : undefined,\n\t});\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AACjB,kBAAgC;AAChC,uBAA0B;AAE1B,iBAA4B;AAE5B,UAAqB;AAErB,SAAoB;AAEpB,oBAAkC;AAQ3B,SAAS,UACf,MACsD;AACtD,QAAM,MAAM,KAAK,MAAM,GAAG,EAAE,IAAI;AAChC,UAAQ,KAAK;AAAA,IACZ,KAAK;AACJ,aAAO,GAAG;AAAA,IACX,KAAK;AACJ,aAAO,GAAG;AAAA,IACX,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACJ,aAAO,WAAW;AAAA,IACnB,KAAK;AACJ,aAAO,IAAI;AAAA,IACZ;AACC,aAAO;AAAA,EACT;AACD;AAGO,MAAM,aAAa,CACzB,UACA,qBACa;AACb,SAAO,iBAAiB,KAAK,CAAC,YAAY;AACzC,UAAM,WAAO,iCAAkB,OAAO;AAEtC,YAAQ,MAAM;AAAA,MACb,KAAK;AACJ,eAAO,SAAS,QAAQ,OAAO;AAAA,MAChC,KAAK;AACJ,eAAO,SAAS,SAAS,EAAE,SAAS,OAAO;AAAA,MAC5C;AAEC,mBAAO,4BAAU,SAAS,SAAS,GAAG,OAAO;AAAA,IAC/C;AAAA,EACD,CAAC;AACF;AASO,SAAS,SAAS,MAAY,SAAmB;AAEvD,SAAO,IAAI,iBAAK,QAAQ,SAAS;AAAA,IAChC,QAAQ;AAAA,MACP,SAAS,CAAC,MAAY,WAAW,GAAG,QAAQ,OAAO;AAAA,IACpD;AAAA,IACA,OAAO;AAAA,IACP,KAAK,KAAK,MAAM;AAAA,IAChB,MAAM,KAAK,MAAM,OAAO,iBAAAA,QAAK,QAAQ,KAAK,MAAM,IAAI,IAAI;AAAA,EACzD,CAAC;AACF;",
6
- "names": ["path"]
7
- }
package/lib/index.js.map DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/index.ts"],
4
- "sourcesContent": ["import makeJson from \"./jsonCommand.js\";\nimport makePot from \"./potCommand.js\";\n\nexport { doTree } from \"./parser/tree.js\";\nexport { parseJsonFile } from \"./extractors/json.js\";\nexport {\n\textractMainFileData,\n\tgenerateHeader,\n\tgetAuthorFromPackage,\n} from \"./extractors/headers.js\";\n\nexport { makeJson, makePot };\nexport default { makeJson, makePot };\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qCAAAA;AAAA,EAAA,iCAAAC;AAAA,EAAA;AAAA;AAAA;AAAA,yBAAqB;AACrB,wBAAoB;AAEpB,kBAAuB;AACvB,kBAA8B;AAC9B,qBAIO;AAGP,IAAO,gBAAQ,EAAE,6BAAAD,SAAU,2BAAAC,QAAQ;",
6
- "names": ["makeJson", "makePot"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/jsonCommand.ts"],
4
- "sourcesContent": ["import MakeJsonCommand from \"./parser/makeJson.js\";\nimport type { MakeJsonArgs } from \"./types.js\";\nimport { printMakePotModuleInfo, printTimeElapsed } from \"./utils/common.js\";\n\nexport default function makeJsonCommand(args: MakeJsonArgs) {\n\tconst makeJsonCommand = new MakeJsonCommand(args);\n\n\tif (Object.keys(args).length > 0) {\n\t\tprintMakePotModuleInfo();\n\t\t/* capture the start time */\n\t\tconst timeStart = new Date();\n\t\tmakeJsonCommand\n\t\t\t.exec()\n\t\t\t.then((result) => {\n\t\t\t\tif (args.debug) {\n\t\t\t\t\tconsole.log(result);\n\t\t\t\t}\n\t\t\t\t/* output the end time */\n\t\t\t\tprintTimeElapsed(\"Make-Json\", timeStart);\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tconsole.error(`\uD83E\uDEE4 make-json - Error: ${error}`);\n\t\t\t});\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA4B;AAE5B,oBAAyD;AAE1C,SAAR,gBAAiC,MAAoB;AAC3D,QAAMA,mBAAkB,IAAI,gBAAAC,QAAgB,IAAI;AAEhD,MAAI,OAAO,KAAK,IAAI,EAAE,SAAS,GAAG;AACjC,8CAAuB;AAEvB,UAAM,YAAY,oBAAI,KAAK;AAC3B,IAAAD,iBACE,KAAK,EACL,KAAK,CAAC,WAAW;AACjB,UAAI,KAAK,OAAO;AACf,gBAAQ,IAAI,MAAM;AAAA,MACnB;AAEA,0CAAiB,aAAa,SAAS;AAAA,IACxC,CAAC,EACA,MAAM,CAAC,UAAU;AACjB,cAAQ,MAAM,gCAAyB,KAAK,EAAE;AAAA,IAC/C,CAAC;AAAA,EACH;AACD;",
6
- "names": ["makeJsonCommand", "MakeJsonCommand"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/makeJson.ts"],
4
- "sourcesContent": ["#!/usr/bin/env node\n\nimport { getJsonArgs } from \"./cli/getJsonArgs.js\";\nimport makeJson from \"./jsonCommand.js\";\n\nconst args = getJsonArgs();\n\nmakeJson(args);\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAEA,yBAA4B;AAC5B,yBAAqB;AAErB,MAAM,WAAO,gCAAY;AAAA,IAEzB,mBAAAA,SAAS,IAAI;",
6
- "names": ["makeJson"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/makePot.ts"],
4
- "sourcesContent": ["#!/usr/bin/env node\n\nimport { getArgs } from \"./cli/getArgs.js\";\nimport makepotCommand from \"./potCommand.js\";\nimport type { Args } from \"./types.js\";\n\n/** Main execution */\nmakepotCommand(getArgs() as Args);\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAEA,qBAAwB;AACxB,wBAA2B;AAAA,IAI3B,kBAAAA,aAAe,wBAAQ,CAAS;",
6
- "names": ["makepotCommand"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/parser/exec.ts"],
4
- "sourcesContent": ["import path from \"node:path\";\nimport type { SingleBar } from \"cli-progress\";\nimport { type GetTextTranslations, po } from \"gettext-parser\";\nimport Tannin from \"tannin\";\nimport { generateHeader, translationsHeaders } from \"../extractors/headers.js\";\nimport { getCharset, getEncodingCharset } from \"../fs/fs\";\nimport type { Args, Patterns } from \"../types.js\";\nimport { getCopyright, printStats } from \"../utils/common.js\";\nimport { getPatterns } from \"./patterns.js\";\nimport { processFiles } from \"./process.js\";\nimport { initProgress } from \"./progress.js\";\nimport { taskRunner } from \"./taskRunner.js\";\n\n/**\n * Returns the output path recap\n *\n * @param {string} cwd - The current working directory\n * @param {Patterns} patterns - The patterns to be used for the extraction process\n * @return {string} - The output path recap\n */\nfunction outputPathRecap(cwd: string, patterns: Patterns): string {\n\treturn `\\nScript Path: ${cwd}\\nfor ${patterns.include.join()}\\nignoring patterns: ${patterns.exclude.join()}\\n`;\n}\n\n/**\n * Runs the parser and generates the pot file or the json file based on the command line arguments\n *\n * @param {Args} args - The command line arguments\n * @return {Promise<string>} - A promise that resolves with the generated pot file\n */\nexport async function exec(args: Args): Promise<string> {\n\tif (!args.options?.silent) {\n\t\tconsole.log(\"\uD83D\uDCDD Starting makePot for\", args?.slug);\n\t\tprintStats();\n\t}\n\n\t// audit\n\tif (args.options?.skip.audit) {\n\t\tconsole.log(\"\\nAudit strings...\");\n\t\tconsole.log(\"TODO\");\n\t\t/**\n\t\t * TODO audit strings\n\t\t *\n\t\t * Skips string audit where it tries to find possible mistakes in translatable strings. Useful when running in an automated environment.\n\t\t *\n\t\t **/\n\t\tconsole.log(\"\u2705 Done\");\n\t}\n\n\t/** The pot file header contains the data about the plugin or theme */\n\tconst potHeader = await generateHeader(args);\n\n\t/** We need to find the main file data so that the definitions are extracted from the plugin or theme files */\n\tlet translationsUnion = translationsHeaders(args);\n\n\tif (!args.options?.silent)\n\t\toutputPathRecap(path.resolve(args.paths.cwd), args.patterns);\n\n\t/**\n\t * The progress bar that is used to show the progress of the extraction process.\n\t */\n\tconst progressBar: SingleBar = initProgress(args, 0);\n\n\tprogressBar.start(3, 1, {\n\t\tfilename: `Resolving files in ${path.resolve(args.paths.cwd)}`,\n\t});\n\n\t/**\n\t * Extract the strings from the files\n\t */\n\tconst patterns = getPatterns(args);\n\tconst files = await processFiles(patterns, args);\n\n\tprogressBar.update(2, {\n\t\tfilename: `Found ${files.length} files`,\n\t});\n\n\ttranslationsUnion = await taskRunner(\n\t\tfiles,\n\t\ttranslationsUnion,\n\t\targs,\n\t\tprogressBar,\n\t);\n\n\tif (args.options?.json) {\n\t\t// generate the json file\n\t\tconst jedData: {\n\t\t\t[p: string]: { [p: string]: [string, string] };\n\t\t} = {\n\t\t\t[args.slug]: {\n\t\t\t\t\"\": potHeader,\n\t\t\t\t...(translationsUnion.toJson() as { [p: string]: [string, string] }),\n\t\t\t},\n\t\t};\n\t\tconst i18n = new Tannin(jedData);\n\n\t\treturn i18n.toString();\n\t}\n\n\t// generate the pot file json\n\tconst getTextTranslations: GetTextTranslations = {\n\t\tcharset: getEncodingCharset(args.options?.charset),\n\t\theaders: potHeader as { [headerName: string]: string },\n\t\ttranslations: translationsUnion.toJson(),\n\t};\n\n\t// And then compile the pot file to a string\n\tconst pluginTranslations = po\n\t\t.compile(getTextTranslations)\n\t\t.toString(getCharset(args.options?.charset));\n\n\t// return the pot file as a string, prefixed with the header\n\tconst copyrightComment =\n\t\targs.options?.fileComment ||\n\t\tgetCopyright(\n\t\t\targs.slug,\n\t\t\t(args.headers?.license as string) ?? \"GPL v2 or later\",\n\t\t);\n\treturn `${copyrightComment}\\n${pluginTranslations}`;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AAEjB,4BAA6C;AAC7C,oBAAmB;AACnB,qBAAoD;AACpD,gBAA+C;AAE/C,oBAAyC;AACzC,sBAA4B;AAC5B,qBAA6B;AAC7B,sBAA6B;AAC7B,wBAA2B;AAS3B,SAAS,gBAAgB,KAAa,UAA4B;AACjE,SAAO;AAAA,eAAkB,GAAG;AAAA,MAAS,SAAS,QAAQ,KAAK,CAAC;AAAA,qBAAwB,SAAS,QAAQ,KAAK,CAAC;AAAA;AAC5G;AAQA,eAAsB,KAAK,MAA6B;AACvD,MAAI,CAAC,KAAK,SAAS,QAAQ;AAC1B,YAAQ,IAAI,kCAA2B,MAAM,IAAI;AACjD,kCAAW;AAAA,EACZ;AAGA,MAAI,KAAK,SAAS,KAAK,OAAO;AAC7B,YAAQ,IAAI,oBAAoB;AAChC,YAAQ,IAAI,MAAM;AAOlB,YAAQ,IAAI,aAAQ;AAAA,EACrB;AAGA,QAAM,YAAY,UAAM,+BAAe,IAAI;AAG3C,MAAI,wBAAoB,oCAAoB,IAAI;AAEhD,MAAI,CAAC,KAAK,SAAS;AAClB,oBAAgB,iBAAAA,QAAK,QAAQ,KAAK,MAAM,GAAG,GAAG,KAAK,QAAQ;AAK5D,QAAM,kBAAyB,8BAAa,MAAM,CAAC;AAEnD,cAAY,MAAM,GAAG,GAAG;AAAA,IACvB,UAAU,sBAAsB,iBAAAA,QAAK,QAAQ,KAAK,MAAM,GAAG,CAAC;AAAA,EAC7D,CAAC;AAKD,QAAM,eAAW,6BAAY,IAAI;AACjC,QAAM,QAAQ,UAAM,6BAAa,UAAU,IAAI;AAE/C,cAAY,OAAO,GAAG;AAAA,IACrB,UAAU,SAAS,MAAM,MAAM;AAAA,EAChC,CAAC;AAED,sBAAoB,UAAM;AAAA,IACzB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAEA,MAAI,KAAK,SAAS,MAAM;AAEvB,UAAM,UAEF;AAAA,MACH,CAAC,KAAK,IAAI,GAAG;AAAA,QACZ,IAAI;AAAA,QACJ,GAAI,kBAAkB,OAAO;AAAA,MAC9B;AAAA,IACD;AACA,UAAM,OAAO,IAAI,cAAAC,QAAO,OAAO;AAE/B,WAAO,KAAK,SAAS;AAAA,EACtB;AAGA,QAAM,sBAA2C;AAAA,IAChD,aAAS,8BAAmB,KAAK,SAAS,OAAO;AAAA,IACjD,SAAS;AAAA,IACT,cAAc,kBAAkB,OAAO;AAAA,EACxC;AAGA,QAAM,qBAAqB,yBACzB,QAAQ,mBAAmB,EAC3B,aAAS,sBAAW,KAAK,SAAS,OAAO,CAAC;AAG5C,QAAM,mBACL,KAAK,SAAS,mBACd;AAAA,IACC,KAAK;AAAA,IACJ,KAAK,SAAS,WAAsB;AAAA,EACtC;AACD,SAAO,GAAG,gBAAgB;AAAA,EAAK,kBAAkB;AAClD;",
6
- "names": ["path", "Tannin"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/parser/makeJson.ts"],
4
- "sourcesContent": ["import crypto from \"node:crypto\";\nimport * as fs from \"node:fs\";\nimport path from \"node:path\";\nimport {\n\ttype GetTextTranslation,\n\ttype GetTextTranslations,\n\tpo,\n} from \"gettext-parser\";\nimport { glob } from \"glob\";\nimport { IsoCodeRegex, modulePath } from \"../const.js\";\nimport type { JedData, MakeJson, MakeJsonArgs } from \"../types.js\";\nimport { getPkgJsonData } from \"../utils/common.js\";\n\nexport class MakeJsonCommand {\n\t/**\n\t * The source file path.\n\t * Should be the \"build\" directory containing .js files\n\t * @private\n\t */\n\tprivate readonly source: string;\n\t/**\n\t * The destination file path.\n\t * Should be the \"languages\" directory containing .po files\n\t * @private\n\t */\n\tprivate readonly destination: string;\n\t/**\n\t * The allowed file extensions.\n\t * @private\n\t */\n\tprivate readonly allowedFormats: string[];\n\t/**\n\t * Remove old POT files.\n\t * @private\n\t */\n\tprivate readonly purge: boolean;\n\t/**\n\t * Pretty print JSON.\n\t * @private\n\t */\n\tprivate readonly prettyPrint: boolean;\n\t/**\n\t * Enable debug mode.\n\t * @private\n\t */\n\tprivate debug: boolean;\n\t/**\n\t * The script to be translated.\n\t * @private\n\t */\n\tprivate scriptName: string | string[] | undefined;\n\t/**\n\t * The paths to be translated.\n\t * @private\n\t */\n\tprivate paths: object | undefined;\n\t/**\n\t * The source directory.\n\t * @private\n\t */\n\tprivate readonly sourceDir: string;\n\n\t/**\n\t * The constructor.\n\t * @param args - The arguments to the command.\n\t */\n\tpublic constructor(args: MakeJsonArgs) {\n\t\tthis.sourceDir = path.relative(args.paths.cwd, args.source ?? \"\");\n\t\tif (!fs.existsSync(this.sourceDir)) {\n\t\t\tconsole.error(\"Source directory not found\", args);\n\t\t\tthrow new Error(`Source directory ${this.sourceDir} not found`);\n\t\t}\n\n\t\tthis.scriptName = args.scriptName;\n\t\tthis.source = args.source;\n\t\tthis.destination = args.destination;\n\t\tthis.allowedFormats = args.allowedFormats ?? [\n\t\t\t\".ts\",\n\t\t\t\".tsx\",\n\t\t\t\".js\",\n\t\t\t\".jsx\",\n\t\t\t\".mjs\",\n\t\t\t\".cjs\",\n\t\t];\n\t\tthis.purge = args.purge;\n\t\tthis.prettyPrint = args.prettyPrint;\n\t\tthis.debug = args.debug;\n\t\tthis.paths = args.paths;\n\t}\n\n\t/**\n\t * The main function. Parses the PO files and generates the JSON files.\n\t */\n\tpublic async exec(): Promise<Record<string, MakeJson>> {\n\t\t// get all the files in the source directory\n\t\tconst files = await glob(\"**/*.po\", { cwd: this.destination, nodir: true });\n\n\t\tconsole.log(\"Found po files\", files, \"in\", this.destination, \"folder\");\n\n\t\t// get all the po files\n\t\tconst output: Record<string, MakeJson> = {};\n\t\tfor (const file of files) {\n\t\t\tif (!this.scriptName) {\n\t\t\t\tthis.scriptName = await glob(\"*.js\", {\n\t\t\t\t\tcwd: this.source,\n\t\t\t\t\tnodir: true,\n\t\t\t\t});\n\t\t\t\tconsole.log(\n\t\t\t\t\t`Found script: ${this.scriptName} in ${this.source} folder`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// TODO: tree the script to get the translations used in there, then use reduce to filter the translations\n\n\t\t\tif (typeof this.scriptName === \"string\") {\n\t\t\t\tconst pot = this.addPot(file, this.scriptName);\n\t\t\t\toutput[pot.filename] = pot.data;\n\t\t\t} else if (Array.isArray(this.scriptName)) {\n\t\t\t\tfor (const script of this.scriptName) {\n\t\t\t\t\tconst pot = this.addPot(file, script);\n\t\t\t\t\toutput[pot.filename] = pot.data;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// write the json files\n\t\tfor (const [filename, content] of Object.entries(output)) {\n\t\t\tlet contentString: string;\n\t\t\tif (this.purge) {\n\t\t\t\tif (fs.existsSync(path.join(this.destination, filename))) {\n\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t`Removing ${path.join(this.destination, filename)} as the purge option is enabled`,\n\t\t\t\t\t);\n\t\t\t\t\tfs.unlinkSync(path.join(this.destination, filename));\n\t\t\t\t}\n\t\t\t\tcontentString = JSON.stringify(\n\t\t\t\t\tcontent,\n\t\t\t\t\tnull,\n\t\t\t\t\tthis?.prettyPrint ? 2 : 0,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tconst oldJedContent = fs.readFileSync(\n\t\t\t\t\tpath.join(this.source, filename),\n\t\t\t\t\t\"utf8\",\n\t\t\t\t);\n\n\t\t\t\tcontentString = JSON.stringify(\n\t\t\t\t\t{ ...content, ...JSON.parse(oldJedContent) },\n\t\t\t\t\tnull,\n\t\t\t\t\tthis?.prettyPrint ? 2 : 0,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst destinationPath = path.join(this.destination, filename);\n\t\t\tfs.writeFileSync(destinationPath, contentString);\n\t\t\tconsole.log(`JSON file written to ${destinationPath}`);\n\t\t}\n\n\t\t// return the output\n\t\treturn output;\n\t}\n\n\t/**\n\t * Process a PO file and return the JSON data.\n\t * @param file - The path to the PO file.\n\t * @param script - The script to be translated.\n\t * @param encoding - The encoding of the PO file.\n\t */\n\tpublic processFile(\n\t\tfile: string,\n\t\tscript: string,\n\t\tencoding: BufferEncoding = \"utf8\",\n\t): MakeJson {\n\t\t// Get the file path\n\t\tconst filePath = path.join(this.destination, file);\n\n\t\t// Read the source file\n\t\tconst content = fs.readFileSync(filePath, encoding) as string;\n\n\t\t// Extract the ISO code\n\t\tconst languageIsoCode = this.extractIsoCode(filePath);\n\n\t\t// Parse the source file\n\t\tconst poContent = this.parsePoFile(content);\n\n\t\t// Convert to Jed json dataset\n\t\treturn this.convertToJed(\n\t\t\tpoContent.headers,\n\t\t\tpoContent.translations,\n\t\t\tscript,\n\t\t\tlanguageIsoCode,\n\t\t);\n\t}\n\n\t/**\n\t * Takes a PO file and returns the header and translations.\n\t * @param content - The content of the PO file.\n\t * @private\n\t *\n\t * @returns An object containing the header and translations.\n\t */\n\tprivate parsePoFile(content: string): GetTextTranslations {\n\t\treturn po.parse(content);\n\t}\n\n\t/**\n\t * Converts PO data to Jed data.\n\t * @param header - The header of the PO file.\n\t * @param translations - The translations of the PO file.\n\t * @param source - The source of the PO file.\n\t * @param languageIsoCode - The ISO code of the language.\n\t * @private\n\t *\n\t * @return An object containing the Jed data.\n\t */\n\tprivate convertToJed(\n\t\theader: Record<string, string>,\n\t\ttranslations: {\n\t\t\t[msgctxt: string]: { [msgId: string]: GetTextTranslation };\n\t\t},\n\t\tsource: string,\n\t\tlanguageIsoCode?: string,\n\t): MakeJson {\n\t\tconst packageJson = getPkgJsonData(modulePath, \"name\", \"version\") as {\n\t\t\tname: string;\n\t\t\tversion: string;\n\t\t};\n\n\t\t// Domain name to use for the Jed format\n\t\tconst domain = \"messages\";\n\n\t\tconst generator = `${packageJson.name}/${packageJson.version}`;\n\n\t\t// Initialize the Jed-compatible structure\n\t\tconst jedData: JedData = {\n\t\t\t[domain]: {\n\t\t\t\t\"\": {\n\t\t\t\t\tdomain: domain,\n\t\t\t\t\tlang: languageIsoCode || header.Language || \"en\",\n\t\t\t\t\tplural_forms:\n\t\t\t\t\t\theader[\"Plural-Forms\"] || \"nplurals=2; plural=(n != 1);\",\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\n\t\t// Process all translations\n\t\tfor (const msgctxt of Object.keys(translations)) {\n\t\t\tconst contextTranslations = translations[msgctxt];\n\n\t\t\tfor (const msgid of Object.keys(contextTranslations)) {\n\t\t\t\tconst translation = contextTranslations[msgid];\n\n\t\t\t\t// Skip empty msgid (header) as we've already handled it\n\t\t\t\tif (msgid === \"\") continue;\n\n\t\t\t\t// Construct the key using context if available\n\t\t\t\tconst key =\n\t\t\t\t\tmsgctxt && msgctxt !== \"\" ? `${msgctxt}\\u0004${msgid}` : msgid;\n\n\t\t\t\t// Add the translation to the Jed data structure\n\t\t\t\tjedData[domain][key] = translation.msgstr;\n\t\t\t}\n\t\t}\n\n\t\tconst makeJson: {\n\t\t\tdomain: string;\n\t\t\tgenerator: string;\n\t\t\t\"translation-revision-date\": string;\n\t\t\tsource: string;\n\t\t\tlocale_data: JedData;\n\t\t} = {\n\t\t\t\"translation-revision-date\": new Date().toISOString(),\n\t\t\tgenerator: generator,\n\t\t\tsource: path.join(this.sourceDir, source).replace(/\\\\/g, \"/\"),\n\t\t\tdomain,\n\t\t\tlocale_data: jedData,\n\t\t};\n\n\t\treturn makeJson as MakeJson;\n\t}\n\n\t/**\n\t * Gets the ISO code from the filename.\n\t * @param filename The filename to extract the ISO code from.\n\t * @private\n\t *\n\t * @returns The ISO code if found, otherwise null.\n\t */\n\tprivate extractIsoCode(filename: string): string | undefined {\n\t\tconst match = filename.match(IsoCodeRegex);\n\t\treturn match ? match[1] : undefined;\n\t}\n\n\tprivate md5(text: string): string {\n\t\treturn crypto.createHash(\"md5\").update(text).digest(\"hex\");\n\t}\n\n\tprivate generateFilename(script: string, file: string): string {\n\t\tconst scriptName = this.md5(script);\n\t\t//build the filename for the json file using the po files\n\t\treturn file.replace(\".po\", `-${scriptName}.json`);\n\t}\n\n\t/**\n\t * Adds a script to the output object.\n\t * @private\n\t *\n\t * @param potFile - The pot file to parse.\n\t * @param script - The script to add.\n\t * @return {Record<string, JedData>} - The output object.\n\t * */\n\tprivate addPot(\n\t\tpotFile: string,\n\t\tscript: string,\n\t): { filename: string; data: MakeJson } {\n\t\tconst filename = this.generateFilename(\n\t\t\tpath.join(this.source, script).replace(/\\\\/g, \"/\"),\n\t\t\tpotFile,\n\t\t);\n\t\t// build the output object\n\t\treturn {\n\t\t\tfilename,\n\t\t\tdata: this.processFile(potFile, script),\n\t\t};\n\t}\n}\n\nexport default MakeJsonCommand;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAmB;AACnB,SAAoB;AACpB,uBAAiB;AACjB,4BAIO;AACP,kBAAqB;AACrB,mBAAyC;AAEzC,oBAA+B;AAExB,MAAM,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMX;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKT;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAA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AQ,SAAS,MAAM,yBAAY;AACzC,WAAO,QAAQ,MAAM,CAAC,IAAI;AAAA,EAC3B;AAAA,EAEQ,IAAI,MAAsB;AACjC,WAAO,mBAAAC,QAAO,WAAW,KAAK,EAAE,OAAO,IAAI,EAAE,OAAO,KAAK;AAAA,EAC1D;AAAA,EAEQ,iBAAiB,QAAgB,MAAsB;AAC9D,UAAM,aAAa,KAAK,IAAI,MAAM;AAElC,WAAO,KAAK,QAAQ,OAAO,IAAI,UAAU,OAAO;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUQ,OACP,SACA,QACuC;AACvC,UAAM,WAAW,KAAK;AAAA,MACrB,iBAAAD,QAAK,KAAK,KAAK,QAAQ,MAAM,EAAE,QAAQ,OAAO,GAAG;AAAA,MACjD;AAAA,IACD;AAEA,WAAO;AAAA,MACN;AAAA,MACA,MAAM,KAAK,YAAY,SAAS,MAAM;AAAA,IACvC;AAAA,EACD;AACD;AAEA,IAAO,mBAAQ;",
6
- "names": ["path", "crypto"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/parser/makePot.ts"],
4
- "sourcesContent": ["import { extractMainFileData } from \"../extractors/headers.js\";\nimport { extractPackageJson } from \"../extractors/packageJson.js\";\nimport { writeFile } from \"../fs/fs.js\";\nimport type { Args } from \"../types.js\";\nimport { exec } from \"./exec.js\";\n\n/**\n * Generates a pot file for localization.\n *\n * @param args - the command line arguments\n * @return {string} - a promise that resolves when the pot file is generated\n */\nexport async function makePot(args: Args): Promise<string> {\n\t/** Collect metadata from the get package json */\n\tconst pkgData = extractPackageJson(args);\n\n\t/** Get metadata from the main file (theme and plugin) */\n\tconst metadata = extractMainFileData(args);\n\n\t/** Merge the metadata to get a single object with all the headers */\n\targs.headers = {\n\t\t...args.headers,\n\t\t...pkgData,\n\t\t...metadata,\n\t} as Args[\"headers\"];\n\n\t/** Generate the pot file */\n\treturn await exec(args)\n\t\t.then((jsonTranslations) => {\n\t\t\twriteFile(jsonTranslations, args);\n\n\t\t\treturn jsonTranslations;\n\t\t})\n\t\t.catch((error) => {\n\t\t\tconsole.error(error);\n\n\t\t\treturn \"\";\n\t\t});\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAoC;AACpC,yBAAmC;AACnC,gBAA0B;AAE1B,kBAAqB;AAQrB,eAAsB,QAAQ,MAA6B;AAE1D,QAAM,cAAU,uCAAmB,IAAI;AAGvC,QAAM,eAAW,oCAAoB,IAAI;AAGzC,OAAK,UAAU;AAAA,IACd,GAAG,KAAK;AAAA,IACR,GAAG;AAAA,IACH,GAAG;AAAA,EACJ;AAGA,SAAO,UAAM,kBAAK,IAAI,EACpB,KAAK,CAAC,qBAAqB;AAC3B,6BAAU,kBAAkB,IAAI;AAEhC,WAAO;AAAA,EACR,CAAC,EACA,MAAM,CAAC,UAAU;AACjB,YAAQ,MAAM,KAAK;AAEnB,WAAO;AAAA,EACR,CAAC;AACH;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/parser/patterns.ts"],
4
- "sourcesContent": ["import type { Args, Patterns } from \"../types.js\";\n\n/**\n * Returns the patterns based on the given arguments.\n *\n * @param args - The arguments for the extract process.\n */\nexport function getPatterns(args: Args) {\n\tconst pattern = {\n\t\tinclude: args.patterns.include || [],\n\t\texclude: args.patterns.exclude || [],\n\t\tmergePaths: args.patterns.mergePaths,\n\t\tsubtractPaths: args.patterns.subtractPaths,\n\t\tsubtractAndMerge: args.patterns.subtractAndMerge,\n\t} as Patterns;\n\n\t// Additional logic to handle different file types and formats\n\tif (args.options) {\n\t\t// js typescript mjs cjs etc\n\t\tif (args.options.skip.blade) {\n\t\t\tpattern.exclude.push(\"**/blade.php\");\n\t\t} else if (args.options.skip.php) {\n\t\t\tpattern.exclude.push(\"**/*.php\", \"**/*.blade.php\");\n\t\t}\n\n\t\t// js typescript mjs cjs etc\n\t\tif (args.options.skip.js) {\n\t\t\tpattern.exclude.push(\"**/*.{js,jsx,ts,tsx,mjs,cjs}\");\n\t\t}\n\n\t\tif (args.options.skip.blockJson) {\n\t\t\tpattern.exclude.push(\"block.json\");\n\t\t}\n\n\t\tif (args.options.skip.themeJson) {\n\t\t\tpattern.exclude.push(\"theme.json\");\n\t\t}\n\t}\n\n\treturn pattern;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOO,SAAS,YAAY,MAAY;AACvC,QAAM,UAAU;AAAA,IACf,SAAS,KAAK,SAAS,WAAW,CAAC;AAAA,IACnC,SAAS,KAAK,SAAS,WAAW,CAAC;AAAA,IACnC,YAAY,KAAK,SAAS;AAAA,IAC1B,eAAe,KAAK,SAAS;AAAA,IAC7B,kBAAkB,KAAK,SAAS;AAAA,EACjC;AAGA,MAAI,KAAK,SAAS;AAEjB,QAAI,KAAK,QAAQ,KAAK,OAAO;AAC5B,cAAQ,QAAQ,KAAK,cAAc;AAAA,IACpC,WAAW,KAAK,QAAQ,KAAK,KAAK;AACjC,cAAQ,QAAQ,KAAK,YAAY,gBAAgB;AAAA,IAClD;AAGA,QAAI,KAAK,QAAQ,KAAK,IAAI;AACzB,cAAQ,QAAQ,KAAK,8BAA8B;AAAA,IACpD;AAEA,QAAI,KAAK,QAAQ,KAAK,WAAW;AAChC,cAAQ,QAAQ,KAAK,YAAY;AAAA,IAClC;AAEA,QAAI,KAAK,QAAQ,KAAK,WAAW;AAChC,cAAQ,QAAQ,KAAK,YAAY;AAAA,IAClC;AAAA,EACD;AAEA,SAAO;AACR;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/parser/process.ts"],
4
- "sourcesContent": ["import path from \"node:path\";\nimport type { SingleBar } from \"cli-progress\";\nimport type { SetOfBlocks } from \"gettext-merger\";\nimport { allowedFormats } from \"../const.js\";\nimport { parseJsonCallback } from \"../extractors/json.js\";\nimport { readFileAsync } from \"../fs/fs.js\";\nimport { getFiles } from \"../fs/glob.js\";\nimport type { Args, Patterns } from \"../types.js\";\nimport { doTree } from \"./tree.js\";\n\n/**\n * Processes the given files and returns an array of promises that resolve to TranslationStrings.\n *\n * @param patterns\n * @param {Args} args - The arguments for processing the files.\n * @param progressBar - The progress bar element.\n * @return {Promise<SetOfBlocks[]>} - An array of promises that resolve to TranslationStrings.\n */\nexport async function processFiles(\n\tpatterns: Patterns,\n\targs: Args,\n\tprogressBar?: SingleBar,\n): Promise<Promise<SetOfBlocks>[]> {\n\tconst tasks: Promise<SetOfBlocks>[] = [];\n\tlet filesCount = 0;\n\n\tconst files = getFiles(args, patterns);\n\n\t// loop through the files and parse them\n\tfor await (const file of files) {\n\t\tfilesCount++;\n\t\tconst filename = path.basename(file);\n\t\tconst ext = path.extname(file).replace(/^./, \"\");\n\t\tconst fileRealPath = path.resolve(args.paths.cwd, file);\n\n\t\tif (filename === \"theme.json\" || filename === \"block.json\") {\n\t\t\ttasks.push(\n\t\t\t\treadFileAsync(fileRealPath).then((sourceCode) =>\n\t\t\t\t\tparseJsonCallback(sourceCode, args.paths.cwd, filename),\n\t\t\t\t),\n\t\t\t);\n\t\t} else if (allowedFormats.includes(ext)) {\n\t\t\ttasks.push(\n\t\t\t\treadFileAsync(fileRealPath).then((content) => doTree(content, file)),\n\t\t\t);\n\t\t}\n\n\t\tif (progressBar) {\n\t\t\tprogressBar.update(filesCount, { filename: filename });\n\t\t\tprogressBar.setTotal(Object.values(files).length);\n\t\t\tprogressBar.render();\n\t\t}\n\t}\n\n\treturn tasks;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAiB;AAGjB,mBAA+B;AAC/B,kBAAkC;AAClC,gBAA8B;AAC9B,kBAAyB;AAEzB,kBAAuB;AAUvB,eAAsB,aACrB,UACA,MACA,aACkC;AAClC,QAAM,QAAgC,CAAC;AACvC,MAAI,aAAa;AAEjB,QAAM,YAAQ,sBAAS,MAAM,QAAQ;AAGrC,mBAAiB,QAAQ,OAAO;AAC/B;AACA,UAAM,WAAW,iBAAAA,QAAK,SAAS,IAAI;AACnC,UAAM,MAAM,iBAAAA,QAAK,QAAQ,IAAI,EAAE,QAAQ,MAAM,EAAE;AAC/C,UAAM,eAAe,iBAAAA,QAAK,QAAQ,KAAK,MAAM,KAAK,IAAI;AAEtD,QAAI,aAAa,gBAAgB,aAAa,cAAc;AAC3D,YAAM;AAAA,YACL,yBAAc,YAAY,EAAE;AAAA,UAAK,CAAC,mBACjC,+BAAkB,YAAY,KAAK,MAAM,KAAK,QAAQ;AAAA,QACvD;AAAA,MACD;AAAA,IACD,WAAW,4BAAe,SAAS,GAAG,GAAG;AACxC,YAAM;AAAA,YACL,yBAAc,YAAY,EAAE,KAAK,CAAC,gBAAY,oBAAO,SAAS,IAAI,CAAC;AAAA,MACpE;AAAA,IACD;AAEA,QAAI,aAAa;AAChB,kBAAY,OAAO,YAAY,EAAE,SAAmB,CAAC;AACrD,kBAAY,SAAS,OAAO,OAAO,KAAK,EAAE,MAAM;AAChD,kBAAY,OAAO;AAAA,IACpB;AAAA,EACD;AAEA,SAAO;AACR;",
6
- "names": ["path"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/parser/progress.ts"],
4
- "sourcesContent": ["import cliProgress, { type SingleBar } from \"cli-progress\";\nimport type { Args } from \"../types.js\";\n\n/**\n * Initializes a progress bar and returns the progress bar element.\n *\n * @param {Args} args - The argument object containing the source directory and other options.\n * @param {number} filesCount - An array of file names.\n * @return {cliProgress.SingleBar} The progress bar element.\n */\nexport function initProgress(args: Args, filesCount: number): SingleBar {\n\t// Set up the progress bar\n\treturn new cliProgress.SingleBar(\n\t\t{\n\t\t\tclearOnComplete: true,\n\t\t\tetaBuffer: 1000,\n\t\t\thideCursor: true,\n\t\t\tformat:\n\t\t\t\t\" {bar} {percentage}% | ETA: {eta}s | {filename} | {value}/{total}\",\n\t\t},\n\t\tcliProgress.Presets.shades_classic,\n\t);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA4C;AAUrC,SAAS,aAAa,MAAY,YAA+B;AAEvE,SAAO,IAAI,oBAAAA,QAAY;AAAA,IACtB;AAAA,MACC,iBAAiB;AAAA,MACjB,WAAW;AAAA,MACX,YAAY;AAAA,MACZ,QACC;AAAA,IACF;AAAA,IACA,oBAAAA,QAAY,QAAQ;AAAA,EACrB;AACD;",
6
- "names": ["cliProgress"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/parser/taskRunner.ts"],
4
- "sourcesContent": ["import * as os from \"node:os\";\nimport path from \"node:path\";\nimport type { SingleBar } from \"cli-progress\";\nimport type { SetOfBlocks } from \"gettext-merger\";\nimport type { Args } from \"../types.js\";\n\n/**\n * Task runner for the extraction process.\n *\n * @param tasks - The tasks to run\n * @param destination - The destination\n * @param args - The command line arguments\n * @param progressBar\n */\nexport async function taskRunner(\n\ttasks: Promise<SetOfBlocks>[],\n\tdestination: SetOfBlocks,\n\targs: Args,\n\tprogressBar: SingleBar,\n) {\n\tconst messages = [];\n\tawait Promise.allSettled(tasks)\n\t\t.then((strings) => {\n\t\t\t/**\n\t\t\t * Return the strings that are not rejected (they are fulfilled)\n\t\t\t */\n\t\t\treturn strings\n\t\t\t\t.map((block) => block.status === \"fulfilled\" && block.value)\n\t\t\t\t.filter(Boolean) as SetOfBlocks[]; // remove nullish\n\t\t})\n\t\t.then((consolidated) => {\n\t\t\t/** Log the results */\n\t\t\tif (args.options?.silent !== true) {\n\t\t\t\tfor (const result of consolidated) {\n\t\t\t\t\tif (result.blocks.length > 0) {\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * Add the strings to the destination set\n\t\t\t\t\t\t */\n\t\t\t\t\t\tdestination.addArray(result.blocks);\n\t\t\t\t\t\t/* Log the results */\n\t\t\t\t\t\tmessages.push(\n\t\t\t\t\t\t\t`\u2705 ${result.path} [${result.blocks.map((b) => b.msgid).join(\", \")}]`,\n\t\t\t\t\t\t);\n\t\t\t\t\t} else messages.push(`\u274C ${result.path} has no strings`);\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t\t.catch((err) => {\n\t\t\treturn new Error(err);\n\t\t});\n\n\tprogressBar.stop();\n\n\tconsole.log(\"\\n\uD83C\uDF89 Done!\");\n\tconsole.log(\n\t\t`\uD83D\uDCDD Found ${Object.values(destination.blocks).length} translation strings in ${path.resolve(args.paths.cwd)}.`,\n\t);\n\n\tconsole.log(messages.join(os.EOL));\n\n\treturn destination;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAoB;AACpB,uBAAiB;AAajB,eAAsB,WACrB,OACA,aACA,MACA,aACC;AACD,QAAM,WAAW,CAAC;AAClB,QAAM,QAAQ,WAAW,KAAK,EAC5B,KAAK,CAAC,YAAY;AAIlB,WAAO,QACL,IAAI,CAAC,UAAU,MAAM,WAAW,eAAe,MAAM,KAAK,EAC1D,OAAO,OAAO;AAAA,EACjB,CAAC,EACA,KAAK,CAAC,iBAAiB;AAEvB,QAAI,KAAK,SAAS,WAAW,MAAM;AAClC,iBAAW,UAAU,cAAc;AAClC,YAAI,OAAO,OAAO,SAAS,GAAG;AAI7B,sBAAY,SAAS,OAAO,MAAM;AAElC,mBAAS;AAAA,YACR,UAAK,OAAO,IAAI,KAAK,OAAO,OAAO,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,IAAI,CAAC;AAAA,UAClE;AAAA,QACD,MAAO,UAAS,KAAK,UAAK,OAAO,IAAI,iBAAiB;AAAA,MACvD;AAAA,IACD;AAAA,EACD,CAAC,EACA,MAAM,CAAC,QAAQ;AACf,WAAO,IAAI,MAAM,GAAG;AAAA,EACrB,CAAC;AAEF,cAAY,KAAK;AAEjB,UAAQ,IAAI,mBAAY;AACxB,UAAQ;AAAA,IACP,mBAAY,OAAO,OAAO,YAAY,MAAM,EAAE,MAAM,2BAA2B,iBAAAA,QAAK,QAAQ,KAAK,MAAM,GAAG,CAAC;AAAA,EAC5G;AAEA,UAAQ,IAAI,SAAS,KAAK,GAAG,GAAG,CAAC;AAEjC,SAAO;AACR;",
6
- "names": ["path"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/parser/tree.ts"],
4
- "sourcesContent": ["import Parser, { type SyntaxNode } from \"tree-sitter\";\nimport { i18nFunctions } from \"../const.js\";\n\nimport { Block, SetOfBlocks } from \"gettext-merger\";\nimport { getParser } from \"../fs/glob.js\";\nimport { reverseSlashes, stripTranslationMarkup } from \"../utils/common.js\";\n\n/**\n * Collect comments from the AST node and its preceding siblings.\n *\n * @param {SyntaxNode} node - The AST node.\n * @return {string[]} An array of collected comments.\n */\nfunction collectComments(node: SyntaxNode): string | undefined {\n\tlet currentNode = node;\n\tlet depth = 0;\n\n\t// Check the node's preceding siblings for comments\n\twhile (currentNode && depth < 6) {\n\t\tif (\n\t\t\tcurrentNode?.previousSibling?.type === \"comment\" &&\n\t\t\tcurrentNode?.previousSibling?.text.toLowerCase().includes(\"translators\")\n\t\t) {\n\t\t\treturn currentNode?.previousSibling?.text\n\t\t\t\t? stripTranslationMarkup(currentNode.previousSibling.text)\n\t\t\t\t: undefined;\n\t\t}\n\t\tdepth++;\n\t\tcurrentNode = currentNode.parent as SyntaxNode;\n\t}\n}\n\n/**\n * Parses the source code using the specified language parser and extracts the strings from the file.\n *\n * @param {string} sourceCode - The source code to be parsed.\n * @param {string} filepath - The path to the file being parsed.\n * @return {SetOfBlocks} An array of translation strings.\n */\nexport function doTree(sourceCode: string, filepath: string): SetOfBlocks {\n\t// set up the parser\n\tconst parser = new Parser();\n\tconst parserExt = getParser(filepath);\n\t// if no parser is found return empty\n\tif (!parserExt) return new SetOfBlocks([], filepath);\n\t// set the parser language\n\tparser.setLanguage(parserExt);\n\n\t// parse the file\n\tconst tree = parser.parse(sourceCode);\n\n\t// set up the translation object\n\tconst gettextTranslations: SetOfBlocks = new SetOfBlocks([], filepath);\n\n\tconst typeToMatch =\n\t\tfilepath.split(\".\").pop()?.toLowerCase() !== \"php\"\n\t\t\t? \"call_expression\"\n\t\t\t: \"function_call_expression\";\n\n\tconst stringType = [\n\t\t\"name\",\n\t\t\"string\",\n\t\t\"string_value\",\n\t\t\"variable_name\",\n\t\t\"binary_expression\",\n\t\t\"member_expression\",\n\t\t\"subscript_expression\",\n\t\t\"shell_command_expression\",\n\t\t\"function_call_expression\",\n\t\t\"encapsed_string\",\n\t];\n\n\t/**\n\t * Traverse the tree \uD83C\uDF33\n\t *\n\t * @param {SyntaxNode} node The node to traverse through\n\t */\n\tfunction traverse(node: SyntaxNode): void {\n\t\t// Walk the tree\n\t\tif (node?.children.length)\n\t\t\tfor (const child of node.children) {\n\t\t\t\ttraverse(child);\n\t\t\t}\n\n\t\t// Check if the node matches\n\t\tif (node?.type === typeToMatch) {\n\t\t\t// The function name is the first child\n\t\t\tconst functionName = node.firstChild?.text ?? null;\n\t\t\tif (\n\t\t\t\tfunctionName === null ||\n\t\t\t\t!Object.keys(i18nFunctions).includes(functionName)\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// The arguments are the last child\n\t\t\tconst argsNode = node.lastChild;\n\t\t\tif (\n\t\t\t\targsNode === null ||\n\t\t\t\targsNode.childCount === 0 ||\n\t\t\t\targsNode.type !== \"arguments\"\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Get the whole gettext translation string\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\t\tconst [_fn, raw] = node.children;\n\t\t\tconst translation: Partial<{\n\t\t\t\tmsgctxt: string;\n\t\t\t\tmsgid: string;\n\t\t\t\tmsgid_plural: string;\n\t\t\t\tmsgstr: string;\n\t\t\t}> = {};\n\n\t\t\tconst translationKeys =\n\t\t\t\ti18nFunctions[functionName as keyof typeof i18nFunctions];\n\n\t\t\tconst children = raw.children.slice(1, -1);\n\t\t\tlet translationKeyIndex = 0;\n\n\t\t\t// Get the translation from the arguments (the quoted strings)\n\t\t\tfor (const child of children) {\n\t\t\t\tlet node = child;\n\t\t\t\tlet nodeValue: string | string[] = node.text;\n\n\t\t\t\t// unwrap the argument node, which is used in PHP.\n\t\t\t\tif (child.type === \"argument\") {\n\t\t\t\t\tif (child.children.length === 0) continue;\n\t\t\t\t\tnode = child.children[0];\n\t\t\t\t}\n\n\t\t\t\tif (node?.type === \",\") {\n\t\t\t\t\t// skip the comma between arguments\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (node?.type && stringType.includes(node.type)) {\n\t\t\t\t\t// unquote the strings\n\t\t\t\t\tnodeValue = nodeValue.slice(1, -1);\n\t\t\t\t} else {\n\t\t\t\t\t// unexpected node type this string is not translatable and should be skipped\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`Unexpected node type: ${node?.type} is ${translationKeys[translationKeyIndex]} for ${nodeValue} in ${filepath}`,\n\t\t\t\t\t);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// the translation key (eg. msgid)\n\t\t\t\tconst currentKey = translationKeys[\n\t\t\t\t\ttranslationKeyIndex\n\t\t\t\t] as keyof typeof translation;\n\n\t\t\t\t// the value of that key\n\t\t\t\ttranslation[currentKey] = nodeValue;\n\n\t\t\t\t// increment the index of the translation key\n\t\t\t\ttranslationKeyIndex += 1;\n\t\t\t}\n\n\t\t\t// TODO: Alert about wrong translation domain?\n\t\t\tconst comments = collectComments(argsNode);\n\n\t\t\t// Get the translation data\n\t\t\tconst block = new Block({\n\t\t\t\tmsgctxt: translation.msgctxt,\n\t\t\t\tmsgid: translation.msgid ?? \"\",\n\t\t\t\tmsgid_plural: translation.msgid_plural,\n\t\t\t\tmsgstr: translation.msgid_plural ? [\"\", \"\"] : [\"\"],\n\t\t\t\tcomments: {\n\t\t\t\t\ttranslator: comments ? [comments] : undefined,\n\t\t\t\t\treference: [\n\t\t\t\t\t\t`${reverseSlashes(filepath)}:${node.startPosition.row + 1}`,\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t} as Block);\n\n\t\t\tgettextTranslations.add(block);\n\t\t}\n\t}\n\n\ttraverse(tree.rootNode);\n\n\t// Return both matches and entries\n\treturn gettextTranslations;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAwC;AACxC,mBAA8B;AAE9B,4BAAmC;AACnC,kBAA0B;AAC1B,oBAAuD;AAQvD,SAAS,gBAAgB,MAAsC;AAC9D,MAAI,cAAc;AAClB,MAAI,QAAQ;AAGZ,SAAO,eAAe,QAAQ,GAAG;AAChC,QACC,aAAa,iBAAiB,SAAS,aACvC,aAAa,iBAAiB,KAAK,YAAY,EAAE,SAAS,aAAa,GACtE;AACD,aAAO,aAAa,iBAAiB,WAClC,sCAAuB,YAAY,gBAAgB,IAAI,IACvD;AAAA,IACJ;AACA;AACA,kBAAc,YAAY;AAAA,EAC3B;AACD;AASO,SAAS,OAAO,YAAoB,UAA+B;AAEzE,QAAM,SAAS,IAAI,mBAAAA,QAAO;AAC1B,QAAM,gBAAY,uBAAU,QAAQ;AAEpC,MAAI,CAAC,UAAW,QAAO,IAAI,kCAAY,CAAC,GAAG,QAAQ;AAEnD,SAAO,YAAY,SAAS;AAG5B,QAAM,OAAO,OAAO,MAAM,UAAU;AAGpC,QAAM,sBAAmC,IAAI,kCAAY,CAAC,GAAG,QAAQ;AAErE,QAAM,cACL,SAAS,MAAM,GAAG,EAAE,IAAI,GAAG,YAAY,MAAM,QAC1C,oBACA;AAEJ,QAAM,aAAa;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA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QACvB,SAAS,YAAY;AAAA,QACrB,OAAO,YAAY,SAAS;AAAA,QAC5B,cAAc,YAAY;AAAA,QAC1B,QAAQ,YAAY,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;AAAA,QACjD,UAAU;AAAA,UACT,YAAY,WAAW,CAAC,QAAQ,IAAI;AAAA,UACpC,WAAW;AAAA,YACV,OAAG,8BAAe,QAAQ,CAAC,IAAI,KAAK,cAAc,MAAM,CAAC;AAAA,UAC1D;AAAA,QACD;AAAA,MACD,CAAU;AAEV,0BAAoB,IAAI,KAAK;AAAA,IAC9B;AAAA,EACD;AAEA,WAAS,KAAK,QAAQ;AAGtB,SAAO;AACR;",
6
- "names": ["Parser", "node"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/potCommand.ts"],
4
- "sourcesContent": ["import { makePot } from \"./parser/makePot.js\";\n\nimport type { Args } from \"./types.js\";\nimport { printMakePotModuleInfo, printTimeElapsed } from \"./utils/common.js\";\n\nexport default function potCommand(args: Args) {\n\tif (Object.keys(args).length > 0) {\n\t\tprintMakePotModuleInfo();\n\t\t/* capture the start time */\n\t\tconst timeStart = new Date();\n\t\t/** make the pot file */\n\t\tmakePot(args)\n\t\t\t.then(() => {\n\t\t\t\t/* output the end time */\n\t\t\t\tprintTimeElapsed(\"Make-Pot\", timeStart);\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tconsole.error(`\uD83E\uDEE4 Make-pot - ${error}`);\n\t\t\t});\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAwB;AAGxB,oBAAyD;AAE1C,SAAR,WAA4B,MAAY;AAC9C,MAAI,OAAO,KAAK,IAAI,EAAE,SAAS,GAAG;AACjC,8CAAuB;AAEvB,UAAM,YAAY,oBAAI,KAAK;AAE3B,gCAAQ,IAAI,EACV,KAAK,MAAM;AAEX,0CAAiB,YAAY,SAAS;AAAA,IACvC,CAAC,EACA,MAAM,CAAC,UAAU;AACjB,cAAQ,MAAM,wBAAiB,KAAK,EAAE;AAAA,IACvC,CAAC;AAAA,EACH;AACD;",
6
- "names": []
7
- }
package/lib/types.js.map DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/types.ts"],
4
- "sourcesContent": ["import type { GetTextTranslation } from \"gettext-parser\";\nimport type { pkgJsonHeaders, pluginHeaders, themeHeaders } from \"./const.js\";\n\nexport type ThemeHeadersType = typeof themeHeaders;\nexport type PluginHeadersType = typeof pluginHeaders;\nexport type PkgHeadersType = typeof pkgJsonHeaders;\n\n/**\n * The args headers Object types\n */\nexport type PotHeaders =\n\t| keyof PkgHeadersType\n\t| keyof PluginHeadersType\n\t| keyof ThemeHeadersType\n\t| \"license\"\n\t| \"email\"\n\t| \"language\"\n\t| \"domain\"\n\t| \"bugs\";\n\n// type is the value of the themeHeader Object\nexport type DomainType =\n\t| \"plugin\"\n\t| \"theme\"\n\t| \"block\"\n\t| \"theme-block\"\n\t| \"generic\";\n\n/**\n * The patterns to use when extracting strings from files.\n *\n * @param {string} mergePaths - Comma-separated list of POT files whose contents should be merged with the extracted strings.\n * If left empty, defaults to the destination POT file. POT file headers will be ignored.\n * @param {string} subtractPaths - Comma-separated list of POT files whose contents should act as some sort of denylist\n * for string extraction. Any string which is found on that denylist will not be extracted. This can be useful when\n * you want to create multiple POT files from the same source directory with slightly different content and no duplicate\n * strings between them.\n * @param {boolean} subtractAndMerge - Whether source code references and comments from the generated POT file should be\n * instead added to the POT file used for subtraction. Warning: this modifies the files passed to `subtractPaths`!\n * @param {string} include - Comma-separated list of files and paths that should be used for string extraction.\n * If provided, only these files and folders will be taken into account for string extraction.\n * For example, `--include=\"src,my-file.php` will ignore anything besides `my-file.php` and files in the `src`\n * directory. Simple glob patterns can be used, i.e. `--include=foo-*.php` includes any PHP file with the `foo-`\n * prefix. Leading and trailing slashes are ignored, i.e. `/my/directory/` is the same as `my/directory`.\n * @param {string} exclude - Comma-separated list of files and paths that should be skipped for string extraction.\n * For example, `--exclude=.github,myfile.php` would ignore any strings found within `myfile.php` or the `.github`\n * folder. Simple glob patterns can be used, i.e. `--exclude=foo-*.php` excludes any PHP file with the `foo-`\n * prefix. Leading and trailing slashes are ignored, i.e. `/my/directory/` is the same as `my/directory`.\n * The following files and folders are always excluded: node_modules, .git, .svn, .CVS, .hg, vendor, *.min.js.\n */\nexport interface Patterns {\n\tmergePaths?: string[];\n\tsubtractPaths?: string[];\n\tsubtractAndMerge?: boolean;\n\tinclude: string[];\n\texclude: string[];\n}\n\n/**\n * Create a POT file for a WordPress project.\n *\n * Scans PHP, Blade-PHP, and JavaScript files for translatable strings, as well as theme stylesheets and plugin files\n * if the source directory is detected as either a plugin or theme.\n *\n * @param {string} sourceDirectory - Directory to scan for string extraction.\n * @param {string} destination - Name of the resulting POT file.\n * @param {string | undefined} slug - Plugin or theme slug. Defaults to the source directory's basename.\n * @param {'plugin' | 'theme' | 'block' | 'theme-block' | 'generic'} domain - Text domain to look for in the source code,\n * unless the `ignoreDomain` option is used. By default, the \"Text Domain\" header of the plugin or theme is used.\n * If none is provided, it falls back to the project slug.\n * @param {boolean} ignoreDomain - Ignore the text domain completely and extract strings with any text domain.\n * @param {{}} headers - Array in JSON format of custom headers which will be added to the POT file. Defaults to empty array.\n * @param {boolean} location - Whether to write `#: filename:line` lines. Defaults to true, use `--no-location`\n * to skip the removal. Note that disabling this option makes it harder for technically skilled translators\n * to understand each message\u2019s context.\n * @param {boolean} skipJs - Skips JavaScript string extraction. Useful when this is done in another build step, e.g. through Babel.\n * @param {boolean} skipPhp - Skips PHP string extraction.\n * @param {boolean} skipBlade - Skips Blade-PHP string extraction.\n * @param {boolean} skipBlockJson - Skips string extraction from block.json files.\n * @param {boolean} skipThemeJson - Skips string extraction from theme.json files.\n * @param {boolean} skipAudit - Skips string audit where it tries to find possible mistakes in translatable strings.\n * Useful when running in an automated environment.\n * @param {string} fileComment - String that should be added as a comment to the top of the resulting POT file.\n * By default, a copyright comment is added for WordPress plugins and themes.\n * @param {string} packageName - Name to use for the package name in the resulting POT file's `Project-Id-Version` header.\n * Overrides the plugin or theme name, if applicable.\n * @param {boolean} silent - Whether to hide progress information.\n */\nexport interface Args {\n\tslug: string;\n\tdomain: DomainType;\n\tpaths: {\n\t\tcwd: string;\n\t\tout: string;\n\t\troot?: string;\n\t};\n\toptions?: {\n\t\tignoreDomain?: boolean;\n\t\tsilent?: boolean;\n\t\tjson?: boolean;\n\t\tlocation?: boolean;\n\t\tpackageName?: string;\n\t\toutput?: boolean;\n\t\tfileComment?: string;\n\t\tcharset?: string;\n\t\tskip: {\n\t\t\tjs?: boolean;\n\t\t\tphp?: boolean;\n\t\t\tblade?: boolean;\n\t\t\tblockJson?: boolean;\n\t\t\tthemeJson?: boolean;\n\t\t\taudit?: boolean;\n\t\t};\n\t};\n\theaders?: { [key in PotHeaders]: string };\n\tpatterns: Patterns;\n}\n\n/**\n * The arguments for the `makeJson` command.\n * \t@param {string} source the source directory\n * \t@param {string | null} destination the destination directory (defaults to source)\n * \t@param {string[] | null} allowedFormats the allowed files\n * \t@param {boolean} purge remove old json files (otherwise the content will be merged)\n * \t@param {boolean} prettyPrint?: pretty print json\n * \t@param {boolean} debug: enable debug mode\n */\nexport interface MakeJsonArgs {\n\ttimeStart: number;\n\tprettyPrint: boolean;\n\tdebug: boolean;\n\tdestination: string;\n\tscriptName?: string;\n\tpurge: boolean;\n\tsource: string;\n\tslug: string;\n\tallowedFormats?: string[];\n\tpaths: {\n\t\tcwd: string;\n\t\tout?: string;\n\t\troot?: string;\n\t};\n}\n\nexport interface I18nSchema {\n\t[key: string]: string | string[] | I18nSchema | I18nSchema[];\n}\n\n/**\n * Translation string metadata.\n * Gettext format: https://www.gnu.org/savannah-checkouts/gnu/gettext/FAQ.html\n *\n * @property {string} msgctxt - context for this translation, if not present the default context applies\n * @property {string} msgid - string to be translated\n * @property {string} msgid_plural the plural form of the original string (might not be present)\n * @property {string[]} msgstr an array of translations\n * @property {{}} comments an object with the following properties: translator, reference, extracted, flag, previous.\n */\nexport interface TranslationStrings {\n\t[msgctxt: string]: { [msgId: string]: GetTextTranslation };\n}\n\n/**\n * The JSON data returned by the `makeJson` command.\n * @param {string} domain\n * @param {Record<string, unknown>} locale_data\n */\nexport interface JedData {\n\t[domain: string]: {\n\t\t[key: string]: string | string[];\n\t};\n}\n\nexport interface MakeJson {\n\tdomain: string;\n\tgenerator: string;\n\t\"translation-revision-date\": string;\n\tsource: string;\n\tlocale_data: JedData;\n}\n\n/**\n * The header data of the current plugin / theme as returned by the `extractHeaders` command.\n */\nexport interface I18nHeaders {\n\tauthorString: string;\n\tbugs: string;\n\tlicense: string;\n\tauthor?: string;\n\txDomain: string;\n\tlanguage: string;\n\tversion: string;\n\tslug: string;\n\temail: string | undefined;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
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": ";;;;;;;;;;;;;;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AAM,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
- }
@@ -1,7 +0,0 @@
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
- }