Skip to content

Commit b5a2036

Browse files
authored
Merge pull request #68 from Sekiro-kost/master
new script for rename template by new pluginId
2 parents 6a35720 + f4a87c9 commit b5a2036

File tree

2 files changed

+229
-2
lines changed

2 files changed

+229
-2
lines changed
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
<?php
2+
3+
4+
$scriptFileName = basename(__FILE__);
5+
6+
7+
function replacePluginIdInFiles($directory, $newId) {
8+
global $scriptFileName;
9+
$oldId = 'template';
10+
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
11+
12+
foreach ($files as $file) {
13+
if ($file->isFile()) {
14+
15+
$fileName = $file->getFilename();
16+
if ($fileName === $scriptFileName) {
17+
continue;
18+
}
19+
20+
$filePath = $file->getRealPath();
21+
$fileContents = file_get_contents($filePath);
22+
23+
$lines = explode(PHP_EOL, $fileContents);
24+
foreach ($lines as &$line) {
25+
if (strpos($line, "include_file('core', 'plugin.template', 'js');") === false) {
26+
$line = str_replace($oldId, $newId, $line);
27+
}
28+
}
29+
$fileContents = implode(PHP_EOL, $lines);
30+
31+
file_put_contents($filePath, $fileContents);
32+
}
33+
}
34+
}
35+
36+
function renameFiles($directory, $newId) {
37+
global $scriptFileName;
38+
$oldId = 'template';
39+
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
40+
41+
foreach ($files as $file) {
42+
if ($file->isFile()) {
43+
$filePath = $file->getRealPath();
44+
$fileName = $file->getFilename();
45+
46+
if (strpos($fileName, $oldId) !== false) {
47+
$newFileName = str_replace($oldId, $newId, $fileName);
48+
$newFilePath = $file->getPath() . DIRECTORY_SEPARATOR . $newFileName;
49+
rename($filePath, $newFilePath);
50+
}
51+
}
52+
}
53+
}
54+
55+
function processDirectories($directories, $newId) {
56+
foreach ($directories as $directory) {
57+
replacePluginIdInFiles($directory, $newId);
58+
renameFiles($directory, $newId);
59+
}
60+
}
61+
62+
$pathInfoJson = __DIR__ . '/info.json';
63+
$jsonContent = file_get_contents($pathInfoJson);
64+
$dataJson = json_decode($jsonContent, true);
65+
66+
67+
echo "Quel est le nom de votre plugin ? ";
68+
$namePlugin = trim(fgets(STDIN));
69+
70+
71+
if ($namePlugin !== '') {
72+
$dataJson['name'] = $namePlugin;
73+
echo "Plugin renommé.\n";
74+
}
75+
76+
echo "Choisissez la catégorie de votre plugin :\n";
77+
echo "1. Securité\n";
78+
echo "2. Protocole Domotique\n";
79+
echo "3. Passereille Domotique\n";
80+
echo "4. Programmation\n";
81+
echo "5. Organisation\n";
82+
echo "6. Météo\n";
83+
echo "7. Communication\n";
84+
echo "8. Objets connectés\n";
85+
echo "9. Multimédia\n";
86+
echo "10. Confort\n";
87+
echo "11. Monitoring\n";
88+
echo "12. Santé\n";
89+
echo "13. Nature\n";
90+
echo "14. Automatisme\n";
91+
echo "15. Energie\n";
92+
echo "16. Autre\n";
93+
94+
$categoryChoice = trim(fgets(STDIN));
95+
96+
switch ($categoryChoice) {
97+
case '1':
98+
$dataJson['category'] = 'security';
99+
break;
100+
case '2':
101+
$dataJson['category'] = 'automation protocol';
102+
break;
103+
case '3':
104+
$dataJson['category'] = 'home automation protocol';
105+
break;
106+
case '4':
107+
$dataJson['category'] = 'programming';
108+
break;
109+
case '5':
110+
$dataJson['category'] = 'organization';
111+
break;
112+
case '6':
113+
$dataJson['category'] = 'weather';
114+
break;
115+
case '7':
116+
$dataJson['category'] = 'communication';
117+
break;
118+
case '8':
119+
$dataJson['category'] = 'devicecommunication';
120+
break;
121+
case '9':
122+
$dataJson['category'] = 'multimedia';
123+
break;
124+
case '10':
125+
$dataJson['category'] = 'wellness';
126+
break;
127+
case '11':
128+
$dataJson['category'] = 'monitoring';
129+
break;
130+
case '12':
131+
$dataJson['category'] = 'health';
132+
break;
133+
case '13':
134+
$dataJson['category'] = 'nature';
135+
break;
136+
case '14':
137+
$dataJson['category'] = 'automatisation';
138+
break;
139+
case '15':
140+
$dataJson['category'] = 'energy';
141+
break;
142+
case '16':
143+
$dataJson['category'] = 'other';
144+
break;
145+
default:
146+
echo "Choix invalide. La catégorie par défaut 'programming' sera utilisée.\n";
147+
$data['category'] = 'programming';
148+
break;
149+
}
150+
151+
// echo "Vous avez choisir la catégorie '$categoryChoice'.\n";
152+
153+
echo "Votre plugin possede t-il un démon ? (oui/non) : ";
154+
$demonResponse = trim(fgets(STDIN));
155+
156+
if (strtolower($demonResponse) === 'oui' || strtolower($demonResponse) === 'o') {
157+
158+
$dataJson['hasOwnDeamon'] = true;
159+
echo "La prise en compte du démon est activée.\n";
160+
} else {
161+
echo "Vous avez entré '$demonResponse'. Confirmez-vous cette modification ? (oui/non) : ";
162+
$confirmationDemon = trim(fgets(STDIN));
163+
164+
if (strtolower($confirmationDemon) === 'oui' || strtolower($confirmationDemon) === 'o') {
165+
echo "Suppression du repertoire démon.\n";
166+
$demonDirectory = __DIR__ . '/../resources';
167+
$files = new RecursiveIteratorIterator(
168+
new RecursiveDirectoryIterator($demonDirectory, RecursiveDirectoryIterator::SKIP_DOTS),
169+
RecursiveIteratorIterator::CHILD_FIRST
170+
);
171+
foreach ($files as $file) {
172+
if ($file->isFile()) {
173+
unlink($file->getRealPath());
174+
} elseif ($file->isDir()) {
175+
rmdir($file->getRealPath());
176+
}
177+
}
178+
rmdir($demonDirectory);
179+
}
180+
}
181+
182+
echo "Votre plugin possede t-il des dépendances ? (oui/non) : ";
183+
$dependancyResponse = trim(fgets(STDIN));
184+
185+
186+
187+
if (strtolower($dependancyResponse) === 'oui' || strtolower($dependancyResponse) === 'o') {
188+
189+
$dataJson['hasDependency'] = true;
190+
echo "La prise en compte des dépendances est activée.\n";
191+
}
192+
193+
194+
echo "Quel est l'ID du plugin : ";
195+
$newId = trim(fgets(STDIN));
196+
197+
echo "Vous avez entré '$newId'. Confirmez-vous cette modification ? (oui/non) : ";
198+
$confirmation = trim(fgets(STDIN));
199+
200+
201+
if (strtolower($confirmation) === 'oui' || strtolower($confirmation) === 'o') {
202+
203+
$dataJson['id'] = $newId;
204+
205+
$dataJson['changelog_beta'] = str_replace('template', $newId, $dataJson['changelog_beta']);
206+
$dataJson['changelog'] = str_replace('template', $newId, $dataJson['changelog']);
207+
$dataJson['documentation_beta'] = str_replace('template', $newId, $dataJson['documentation_beta']);
208+
$dataJson['documentation'] = str_replace('template', $newId, $dataJson['documentation']);
209+
210+
$directories = [
211+
__DIR__ . '/../core/class',
212+
__DIR__ . '/../desktop',
213+
__DIR__ . '/../core/php',
214+
__DIR__ . '/../desktop/modal',
215+
__DIR__ . '/../desktop/php',
216+
__DIR__ . '/../desktop/js',
217+
__DIR__ ,
218+
];
219+
220+
processDirectories($directories, $newId);
221+
echo "L'ID du plugin a été remplacé et les fichiers ont été renommés avec succès.\n";
222+
} else {
223+
echo "Modification annulée.\n";
224+
}
225+
226+
$newJsonContent = json_encode($dataJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
227+
file_put_contents($pathInfoJson, $newJsonContent);

plugin_info/packages.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
"requests" : {"reinstall" : true}
99
},
1010
"npm": {
11-
"plugins/template/ressources/demaond" : {}
11+
"plugins/template/ressources/demond" : {}
1212
},
1313
"composer": {
1414
"plugins/template" : {}
1515
},
1616
"yarn": {
17-
"plugins/template/ressources/demaond" : {}
17+
"plugins/template/ressources/demond" : {}
1818
},
1919
"plugin": {
2020
},

0 commit comments

Comments
 (0)