Skip to content

Commit

Permalink
Merge pull request #20 from bandtank/php-update
Browse files Browse the repository at this point in the history
Added ES6 support to init.php
  • Loading branch information
yurikuzn authored Oct 3, 2023
2 parents 592dc06 + 5f56915 commit c8ff336
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ You need to set the following paths to be ignored in your IDE:

*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`
Expand Down
2 changes: 1 addition & 1 deletion extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "{@nameLabel}",
"description": "{@description}",
"author": "{@author}",
"bundled": false,
"bundled": {@bundled},
"acceptableVersions": [
">=7.3.0"
],
Expand Down
33 changes: 31 additions & 2 deletions init.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 modules in frontend? [y/n]\n");
$fh = fopen('php://stdin', 'r');
$es6 = trim(fgets($fh)) === 'y';
$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);

Expand All @@ -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);
};
Expand All @@ -41,11 +50,31 @@
$replacePlaceholders('extension.json');
$replacePlaceholders('config-default.json');
$replacePlaceholders('README.md');
$replacePlaceholders('src/files/custom/Espo/Modules/MyModuleName/Resources/module.json');

if ($es6) {
$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";
echo "Ready. Now you need to run 'npm install'.\n";
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"order": 50,
"bundled": false,
"jsTranspiled": false
"bundled": {@bundled},
"jsTranspiled": {@jsTranspiled}
}

0 comments on commit c8ff336

Please sign in to comment.