From 0bd8bd37ccfbf5f9437a31a2898c8114228ce17d Mon Sep 17 00:00:00 2001 From: Anthony Andriano Date: Tue, 26 Sep 2023 13:20:43 -0600 Subject: [PATCH 1/6] added es6 support to init.php --- README.md | 16 +---------- extension.json | 2 +- init.php | 28 ++++++++++++++++++- .../MyModuleName/Resources/module.json | 4 +-- 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index e645bda..e206641 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Run: php init.php ``` -It will ask to enter an extension name and some other information. +It will ask to enter an extension name and some other information. As of v8.0, `init.php` will ask if you want to use ES6 for frontend code. After that, you can remove `init.php` file from your respository. Commit changes and proceed to configuration & building. @@ -230,21 +230,7 @@ You need to set the following paths to be ignored in your IDE: * `site/tests/unit/Espo/Modules/{@name}` * `site/tests/integration/Espo/Modules/{@name}` -## Using ES modules -*As of v8.0.* - -1. Set *bundled* to true in `extension.json`. -2. Set *bundled* and *jsTranspiled* to true in `src/files/custom/Espo/Modules/{@name}/Resources/module.json`. -3. Add `src/files/custom/Espo/Modules/{@name}/Resources/metadata/app/client.json` - ```json - { - "scriptList": [ - "__APPEND__", - "client/custom/modules/{@nameHyphen}/lib/init.js" - ] - } - ``` ## License diff --git a/extension.json b/extension.json index 448de8d..ea0563c 100644 --- a/extension.json +++ b/extension.json @@ -3,7 +3,7 @@ "name": "{@nameLabel}", "description": "{@description}", "author": "{@author}", - "bundled": false, + "bundled": {@bundled}, "acceptableVersions": [ ">=7.3.0" ], diff --git a/init.php b/init.php index 2d73287..536cce5 100644 --- a/init.php +++ b/init.php @@ -24,7 +24,14 @@ $author = trim(fgets($fh)); fclose($fh); -$replacePlaceholders = function (string $file) use ($name, $nameHyphen, $nameLabel, $description, $author) +fwrite(\STDOUT, "Do you want to use ES6? [y/n]\n"); +$fh = fopen('php://stdin', 'r'); +$es6 = trim(fgets($fh)); +$bundled = $es6 ? "true" : "false"; +$jsTranspiled = $es6 ? "true" : "false"; +fclose($fh); + +$replacePlaceholders = function (string $file) use ($name, $nameHyphen, $nameLabel, $description, $author, $bundled, $jsTranspiled) { $content = file_get_contents($file); @@ -33,6 +40,8 @@ $content = str_replace('{@nameLabel}', $nameLabel, $content); $content = str_replace('{@description}', $description, $content); $content = str_replace('{@author}', $author, $content); + $content = str_replace('{@bundled}', $bundled, $content); + $content = str_replace('{@jsTranspiled}', $jsTranspiled, $content); file_put_contents($file, $content); }; @@ -41,6 +50,23 @@ $replacePlaceholders('extension.json'); $replacePlaceholders('config-default.json'); $replacePlaceholders('README.md'); +$replacePlaceholders('src/files/custom/Espo/Modules/MyModuleName/Resources/module.json'); + +if($es6) { + $content = << Date: Tue, 26 Sep 2023 13:47:22 -0600 Subject: [PATCH 2/6] bug fix: set es6 boolean correctly --- init.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.php b/init.php index 536cce5..2bdf7e7 100644 --- a/init.php +++ b/init.php @@ -26,7 +26,7 @@ fwrite(\STDOUT, "Do you want to use ES6? [y/n]\n"); $fh = fopen('php://stdin', 'r'); -$es6 = trim(fgets($fh)); +$es6 = trim(fgets($fh)) === 'y'; $bundled = $es6 ? "true" : "false"; $jsTranspiled = $es6 ? "true" : "false"; fclose($fh); From 287adb4033bae0b27d007c6e4be0b2fc8604bade Mon Sep 17 00:00:00 2001 From: Anthony Andriano Date: Tue, 26 Sep 2023 14:00:05 -0600 Subject: [PATCH 3/6] fixed spacing in readme --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index e206641..99ec19c 100644 --- a/README.md +++ b/README.md @@ -230,8 +230,6 @@ You need to set the following paths to be ignored in your IDE: * `site/tests/unit/Espo/Modules/{@name}` * `site/tests/integration/Espo/Modules/{@name}` - - ## License Change a license in `LICENSE` file. The current license is intended for scripts of this repository. It's not supposed to be used for code of your extension. From db3ac8477183463004e91a216af809a9c7b0b309 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Wed, 27 Sep 2023 10:10:29 +0300 Subject: [PATCH 4/6] Update README.md --- README.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 99ec19c..5a3cf1b 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Run: php init.php ``` -It will ask to enter an extension name and some other information. As of v8.0, `init.php` will ask if you want to use ES6 for frontend code. +It will ask to enter an extension name and some other information. After that, you can remove `init.php` file from your respository. Commit changes and proceed to configuration & building. @@ -230,6 +230,24 @@ You need to set the following paths to be ignored in your IDE: * `site/tests/unit/Espo/Modules/{@name}` * `site/tests/integration/Espo/Modules/{@name}` +## Using ES modules + +*As of v8.0.* + +The initialization script asks whether you want to use ES6 modules. If you choose "NO", you still can switch to ES6 later: + +1. Set *bundled* to true in `extension.json`. +2. Set *bundled* and *jsTranspiled* to true in `src/files/custom/Espo/Modules/{@name}/Resources/module.json`. +3. Add `src/files/custom/Espo/Modules/{@name}/Resources/metadata/app/client.json` + ```json + { + "scriptList": [ + "__APPEND__", + "client/custom/modules/{@nameHyphen}/lib/init.js" + ] + } + ``` + ## License Change a license in `LICENSE` file. The current license is intended for scripts of this repository. It's not supposed to be used for code of your extension. From 959cf4579b2cd707b18893fd69d6d537db89493c Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Wed, 27 Sep 2023 10:13:35 +0300 Subject: [PATCH 5/6] Update init.php --- init.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/init.php b/init.php index 2bdf7e7..0719563 100644 --- a/init.php +++ b/init.php @@ -52,8 +52,8 @@ $replacePlaceholders('README.md'); $replacePlaceholders('src/files/custom/Espo/Modules/MyModuleName/Resources/module.json'); -if($es6) { - $content = << Date: Wed, 27 Sep 2023 10:19:17 +0300 Subject: [PATCH 6/6] Update init.php --- init.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.php b/init.php index 0719563..5b88e90 100644 --- a/init.php +++ b/init.php @@ -24,7 +24,7 @@ $author = trim(fgets($fh)); fclose($fh); -fwrite(\STDOUT, "Do you want to use ES6? [y/n]\n"); +fwrite(\STDOUT, "Do you want to use ES6 modules in frontend? [y/n]\n"); $fh = fopen('php://stdin', 'r'); $es6 = trim(fgets($fh)) === 'y'; $bundled = $es6 ? "true" : "false";