-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.php
48 lines (37 loc) · 1.39 KB
/
install.php
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
<?php
$package_name = basename(__DIR__);
$class_name = str_replace('-', '', ucwords($package_name, '-'));
//Replace content and rename classes
foreach ([
'/composer.json',
'/README.md',
'/src/Skeleton.php',
'/tests/SkeletonTest.php',
'/phpunit.xml.dist',
] as $file) {
$content = file_get_contents(__DIR__.$file);
$content = str_replace('skeleton', $package_name, $content);
$content = str_replace('Skeleton', $class_name, $content);
if ($file === '/README.md') {
//Remove the note in README.md
$content = explode('---', $content, 2);
$content = ltrim($content[1]);
}
file_put_contents(__DIR__.$file, $content);
//Rename Skeleton classes
if (strpos($file, 'Skeleton') !== false) {
$newFile = str_replace('Skeleton', $class_name, $file);
rename(__DIR__.$file, __DIR__.$newFile);
}
}
//Supersede .gitattributes
unlink('.gitattributes');
rename('.gitattributes.skeleton', '.gitattributes');
$composer = json_decode(file_get_contents(__DIR__.'/composer.json'), true);
//Remove the "post-create-project-cmd" composer script
unset($composer['scripts']['post-create-project-cmd']);
//Remove the "template" keyword
array_shift($composer['keywords']);
file_put_contents(__DIR__.'/composer.json', json_encode($composer, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
//Remove myself
unlink(__FILE__);