evophp 1.0.20 → 1.0.22
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 +117 -19
- package/package.json +1 -1
package/new-plugin.js
CHANGED
|
@@ -29,7 +29,7 @@ const { readLineAsync, splitPluginName } = require(helpersPath);
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// Validate name and split it into author and item name
|
|
32
|
-
const [author,
|
|
32
|
+
const [author, pluginName] = await splitPluginName(name);
|
|
33
33
|
|
|
34
34
|
// Validate PAT by checking the authenticated user's username
|
|
35
35
|
const userData = await getUserData(gitHubToken);
|
|
@@ -48,34 +48,107 @@ const { readLineAsync, splitPluginName } = require(helpersPath);
|
|
|
48
48
|
console.log("Creating a new plugin (EvoPlugin and EvoPlugin.js)...");
|
|
49
49
|
|
|
50
50
|
// Create repository for EvoPlugin
|
|
51
|
-
await createGitHubRepo(gitHubToken, templateRepo,
|
|
51
|
+
await createGitHubRepo(gitHubToken, templateRepo, pluginName);
|
|
52
52
|
|
|
53
53
|
// Clone the newly created repositories
|
|
54
|
-
cloneDir = path.join('Public', 'Modules',
|
|
55
|
-
await cloneRepository(author,
|
|
54
|
+
cloneDir = path.join('Public', 'Modules', pluginName);
|
|
55
|
+
await cloneRepository(author, pluginName, cloneDir);
|
|
56
56
|
|
|
57
57
|
// Create repository for EvoPlugin.js (plugin.js)
|
|
58
58
|
templateRepo = 'kinsokafor/EvoPlugin.js';
|
|
59
|
-
await createGitHubRepo(gitHubToken, templateRepo, `${
|
|
59
|
+
await createGitHubRepo(gitHubToken, templateRepo, `${pluginName}.js`);
|
|
60
60
|
|
|
61
61
|
// Clone the newly created repositories
|
|
62
|
-
cloneDir = path.join('EvoJsDev', 'Modules',
|
|
63
|
-
await cloneRepository(author,
|
|
62
|
+
cloneDir = path.join('EvoJsDev', 'Modules', pluginName);
|
|
63
|
+
await cloneRepository(author, pluginName, cloneDir);
|
|
64
|
+
|
|
65
|
+
var pluginPrefix = await readLineAsync("Enter Plugin Prefix?");
|
|
66
|
+
while(!test(pluginPrefix, 3)) {
|
|
67
|
+
pluginPrefix = await readLineAsync("Enter Plugin Prefix?");
|
|
68
|
+
}
|
|
69
|
+
pluginPrefix = pluginPrefix.trim().replaceAll(" ", "").toUpperCase()
|
|
70
|
+
|
|
71
|
+
var entryURI = await readLineAsync("Entry URI?");
|
|
72
|
+
while(!test(entryURI, 20)) {
|
|
73
|
+
entryURI = await readLineAsync("Entry URI?");
|
|
74
|
+
}
|
|
75
|
+
entryURI = entryURI.trim().replaceAll(" ", "").toLowerCase()
|
|
76
|
+
|
|
77
|
+
const entry = pluginPrefix + "Main"
|
|
78
|
+
|
|
79
|
+
await editFile(`./EvoJsDev/Modules/${pluginName}/config.json`, {
|
|
80
|
+
pluginName: pluginName,
|
|
81
|
+
entry: entry
|
|
82
|
+
}).then(file => {
|
|
83
|
+
try {
|
|
84
|
+
fs.rename(`./EvoJsDev/Modules/${pluginName}/Entry`,
|
|
85
|
+
`./EvoJsDev/Modules/${pluginName}/${entry}`, function(err) {
|
|
86
|
+
if ( err ) console.error('ERROR: ' + err);
|
|
87
|
+
});
|
|
88
|
+
} catch(e) {}
|
|
89
|
+
|
|
90
|
+
const configFile = path.resolve(__dirname, `./EvoJsDev/Modules/${pluginName}/config.json`)
|
|
91
|
+
if (fs.existsSync(configFile)) {
|
|
92
|
+
const pluginConfig = require(configFile)
|
|
93
|
+
mergeConfig(pluginConfig)
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
await editFile(`./Public/Modules/${pluginName}/Routes.php`, {
|
|
98
|
+
pluginName: pluginName,
|
|
99
|
+
entry: entry,
|
|
100
|
+
entryURI: entryURI,
|
|
101
|
+
pluginPrefix: pluginPrefix
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
if (fs.existsSync(path.resolve(__dirname, `./Public/Modules/${pluginName}/Controller.php`))) {
|
|
105
|
+
await editFile(`./Public/Modules/${pluginName}/Controller.php`, {
|
|
106
|
+
pluginName: pluginName,
|
|
107
|
+
pluginPrefix: pluginPrefix
|
|
108
|
+
}).then(file => {
|
|
109
|
+
|
|
110
|
+
fs.rename(`./Public/Modules/${pluginName}/Controller.php`,
|
|
111
|
+
`./Public/Modules/${pluginName}/${pluginPrefix}Controller.php`, function(err) {
|
|
112
|
+
if ( err ) console.error('ERROR: ' + err);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
fs.rename(`./Public/Modules/${pluginName}/Views/Entry`,
|
|
116
|
+
`./Public/Modules/${pluginName}/Views/${entry}`, function(err) {
|
|
117
|
+
if ( err ) console.error('ERROR: ' + err);
|
|
118
|
+
});
|
|
119
|
+
})
|
|
120
|
+
}
|
|
64
121
|
|
|
65
122
|
} else if (type === 'theme') {
|
|
66
123
|
templateRepo = 'kinsokafor/EvoTheme'; // Theme template
|
|
67
124
|
console.log("Creating a new theme (EvoTheme)...");
|
|
68
125
|
|
|
69
126
|
// Create repository for EvoTheme
|
|
70
|
-
await createGitHubRepo(gitHubToken, templateRepo,
|
|
127
|
+
await createGitHubRepo(gitHubToken, templateRepo, pluginName);
|
|
71
128
|
|
|
72
129
|
// Clone the newly created repositories
|
|
73
|
-
cloneDir = path.join('Public', 'Themes',
|
|
74
|
-
await cloneRepository(author,
|
|
130
|
+
cloneDir = path.join('Public', 'Themes', pluginName);
|
|
131
|
+
await cloneRepository(author, pluginName, cloneDir);
|
|
132
|
+
|
|
133
|
+
await editFile(`./Public/Themes/${pluginName}/Data/index.data.php`, {
|
|
134
|
+
pluginName: pluginName
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
await editFile(`./Public/Themes/${pluginName}/Data/login.data.php`, {
|
|
138
|
+
pluginName: pluginName
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
await editFile(`./Public/Themes/${pluginName}/Views/index.blade.php`, {
|
|
142
|
+
pluginName: pluginName
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
await editFile(`./Public/Themes/${pluginName}/Views/login.blade.php`, {
|
|
146
|
+
pluginName: pluginName
|
|
147
|
+
})
|
|
75
148
|
}
|
|
76
149
|
|
|
77
150
|
|
|
78
|
-
console.log(`The ${type} "${
|
|
151
|
+
console.log(`The ${type} "${pluginName}" has been set up successfully!`);
|
|
79
152
|
|
|
80
153
|
} catch (error) {
|
|
81
154
|
console.error("An error occurred while setting up the plugin or theme:", error.message);
|
|
@@ -84,12 +157,12 @@ const { readLineAsync, splitPluginName } = require(helpersPath);
|
|
|
84
157
|
})();
|
|
85
158
|
|
|
86
159
|
// Function to create a repository from a template
|
|
87
|
-
async function createGitHubRepo(token, templateRepo,
|
|
160
|
+
async function createGitHubRepo(token, templateRepo, pluginName) {
|
|
88
161
|
try {
|
|
89
162
|
const response = await axios.post(
|
|
90
163
|
`https://api.github.com/repos/${templateRepo}/generate`,
|
|
91
164
|
{
|
|
92
|
-
name:
|
|
165
|
+
name: pluginName,
|
|
93
166
|
private: false, // Set to true if you want the repository to be private
|
|
94
167
|
description: `A new ${templateRepo.split('/')[1]} created from template.`,
|
|
95
168
|
},
|
|
@@ -102,7 +175,7 @@ async function createGitHubRepo(token, templateRepo, itemName) {
|
|
|
102
175
|
);
|
|
103
176
|
|
|
104
177
|
if (response.status === 201) {
|
|
105
|
-
console.log(`Successfully created the repository: ${
|
|
178
|
+
console.log(`Successfully created the repository: ${pluginName} from ${templateRepo}`);
|
|
106
179
|
} else {
|
|
107
180
|
console.error('Failed to create the repository:', response.data);
|
|
108
181
|
process.exit(1);
|
|
@@ -114,22 +187,22 @@ async function createGitHubRepo(token, templateRepo, itemName) {
|
|
|
114
187
|
}
|
|
115
188
|
|
|
116
189
|
// Function to clone the newly created repository
|
|
117
|
-
async function cloneRepository(author,
|
|
190
|
+
async function cloneRepository(author, pluginName, cloneDir) {
|
|
118
191
|
try {
|
|
119
192
|
// Ensure directories do not exist before cloning
|
|
120
193
|
if (fs.existsSync(cloneDir)) {
|
|
121
|
-
console.log(`The plugin "${
|
|
194
|
+
console.log(`The plugin "${pluginName}" already exists in the directory. Exiting.`);
|
|
122
195
|
process.exit(0);
|
|
123
196
|
}
|
|
124
197
|
|
|
125
|
-
const cloneUrl = `https://github.com/${author}/${
|
|
198
|
+
const cloneUrl = `https://github.com/${author}/${pluginName}.git`;
|
|
126
199
|
|
|
127
200
|
console.log(`Cloning the newly created repository from GitHub...`);
|
|
128
201
|
execSync(`git clone ${cloneUrl} ${cloneDir}`, { stdio: 'inherit' });
|
|
129
202
|
|
|
130
|
-
console.log(`Cloned the repository ${
|
|
203
|
+
console.log(`Cloned the repository ${pluginName} successfully.`);
|
|
131
204
|
} catch (error) {
|
|
132
|
-
console.error(`Error cloning the repository ${
|
|
205
|
+
console.error(`Error cloning the repository ${pluginName}:`, error.message);
|
|
133
206
|
process.exit(1);
|
|
134
207
|
}
|
|
135
208
|
}
|
|
@@ -149,3 +222,28 @@ async function getUserData(token) {
|
|
|
149
222
|
process.exit(1);
|
|
150
223
|
}
|
|
151
224
|
}
|
|
225
|
+
|
|
226
|
+
const editFile = async (file, data) => {
|
|
227
|
+
return new Promise((resolve, reject) => {
|
|
228
|
+
fs.readFile(file, 'utf8', (err, fileData) => {
|
|
229
|
+
if (err) {
|
|
230
|
+
console.error('Error reading color scheme file:', err);
|
|
231
|
+
reject(err)
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
for(var i in data) {
|
|
235
|
+
fileData = fileData.replaceAll(`<${i}>`, data[i])
|
|
236
|
+
}
|
|
237
|
+
// Write the content to the destination file
|
|
238
|
+
fs.writeFile(file, fileData, 'utf8', (err) => {
|
|
239
|
+
if (err) {
|
|
240
|
+
console.error('Error writing color scheme file:', err);
|
|
241
|
+
reject(err)
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
console.log(`${file} file created successfully.`);
|
|
245
|
+
resolve(file);
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
})
|
|
249
|
+
}
|