evophp 1.0.31 → 1.1.1

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 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("Public", "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
- })();
package/installer.js DELETED
@@ -1,223 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const { execSync } = require("child_process");
4
- const path = require("path");
5
- const fs = require("fs");
6
- const { readLineAsync } = require(path.resolve(__dirname, 'helpers.js'));
7
-
8
- let [, , command, type, name] = process.argv;
9
-
10
- (async () => {
11
- try {
12
- if (command === "i" || command === "install") {
13
- // sample command
14
- // evophp (i | install) (plugin | theme) <author/name>
15
-
16
- if (!name) {
17
- console.error("Please specify the plugin or theme name.");
18
- process.exit(1);
19
- }
20
-
21
- console.log(`Installing plugin/theme: ${name}...`);
22
- try {
23
- const pluginPath = path.resolve(__dirname, "install-plugin.js");
24
- execSync(`node "${pluginPath}" ${type} ${name}`, {
25
- stdio: "inherit",
26
- });
27
- } catch (error) {
28
- console.error(`Error installing plugin/theme: ${error.message}`);
29
- process.exit(1);
30
- }
31
- } else if (command === "n" || command === "new") {
32
- // sample command
33
- // evophp (n | new) (plugin | theme) <author/name>
34
-
35
- // Validate type and name
36
- if (!type || !name) {
37
- console.error("Please specify the type (plugin/theme) and the name.");
38
- process.exit(1);
39
- }
40
-
41
- // Ensure valid type is provided (plugin or theme)
42
- type = type.toLowerCase();
43
- if (!["plugin", "theme"].includes(type)) {
44
- console.error(
45
- "Invalid type. Please specify either 'plugin' or 'theme'."
46
- );
47
- process.exit(1);
48
- }
49
-
50
- console.log(`Creating a new ${type}: ${name}...`);
51
- try {
52
- const pluginPath = path.resolve(__dirname, "new-plugin.js");
53
- execSync(`node "${pluginPath}" ${type} ${name}`, { stdio: "inherit" });
54
- } catch (error) {
55
- console.error(`Error creating new ${type}: ${error.message}`);
56
- process.exit(1);
57
- }
58
- } else if (command === "install-dependencies" || command === "d") {
59
- // sample command
60
- // evophp (d | install-dependencies) <plugin-name> ?(--save-dev | --save)
61
- const args = name ? [name] : [];
62
-
63
- name = type;
64
- if (!name) {
65
- console.error("Please specify the name of the plugin.");
66
- process.exit(1);
67
- }
68
-
69
- console.log(`Running install-dependencies for ${name}...`);
70
-
71
- try {
72
- const pluginPath = path.resolve(__dirname, "install-dependencies.js");
73
- execSync(`node "${pluginPath}" ${name} ${args.join(' ')}`, { stdio: "inherit" });
74
- } catch (error) {
75
- console.error(`Error installing dependencies: ${error.message}`);
76
- process.exit(1);
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
- }
98
- } else if (command === "init") {
99
- // sample command
100
- // evophp init ?<projectName>
101
-
102
- name = type;
103
- if (!name) {
104
- name = await readLineAsync("Enter the name of the project:");
105
- if (!name.trim()) {
106
- console.error("Invalid name. Please provide a valid project name.");
107
- process.exit(1);
108
- }
109
- }
110
-
111
- console.log(`Initializing new project: ${name}...`);
112
-
113
- try {
114
- // Clone the repository
115
- console.log("Cloning the Evolution repository...");
116
- execSync(
117
- `git clone https://github.com/kinsokafor/evolution.git ${name}`,
118
- { stdio: "inherit" }
119
- );
120
-
121
- // Navigate to the project directory
122
- const projectPath = path.join(process.cwd(), name);
123
- process.chdir(projectPath);
124
-
125
- // Run `node evolution`
126
- console.log(`Running node evolution for project: ${name}...`);
127
- execSync(`node evolution ${name}`, { stdio: "inherit" });
128
-
129
- // Install Composer dependencies if applicable
130
- if (fs.existsSync("composer.json")) {
131
- console.log("Installing Composer dependencies...");
132
- execSync("composer install", { stdio: "inherit" });
133
- } else {
134
- console.log(
135
- "Composer file not found, skipping Composer installation."
136
- );
137
- }
138
-
139
- // Install NPM dependencies
140
- console.log("Installing NPM dependencies...");
141
- execSync("npm install", { stdio: "inherit" });
142
-
143
- console.log(
144
- "Project initialization complete! Navigate to your project folder:"
145
- );
146
- console.log(`cd ${name}`);
147
- } catch (error) {
148
- console.error(`Error initializing project: ${error.message}`);
149
- process.exit(1);
150
- }
151
- } else if (command === "help" || command === "h") {
152
- console.log(`
153
- ==========================================
154
- EvoPHP CLI - Help Guide
155
- ==========================================
156
-
157
- All Commands:
158
- Initialization:
159
- evophp init ?<project-name>
160
- Initialize a new project.
161
- - Example: evophp init
162
- - Example: evophp init example-project
163
-
164
- Plugin/Theme Creation:
165
- evophp n | new plugin | theme <author>/<name>
166
- Create a new plugin or theme.
167
- - Example (plugin): evophp new plugin example-author/example-plugin
168
- - Example (theme): evophp new theme example-author/example-theme
169
- - Example (plugin shorthand): evophp n plugin example-author/example-plugin
170
- - Example (theme shorthand): evophp n theme example-author/example-theme
171
-
172
- Plugin/Theme Installation:
173
- evophp i | install plugin | theme <author>/<name>
174
- Install a plugin or theme.
175
- - Example (plugin): evophp install plugin example-author/example-plugin
176
- - Example (theme): evophp install theme example-author/example-theme
177
- - Example (plugin shorthand): evophp i plugin example-author/example-plugin
178
- - Example (theme shorthand): evophp i theme example-author/example-theme
179
-
180
- Plugin/Theme Uninstallation:
181
- evophp u | uninstall plugin | theme <plugin-name>
182
- Uninstall a plugin or theme.
183
- - Example (plugin): evophp uninstall plugin example-plugin
184
- - Example (theme): evophp uninstall theme example-theme
185
- - Example (plugin shorthand): evophp u plugin example-plugin
186
- - Example (theme shorthand): evophp u theme example-theme
187
-
188
- Dependency Management:
189
- evophp d | install-dependencies <plugin-name>
190
- Install npm production dependencies.
191
- - Example: evophp install-dependencies example-plugin
192
- - Example (shorthand): evophp d example-plugin
193
-
194
- evophp d | install-dependencies <plugin-name> --dev | --save-dev
195
- Install npm development dependencies.
196
- - Example: evophp install-dependencies example-plugin --dev
197
- - Example (shorthand): evophp d example-plugin --dev
198
-
199
- evophp d | install-dependencies <plugin-name> --composer
200
- Install composer dependencies.
201
- - Example: evophp install-dependencies example-plugin --composer
202
- - Example (shorthand): evophp d example-plugin --composer
203
-
204
- ==========================================
205
- Notes:
206
- - <author> must be a valid GitHub username.
207
- - <name> must be a unique repository name (not already existing on GitHub).
208
-
209
- For further details, visit the official EvoPHP documentation.
210
- ==========================================
211
-
212
- `);
213
- process.exit(1);
214
- } else {
215
- console.error(`Unknown command: "${command}".`);
216
- console.log(`run evophp help for list of all acceptable commands.`);
217
- process.exit(1);
218
- }
219
- } catch (error) {
220
- console.error("An unexpected error occurred:", error.message);
221
- process.exit(1);
222
- }
223
- })();