-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost_create_project.php
61 lines (48 loc) · 2 KB
/
post_create_project.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
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
file_put_contents(__DIR__ . '/Readme.md', <<<PHP
## Local development
See https://github.com/simplia/integration/blob/master/docs/local.md
PHP
);
$composer = json_decode(file_get_contents(__DIR__ . '/composer.json'), true, 512, JSON_THROW_ON_ERROR);
unset($composer['scripts']);
do {
$authorName = readline('Author name: ');
if (!preg_match('~^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]?|-{0,2})[a-z0-9]+)*$~', $authorName)) {
echo 'Invalid namespace/name' . PHP_EOL;
$projectName = null;
}
} while (empty($authorName));
do {
$authorEmail = readline('Author email: ');
if (!filter_var($authorEmail, FILTER_VALIDATE_EMAIL)) {
echo 'Invalid email' . PHP_EOL;
$authorEmail = null;
}
} while (empty($authorEmail));
do {
$projectName = readline('Project namespace/name: ');
// https://getcomposer.org/doc/04-schema.md#name
if (!preg_match('~^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]?|-{0,2})[a-z0-9]+)*$~', $projectName)) {
echo 'Invalid namespace/name' . PHP_EOL;
$projectName = null;
}
} while (empty($projectName));
$description = readline('Project description: ');
$composer['name'] = $projectName;
$composer['description'] = $description;
$composer['authors'] = [
[
'name' => $authorName,
'email' => $authorEmail,
],
];
file_put_contents(__DIR__ . '/composer.json', json_encode($composer, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL);
file_put_contents(__DIR__ . '/manifest.xml', str_replace('%description%', htmlspecialchars($description), file_get_contents(__DIR__ . '/manifest.xml')));
if (!mkdir($concurrentDirectory = __DIR__ . '/src') && !is_dir($concurrentDirectory)) {
throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
}
if (!mkdir($concurrentDirectory = __DIR__ . '/tests') && !is_dir($concurrentDirectory)) {
throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
}
unlink(__FILE__);