Repository navigation
Expand file tree
/
Copy pathinit.php
More file actions
86 lines (68 loc) · 2.21 KB
/
Copy pathinit.php
File metadata and controls
86 lines (68 loc) · 2.21 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?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 (!str_ends_with($description, '.')) {
$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 = strtr($content, [
'{@name}' => $name,
'{@nameHyphen}' => $nameHyphen,
'{@nameLabel}' => $nameLabel,
'{@description}' => $description,
'{@author}' => $author,
'{@bundled}' => 'true',
'{@jsTranspiled}' => 'true',
]);
file_put_contents($file, $content);
};
$files = [
'package.json',
'extension.json',
'jsconfig.json',
'tsconfig.json',
'config-default.json',
'phpstan.neon',
'composer.json',
'README.md',
'src/files/custom/Espo/Modules/MyModuleName/Resources/module.json',
'.github/workflows/test.yml.disabled',
];
foreach ($files as $file) {
$replacePlaceholders($file);
}
$content = <<<CLIENT_JSON
{
"scriptList": [
"__APPEND__",
"client/custom/modules/{@nameHyphen}/lib/init.js"
]
}
CLIENT_JSON;
$path = 'src/files/custom/Espo/Modules/MyModuleName/Resources/metadata/app/';
mkdir($path, 0755, true);
$path .= "client.json";
file_put_contents($path, $content);
$replacePlaceholders($path);
rename('src/files/custom/Espo/Modules/MyModuleName', 'src/files/custom/Espo/Modules/'. $name);
rename('src/files/client/custom/modules/my-module-name', 'src/files/client/custom/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";