-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.php
55 lines (41 loc) · 1.85 KB
/
init.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
<?php
fwrite(\STDOUT, "Enter an extension name:\n");
$fh = fopen('php://stdin', 'r');
$name = trim(fgets($fh));
fclose($fh);
$nameLabel = $name;
$name = ucfirst($name);
$name = str_replace(' ', '', ucwords(preg_replace('/^a-z0-9]+/', ' ', $name)));
$nameHyphen = strtolower(preg_replace('/(?<!^)[A-Z]/', '-$0', $name));
fwrite(\STDOUT, "Enter a description text:\n");
$fh = fopen('php://stdin', 'r');
$description = trim(fgets($fh));
fclose($fh);
if (substr($description, -1) !== '.') $description .= '.';
fwrite(\STDOUT, "Enter an author name:\n");
$fh = fopen('php://stdin', 'r');
$author = trim(fgets($fh));
fclose($fh);
$replacePlaceholders = function (string $file) use ($name, $nameHyphen, $nameLabel, $description, $author)
{
$content = file_get_contents($file);
$content = str_replace('{@name}', $name, $content);
$content = str_replace('{@nameHyphen}', $nameHyphen, $content);
$content = str_replace('{@nameLabel}', $nameLabel, $content);
$content = str_replace('{@description}', $description, $content);
$content = str_replace('{@author}', $author, $content);
file_put_contents($file, $content);
};
$replacePlaceholders('.vscode/settings.json');
$replacePlaceholders('.eslintrc.json');
$replacePlaceholders('package.json');
$replacePlaceholders('extension.json');
$replacePlaceholders('config-default.json');
$replacePlaceholders('README.md');
$replacePlaceholders('NOTICE');
$replacePlaceholders('composer.json');
rename('src/files/application/Espo/Modules/MyModuleName', 'src/files/application/Espo/Modules/'. $name);
rename('src/files/client/modules/my-module-name', 'src/files/client/modules/'. $nameHyphen);
rename('tests/unit/Espo/Modules/MyModuleName', 'tests/unit/Espo/Modules/'. $name);
rename('tests/integration/Espo/Modules/MyModuleName', 'tests/integration/Espo/Modules/'. $name);
echo "Ready. Now you need to run 'npm install'.\n";