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/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
- })();