@wp-blocks/make-pot 1.0.2 → 1.3.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.
- package/README.md +18 -1
- package/biome.json +12 -0
- package/lib/assets/block-i18n.js +1 -0
- package/lib/assets/package-i18n.js +1 -0
- package/lib/assets/theme-i18n.js +1 -0
- package/lib/assets/wp-plugin-i18n.js +1 -0
- package/lib/assets/wp-theme-i18n.js +1 -0
- package/lib/cli/getArgs.js +1 -0
- package/lib/cli/parseCli.js +1 -111
- package/lib/const.js +1 -93
- package/lib/extractors/css.js +1 -42
- package/lib/extractors/headers.js +1 -63
- package/lib/extractors/json.js +1 -82
- package/lib/extractors/php.js +2 -49
- package/lib/extractors/schema.js +1 -121
- package/lib/extractors/text.js +1 -19
- package/lib/extractors/utils.js +1 -54
- package/lib/fs/fs.js +1 -0
- package/lib/fs/glob.js +3 -95
- package/lib/index.js +1 -26
- package/lib/parser/exec.js +3 -71
- package/lib/parser/makePot.js +1 -35
- package/lib/parser/patterns.js +1 -34
- package/lib/parser/process.js +1 -70
- package/lib/parser/progress.js +1 -0
- package/lib/parser/taskRunner.js +1 -0
- package/lib/parser/tree.js +1 -87
- package/lib/run.js +1 -0
- package/lib/types.js +1 -3
- package/lib/utils/common.js +2 -0
- package/package.json +68 -62
- package/tsconfig.json +3 -19
- package/ .prettierignore +0 -3
- package/.editorconfig +0 -15
- package/.eslintrc.json +0 -12
- package/jest.config.json +0 -18
- package/lib/assets/block-i18n.json +0 -17
- package/lib/assets/package-i18n.json +0 -13
- package/lib/assets/theme-i18n.json +0 -86
- package/lib/assets/wp-plugin-i18n.json +0 -14
- package/lib/assets/wp-theme-i18n.json +0 -13
- package/lib/cli/index.d.ts +0 -1
- package/lib/cli/index.js +0 -114
- package/lib/cli/index.js.map +0 -1
- package/lib/cli/parseCli.d.ts +0 -3
- package/lib/cli/parseCli.js.map +0 -1
- package/lib/cliArgs.d.ts +0 -4
- package/lib/cliArgs.js +0 -216
- package/lib/cliArgs.js.map +0 -1
- package/lib/consolidate.d.ts +0 -2
- package/lib/consolidate.js +0 -37
- package/lib/consolidate.js.map +0 -1
- package/lib/const.d.ts +0 -140
- package/lib/const.js.map +0 -1
- package/lib/extractors/css.d.ts +0 -2
- package/lib/extractors/css.js.map +0 -1
- package/lib/extractors/headers.d.ts +0 -6
- package/lib/extractors/headers.js.map +0 -1
- package/lib/extractors/index.d.ts +0 -2
- package/lib/extractors/index.js +0 -60
- package/lib/extractors/index.js.map +0 -1
- package/lib/extractors/json.d.ts +0 -9
- package/lib/extractors/json.js.map +0 -1
- package/lib/extractors/php.d.ts +0 -3
- package/lib/extractors/php.js.map +0 -1
- package/lib/extractors/schema.d.ts +0 -13
- package/lib/extractors/schema.js.map +0 -1
- package/lib/extractors/text.d.ts +0 -1
- package/lib/extractors/text.js.map +0 -1
- package/lib/extractors/utils.d.ts +0 -5
- package/lib/extractors/utils.js.map +0 -1
- package/lib/fs/glob.d.ts +0 -13
- package/lib/fs/glob.js.map +0 -1
- package/lib/fs/index.d.ts +0 -2
- package/lib/fs/index.js +0 -69
- package/lib/fs/index.js.map +0 -1
- package/lib/fs.d.ts +0 -2
- package/lib/fs.js +0 -69
- package/lib/fs.js.map +0 -1
- package/lib/glob.d.ts +0 -13
- package/lib/glob.js +0 -95
- package/lib/glob.js.map +0 -1
- package/lib/index.d.ts +0 -2
- package/lib/index.js.map +0 -1
- package/lib/makePot.d.ts +0 -2
- package/lib/makePot.js +0 -83
- package/lib/makePot.js.map +0 -1
- package/lib/maps.d.ts +0 -122
- package/lib/maps.js +0 -73
- package/lib/maps.js.map +0 -1
- package/lib/parser/consolidate.d.ts +0 -2
- package/lib/parser/consolidate.js +0 -37
- package/lib/parser/consolidate.js.map +0 -1
- package/lib/parser/exec.d.ts +0 -3
- package/lib/parser/exec.js.map +0 -1
- package/lib/parser/index.d.ts +0 -2
- package/lib/parser/index.js +0 -24
- package/lib/parser/index.js.map +0 -1
- package/lib/parser/makePot.d.ts +0 -2
- package/lib/parser/makePot.js.map +0 -1
- package/lib/parser/patterns.d.ts +0 -2
- package/lib/parser/patterns.js.map +0 -1
- package/lib/parser/process.d.ts +0 -5
- package/lib/parser/process.js.map +0 -1
- package/lib/parser/tree.d.ts +0 -2
- package/lib/parser/tree.js.map +0 -1
- package/lib/parser.d.ts +0 -6
- package/lib/parser.js +0 -110
- package/lib/parser.js.map +0 -1
- package/lib/tree.d.ts +0 -2
- package/lib/tree.js +0 -78
- package/lib/tree.js.map +0 -1
- package/lib/types.d.ts +0 -50
- package/lib/types.js.map +0 -1
- package/lib/utils/index.d.ts +0 -8
- package/lib/utils/index.js +0 -78
- package/lib/utils/index.js.map +0 -1
- package/lib/utils.d.ts +0 -8
- package/lib/utils.js +0 -78
- package/lib/utils.js.map +0 -1
- package/tests/consolidate.test.ts +0 -77
- package/tests/extract.test.ts +0 -391
- package/tests/getFiles.test.ts +0 -114
- package/tests/getStrings.test.ts +0 -85
- package/tests/ignoreFunction.test.ts +0 -126
- package/tests/jsonParse.test.ts +0 -51
- package/tests/tree.test.ts +0 -152
- /package/{LICENSE.md → LICENSE} +0 -0
package/README.md
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
[](https://www.npmjs.com/package/@wp-blocks/make-pot)
|
|
2
|
+
[](https://github.com/wp-blocks/make-pot?tab=GPL-3.0-1-ov-file#readme)
|
|
3
|
+
[](https://github.com/wp-blocks/make-pot/actions/workflows/node.js.yml)
|
|
4
|
+
|
|
5
|
+
## Make Pot
|
|
2
6
|
|
|
3
7
|
`make-pot` is a Node.js module designed to generate the `.pot` file for your WordPress plugin or theme. This file serves as the basis for internationalization, allowing translators to localize your plugin or theme into different languages.
|
|
4
8
|
|
|
@@ -49,6 +53,17 @@ npx @wp-blocks/make-pot [sourceDirectory] [destination] [options]
|
|
|
49
53
|
- `--json`: Outputs the JSON gettext data.
|
|
50
54
|
- `--output`: Outputs the gettext data.
|
|
51
55
|
|
|
56
|
+
## As a build chain step
|
|
57
|
+
|
|
58
|
+
The `make-pot` module can be used as a build step in your build chain.
|
|
59
|
+
To do so, create a `build:makepot` action in your `package.json` with the following content (refer to the [options](https://github.com/wp-blocks/make-pot?tab=readme-ov-file#options) for more information):
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"build:makepot": "npx @wp-blocks/make-pot [sourceDirectory] [destination] [options]"
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
52
67
|
### Credits
|
|
53
68
|
|
|
54
69
|
This module is heavily inspired by the original `makepot` command from [WP-CLI](https://github.com/wp-cli/i18n-command).
|
|
@@ -56,3 +71,5 @@ Special thanks to the maintainers in particular [Swissspidy](https://github.com/
|
|
|
56
71
|
has been very helpful with suggestions and tips on how to rebuild `make-pot`.
|
|
57
72
|
|
|
58
73
|
Feel free to contribute or report issues on [GitHub](https://github.com/example/example).
|
|
74
|
+
|
|
75
|
+
This tool is licensed under the [GNU General Public License v3](LICENSE).
|
package/biome.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var l=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var s=(o,i)=>{for(var e in i)l(o,e,{get:i[e],enumerable:!0})},b=(o,i,e,r)=>{if(i&&typeof i=="object"||typeof i=="function")for(let t of c(i))!k.call(o,t)&&t!==e&&l(o,t,{get:()=>i[t],enumerable:!(r=a(i,t))||r.enumerable});return o};var d=o=>b(l({},"__esModule",{value:!0}),o);var y={};s(y,{default:()=>n});module.exports=d(y);var n={title:"block title",description:"block description",keywords:["block keyword"],styles:[{label:"block style label"}],variations:[{title:"block variation title",description:"block variation description",keywords:["block variation keyword"]}]};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var u=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var t=Object.prototype.hasOwnProperty;var n=(e,r)=>{for(var s in r)u(e,s,{get:r[s],enumerable:!0})},b=(e,r,s,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of l(r))!t.call(e,i)&&i!==s&&u(e,i,{get:()=>r[i],enumerable:!(o=a(r,i))||o.enumerable});return e};var g=e=>b(u({},"__esModule",{value:!0}),e);var p={};n(p,{default:()=>m});module.exports=g(p);var m={name:"name",url:"url",description:"description",author:"author",authorEmail:"authorEmail",version:"version",bugs:"bugs","bugs.url":"bugsUrl","bugs.email":"bugsEmail",license:"license",repository:"repository"};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var m=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var p=(a,e)=>{for(var t in e)m(a,t,{get:e[t],enumerable:!0})},r=(a,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of s(e))!l.call(a,n)&&n!==t&&m(a,n,{get:()=>e[n],enumerable:!(i=o(e,n))||i.enumerable});return a};var c=a=>r(m({},"__esModule",{value:!0}),a);var z={};p(z,{default:()=>g});module.exports=c(z);var g={title:"Style variation name",settings:{typography:{fontSizes:[{name:"Font size name"}],fontFamilies:[{name:"Font family name"}]},color:{palette:[{name:"Color name"}],gradients:[{name:"Gradient name"}],duotone:[{name:"Duotone name"}]},spacing:{spacingSizes:[{name:"Space size name"}]},blocks:{"*":{typography:{fontSizes:[{name:"Font size name"}],fontFamilies:[{name:"Font family name"}]},color:{palette:[{name:"Color name"}],gradients:[{name:"Gradient name"}]},spacing:{spacingSizes:[{name:"Space size name"}]}}}},customTemplates:[{title:"Custom template name"}],templateParts:[{title:"Template part name"}]};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var a=Object.defineProperty;var r=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var s=Object.prototype.hasOwnProperty;var l=(i,e)=>{for(var t in e)a(i,t,{get:e[t],enumerable:!0})},U=(i,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of u(e))!s.call(i,n)&&n!==t&&a(i,n,{get:()=>e[n],enumerable:!(o=r(e,n))||o.enumerable});return i};var g=i=>U(a({},"__esModule",{value:!0}),i);var h={};l(h,{default:()=>c});module.exports=g(h);var c={name:"Plugin Name",slug:"Plugin Slug",url:"Plugin URI",description:"Description",version:"Version",author:"Author",authorUri:"Author URI",tags:"Tags",license:"License",licenseUri:"License URI",updateUri:"Update URI",domainPath:"Domain Path",textDomain:"Text Domain"};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var n=Object.defineProperty;var r=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var m=(i,e)=>{for(var a in e)n(i,a,{get:e[a],enumerable:!0})},c=(i,e,a,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of s(e))!h.call(i,t)&&t!==a&&n(i,t,{get:()=>e[t],enumerable:!(o=r(e,t))||o.enumerable});return i};var u=i=>c(n({},"__esModule",{value:!0}),i);var l={};m(l,{default:()=>U});module.exports=u(l);var U={name:"Theme Name",author:"Author",authorUri:"Author URI",description:"Description",url:"Theme URI",tags:"Tags",version:"Version",license:"License",licenseUri:"License URI",domainPath:"Domain Path",textDomain:"Text Domain"};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var l=Object.create;var o=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var m=(e,i)=>{for(var t in i)o(e,t,{get:i[t],enumerable:!0})},n=(e,i,t,r)=>{if(i&&typeof i=="object"||typeof i=="function")for(let s of g(i))!y.call(e,s)&&s!==t&&o(e,s,{get:()=>i[s],enumerable:!(r=b(i,s))||r.enumerable});return e};var a=(e,i,t)=>(t=e!=null?l(u(e)):{},n(i||!e||!e.__esModule?o(t,"default",{value:e,enumerable:!0}):t,e)),f=e=>n(o({},"__esModule",{value:!0}),e);var S={};m(S,{getArgs:()=>h});module.exports=f(S);var p=a(require("node:process")),k=a(require("yargs")),c=require("yargs/helpers"),d=require("./parseCli.js");function h(e={}){const i=k.default((0,c.hideBin)(p.default.argv)).help("h").alias("help","help").usage("Usage: $0 <source> [destination] [options]").positional("sourceDirectory",{describe:"Source directory",type:"string"}).positional("destination",{describe:"Destination directory",type:"string"}).options({slug:{describe:"Plugin or theme slug",type:"string"},domain:{describe:"Text domain to look for in the source code",type:"string"},"skip-js":{describe:"Skip JavaScript files",type:"boolean"},"skip-php":{describe:"Skip PHP files",type:"boolean"},"skip-blade":{describe:"Skip Blade files",type:"boolean"},"skip-block-json":{describe:"Skip block.json files",type:"boolean"},"skip-theme-json":{describe:"Skip theme.json files",type:"boolean"},"skip-audit":{describe:"Skip auditing of strings",type:"boolean"},headers:{describe:"Headers",type:"string"},"file-comment":{describe:"File comment",type:"string"},"package-name":{describe:"Package name",type:"string"},location:{describe:"Include location information",type:"boolean"},"ignore-domain":{describe:"Ignore text domain",type:"boolean"},mergePaths:{describe:"Merge with existing POT file(s)",type:"string"},subtractPaths:{describe:"Subtract strings from existing POT file(s)",type:"string"},subtractAndMerge:{describe:"Subtract and merge strings from existing POT file(s)",type:"boolean"},include:{describe:"Include specific files",type:"string"},exclude:{describe:"Exclude specific files",type:"string"},silent:{describe:"No output to stdout",type:"boolean"},json:{describe:"Output the json gettext data",type:"boolean"},output:{describe:"Output the gettext data",type:"boolean"}}).parseSync();return(0,d.parseCliArgs)({...e,...i})}0&&(module.exports={getArgs});
|
package/lib/cli/parseCli.js
CHANGED
|
@@ -1,111 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.parseCliArgs = void 0;
|
|
27
|
-
const utils_1 = require("../utils");
|
|
28
|
-
const path = __importStar(require("path"));
|
|
29
|
-
const process = __importStar(require("process"));
|
|
30
|
-
const const_1 = require("../const");
|
|
31
|
-
const node_fs_1 = __importStar(require("node:fs"));
|
|
32
|
-
function isThemeOrPlugin(currentPath = '/', slug) {
|
|
33
|
-
const currentWorkingDirectory = currentPath;
|
|
34
|
-
try {
|
|
35
|
-
(0, node_fs_1.accessSync)(path.join(currentWorkingDirectory, slug + '.php'), node_fs_1.default.constants.R_OK);
|
|
36
|
-
return 'plugin';
|
|
37
|
-
}
|
|
38
|
-
catch (err) {
|
|
39
|
-
console.log('the current working directory ' +
|
|
40
|
-
currentWorkingDirectory +
|
|
41
|
-
' does not contain a ' +
|
|
42
|
-
slug +
|
|
43
|
-
'.php file');
|
|
44
|
-
}
|
|
45
|
-
try {
|
|
46
|
-
(0, node_fs_1.accessSync)(path.join(currentWorkingDirectory, 'style.css'), node_fs_1.default.constants.R_OK);
|
|
47
|
-
return 'theme';
|
|
48
|
-
}
|
|
49
|
-
catch (err) {
|
|
50
|
-
console.log('the current working directory ' +
|
|
51
|
-
currentWorkingDirectory +
|
|
52
|
-
' does not contain a style.css file');
|
|
53
|
-
}
|
|
54
|
-
if (currentWorkingDirectory.includes('themes')) {
|
|
55
|
-
return 'theme';
|
|
56
|
-
}
|
|
57
|
-
else if (currentWorkingDirectory.includes('plugins')) {
|
|
58
|
-
return 'plugin';
|
|
59
|
-
}
|
|
60
|
-
return 'generic';
|
|
61
|
-
}
|
|
62
|
-
function parseCliArgs(args) {
|
|
63
|
-
var _a, _b, _c, _d, _e, _f;
|
|
64
|
-
const inputPath = typeof args._[0] === 'string' ? args._[0] : '.';
|
|
65
|
-
const outputPath = typeof args._[1] === 'string' ? args._[1] : '.';
|
|
66
|
-
const currentWorkingDirectory = process.cwd();
|
|
67
|
-
const slug = args.slug && typeof args.slug === 'string'
|
|
68
|
-
? args.slug
|
|
69
|
-
: path.basename(path.resolve(currentWorkingDirectory, inputPath));
|
|
70
|
-
const cwd = path.relative(currentWorkingDirectory, inputPath);
|
|
71
|
-
const out = path.relative(currentWorkingDirectory, outputPath);
|
|
72
|
-
const domain = (_a = args === null || args === void 0 ? void 0 : args.domain) !== null && _a !== void 0 ? _a : isThemeOrPlugin(path.resolve(cwd), slug);
|
|
73
|
-
const parsedArgs = {
|
|
74
|
-
slug: slug,
|
|
75
|
-
domain: domain,
|
|
76
|
-
paths: { cwd: cwd, out: out },
|
|
77
|
-
options: {
|
|
78
|
-
ignoreDomain: !!(args === null || args === void 0 ? void 0 : args.ignoreDomain),
|
|
79
|
-
packageName: String(args.packageName),
|
|
80
|
-
silent: !!args.silent,
|
|
81
|
-
json: !!args.json,
|
|
82
|
-
location: !!(args === null || args === void 0 ? void 0 : args.location),
|
|
83
|
-
output: !!(args === null || args === void 0 ? void 0 : args.output),
|
|
84
|
-
fileComment: args.fileComment
|
|
85
|
-
? String(args.fileComment)
|
|
86
|
-
: undefined,
|
|
87
|
-
skip: {
|
|
88
|
-
js: !!args.skipJs,
|
|
89
|
-
php: !!args.skipPhp,
|
|
90
|
-
blade: !!args.skipBlade,
|
|
91
|
-
blockJson: !!args.skipBlockJson,
|
|
92
|
-
themeJson: !!args.skipThemeJson,
|
|
93
|
-
audit: !!args.skipAudit,
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
headers: {
|
|
97
|
-
fileComment: (_b = args.fileComment) !== null && _b !== void 0 ? _b : '',
|
|
98
|
-
},
|
|
99
|
-
patterns: {
|
|
100
|
-
mergePaths: (_c = (0, utils_1.stringstring)(args.mergePaths)) !== null && _c !== void 0 ? _c : [],
|
|
101
|
-
subtractPaths: (_d = (0, utils_1.stringstring)(args.subtractPaths)) !== null && _d !== void 0 ? _d : [],
|
|
102
|
-
subtractAndMerge: !!args.subtractAndMerge,
|
|
103
|
-
include: (_e = (0, utils_1.stringstring)(args.include)) !== null && _e !== void 0 ? _e : ['**'],
|
|
104
|
-
exclude: (_f = (0, utils_1.stringstring)(args.exclude)) !== null && _f !== void 0 ? _f : const_1.DEFAULT_EXCLUDED_PATH,
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
parsedArgs.paths.root = args.root ? String(args.root) : undefined;
|
|
108
|
-
return parsedArgs;
|
|
109
|
-
}
|
|
110
|
-
exports.parseCliArgs = parseCliArgs;
|
|
111
|
-
//# sourceMappingURL=parseCli.js.map
|
|
1
|
+
"use strict";var y=Object.create;var p=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var A=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var P=(t,e)=>{for(var n in e)p(t,n,{get:e[n],enumerable:!0})},a=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of k(e))!D.call(t,s)&&s!==n&&p(t,s,{get:()=>e[s],enumerable:!(i=g(e,s))||i.enumerable});return t};var u=(t,e,n)=>(n=t!=null?y(A(t)):{},a(e||!t||!t.__esModule?p(n,"default",{value:t,enumerable:!0}):n,t)),_=t=>a(p({},"__esModule",{value:!0}),t);var j={};P(j,{parseCliArgs:()=>T});module.exports=_(j);var r=u(require("node:fs")),o=u(require("node:path")),b=u(require("node:process")),d=require("../const.js"),c=require("../utils/common.js");function w(t="/",e="default"){const n=t;try{return(0,r.accessSync)(o.join(n,`${e}.php`),r.default.constants.R_OK),"plugin"}catch{console.log(`the current working directory ${n} does not contain a ${e}.php file`)}try{return(0,r.accessSync)(o.join(n,"style.css"),r.default.constants.R_OK),"theme"}catch{console.log(`the current working directory ${n} does not contain a style.css file`)}return n.includes(`wp-content${o.sep}themes`)?"theme":n.includes(`wp-content${o.sep}plugins`)?"plugin":"generic"}function T(t){const e=typeof t._[0]=="string"?t._[0]:".",n=typeof t._[1]=="string"?t._[1]:".",i=b.cwd(),s=t.slug&&typeof t.slug=="string"?t.slug:o.basename(o.resolve(i,e)),l=o.relative(i,e),f=o.relative(i,n),h=t?.domain??w(o.resolve(l),s),m={slug:s,domain:h,paths:{cwd:l,out:f},options:{ignoreDomain:!!t?.ignoreDomain,packageName:String(t.packageName),silent:!!t.silent,json:!!t.json,location:!!t?.location,output:!!t?.output,fileComment:t.fileComment?String(t.fileComment):void 0,skip:{js:!!t.skipJs,php:!!t.skipPhp,blade:!!t.skipBlade,blockJson:!!t.skipBlockJson,themeJson:!!t.skipThemeJson,audit:!!t.skipAudit}},patterns:{mergePaths:(0,c.stringstring)(t.mergePaths)??[],subtractPaths:(0,c.stringstring)(t.subtractPaths)??[],subtractAndMerge:!!t.subtractAndMerge,include:(0,c.stringstring)(t.include)??["**"],exclude:(0,c.stringstring)(t.exclude)??d.DEFAULT_EXCLUDED_PATH}};return m.paths.root=t.root?String(t.root):void 0,m}0&&(module.exports={parseCliArgs});
|
package/lib/const.js
CHANGED
|
@@ -1,93 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.i18nFunctions = exports.allowedFiles = exports.DEFAULT_EXCLUDED_PATH = exports.themeHeaders = exports.pluginHeaders = exports.pkgJsonHeaders = exports.blockJson = exports.themeJson = exports.pkgJson = void 0;
|
|
27
|
-
const blocki18n = __importStar(require("./assets/block-i18n.json"));
|
|
28
|
-
const themei18n = __importStar(require("./assets/theme-i18n.json"));
|
|
29
|
-
const packagei18n = __importStar(require("./assets/package-i18n.json"));
|
|
30
|
-
const wpThemei18n = __importStar(require("./assets/wp-theme-i18n.json"));
|
|
31
|
-
const wpPlugini18n = __importStar(require("./assets/wp-plugin-i18n.json"));
|
|
32
|
-
const package_json_1 = require("../package.json");
|
|
33
|
-
exports.pkgJson = {
|
|
34
|
-
name: package_json_1.name,
|
|
35
|
-
version: package_json_1.version,
|
|
36
|
-
description: package_json_1.description,
|
|
37
|
-
};
|
|
38
|
-
exports.themeJson = themei18n;
|
|
39
|
-
exports.blockJson = blocki18n;
|
|
40
|
-
exports.pkgJsonHeaders = packagei18n;
|
|
41
|
-
exports.pluginHeaders = wpPlugini18n;
|
|
42
|
-
exports.themeHeaders = wpThemei18n;
|
|
43
|
-
exports.DEFAULT_EXCLUDED_PATH = [
|
|
44
|
-
'.git',
|
|
45
|
-
'node_modules',
|
|
46
|
-
'vendor',
|
|
47
|
-
'build',
|
|
48
|
-
'dist',
|
|
49
|
-
'uploads',
|
|
50
|
-
'Gruntfile.js',
|
|
51
|
-
'webpack.config.js',
|
|
52
|
-
'**/*.min.js',
|
|
53
|
-
'tsconfig.js',
|
|
54
|
-
'**.test.**',
|
|
55
|
-
'tests',
|
|
56
|
-
];
|
|
57
|
-
exports.allowedFiles = [
|
|
58
|
-
'php',
|
|
59
|
-
'js',
|
|
60
|
-
'jsx',
|
|
61
|
-
'ts',
|
|
62
|
-
'tsx',
|
|
63
|
-
'mjs',
|
|
64
|
-
'cjs',
|
|
65
|
-
'txt',
|
|
66
|
-
'html',
|
|
67
|
-
'json',
|
|
68
|
-
];
|
|
69
|
-
exports.i18nFunctions = {
|
|
70
|
-
__: ['msgid', 'text_domain'],
|
|
71
|
-
esc_attr__: ['msgid', 'text_domain'],
|
|
72
|
-
esc_html__: ['msgid', 'text_domain'],
|
|
73
|
-
esc_xml__: ['msgid', 'text_domain'],
|
|
74
|
-
_e: ['msgid', 'text_domain'],
|
|
75
|
-
esc_attr_e: ['msgid', 'text_domain'],
|
|
76
|
-
esc_html_e: ['msgid', 'text_domain'],
|
|
77
|
-
esc_xml_e: ['msgid', 'text_domain'],
|
|
78
|
-
_x: ['msgid', 'msgctxt', 'text_domain'],
|
|
79
|
-
_ex: ['msgid', 'msgctxt', 'text_domain'],
|
|
80
|
-
esc_attr_x: ['msgid', 'msgctxt', 'text_domain'],
|
|
81
|
-
esc_html_x: ['msgid', 'msgctxt', 'text_domain'],
|
|
82
|
-
esc_xml_x: ['msgid', 'msgctxt', 'text_domain'],
|
|
83
|
-
_n: ['msgid', 'msgid_plural', 'number', 'text_domain'],
|
|
84
|
-
_nx: ['msgid', 'msgid_plural', 'number', 'msgctxt', 'text_domain'],
|
|
85
|
-
_n_noop: ['msgid', 'msgid_plural', 'text_domain'],
|
|
86
|
-
_nx_noop: ['msgid', 'msgid_plural', 'msgctxt', 'text_domain'],
|
|
87
|
-
_: ['msgid', 'text_domain'],
|
|
88
|
-
_c: ['msgid', 'text_domain'],
|
|
89
|
-
_nc: ['msgid', 'msgid_plural', 'number', 'text_domain'],
|
|
90
|
-
__ngettext: ['msgid', 'msgid_plural', 'number', 'text_domain'],
|
|
91
|
-
__ngettext_noop: ['msgid', 'msgid_plural', 'text_domain'],
|
|
92
|
-
};
|
|
93
|
-
//# sourceMappingURL=const.js.map
|
|
1
|
+
"use strict";var c=Object.create;var _=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var f=(t,m)=>{for(var s in m)_(t,s,{get:m[s],enumerable:!0})},n=(t,m,s,o)=>{if(m&&typeof m=="object"||typeof m=="function")for(let e of l(m))!b.call(t,e)&&e!==s&&_(t,e,{get:()=>m[e],enumerable:!(o=p(m,e))||o.enumerable});return t};var i=(t,m,s)=>(s=t!=null?c(u(t)):{},n(m||!t||!t.__esModule?_(s,"default",{value:t,enumerable:!0}):s,t)),h=t=>n(_({},"__esModule",{value:!0}),t);var T={};f(T,{DEFAULT_EXCLUDED_PATH:()=>E,allowedFiles:()=>F,blockJson:()=>k,i18nFunctions:()=>J,pkgJsonHeaders:()=>w,pluginHeaders:()=>H,themeHeaders:()=>D,themeJson:()=>j});module.exports=h(T);var d=i(require("./assets/block-i18n.js")),x=i(require("./assets/package-i18n.js")),g=i(require("./assets/theme-i18n.js")),a=i(require("./assets/wp-plugin-i18n.js")),r=i(require("./assets/wp-theme-i18n.js"));const j=g.default,k=d.default,w=x.default,H=a.default,D=r.default,E=[".git","node_modules","vendor","build","dist","uploads","Gruntfile.js","webpack.config.js","**/*.min.js","tsconfig.js","**.test.**","tests"],F=["php","js","jsx","ts","tsx","mjs","cjs"],J={__:["msgid","text_domain"],esc_attr__:["msgid","text_domain"],esc_html__:["msgid","text_domain"],esc_xml__:["msgid","text_domain"],_e:["msgid","text_domain"],esc_attr_e:["msgid","text_domain"],esc_html_e:["msgid","text_domain"],esc_xml_e:["msgid","text_domain"],_x:["msgid","msgctxt","text_domain"],_ex:["msgid","msgctxt","text_domain"],esc_attr_x:["msgid","msgctxt","text_domain"],esc_html_x:["msgid","msgctxt","text_domain"],esc_xml_x:["msgid","msgctxt","text_domain"],_n:["msgid","msgid_plural","number","text_domain"],_nx:["msgid","msgid_plural","number","msgctxt","text_domain"],_n_noop:["msgid","msgid_plural","text_domain"],_nx_noop:["msgid","msgid_plural","msgctxt","text_domain"],_:["msgid","text_domain"],_c:["msgid","text_domain"],_nc:["msgid","msgid_plural","number","text_domain"],__ngettext:["msgid","msgid_plural","number","text_domain"],__ngettext_noop:["msgid","msgid_plural","text_domain"]};0&&(module.exports={DEFAULT_EXCLUDED_PATH,allowedFiles,blockJson,i18nFunctions,pkgJsonHeaders,pluginHeaders,themeHeaders,themeJson});
|
package/lib/extractors/css.js
CHANGED
|
@@ -1,42 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.extractCssThemeData = void 0;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const utils_1 = require("../utils");
|
|
10
|
-
const text_1 = require("./text");
|
|
11
|
-
const const_1 = require("../const");
|
|
12
|
-
const utils_2 = require("./utils");
|
|
13
|
-
function extractCssThemeData(args) {
|
|
14
|
-
let fileData = {};
|
|
15
|
-
const styleCssFile = path_1.default.join(args.paths.cwd, 'style.css');
|
|
16
|
-
if (fs_1.default.existsSync(styleCssFile)) {
|
|
17
|
-
const fileContent = fs_1.default.readFileSync(styleCssFile, 'utf8');
|
|
18
|
-
const commentBlock = (0, utils_1.getCommentBlock)(fileContent);
|
|
19
|
-
fileData = (0, text_1.extractFileData)(commentBlock);
|
|
20
|
-
if ('Theme Name' in fileData) {
|
|
21
|
-
console.log('Theme stylesheet detected.');
|
|
22
|
-
console.log(`Theme stylesheet: ${styleCssFile}`);
|
|
23
|
-
args.domain = 'theme';
|
|
24
|
-
const themeInfo = {};
|
|
25
|
-
for (const keyValueMatch of Object.entries(fileData)) {
|
|
26
|
-
if (keyValueMatch && keyValueMatch[0] && keyValueMatch[1]) {
|
|
27
|
-
const header = (0, utils_2.getKeyByValue)(const_1.themeHeaders, keyValueMatch[0].trim());
|
|
28
|
-
if (header === undefined)
|
|
29
|
-
continue;
|
|
30
|
-
themeInfo[header] = keyValueMatch[1].trim();
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return themeInfo;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
console.log(`Theme stylesheet not found in ${styleCssFile}`);
|
|
38
|
-
}
|
|
39
|
-
return {};
|
|
40
|
-
}
|
|
41
|
-
exports.extractCssThemeData = extractCssThemeData;
|
|
42
|
-
//# sourceMappingURL=css.js.map
|
|
1
|
+
"use strict";var u=Object.create;var i=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var k=(e,t)=>{for(var o in t)i(e,o,{get:t[o],enumerable:!0})},f=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of x(t))!j.call(e,s)&&s!==o&&i(e,s,{get:()=>t[s],enumerable:!(r=T(t,s))||r.enumerable});return e};var a=(e,t,o)=>(o=e!=null?u(C(e)):{},f(t||!e||!e.__esModule?i(o,"default",{value:e,enumerable:!0}):o,e)),B=e=>f(i({},"__esModule",{value:!0}),e);var F={};k(F,{extractCssThemeData:()=>D});module.exports=B(F);var m=a(require("node:fs")),h=a(require("node:path")),d=require("../const.js"),p=require("../utils/common.js"),y=require("./text.js"),g=require("./utils.js");function D(e){let t={};const o=h.default.join(e.paths.cwd,"style.css");if(m.default.existsSync(o)){const r=m.default.readFileSync(o,"utf8"),s=(0,p.getCommentBlock)(r);if(t=(0,y.extractFileData)(s),"Theme Name"in t){console.log("Theme stylesheet detected."),console.log(`Theme stylesheet: ${o}`),e.domain="theme";const c={};for(const n of Object.entries(t))if(n&&n[0]&&n[1]){const l=(0,g.getKeyByValue)(d.themeHeaders,n[0].trim());if(l===void 0)continue;c[l]=n[1].trim()}return c}}else console.log(`Theme stylesheet not found in ${o}`);return{}}0&&(module.exports={extractCssThemeData});
|
|
@@ -1,63 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.translationsHeaders = exports.extractMainFileData = exports.generateHeader = void 0;
|
|
4
|
-
const php_1 = require("./php");
|
|
5
|
-
const css_1 = require("./css");
|
|
6
|
-
const utils_1 = require("./utils");
|
|
7
|
-
const const_1 = require("../const");
|
|
8
|
-
function generateHeader(args) {
|
|
9
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
10
|
-
const headerData = Object.assign(Object.assign({}, args.headers), { author: ((_a = args.headers) === null || _a === void 0 ? void 0 : _a.author) || 'AUTHOR', slug: args.slug || 'PLUGIN NAME', email: ((_b = args.headers) === null || _b === void 0 ? void 0 : _b.email) || 'EMAIL', license: ((_c = args.headers) === null || _c === void 0 ? void 0 : _c.license) || 'gpl-2.0 or later', version: ((_d = args.headers) === null || _d === void 0 ? void 0 : _d.version) || '1.0.0', language: ((_e = args.headers) === null || _e === void 0 ? void 0 : _e.language) || 'en', domain: ((_f = args.headers) === null || _f === void 0 ? void 0 : _f.textDomain) || ((_g = args.headers) === null || _g === void 0 ? void 0 : _g.slug) || undefined, bugs: {
|
|
11
|
-
url: ((_h = args.headers) === null || _h === void 0 ? void 0 : _h.bugsUrl) ||
|
|
12
|
-
'https://wordpress.org/support/plugin/' + args.slug,
|
|
13
|
-
email: ((_j = args.headers) === null || _j === void 0 ? void 0 : _j.bugsEmail) ||
|
|
14
|
-
((_k = args.headers) === null || _k === void 0 ? void 0 : _k.authoremail) ||
|
|
15
|
-
'AUTHOR EMAIL',
|
|
16
|
-
} });
|
|
17
|
-
const authorString = `${headerData.author} <${headerData.email}>`;
|
|
18
|
-
const domain = headerData.domain ? `X-Domain: ${headerData.domain}` : '';
|
|
19
|
-
return {
|
|
20
|
-
'Project-Id-Version': `${headerData.slug} ${headerData.version}`,
|
|
21
|
-
'Report-Msgid-Bugs-To': authorString,
|
|
22
|
-
'MIME-Version': `1.0`,
|
|
23
|
-
'Content-Transfer-Encoding': `8bit`,
|
|
24
|
-
'content-type': 'text/plain; charset=iso-8859-1',
|
|
25
|
-
'plural-forms': 'nplurals=2; plural=(n!=1);',
|
|
26
|
-
'POT-Creation-Date': `${new Date().toISOString()}`,
|
|
27
|
-
'PO-Revision-Date': `${new Date().getFullYear()}-MO-DA HO:MI+ZONE`,
|
|
28
|
-
'Last-Translator': authorString,
|
|
29
|
-
'Language-Team': authorString,
|
|
30
|
-
'X-Generator': `${const_1.pkgJson.name} ${const_1.pkgJson.version}`,
|
|
31
|
-
Language: `${headerData.language}`,
|
|
32
|
-
domain,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
exports.generateHeader = generateHeader;
|
|
36
|
-
function extractMainFileData(args) {
|
|
37
|
-
let extractedData = {};
|
|
38
|
-
if (['plugin', 'block', 'generic'].includes(args.domain)) {
|
|
39
|
-
extractedData = (0, php_1.extractPhpPluginData)(args);
|
|
40
|
-
}
|
|
41
|
-
else if (['theme', 'theme-block'].includes(args.domain)) {
|
|
42
|
-
extractedData = (0, css_1.extractCssThemeData)(args);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
console.log('No main file detected.');
|
|
46
|
-
}
|
|
47
|
-
return extractedData;
|
|
48
|
-
}
|
|
49
|
-
exports.extractMainFileData = extractMainFileData;
|
|
50
|
-
function translationsHeaders(args) {
|
|
51
|
-
const { domain, headers } = args;
|
|
52
|
-
const { name, description, author, authorUri, url } = headers;
|
|
53
|
-
const fakePath = domain === 'plugin' ? args.slug + '.php' : 'style.css';
|
|
54
|
-
return {
|
|
55
|
-
[name]: (0, utils_1.gentranslation)(`Name of the ${domain}`, name, fakePath),
|
|
56
|
-
[url]: (0, utils_1.gentranslation)(`Url of the ${domain}`, url, fakePath),
|
|
57
|
-
[description]: (0, utils_1.gentranslation)(`Description of the ${domain}`, description, fakePath),
|
|
58
|
-
[author]: (0, utils_1.gentranslation)(`Author of the ${domain}`, author, fakePath),
|
|
59
|
-
[authorUri]: (0, utils_1.gentranslation)(`Author URI of the ${domain}`, authorUri, fakePath),
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
exports.translationsHeaders = translationsHeaders;
|
|
63
|
-
//# sourceMappingURL=headers.js.map
|
|
1
|
+
"use strict";var c=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var A=(e,t)=>{for(var o in t)c(e,o,{get:t[o],enumerable:!0})},P=(e,t,o,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of D(t))!$.call(e,n)&&n!==o&&c(e,n,{get:()=>t[n],enumerable:!(a=f(t,n))||a.enumerable});return e};var O=e=>P(c({},"__esModule",{value:!0}),e);var k={};A(k,{extractMainFileData:()=>I,generateHeader:()=>x,translationsHeaders:()=>M});module.exports=O(k);var d=require("gettext-merger"),g=require("../utils/common"),h=require("./css.js"),p=require("./php.js"),s=require("./utils.js");function x(e){const{author:t,textDomain:o}=e.headers,{name:a,version:n}=(0,g.getPkgJsonData)("name","version"),i="EMAIL",u="en",l=`${t} <${i}>`,r=o?`X-Domain: ${o}`:"",H={url:"https://wordpress.org/support/plugin/"+e.slug,email:i||"AUTHOR EMAIL"},m={...e.headers,author:e.headers?.author||"AUTHOR",slug:e.slug||"PLUGIN NAME",email:i,license:e.headers?.license||"gpl-2.0 or later",version:e.headers?.version||"1.0.0",language:u,domain:e.headers?.textDomain||e.headers?.slug||"PLUGIN DOMAIN"};return{"Project-Id-Version":`${m.slug} ${m.version}`,"Report-Msgid-Bugs-To":l,"MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","content-type":"text/plain; charset=iso-8859-1","plural-forms":"nplurals=2; plural=(n!=1);","POT-Creation-Date":`${new Date().toISOString()}`,"PO-Revision-Date":`${new Date().getFullYear()}-MO-DA HO:MI+ZONE`,"Last-Translator":l,"Language-Team":l,"X-Generator":`${a} ${n}`,Language:`${u}`,domain:r}}function I(e){let t={};return["plugin","block","generic"].includes(e.domain)?t=(0,p.extractPhpPluginData)(e):["theme","theme-block"].includes(e.domain)?t=(0,h.extractCssThemeData)(e):console.log("No main file detected."),t}function M(e){const{domain:t,headers:o}=e,{name:a,description:n,author:i,authorUri:u,url:l}=o,r=t==="plugin"?`${e.slug}.php`:"style.css";return new d.SetOfBlocks([(0,s.gentranslation)(`Name of the ${t}`,a,r),(0,s.gentranslation)(`Url of the ${t}`,l,r),(0,s.gentranslation)(`Description of the ${t}`,n,r),(0,s.gentranslation)(`Author of the ${t}`,i,r),(0,s.gentranslation)(`Author URI of the ${t}`,u,r)])}0&&(module.exports={extractMainFileData,generateHeader,translationsHeaders});
|
package/lib/extractors/json.js
CHANGED
|
@@ -1,82 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.parseJsonCallback = exports.extractPackageJson = exports.getJsonComment = exports.parseJsonFile = void 0;
|
|
16
|
-
const const_1 = require("../const");
|
|
17
|
-
const schema_1 = require("./schema");
|
|
18
|
-
const path_1 = __importDefault(require("path"));
|
|
19
|
-
const fs_1 = __importDefault(require("fs"));
|
|
20
|
-
const utils_1 = require("./utils");
|
|
21
|
-
function parseJsonFile(opts) {
|
|
22
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const jsonTranslations = yield schema_1.JsonSchemaExtractor.fromString(opts.fileContent, {
|
|
24
|
-
file: opts.filename,
|
|
25
|
-
schema: opts.filename === 'theme.json'
|
|
26
|
-
? schema_1.JsonSchemaExtractor.themeJsonSource
|
|
27
|
-
: schema_1.JsonSchemaExtractor.blockJsonSource,
|
|
28
|
-
schemaFallback: opts.filename === 'theme.json'
|
|
29
|
-
? schema_1.JsonSchemaExtractor.themeJsonFallback
|
|
30
|
-
: schema_1.JsonSchemaExtractor.blockJsonFallback,
|
|
31
|
-
addReferences: true,
|
|
32
|
-
});
|
|
33
|
-
return jsonTranslations !== null && jsonTranslations !== void 0 ? jsonTranslations : {};
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
exports.parseJsonFile = parseJsonFile;
|
|
37
|
-
function getSchema(type) {
|
|
38
|
-
switch (type) {
|
|
39
|
-
case 'block.json':
|
|
40
|
-
return const_1.blockJson;
|
|
41
|
-
case 'theme.json':
|
|
42
|
-
return const_1.themeJson;
|
|
43
|
-
default:
|
|
44
|
-
return {};
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
function getJsonComment(key, type) {
|
|
48
|
-
const comments = getSchema(type);
|
|
49
|
-
return key in Object.values(comments)
|
|
50
|
-
? comments[key]
|
|
51
|
-
: key;
|
|
52
|
-
}
|
|
53
|
-
exports.getJsonComment = getJsonComment;
|
|
54
|
-
function extractPackageJson(args) {
|
|
55
|
-
const fields = const_1.pkgJsonHeaders;
|
|
56
|
-
const pkgJsonMeta = {};
|
|
57
|
-
const packageJsonPath = args.paths.cwd
|
|
58
|
-
? path_1.default.join(args.paths.cwd, 'package.json')
|
|
59
|
-
: 'package.json';
|
|
60
|
-
if (fs_1.default.existsSync(packageJsonPath)) {
|
|
61
|
-
const packageJson = JSON.parse(fs_1.default.readFileSync(packageJsonPath, 'utf8'));
|
|
62
|
-
for (const field of Object.keys(fields)) {
|
|
63
|
-
if (field in packageJson) {
|
|
64
|
-
pkgJsonMeta[field] = packageJson[field];
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return pkgJsonMeta;
|
|
69
|
-
}
|
|
70
|
-
exports.extractPackageJson = extractPackageJson;
|
|
71
|
-
function parseJsonCallback(fileContent, filePath, filename) {
|
|
72
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
const data = yield parseJsonFile({
|
|
74
|
-
fileContent: fileContent,
|
|
75
|
-
filename: filename,
|
|
76
|
-
filepath: filePath,
|
|
77
|
-
});
|
|
78
|
-
return (0, utils_1.yieldParsedData)(data, filename, path_1.default.join(filePath, filename));
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
exports.parseJsonCallback = parseJsonCallback;
|
|
82
|
-
//# sourceMappingURL=json.js.map
|
|
1
|
+
"use strict";var k=Object.create;var c=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,d=Object.prototype.hasOwnProperty;var b=(e,n)=>{for(var t in n)c(e,t,{get:n[t],enumerable:!0})},l=(e,n,t,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of j(n))!d.call(e,o)&&o!==t&&c(e,o,{get:()=>n[o],enumerable:!(s=u(n,o))||s.enumerable});return e};var g=(e,n,t)=>(t=e!=null?k(J(e)):{},l(n||!e||!e.__esModule?c(t,"default",{value:e,enumerable:!0}):t,e)),S=e=>l(c({},"__esModule",{value:!0}),e);var F={};b(F,{extractPackageJson:()=>w,getJsonComment:()=>x,parseJsonCallback:()=>C,parseJsonFile:()=>h});module.exports=S(F);var m=g(require("node:fs")),f=g(require("node:path")),a=require("../const.js"),r=require("./schema.js"),p=require("./utils.js");async function h(e){return await r.JsonSchemaExtractor.fromString(e.fileContent,{file:e.filename,schema:e.filename==="theme.json"?r.JsonSchemaExtractor.themeJsonSource:r.JsonSchemaExtractor.blockJsonSource,schemaFallback:e.filename==="theme.json"?r.JsonSchemaExtractor.themeJsonFallback:r.JsonSchemaExtractor.blockJsonFallback,addReferences:!0})??{}}function y(e){switch(e){case"block.json":return a.blockJson;case"theme.json":return a.themeJson;default:return{}}}function x(e,n){const t=y(n);return e in Object.values(t)?t[e]:e}function w(e){const n=a.pkgJsonHeaders,t={},s=e.paths.cwd?f.default.join(e.paths.cwd,"package.json"):"package.json";if(m.default.existsSync(s)){const o=JSON.parse(m.default.readFileSync(s,"utf8"));for(const i of Object.keys(n))i in o&&(t[i]=o[i])}return t}async function C(e,n,t){const s=await h({fileContent:e,filename:t,filepath:n});return(0,p.yieldParsedData)(s,t,f.default.join(n,t))}0&&(module.exports={extractPackageJson,getJsonComment,parseJsonCallback,parseJsonFile});
|
package/lib/extractors/php.js
CHANGED
|
@@ -1,49 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.parsePHPFile = exports.extractPhpPluginData = void 0;
|
|
7
|
-
const const_1 = require("../const");
|
|
8
|
-
const utils_1 = require("./utils");
|
|
9
|
-
const path_1 = __importDefault(require("path"));
|
|
10
|
-
const fs_1 = __importDefault(require("fs"));
|
|
11
|
-
function extractPhpPluginData(args) {
|
|
12
|
-
let fileData = {};
|
|
13
|
-
const folderPhpFile = path_1.default.join(args.paths.cwd, `${args.slug}.php`);
|
|
14
|
-
if (fs_1.default.existsSync(folderPhpFile)) {
|
|
15
|
-
const fileContent = fs_1.default.readFileSync(folderPhpFile, 'utf8');
|
|
16
|
-
fileData = parsePHPFile(fileContent);
|
|
17
|
-
console.log('Plugin file detected.');
|
|
18
|
-
console.log(`Plugin file: ${folderPhpFile}`);
|
|
19
|
-
args.domain = 'plugin';
|
|
20
|
-
return fileData;
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
console.log('Plugin file not found.');
|
|
24
|
-
console.log(`Missing Plugin filename: ${folderPhpFile}`);
|
|
25
|
-
}
|
|
26
|
-
return {};
|
|
27
|
-
}
|
|
28
|
-
exports.extractPhpPluginData = extractPhpPluginData;
|
|
29
|
-
function parsePHPFile(phpContent) {
|
|
30
|
-
const match = phpContent.match(/\/\*\*([\s\S]*?)\*\//);
|
|
31
|
-
if (match && match[1]) {
|
|
32
|
-
const commentBlock = match[1];
|
|
33
|
-
const lines = commentBlock.split('\n');
|
|
34
|
-
const pluginInfo = {};
|
|
35
|
-
for (const line of lines) {
|
|
36
|
-
const keyValueMatch = line.match(/^\s*\*\s*([^:]+):\s*(.*)/);
|
|
37
|
-
if (keyValueMatch && keyValueMatch[1] && keyValueMatch[2]) {
|
|
38
|
-
const header = (0, utils_1.getKeyByValue)(const_1.pluginHeaders, keyValueMatch[1].trim());
|
|
39
|
-
if (header === undefined)
|
|
40
|
-
continue;
|
|
41
|
-
pluginInfo[header] = keyValueMatch[2].trim();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return pluginInfo;
|
|
45
|
-
}
|
|
46
|
-
return {};
|
|
47
|
-
}
|
|
48
|
-
exports.parsePHPFile = parsePHPFile;
|
|
49
|
-
//# sourceMappingURL=php.js.map
|
|
1
|
+
"use strict";var h=Object.create;var s=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty;var k=(n,t)=>{for(var e in t)s(n,e,{get:t[e],enumerable:!0})},f=(n,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of y(t))!R.call(n,o)&&o!==e&&s(n,o,{get:()=>t[o],enumerable:!(i=P(t,o))||i.enumerable});return n};var g=(n,t,e)=>(e=n!=null?h(x(n)):{},f(t||!n||!n.__esModule?s(e,"default",{value:n,enumerable:!0}):e,n)),B=n=>f(s({},"__esModule",{value:!0}),n);var S={};k(S,{extractPhpPluginData:()=>F,parsePHPFile:()=>a});module.exports=B(S);var l=g(require("node:fs")),m=g(require("node:path")),u=require("../const.js"),p=require("./utils.js");function F(n){let t={};const e=m.default.join(n.paths.cwd,`${n.slug}.php`);if(l.default.existsSync(e)){const i=l.default.readFileSync(e,"utf8");return t=a(i),console.log("Plugin file detected."),console.log(`Plugin file: ${e}`),n.domain="plugin",t}else console.log("Plugin file not found."),console.log(`Missing Plugin filename: ${e}`);return{}}function a(n){const t=n.match(/\/\*\*([\s\S]*?)\*\//);if(t&&t[1]){const i=t[1].split(`
|
|
2
|
+
`),o={};for(const d of i){const r=d.match(/^\s*\*\s*([^:]+):\s*(.*)/);if(r&&r[1]&&r[2]){const c=(0,p.getKeyByValue)(u.pluginHeaders,r[1].trim());if(c===void 0)continue;o[c]=r[2].trim()}}return o}return{}}0&&(module.exports={extractPhpPluginData,parsePHPFile});
|