evophp 1.0.25 → 1.0.27
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 +2 -1
- package/new-plugin.js +43 -10
- package/package.json +4 -3
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.");
|
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
|
|
@@ -186,23 +187,55 @@ async function createGitHubRepo(token, templateRepo, pluginName) {
|
|
|
186
187
|
}
|
|
187
188
|
}
|
|
188
189
|
|
|
189
|
-
// Function to clone the newly created repository
|
|
190
|
+
// Function to clone the newly created repository with retry mechanism
|
|
190
191
|
async function cloneRepository(author, pluginName, cloneDir) {
|
|
191
192
|
try {
|
|
193
|
+
const cloneUrl = `https://github.com/${author}/${pluginName}.git`;
|
|
194
|
+
|
|
192
195
|
// Ensure directories do not exist before cloning
|
|
193
196
|
if (fs.existsSync(cloneDir)) {
|
|
194
197
|
console.log(`The plugin "${pluginName}" already exists in the directory. Exiting.`);
|
|
195
|
-
|
|
198
|
+
return;
|
|
196
199
|
}
|
|
197
|
-
|
|
198
|
-
const cloneUrl = `https://github.com/${author}/${pluginName}.git`;
|
|
199
200
|
|
|
200
201
|
console.log(`Cloning ${author}/${pluginName}.git from GitHub...`);
|
|
201
|
-
execSync(`git clone ${cloneUrl} ${cloneDir}`, { stdio: 'inherit' });
|
|
202
202
|
|
|
203
|
-
|
|
203
|
+
let retries = 5;
|
|
204
|
+
while (retries > 0) {
|
|
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
|
+
}
|
|
213
|
+
execSync(`git clone ${cloneUrl} ${cloneDir}`, { stdio: 'inherit' });
|
|
214
|
+
|
|
215
|
+
// Check if the cloned repository is non-empty
|
|
216
|
+
const files = fs.readdirSync(cloneDir).filter(file => file !== '.git');
|
|
217
|
+
if (files.length > 0) {
|
|
218
|
+
console.log(`Cloned the repository ${pluginName} successfully.`);
|
|
219
|
+
return;
|
|
220
|
+
} else {
|
|
221
|
+
console.warn("Repository appears to be empty. Retrying...");
|
|
222
|
+
retries--;
|
|
223
|
+
await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds before retrying
|
|
224
|
+
}
|
|
225
|
+
} catch (error) {
|
|
226
|
+
console.error(`Error during cloning attempt: ${error.message}`);
|
|
227
|
+
retries--;
|
|
228
|
+
if (retries > 0) {
|
|
229
|
+
console.log(`Retrying... (${5 - retries}/5)`);
|
|
230
|
+
await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds before retrying
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
console.error(`Failed to clone the repository ${pluginName} after multiple attempts.`);
|
|
236
|
+
process.exit(1);
|
|
204
237
|
} catch (error) {
|
|
205
|
-
console.error(`
|
|
238
|
+
console.error(`Unexpected error while cloning the repository ${pluginName}:`, error.message);
|
|
206
239
|
process.exit(1);
|
|
207
240
|
}
|
|
208
241
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "evophp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27",
|
|
4
4
|
"description": "Installer for the Evolution PHP project",
|
|
5
5
|
"main": "installer.js",
|
|
6
6
|
"scripts": {
|
|
@@ -10,7 +10,9 @@
|
|
|
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",
|
|
@@ -20,4 +22,3 @@
|
|
|
20
22
|
"helpers.js"
|
|
21
23
|
]
|
|
22
24
|
}
|
|
23
|
-
|