evophp 1.0.30 → 1.1.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.
@@ -0,0 +1,130 @@
1
+ const readline = require("readline");
2
+ const editJsonFile = require("edit-json-file");
3
+
4
+ /**
5
+ * Prompt user for input with a message
6
+ * @param {string} msg - The prompt message to display
7
+ * @returns {Promise<string>}
8
+ */
9
+ const readLineAsync = (msg) => {
10
+ const rl = readline.createInterface({
11
+ input: process.stdin,
12
+ output: process.stdout
13
+ });
14
+
15
+ return new Promise((resolve) => {
16
+ rl.question(msg, (userRes) => {
17
+ resolve(userRes.trim());
18
+ rl.close();
19
+ });
20
+ });
21
+ };
22
+
23
+ /**
24
+ * Validate and split a name into [author, pluginName]
25
+ * Accepts "author/plugin" or a GitHub URL
26
+ * @param {string} name
27
+ * @returns {Promise<[string, string]>}
28
+ */
29
+ const splitPluginName = async (name) => {
30
+ const isValid = (input) =>
31
+ /^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+$/.test(input);
32
+
33
+ while (true) {
34
+ name = name.replace(/^(https?:\/\/)?(www\.)?github\.com\//, "").trim();
35
+ if (isValid(name)) return name.split("/");
36
+
37
+ console.log("Format must be: author/plugin-name");
38
+ name = await readLineAsync("Enter the plugin name (or 'cancel' to exit): ");
39
+ if (name.toLowerCase() === "cancel") {
40
+ console.log("Process canceled by user.");
41
+ process.exit(1);
42
+ }
43
+ }
44
+ };
45
+
46
+ /**
47
+ * Check if value is a plain object
48
+ */
49
+ const isObject = (item) =>
50
+ item && typeof item === "object" && !Array.isArray(item);
51
+
52
+ /**
53
+ * Deep merge multiple objects into one
54
+ */
55
+ const mergeDeep = async (target, ...sources) => {
56
+ if (!sources.length) return target;
57
+ const source = sources.shift();
58
+
59
+ if (isObject(target) && isObject(source)) {
60
+ for (const key in source) {
61
+ if (isObject(source[key])) {
62
+ if (!target[key]) Object.assign(target, { [key]: {} });
63
+ await mergeDeep(target[key], source[key]);
64
+ } else {
65
+ Object.assign(target, { [key]: source[key] });
66
+ }
67
+ }
68
+ }
69
+
70
+ return mergeDeep(target, ...sources);
71
+ };
72
+
73
+ /**
74
+ * Merge plugin config into config.json
75
+ */
76
+ const mergeConfig = async (config) => {
77
+ const file = editJsonFile("./config.json");
78
+
79
+ for (const key in config) {
80
+ const existing = file.get(key);
81
+ if (existing === undefined) {
82
+ file.set(key, config[key]);
83
+ } else if (isObject(existing)) {
84
+ const merged = await mergeDeep(existing, config[key]);
85
+ file.set(key, merged);
86
+ } else {
87
+ file.set(key, config[key]);
88
+ }
89
+ }
90
+
91
+ file.save();
92
+ };
93
+
94
+ /**
95
+ * Add a new entry point to a plugin's config.json file
96
+ * @param {string} pluginName - The plugin name
97
+ * @param {string} entryName - The entry directory name
98
+ */
99
+ function addPluginEntry(pluginName, entryName) {
100
+ const configPath = path.join("EvoJsDev", "Modules", pluginName, "config.json");
101
+
102
+ if (!fs.existsSync(configPath)) {
103
+ log.error(`Config file not found: ${configPath}`);
104
+ return;
105
+ }
106
+
107
+ const file = editJsonFile(configPath);
108
+ const entryPath = `${entryName}/index`;
109
+
110
+ const current = file.get(`modules.${pluginName}`) || {
111
+ entry: [],
112
+ active: true,
113
+ order: 0
114
+ };
115
+
116
+ if (!current.entry.includes(entryPath)) {
117
+ current.entry.push(entryPath);
118
+ }
119
+
120
+ file.set(`modules.${pluginName}`, current);
121
+ file.save();
122
+ log.success(`Added entry "${entryPath}" to ${pluginName} config.`);
123
+ }
124
+
125
+ module.exports = {
126
+ readLineAsync,
127
+ splitPluginName,
128
+ mergeConfig,
129
+ addPluginEntry
130
+ };
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ info: msg => console.log(`[INFO] ${msg}`),
3
+ error: msg => console.error(`[ERROR] ${msg}`),
4
+ success: msg => console.log(`[✓] ${msg}`),
5
+ warn: msg => console.warn(`[WARN] ${msg}`)
6
+ };
@@ -0,0 +1,16 @@
1
+ const log = require("./logger");
2
+
3
+ function test(str, maxLength) {
4
+ str = str.trim().replaceAll(" ", "");
5
+ if (str.length > maxLength) {
6
+ log.error(`Input can't exceed ${maxLength} characters.`);
7
+ return false;
8
+ }
9
+ if (str.length < 1) {
10
+ log.error(`Input is empty.`);
11
+ return false;
12
+ }
13
+ return str;
14
+ }
15
+
16
+ module.exports = { test };
package/helpers.js DELETED
@@ -1,101 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const readline = require('readline');
4
- const editJsonFile = require("edit-json-file");
5
-
6
- /**
7
- * Prompt user for input with a message
8
- * @param {string} msg - The prompt message to display
9
- * @returns {Promise<string>} - Resolves with user input
10
- */
11
- const readLineAsync = (msg) => {
12
- const rl = readline.createInterface({
13
- input: process.stdin,
14
- output: process.stdout
15
- });
16
-
17
- return new Promise((resolve) => {
18
- rl.question(msg, (userRes) => {
19
- resolve(userRes);
20
- rl.close(); // Ensures the readline interface is closed after resolving
21
- });
22
- });
23
- };
24
-
25
- /**
26
- * Validates and splits the plugin name into [author, pluginName]
27
- * @param {string} name - Plugin name or GitHub URL
28
- * @returns {Promise<string[]>} - Resolves with an array [author, pluginName]
29
- */
30
- const splitPluginName = async (name) => {
31
- const isValidName = (input) =>
32
- /^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+$/.test(input);
33
-
34
- let arr = [];
35
- while (true) {
36
- // Remove common GitHub URL prefixes and trim whitespace
37
- name = name.replace(/^(https?:\/\/)?(www\.)?github\.com\//, '').trim();
38
-
39
- if (isValidName(name)) {
40
- arr = name.split('/');
41
- break;
42
- } else {
43
- console.log(
44
- "Plugin name must include the author's name (e.g., johndoe/exampleplugin)."
45
- );
46
- name = await readLineAsync("Enter the name of the plugin (or type 'cancel' to exit): ");
47
- if (name.toLowerCase() === 'cancel') {
48
- console.log("Process canceled by user.");
49
- process.exit(1);
50
- }
51
- }
52
- }
53
- return arr;
54
- };
55
-
56
- const isObject = (item) => {
57
- return (item && typeof item === 'object' && !Array.isArray(item));
58
- }
59
-
60
- /**
61
- * Deep merge two objects.
62
- * @param target
63
- * @param ...sources
64
- */
65
- const mergeDeep = async (target, ...sources) => {
66
- if (!sources.length) return target;
67
- const source = sources.shift();
68
-
69
- if (isObject(target) && isObject(source)) {
70
- for (const key in source) {
71
- if (isObject(source[key])) {
72
- if (!target[key]) Object.assign(target, { [key]: {} });
73
- mergeDeep(target[key], source[key]);
74
- } else {
75
- Object.assign(target, { [key]: source[key] });
76
- }
77
- }
78
- }
79
-
80
- return mergeDeep(target, ...sources);
81
- }
82
-
83
- const mergeConfig = async (config) => {
84
- let file = editJsonFile("./config.json");
85
- for(var data in config) {
86
- const oldValue = file.get(data);
87
- if(oldValue == undefined) {
88
- file.set(data, config[data]);
89
- } else {
90
- if(isObject(oldValue)) {
91
- var deep = await mergeDeep(oldValue, config[data]);
92
- file.set(data, deep);
93
- } else {
94
- file.set(data, config[data]);
95
- }
96
- }
97
- }
98
- file.save();
99
- }
100
-
101
- module.exports = { readLineAsync, splitPluginName, mergeConfig };
@@ -1,149 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const { execSync } = require("child_process");
4
- const fs = require("fs");
5
- const path = require("path");
6
- const { readLineAsync } = require("./helpers");
7
-
8
- (async () => {
9
- try {
10
- let [, , pluginName, ...args] = process.argv;
11
-
12
- if (!pluginName) {
13
- console.error("Please specify the plugin or theme name.");
14
- process.exit(1);
15
- }
16
-
17
- // Check if flags for prod or dev are provided
18
-
19
- const depType =
20
- args.includes("--dev") ?? args.includes("--save-dev") ? "dev" : "prod";
21
-
22
- if (args.includes("--composer")) {
23
- const pluginPath = path.join("EvoJsDev", "Modules", pluginName);
24
-
25
- if (!fs.existsSync(pluginPath)) {
26
- console.error(`Plugin "${pluginName}" not found in ${pluginPath}.`);
27
- process.exit(1);
28
- }
29
-
30
- const dependenciesFile = path.join(pluginPath, "dependencies.json");
31
- let dependencies = {};
32
- // If dependencies.json exists, read its content
33
- if (fs.existsSync(dependenciesFile)) {
34
- dependencies = JSON.parse(fs.readFileSync(dependenciesFile, "utf-8"));
35
- }
36
-
37
- console.log(
38
- `Current php dependencies in dependencies.json for ${pluginName}:`
39
- );
40
- console.log("Production dependencies:", dependencies.prod || "None");
41
-
42
- // Prompt user for additional dependencies
43
- const additionalDeps = await readLineAsync(
44
- `Enter additional ${depType} dependencies (space separated): `
45
- );
46
- const newDeps = additionalDeps
47
- .split(" ")
48
- .map((dep) => dep.trim())
49
- .filter((dep) => dep);
50
-
51
- // Add new dependencies to the respective array
52
- if (newDeps.length) {
53
- dependencies.prod = (
54
- dependencies.prod
55
- ? dependencies.prod + " " + newDeps.join(" ")
56
- : newDeps.join(" ")
57
- )
58
- .trim()
59
- .split(" ")
60
- .filter((value, index, array) => array.indexOf(value) === index)
61
- .join(" ");
62
- }
63
-
64
- // Write updated dependencies to dependencies.json
65
- fs.writeFileSync(
66
- dependenciesFile,
67
- JSON.stringify(dependencies, null, 2),
68
- "utf-8"
69
- );
70
- console.log("Updated dependencies.json successfully.");
71
-
72
- // Install the new dependencies
73
- if (newDeps.length) {
74
- const installCommand = `composer require ${newDeps.join(" ")}`
75
- console.log(`Installing ${depType} dependencies...`);
76
- execSync(installCommand, { stdio: "inherit" });
77
- }
78
-
79
- console.log("Dependencies installed successfully.");
80
-
81
- } else {
82
- const pluginPath = path.join("EvoJsDev", "Modules", pluginName);
83
-
84
- if (!fs.existsSync(pluginPath)) {
85
- console.error(`Plugin "${pluginName}" not found in ${pluginPath}.`);
86
- process.exit(1);
87
- }
88
-
89
- const dependenciesFile = path.join(pluginPath, "dependencies.json");
90
- let dependencies = {};
91
-
92
- // If dependencies.json exists, read its content
93
- if (fs.existsSync(dependenciesFile)) {
94
- dependencies = JSON.parse(fs.readFileSync(dependenciesFile, "utf-8"));
95
- }
96
-
97
- console.log(
98
- `Current dependencies in dependencies.json for ${pluginName}:`
99
- );
100
- console.log("Production dependencies:", dependencies.prod || "None");
101
- console.log("Development dependencies:", dependencies.dev || "None");
102
-
103
- // Prompt user for additional dependencies
104
- const additionalDeps = await readLineAsync(
105
- `Enter additional ${depType} dependencies (space separated): `
106
- );
107
- const newDeps = additionalDeps
108
- .split(" ")
109
- .map((dep) => dep.trim())
110
- .filter((dep) => dep);
111
-
112
- // Add new dependencies to the respective array
113
- if (newDeps.length) {
114
- dependencies[depType] = (
115
- dependencies[depType]
116
- ? dependencies[depType] + " " + newDeps.join(" ")
117
- : newDeps.join(" ")
118
- )
119
- .trim()
120
- .split(" ")
121
- .filter((value, index, array) => array.indexOf(value) === index)
122
- .join(" ");
123
- }
124
-
125
- // Write updated dependencies to dependencies.json
126
- fs.writeFileSync(
127
- dependenciesFile,
128
- JSON.stringify(dependencies, null, 2),
129
- "utf-8"
130
- );
131
- console.log("Updated dependencies.json successfully.");
132
-
133
- // Install the new dependencies
134
- if (newDeps.length) {
135
- const installCommand =
136
- depType === "prod"
137
- ? `npm install ${newDeps.join(" ")} --save` // For prod dependencies
138
- : `npm install ${newDeps.join(" ")} --save-dev`; // For dev dependencies
139
- console.log(`Installing ${depType} dependencies...`);
140
- execSync(installCommand, { stdio: "inherit" });
141
- }
142
-
143
- console.log("Dependencies installed successfully.");
144
- }
145
- } catch (error) {
146
- console.error("An error occurred:", error.message);
147
- process.exit(1);
148
- }
149
- })();
package/install-plugin.js DELETED
@@ -1,118 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const { execSync } = require('child_process');
4
- const path = require('path');
5
- const helpersPath = path.resolve(__dirname, 'helpers.js');
6
- const { readLineAsync, splitPluginName, mergeConfig } = require(helpersPath);
7
- const fs = require('fs');
8
-
9
- (async () => {
10
- try {
11
- let [, , type, name] = process.argv;
12
-
13
- // Prompt user for type if not provided
14
- if (!type || !['plugin', 'theme'].includes(type.toLowerCase())) {
15
- type = await readLineAsync("What are you installing? (plugin/theme): ");
16
- type = type.toLowerCase();
17
- if (!['plugin', 'theme'].includes(type)) {
18
- console.error("Invalid type. Please specify either 'plugin' or 'theme'.");
19
- process.exit(1);
20
- }
21
- }
22
-
23
-
24
-
25
- // Prompt user for name if not provided
26
- if (!name) {
27
- name = await readLineAsync(
28
- `Enter the ${type} name (e.g., johndoe/example${type}): `
29
- );
30
- }
31
-
32
- // Validate and split the plugin/theme name
33
- const [author, itemName] = await splitPluginName(name);
34
-
35
- // Determine installation paths based on type
36
- let paths;
37
- if (type === 'plugin') {
38
- paths = [
39
- path.join('Public', 'Modules', itemName), // Main plugin path
40
- path.join('EvoJsDev', 'Modules', itemName), // .js plugin path
41
- ];
42
- } else if (type === 'theme') {
43
- paths = [path.join('Public', 'Themes', itemName)];
44
- }
45
-
46
- // Check if any of the paths already exist
47
- for (const pluginPath of paths) {
48
- if (fs.existsSync(pluginPath)) {
49
- console.log(`The ${type} "${itemName}" already exists at ${pluginPath}.`);
50
- process.exit(0);
51
- }
52
- }
53
-
54
- console.log(`Installing ${type} "${itemName}" by "${author}"...`);
55
-
56
- // Clone repositories based on type
57
- if (type === 'plugin') {
58
- // Clone the main plugin repository
59
- const pluginRepoURL = `https://github.com/${author}/${itemName}.git`;
60
- execSync(`git clone ${pluginRepoURL} ${paths[0]}`, { stdio: 'inherit' });
61
-
62
- // Clone the .js plugin repository
63
- const jsRepoURL = `https://github.com/${author}/${itemName}.js.git`;
64
- execSync(`git clone ${jsRepoURL} ${paths[1]}`, { stdio: 'inherit' });
65
-
66
- const configFile = path.resolve(`./EvoJsDev/Modules/${itemName}/config.json`)
67
- if (fs.existsSync(configFile)) {
68
- const pluginConfig = require(configFile)
69
- mergeConfig(pluginConfig)
70
- }
71
-
72
- // Check for dependencies.json in the .js plugin path
73
- const dependenciesFile = path.join(paths[1], 'dependencies.json');
74
- if (fs.existsSync(dependenciesFile)) {
75
- console.log("Found dependencies.json. Installing dependencies...");
76
- const dependencies = JSON.parse(fs.readFileSync(dependenciesFile, 'utf-8'));
77
-
78
- // Install production dependencies
79
- if (dependencies.prod) {
80
- console.log("Installing production dependencies...");
81
- execSync(`npm install ${dependencies.prod}`, { stdio: 'inherit', cwd: process.cwd() });
82
- }
83
-
84
- // Install development dependencies
85
- if (dependencies.dev) {
86
- console.log("Installing development dependencies...");
87
- execSync(`npm install ${dependencies.dev} --save-dev`, { stdio: 'inherit', cwd: process.cwd() });
88
- }
89
- } else {
90
- console.log("No dependencies.json found. Skipping dependency installation.");
91
- }
92
-
93
- // Check for dependencies.json in the .js plugin path
94
- const phpDependenciesFile = path.join(paths[0], 'dependencies.json');
95
- if (fs.existsSync(phpDependenciesFile)) {
96
- console.log("Found dependencies.json. Installing php dependencies...");
97
- const dependencies = JSON.parse(fs.readFileSync(phpDependenciesFile, 'utf-8'));
98
-
99
- // Install production dependencies
100
- if (dependencies.prod) {
101
- console.log("Installing production dependencies...");
102
- execSync(`composer require ${dependencies.prod}`, { stdio: 'inherit', cwd: process.cwd() });
103
- }
104
- } else {
105
- console.log("No php dependencies.json found. Skipping dependency installation.");
106
- }
107
- } else if (type === 'theme') {
108
- // Clone the theme repository
109
- const themeRepoURL = `https://github.com/${author}/${itemName}.git`;
110
- execSync(`git clone ${themeRepoURL} ${paths[0]}`, { stdio: 'inherit' });
111
- }
112
-
113
- console.log(`The ${type} "${itemName}" has been installed successfully.`);
114
- } catch (error) {
115
- console.error("An error occurred while installing:", error.message);
116
- process.exit(1);
117
- }
118
- })();