diff --git a/doc/js2ts.php b/doc/js2ts.php new file mode 100755 index 0000000000..41c75730bf --- /dev/null +++ b/doc/js2ts.php @@ -0,0 +1,193 @@ +#!/usr/bin/env php + + * @copyright 2020 by Ralf Becker + */ + +if (PHP_SAPI !== 'cli') // security precaution: forbit calling as web-page +{ + die('

fix_api.php must NOT be called as web-page --> exiting !!!

'); +} + +// raw replacements +$replace = array( + '/^app.classes.([a-z0-9_]+)(\s*=\s*AppJS.extend)\(.*^}\);/misU' => + function($matches) { + return strtr($matches[0], [ + 'app.classes.'.$matches[1].$matches[2].'(' => 'class '.ucfirst($matches[1]).'App extends EgwApp', + "\n});" => "\n}\n\napp.classes.$matches[1] = ".ucfirst($matches[1])."App;" + ]); + }, + "/^\tappname:\s*'([^']+)',/m" => "\treadonly appname: '$1';", + "/^\t([^: ,;(]+):\s*([^()]+),/m" => "\t\$1: $2;", + "/^\t([^:\n]+):\s*function\s*\(.*this._super.(apply|call)\(/msU" => + function($matches) { + return str_replace('this._super', + $matches[1] === 'init' ? 'super' : 'super.'.$matches[1], $matches[0]); + }, + "/^\t([^:\n]+):\s*function\s*\(/m" => function($matches) { + return "\t".($matches[1] === 'init' ? 'constructor' : $matches[1]).'('; + }, + "/^\t},$/m" => "\t}", + '/^ \* @version \$Id\$\n/m' => '', + '#^ \* @link http://www.egroupware.org#m' => ' * @link: https://www.egroupware.org', +); + +/** + * Add boilerplate for app.js files after header + * + * @param $app + * @param $content + * @return string + */ +function app_js_add($app, $content) +{ + return preg_replace('#^(/\*\*.*\n\ \*/)#Us', <<