evophp 1.0.31 → 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.
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
- })();
package/new-plugin.js DELETED
@@ -1,298 +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 axios = require('axios');
7
- const helpersPath = path.resolve(__dirname, 'helpers.js');
8
- const { readLineAsync, splitPluginName, mergeConfig } = require(helpersPath);
9
- const rimraf = require('rimraf');
10
- const dotenv = require('dotenv');
11
-
12
- dotenv.config({ path: "./.env.development" });
13
-
14
- (async () => {
15
- try {
16
- let [, , type, name] = process.argv;
17
- let cloneDir = ""
18
-
19
- // Ensure type and name are provided
20
- if (!type || !name) {
21
- console.error("Please specify the type (plugin/theme) and the name (e.g., plugin-name).");
22
- process.exit(1);
23
- }
24
-
25
- // Prompt for GitHub Personal Access Token (PAT) if not provided in environment variable
26
- const gitHubToken = process.env.GITHUB_TOKEN || await readLineAsync("Enter your GitHub Personal Access Token: ");
27
-
28
- // Validate type - only 'plugin' or 'theme' allowed
29
- type = type.toLowerCase();
30
- if (!['plugin', 'theme'].includes(type)) {
31
- console.error("Invalid type. Please specify either 'plugin' or 'theme'.");
32
- process.exit(1);
33
- }
34
-
35
- // Validate name and split it into author and item name
36
- const [author, pluginName] = await splitPluginName(name);
37
-
38
- // Validate PAT by checking the authenticated user's username
39
- const userData = await getUserData(gitHubToken);
40
-
41
- if (userData.login !== author) {
42
- console.error(`Invalid GitHub token. The token belongs to ${userData.login}, but it should belong to ${author}.`);
43
- process.exit(1);
44
- }
45
-
46
- console.log(`Authenticated as ${userData.login}. Proceeding with repository creation...`);
47
-
48
- // Define template repository URL based on type
49
- let templateRepo = '';
50
- if (type === 'plugin') {
51
- templateRepo = 'kinsokafor/EvoPlugin'; // Plugin template
52
- console.log("Creating a new plugin (EvoPlugin and EvoPlugin.js)...");
53
-
54
- // Create repository for EvoPlugin
55
- await createGitHubRepo(gitHubToken, templateRepo, pluginName);
56
-
57
- // Clone the newly created repositories
58
- cloneDir = path.join('Public', 'Modules', pluginName);
59
- await cloneRepository(author, pluginName, cloneDir);
60
-
61
- // Create repository for EvoPlugin.js (plugin.js)
62
- templateRepo = 'kinsokafor/EvoPlugin.js';
63
- await createGitHubRepo(gitHubToken, templateRepo, `${pluginName}.js`);
64
-
65
- // Clone the newly created repositories
66
- cloneDir = path.join('EvoJsDev', 'Modules', pluginName);
67
- await cloneRepository(author, `${pluginName}.js`, cloneDir);
68
-
69
- var pluginPrefix = await readLineAsync("Enter Plugin Prefix?");
70
- while(!test(pluginPrefix, 3)) {
71
- pluginPrefix = await readLineAsync("Enter Plugin Prefix?");
72
- }
73
- pluginPrefix = pluginPrefix.trim().replaceAll(" ", "").toUpperCase()
74
-
75
- var entryURI = await readLineAsync("Entry URI?");
76
- while(!test(entryURI, 20)) {
77
- entryURI = await readLineAsync("Entry URI?");
78
- }
79
- entryURI = entryURI.trim().replaceAll(" ", "").toLowerCase()
80
-
81
- const entry = pluginPrefix + "Main"
82
-
83
- await editFile(`./EvoJsDev/Modules/${pluginName}/config.json`, {
84
- pluginName: pluginName,
85
- entry: entry
86
- }).then(file => {
87
- try {
88
- fs.rename(`./EvoJsDev/Modules/${pluginName}/Entry`,
89
- `./EvoJsDev/Modules/${pluginName}/${entry}`, function(err) {
90
- if ( err ) console.error('ERROR: ' + err);
91
- });
92
- } catch(e) {}
93
-
94
- const configFile = path.resolve(`./EvoJsDev/Modules/${pluginName}/config.json`)
95
- if (fs.existsSync(configFile)) {
96
- const pluginConfig = require(configFile)
97
- mergeConfig(pluginConfig)
98
- }
99
- })
100
-
101
- await editFile(`./Public/Modules/${pluginName}/Routes.php`, {
102
- pluginName: pluginName,
103
- entry: entry,
104
- entryURI: entryURI,
105
- pluginPrefix: pluginPrefix
106
- })
107
-
108
- if (fs.existsSync(path.resolve(`./Public/Modules/${pluginName}/Controller.php`))) {
109
- await editFile(`./Public/Modules/${pluginName}/Controller.php`, {
110
- pluginName: pluginName,
111
- pluginPrefix: pluginPrefix
112
- }).then(file => {
113
-
114
- fs.rename(`./Public/Modules/${pluginName}/Controller.php`,
115
- `./Public/Modules/${pluginName}/${pluginPrefix}Controller.php`, function(err) {
116
- if ( err ) console.error('ERROR: ' + err);
117
- });
118
-
119
- fs.rename(`./Public/Modules/${pluginName}/Views/Entry`,
120
- `./Public/Modules/${pluginName}/Views/${entry}`, function(err) {
121
- if ( err ) console.error('ERROR: ' + err);
122
- });
123
- })
124
- }
125
-
126
- } else if (type === 'theme') {
127
- templateRepo = 'kinsokafor/EvoTheme'; // Theme template
128
- console.log("Creating a new theme (EvoTheme)...");
129
-
130
- // Create repository for EvoTheme
131
- await createGitHubRepo(gitHubToken, templateRepo, pluginName);
132
-
133
- // Clone the newly created repositories
134
- cloneDir = path.join('Public', 'Themes', pluginName);
135
- await cloneRepository(author, pluginName, cloneDir);
136
-
137
- await editFile(`./Public/Themes/${pluginName}/Data/index.data.php`, {
138
- pluginName: pluginName
139
- })
140
-
141
- await editFile(`./Public/Themes/${pluginName}/Data/login.data.php`, {
142
- pluginName: pluginName
143
- })
144
-
145
- await editFile(`./Public/Themes/${pluginName}/Views/index.blade.php`, {
146
- pluginName: pluginName
147
- })
148
-
149
- await editFile(`./Public/Themes/${pluginName}/Views/login.blade.php`, {
150
- pluginName: pluginName
151
- })
152
- }
153
-
154
-
155
- console.log(`The ${type} "${pluginName}" has been set up successfully!`);
156
-
157
- } catch (error) {
158
- console.error("An error occurred while setting up the plugin or theme:", error.message);
159
- process.exit(1);
160
- }
161
- })();
162
-
163
- // Function to create a repository from a template
164
- async function createGitHubRepo(token, templateRepo, pluginName) {
165
- try {
166
- const response = await axios.post(
167
- `https://api.github.com/repos/${templateRepo}/generate`,
168
- {
169
- name: pluginName,
170
- private: false, // Set to true if you want the repository to be private
171
- description: `A new ${templateRepo.split('/')[1]} created from template.`,
172
- },
173
- {
174
- headers: {
175
- Authorization: `token ${token}`,
176
- 'Accept': 'application/vnd.github.v3+json',
177
- },
178
- }
179
- );
180
-
181
- if (response.status === 201) {
182
- console.log(`Successfully created the repository: ${pluginName} from ${templateRepo}`);
183
- } else {
184
- console.error('Failed to create the repository:', response.data);
185
- process.exit(1);
186
- }
187
- } catch (error) {
188
- console.error(`Error creating repository from ${templateRepo}:`, error.message);
189
- process.exit(1);
190
- }
191
- }
192
-
193
- // Function to clone the newly created repository with retry mechanism
194
- async function cloneRepository(author, pluginName, cloneDir) {
195
- try {
196
- const cloneUrl = `https://github.com/${author}/${pluginName}.git`;
197
-
198
- // Ensure directories do not exist before cloning
199
- if (fs.existsSync(cloneDir)) {
200
- console.log(`The plugin "${pluginName}" already exists in the directory. Exiting.`);
201
- return;
202
- }
203
-
204
- console.log(`Cloning ${author}/${pluginName}.git from GitHub...`);
205
-
206
- let retries = 5;
207
- while (retries > 0) {
208
- try {
209
- if (fs.existsSync(cloneDir)) {
210
- console.log(`The directory "${cloneDir}" already exists. Deleting it...`);
211
-
212
- // Use rimraf to delete the directory and its contents
213
- rimraf.sync(cloneDir);
214
- console.log(`The directory "${cloneDir}" was deleted.`);
215
- }
216
- execSync(`git clone ${cloneUrl} ${cloneDir}`, { stdio: 'inherit' });
217
-
218
- // Check if the cloned repository is non-empty
219
- const files = fs.readdirSync(cloneDir).filter(file => file !== '.git');
220
- if (files.length > 0) {
221
- console.log(`Cloned the repository ${pluginName} successfully.`);
222
- return;
223
- } else {
224
- console.warn("Repository appears to be empty. Retrying...");
225
- retries--;
226
- await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds before retrying
227
- }
228
- } catch (error) {
229
- console.error(`Error during cloning attempt: ${error.message}`);
230
- retries--;
231
- if (retries > 0) {
232
- console.log(`Retrying... (${5 - retries}/5)`);
233
- await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds before retrying
234
- }
235
- }
236
- }
237
-
238
- console.error(`Failed to clone the repository ${pluginName} after multiple attempts.`);
239
- process.exit(1);
240
- } catch (error) {
241
- console.error(`Unexpected error while cloning the repository ${pluginName}:`, error.message);
242
- process.exit(1);
243
- }
244
- }
245
-
246
- // Function to get user details from GitHub API
247
- async function getUserData(token) {
248
- try {
249
- const response = await axios.get('https://api.github.com/user', {
250
- headers: {
251
- Authorization: `token ${token}`,
252
- 'Accept': 'application/vnd.github.v3+json',
253
- },
254
- });
255
- return response.data;
256
- } catch (error) {
257
- console.error('Error fetching user data from GitHub:', error.message);
258
- process.exit(1);
259
- }
260
- }
261
-
262
- const editFile = async (file, data) => {
263
- return new Promise((resolve, reject) => {
264
- fs.readFile(file, 'utf8', (err, fileData) => {
265
- if (err) {
266
- console.error('Error reading color scheme file:', err);
267
- reject(err)
268
- return;
269
- }
270
- for(var i in data) {
271
- fileData = fileData.replaceAll(`<${i}>`, data[i])
272
- }
273
- // Write the content to the destination file
274
- fs.writeFile(file, fileData, 'utf8', (err) => {
275
- if (err) {
276
- console.error('Error writing color scheme file:', err);
277
- reject(err)
278
- return;
279
- }
280
- console.log(`${file} file created successfully.`);
281
- resolve(file);
282
- });
283
- });
284
- })
285
- }
286
-
287
- const test = (str, maxLength) => {
288
- str = str.trim().replaceAll(" ", "")
289
- if(str.length > maxLength) {
290
- console.error(`Your input cannot be longer than ${maxLength} characters`);
291
- return false
292
- }
293
- if(str.length < 1) {
294
- console.error(`You have not made any entry`);
295
- return false
296
- }
297
- return str;
298
- }
package/uninstall.js DELETED
@@ -1,65 +0,0 @@
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
- })();