evophp 1.0.26 → 1.0.28
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/helpers.js +47 -1
- package/install-dependencies.js +3 -3
- package/install-plugin.js +9 -4
- package/installer.js +26 -4
- package/new-plugin.js +12 -4
- package/package.json +6 -4
- package/uninstall.js +65 -0
package/helpers.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const readline = require('readline');
|
|
4
|
+
const editJsonFile = require("edit-json-file");
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Prompt user for input with a message
|
|
@@ -52,4 +53,49 @@ const splitPluginName = async (name) => {
|
|
|
52
53
|
return arr;
|
|
53
54
|
};
|
|
54
55
|
|
|
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 };
|
package/install-dependencies.js
CHANGED
|
@@ -25,7 +25,7 @@ const { readLineAsync } = require('./helpers');
|
|
|
25
25
|
|
|
26
26
|
const depType = isProd ? 'prod' : 'dev';
|
|
27
27
|
|
|
28
|
-
const pluginPath = path.join('EvoJsDev', '
|
|
28
|
+
const pluginPath = path.join('EvoJsDev', 'Modules', pluginName);
|
|
29
29
|
|
|
30
30
|
if (!fs.existsSync(pluginPath)) {
|
|
31
31
|
console.error(`Plugin "${pluginName}" not found in ${pluginPath}.`);
|
|
@@ -50,9 +50,9 @@ const { readLineAsync } = require('./helpers');
|
|
|
50
50
|
|
|
51
51
|
// Add new dependencies to the respective array
|
|
52
52
|
if (newDeps.length) {
|
|
53
|
-
dependencies[depType] = dependencies[depType]
|
|
53
|
+
dependencies[depType] = (dependencies[depType]
|
|
54
54
|
? dependencies[depType] + ' ' + newDeps.join(' ')
|
|
55
|
-
: newDeps.join(' ');
|
|
55
|
+
: newDeps.join(' ')).trim().split(' ').filter((value, index, array) => array.indexOf(value) === index).join(' ');
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// Write updated dependencies to dependencies.json
|
package/install-plugin.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const { execSync } = require('child_process');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const helpersPath = path.resolve(__dirname, 'helpers.js');
|
|
6
|
-
const { readLineAsync, splitPluginName } = require(helpersPath);
|
|
6
|
+
const { readLineAsync, splitPluginName, mergeConfig } = require(helpersPath);
|
|
7
7
|
const fs = require('fs');
|
|
8
8
|
|
|
9
9
|
(async () => {
|
|
@@ -36,8 +36,8 @@ const fs = require('fs');
|
|
|
36
36
|
let paths;
|
|
37
37
|
if (type === 'plugin') {
|
|
38
38
|
paths = [
|
|
39
|
-
path.join('Public', '
|
|
40
|
-
path.join('EvoJsDev', '
|
|
39
|
+
path.join('Public', 'Modules', itemName), // Main plugin path
|
|
40
|
+
path.join('EvoJsDev', 'Modules', itemName), // .js plugin path
|
|
41
41
|
];
|
|
42
42
|
} else if (type === 'theme') {
|
|
43
43
|
paths = [path.join('Public', 'Themes', itemName)];
|
|
@@ -63,6 +63,12 @@ const fs = require('fs');
|
|
|
63
63
|
const jsRepoURL = `https://github.com/${author}/${itemName}.js.git`;
|
|
64
64
|
execSync(`git clone ${jsRepoURL} ${paths[1]}`, { stdio: 'inherit' });
|
|
65
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
|
+
|
|
66
72
|
// Check for dependencies.json in the .js plugin path
|
|
67
73
|
const dependenciesFile = path.join(paths[1], 'dependencies.json');
|
|
68
74
|
if (fs.existsSync(dependenciesFile)) {
|
|
@@ -90,7 +96,6 @@ const fs = require('fs');
|
|
|
90
96
|
}
|
|
91
97
|
|
|
92
98
|
console.log(`The ${type} "${itemName}" has been installed successfully.`);
|
|
93
|
-
process.exit(1);
|
|
94
99
|
} catch (error) {
|
|
95
100
|
console.error("An error occurred while installing:", error.message);
|
|
96
101
|
process.exit(1);
|
package/installer.js
CHANGED
|
@@ -58,7 +58,8 @@ let [, , command, type, name] = process.argv;
|
|
|
58
58
|
} else if (command === "install-dependencies" || command === "d") {
|
|
59
59
|
// sample command
|
|
60
60
|
// evophp (d | install-dependencies) <plugin-name> ?(--save-dev | --save)
|
|
61
|
-
const args = name ? name : [];
|
|
61
|
+
const args = name ? [name] : [];
|
|
62
|
+
console.log(args)
|
|
62
63
|
name = type;
|
|
63
64
|
if (!name) {
|
|
64
65
|
console.error("Please specify the name of the plugin.");
|
|
@@ -75,6 +76,25 @@ let [, , command, type, name] = process.argv;
|
|
|
75
76
|
process.exit(1);
|
|
76
77
|
}
|
|
77
78
|
|
|
79
|
+
} else if (command === "uninstall" || command === "u") {
|
|
80
|
+
// sample command
|
|
81
|
+
// evophp (u | uninstall) (plugin | theme) <name>
|
|
82
|
+
|
|
83
|
+
if (!name) {
|
|
84
|
+
console.error("Please specify the plugin or theme name.");
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
console.log(`Installing plugin/theme: ${name}...`);
|
|
89
|
+
try {
|
|
90
|
+
const pluginPath = path.resolve(__dirname, "uninstall.js");
|
|
91
|
+
execSync(`node "${pluginPath}" ${type} ${name}`, {
|
|
92
|
+
stdio: "inherit",
|
|
93
|
+
});
|
|
94
|
+
} catch (error) {
|
|
95
|
+
console.error(`Error uninstalling plugin/theme: ${error.message}`);
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
78
98
|
} else if (command === "init") {
|
|
79
99
|
// sample command
|
|
80
100
|
// evophp init ?<projectName>
|
|
@@ -132,9 +152,11 @@ let [, , command, type, name] = process.argv;
|
|
|
132
152
|
console.error(`Unknown command: "${command}".`);
|
|
133
153
|
console.log(`
|
|
134
154
|
Usage:
|
|
135
|
-
i | install <type> <name>
|
|
136
|
-
|
|
137
|
-
|
|
155
|
+
i | install <type> <name> Install a plugin or theme
|
|
156
|
+
u | uninstall <type> <name> Uninstall a plugin or theme
|
|
157
|
+
n | new <type> <name> Create a new plugin or theme
|
|
158
|
+
d | install-dependencies <name> --save | --save-dev Install dependencies
|
|
159
|
+
init <name> Initialize a new project
|
|
138
160
|
`);
|
|
139
161
|
process.exit(1);
|
|
140
162
|
}
|
package/new-plugin.js
CHANGED
|
@@ -5,7 +5,8 @@ const path = require('path');
|
|
|
5
5
|
const fs = require('fs');
|
|
6
6
|
const axios = require('axios');
|
|
7
7
|
const helpersPath = path.resolve(__dirname, 'helpers.js');
|
|
8
|
-
const { readLineAsync, splitPluginName } = require(helpersPath);
|
|
8
|
+
const { readLineAsync, splitPluginName, mergeConfig } = require(helpersPath);
|
|
9
|
+
const rimraf = require('rimraf');
|
|
9
10
|
|
|
10
11
|
(async () => {
|
|
11
12
|
try {
|
|
@@ -87,7 +88,7 @@ const { readLineAsync, splitPluginName } = require(helpersPath);
|
|
|
87
88
|
});
|
|
88
89
|
} catch(e) {}
|
|
89
90
|
|
|
90
|
-
const configFile = path.resolve(
|
|
91
|
+
const configFile = path.resolve(`./EvoJsDev/Modules/${pluginName}/config.json`)
|
|
91
92
|
if (fs.existsSync(configFile)) {
|
|
92
93
|
const pluginConfig = require(configFile)
|
|
93
94
|
mergeConfig(pluginConfig)
|
|
@@ -101,7 +102,7 @@ const { readLineAsync, splitPluginName } = require(helpersPath);
|
|
|
101
102
|
pluginPrefix: pluginPrefix
|
|
102
103
|
})
|
|
103
104
|
|
|
104
|
-
if (fs.existsSync(path.resolve(
|
|
105
|
+
if (fs.existsSync(path.resolve(`./Public/Modules/${pluginName}/Controller.php`))) {
|
|
105
106
|
await editFile(`./Public/Modules/${pluginName}/Controller.php`, {
|
|
106
107
|
pluginName: pluginName,
|
|
107
108
|
pluginPrefix: pluginPrefix
|
|
@@ -202,10 +203,17 @@ async function cloneRepository(author, pluginName, cloneDir) {
|
|
|
202
203
|
let retries = 5;
|
|
203
204
|
while (retries > 0) {
|
|
204
205
|
try {
|
|
206
|
+
if (fs.existsSync(cloneDir)) {
|
|
207
|
+
console.log(`The directory "${cloneDir}" already exists. Deleting it...`);
|
|
208
|
+
|
|
209
|
+
// Use rimraf to delete the directory and its contents
|
|
210
|
+
rimraf.sync(cloneDir);
|
|
211
|
+
console.log(`The directory "${cloneDir}" was deleted.`);
|
|
212
|
+
}
|
|
205
213
|
execSync(`git clone ${cloneUrl} ${cloneDir}`, { stdio: 'inherit' });
|
|
206
214
|
|
|
207
215
|
// Check if the cloned repository is non-empty
|
|
208
|
-
const files = fs.readdirSync(cloneDir);
|
|
216
|
+
const files = fs.readdirSync(cloneDir).filter(file => file !== '.git');
|
|
209
217
|
if (files.length > 0) {
|
|
210
218
|
console.log(`Cloned the repository ${pluginName} successfully.`);
|
|
211
219
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "evophp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.28",
|
|
4
4
|
"description": "Installer for the Evolution PHP project",
|
|
5
5
|
"main": "installer.js",
|
|
6
6
|
"scripts": {
|
|
@@ -10,14 +10,16 @@
|
|
|
10
10
|
"evophp": "installer.js"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"axios": "^1.7.9"
|
|
13
|
+
"axios": "^1.7.9",
|
|
14
|
+
"edit-json-file": "^1.8.0",
|
|
15
|
+
"rimraf": "^6.0.1"
|
|
14
16
|
},
|
|
15
17
|
"files": [
|
|
16
18
|
"installer.js",
|
|
17
19
|
"new-plugin.js",
|
|
18
20
|
"install-plugin.js",
|
|
19
21
|
"install-dependencies.js",
|
|
20
|
-
"helpers.js"
|
|
22
|
+
"helpers.js",
|
|
23
|
+
"uninstall.js"
|
|
21
24
|
]
|
|
22
25
|
}
|
|
23
|
-
|
package/uninstall.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const helpersPath = path.resolve(__dirname, 'helpers.js');
|
|
5
|
+
const { readLineAsync } = require(helpersPath);
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const rimraf = require('rimraf');
|
|
8
|
+
const editJsonFile = require("edit-json-file");
|
|
9
|
+
|
|
10
|
+
(async () => {
|
|
11
|
+
try {
|
|
12
|
+
let [, , type, name] = process.argv;
|
|
13
|
+
|
|
14
|
+
// Prompt user for type if not provided
|
|
15
|
+
if (!type || !['plugin', 'theme'].includes(type.toLowerCase())) {
|
|
16
|
+
type = await readLineAsync("What are you uninstalling? (plugin/theme): ");
|
|
17
|
+
type = type.toLowerCase();
|
|
18
|
+
if (!['plugin', 'theme'].includes(type)) {
|
|
19
|
+
console.error("Invalid type. Please specify either 'plugin' or 'theme'.");
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Prompt user for name if not provided
|
|
25
|
+
if (!name) {
|
|
26
|
+
name = await readLineAsync(
|
|
27
|
+
`Enter the ${type} name (e.g., example${type}): `
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Determine installation paths based on type
|
|
32
|
+
let paths;
|
|
33
|
+
if (type === 'plugin') {
|
|
34
|
+
paths = [
|
|
35
|
+
path.join('Public', 'Modules', name), // Main plugin path
|
|
36
|
+
path.join('EvoJsDev', 'Modules', name), // .js plugin path
|
|
37
|
+
];
|
|
38
|
+
} else if (type === 'theme') {
|
|
39
|
+
paths = [path.join('Public', 'Themes', name)];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Check if any of the paths already exist
|
|
43
|
+
console.log(`Uninstalling ${type} "${name}"...`);
|
|
44
|
+
|
|
45
|
+
for (const pluginPath of paths) {
|
|
46
|
+
if (fs.existsSync(pluginPath)) {
|
|
47
|
+
rimraf.sync(pluginPath);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
// Clone repositories based on type
|
|
54
|
+
if (type === 'plugin') {
|
|
55
|
+
let file = editJsonFile("./config.json");
|
|
56
|
+
file.unset(`modules.${name}`)
|
|
57
|
+
file.save();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
console.log(`The ${type} "${name}" has been uninstalled successfully.`);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error("An error occurred while uninstalling:", error.message);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
})();
|