Skip to content

Commit cd505b9

Browse files
authored
chore: add config for template suffix and tag prefix in component generation (#11954)
Add support for `UI5_TAG_NAME_PREFIX` and `UI5_TEMPLATE_FILENAME_SUFFIX` environment variables, which can be used in third-party repositories to configure the tag name prefix and template filename. * `UI5_TAG_NAME_PREFIX` controls the tag name format: `{custom-prefix}-component-name`, with a default fallback to `"my"`. * `UI5_TEMPLATE_FILENAME_SUFFIX` controls the template filename format: `ComponentName{custom-suffix}.tsx`, with a default fallback to `"Template"`. Fixes: #11523
1 parent 088ef57 commit cd505b9

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

docs/4-development/01-package.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ The initialization script will create several NPM scripts for you in `package.js
9191
| test | Run the dev server and execute the specs from the `test/specs/` directory. |
9292
| create-ui5-element | Create an empty Web Component with the given name. |
9393

94+
95+
**Note**: The `create-ui5-element` command supports two optional environment variables that customize the output when used in a specific component package:
96+
97+
* **UI5_TAG_NAME_PREFIX** - sets the tag name prefix for the generated Web Component. The resulting tag will follow the format: `{UI5_TAG_NAME_PREFIX}-component-name`. Defaults to `my` if not specified.
98+
99+
* **UI5_TEMPLATE_FILENAME_SUFFIX** - sets the suffix for the generated template filename. The resulting filename will follow the format: `ComponentName{UI5_TEMPLATE_FILENAME_SUFFIX}.tsx`. Defaults to `Template` if not specified.
100+
94101
### Files in the main directory
95102

96103
The initialization script will create several files in your package's main directory.

packages/tools/lib/create-new-component/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const fs = require("fs");
22
const prompts = require("prompts");
33
const Component = require("./Component.js");
44
const ComponentTemplate= require("./ComponentTemplate.js");
5+
const dotenv = require('dotenv');
6+
dotenv.config();
57

68
/**
79
* Hyphanates the given PascalCase string and adds prefix, f.e.:
@@ -11,7 +13,7 @@ const ComponentTemplate= require("./ComponentTemplate.js");
1113
const hyphaneteComponentName = (componentName) => {
1214
const result = componentName.replace(/([a-z])([A-Z])/g, '$1-$2' ).toLowerCase();
1315

14-
return `my-${result}`;
16+
return `${process.env.UI5_TAG_NAME_PREFIX ?? "my"}-${result}`;
1517
};
1618

1719
/**
@@ -62,7 +64,7 @@ const generateFiles = (componentName, tagName, library, packageName) => {
6264
const filePaths = {
6365
"main": `./src/${componentName}.ts`,
6466
"css": `./src/themes/${componentName}.css`,
65-
"template": `./src/${componentName}Template.tsx`,
67+
"template": `./src/${componentName}${process.env.UI5_TEMPLATE_FILENAME_SUFFIX ?? "Template"}.tsx`,
6668
};
6769

6870
fs.writeFileSync(filePaths.main, Component(componentName, tagName, library, packageName), { flag: "wx+" });

packages/tools/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"concurrently": "^6.0.0",
4242
"cross-env": "^7.0.3",
4343
"custom-element-jet-brains-integration": "^1.4.4",
44+
"dotenv": "^16.5.0",
4445
"escodegen": "^2.0.0",
4546
"eslint": "^7.22.0",
4647
"eslint-config-airbnb-base": "^14.2.1",

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8630,6 +8630,11 @@ dotenv@^16.3.0, dotenv@^16.4.5:
86308630
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.5.tgz#cdd3b3b604cb327e286b4762e13502f717cb099f"
86318631
integrity sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==
86328632

8633+
dotenv@^16.5.0:
8634+
version "16.5.0"
8635+
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.5.0.tgz#092b49f25f808f020050051d1ff258e404c78692"
8636+
integrity sha512-m/C+AwOAr9/W1UOIZUo232ejMNnJAJtYQjUbHoNTBNTJSvqzzDh7vnrei3o3r3m9blf6ZoDkvcw0VmozNRFJxg==
8637+
86338638
dotenv@~16.3.1:
86348639
version "16.3.2"
86358640
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.2.tgz#3cb611ce5a63002dbabf7c281bc331f69d28f03f"

0 commit comments

Comments
 (0)