-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
27 lines (20 loc) · 805 Bytes
/
utils.js
File metadata and controls
27 lines (20 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const path = require("path");
const fs = require("fs").promises;
const pluginRootFile = "plugin_file_name";
const getPluginInfo = async () => {
try {
const fileDir = path.join(__dirname, `${pluginRootFile}.php`);
const content = await fs.readFile(fileDir, "utf8");
const versionRegex = /Version:\s+([\w.-]+)/;
const textDomainRegex = /Text Domain:\s+\s*([\w-]+)/;
const versionMatch = content.match(versionRegex);
const textDomainMatch = content.match(textDomainRegex);
const version = versionMatch ? versionMatch[1] : "";
const textDomain = textDomainMatch ? textDomainMatch[1] : "";
return { version, textDomain };
} catch (error) {
console.error("Error reading file:", error);
return {};
}
};
module.exports = { pluginRootFile, getPluginInfo };