From c6bd019d52175249cd66cc7916678f4bc63e2c0a Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Sun, 19 Jan 2020 15:36:00 +0100 Subject: [PATCH] script to convert app.js to TypeScript --- doc/js2ts.php | 193 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100755 doc/js2ts.php 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', <<