-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrename-project.php
More file actions
63 lines (50 loc) · 1.85 KB
/
rename-project.php
File metadata and controls
63 lines (50 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
//use => php rename-project.php string_to_replace
if (isset($argc)) {
for ($i = 0; $i < $argc; $i++) {
echo 'Argument #' . $i . ' - ' . $argv[$i] . "\n";
}
} else {
echo "argc and argv disabled\n";
return;
}
if (!isset($argv[1])) {
$argv[1] = basename(getcwd());
echo 'Name project: ' . $argv[1] . "\n";
}
function replaceStringInFile($filename, $stringToReplace, $replaceWith)
{
$content = file_get_contents($filename);
$content_chunks = explode($stringToReplace, $content);
$content = implode($replaceWith, $content_chunks);
file_put_contents($filename, $content);
}
function searchDirectoryFiles($path, $stringToReplace, $replaceWith)
{
if (is_dir($path)) {
if ($dh = opendir($path)) {
while (($file = readdir($dh)) !== false) {
if (is_dir($path . $file) && $file != "." && $file != ".." && strpos($file, 'node_modules') === false && strpos($file, '.git') === false) {
searchDirectoryFiles($path . $file . '/', $stringToReplace, $replaceWith);
} else if (!is_dir($path . $file)) {
echo "\n Replacing: $path$file";
replaceStringInFile($path . $file, $stringToReplace, $replaceWith);
}
}
closedir($dh);
}
} else {
echo "\n Invalid path...";
}
}
function dashesToCamelCase($string, $capitalizeFirstCharacter = false, $replace = '')
{
$str = str_replace('-', $replace, ucwords($string, '-'));
if (!$capitalizeFirstCharacter) {
$str = lcfirst($str);
}
return $str;
}
searchDirectoryFiles(getcwd() . '/', 'package-skeleton', $argv[1]);
searchDirectoryFiles(getcwd() . '/', 'PackageSkeleton', dashesToCamelCase($argv[1], true));
searchDirectoryFiles(getcwd() . '/', 'Package Skeleton', dashesToCamelCase($argv[1], true, ' '));