-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert-extemconf-to-composer.php
executable file
·57 lines (50 loc) · 1.66 KB
/
convert-extemconf-to-composer.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
<?php
/**
* Convert a TYPO3 extension declaration file (ext_emconf.php) to a
* Composer file (composer.json)
*
* Example usage
*
* php convert-extemconf-to-composer.php /path/to/extension/
*
* Example with given Composer vendorname
*
* php convert-extemconf-to-composer.php /path/to/extension/ Your-Vendorname
*/
if(empty($argv[1])) {
die('Missing argument');
}
if(false === is_dir($argv[1])) {
die('No valid path');
}
if(true === is_file($argv[1] . 'composer.json')) {
die('composer.json already exists');
}
$_EXTKEY = basename($argv[1]);
require $argv[1] . 'ext_emconf.php';
$emconf = $EM_CONF[$_EXTKEY];
$vendor = ucwords($argv[2] ?? 'Your-Vendorname', '-_ ') ;
$package = preg_replace('/[_ ]/', '-', strtolower($vendor . '/' . $_EXTKEY));
$namespace = $vendor . '\\' . preg_replace('/[^A-Za-z0-9]/', '', ucwords($_EXTKEY, '-_ ')) . '\\';
$composer = [
'name' => $package,
'description' => $emconf['title'] . ($emconf['description']? ' – ' . $emconf['description'] : ''),
'license' => 'GPL-2.0+',
'type' => 'typo3-cms-extension',
'require' => [
'php' => '>=7.0.0',
'typo3/cms-core' => '^7.6 || ^8.7'
],
'autoload' => [
'psr-4' => [$namespace => 'Classes/']
],
'replace' => [
$_EXTKEY => 'self.version',
'typo3-ter/' . $_EXTKEY => 'self.version'
]
];
$output = json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
file_put_contents($argv[1] . 'composer.json', $output);
echo 'Converted ext_emconf.php into composer.json.' . PHP_EOL;
echo 'Adopt the file to your own needs (eg. modify dependencies)' . PHP_EOL;
exit(1);