@ui5/create-webcomponents-package 0.0.0-1929d08ff

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +38 -0
  3. package/index.js +168 -0
  4. package/package.json +26 -0
  5. package/template/.eslintignore +3 -0
  6. package/template/bundle.esm.js +31 -0
  7. package/template/config/.eslintrc.js +1 -0
  8. package/template/config/postcss.components/postcss.config.js +1 -0
  9. package/template/config/postcss.themes/postcss.config.js +1 -0
  10. package/template/config/rollup.config.js +1 -0
  11. package/template/config/wdio.conf.js +1 -0
  12. package/template/package-scripts.js +11 -0
  13. package/template/src/Assets.js +5 -0
  14. package/template/src/MyFirstComponent.hbs +1 -0
  15. package/template/src/MyFirstComponent.js +51 -0
  16. package/template/src/i18n/messagebundle.properties +2 -0
  17. package/template/src/i18n/messagebundle_de.properties +1 -0
  18. package/template/src/i18n/messagebundle_en.properties +1 -0
  19. package/template/src/i18n/messagebundle_es.properties +1 -0
  20. package/template/src/i18n/messagebundle_fr.properties +1 -0
  21. package/template/src/themes/MyFirstComponent.css +11 -0
  22. package/template/src/themes/sap_belize/parameters-bundle.css +3 -0
  23. package/template/src/themes/sap_belize_hcb/parameters-bundle.css +3 -0
  24. package/template/src/themes/sap_belize_hcw/parameters-bundle.css +3 -0
  25. package/template/src/themes/sap_fiori_3/parameters-bundle.css +3 -0
  26. package/template/src/themes/sap_fiori_3_dark/parameters-bundle.css +3 -0
  27. package/template/src/themes/sap_fiori_3_hcb/parameters-bundle.css +3 -0
  28. package/template/src/themes/sap_fiori_3_hcw/parameters-bundle.css +3 -0
  29. package/template/test/pages/index.html +54 -0
  30. package/template/test/specs/Demo.spec.js +12 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## [1.1.2](https://github.com/SAP/ui5-webcomponents/compare/v1.1.1...v1.1.2) (2022-01-26)
7
+
8
+ **Note:** Version bump only for package @ui5/create-webcomponents-package
package/README.md ADDED
@@ -0,0 +1,38 @@
1
+ ![UI5 icon](https://raw.githubusercontent.com/SAP/ui5-webcomponents/master/docs/images/UI5_logo_wide.png)
2
+
3
+ # UI5 Web Components - Create Package
4
+
5
+ [![Travis CI Build Status](https://travis-ci.org/SAP/ui5-webcomponents.svg?branch=master)](https://travis-ci.org/SAP/ui5-webcomponents)
6
+ [![npm Package Version](https://badge.fury.io/js/%40ui5%2Fwebcomponents.svg)](https://www.npmjs.com/package/@ui5/webcomponents)
7
+
8
+ Provides an `npm init` script for creating new "UI5 Web Components" packages.
9
+
10
+ ## Usage
11
+
12
+ with `npm`
13
+
14
+ - `npm init @ui5/webcomponents-package` (the user will be asked for **name**, **port**, **tag**);
15
+ - `npm init @ui5/webcomponents-package <NEW-PACKAGE-NAME>` (the user will be asked for **port** and **tag** only).
16
+
17
+ And with `yarn`
18
+
19
+ - `yarn create @ui5/webcomponents-package`
20
+ - `yarn create @ui5/webcomponents-package <NEW-PACKAGE-NAME>`.
21
+
22
+ The script creates a new directory, and fills it with a `package.json` file and all necessary source files, and resources for a new
23
+ components package.
24
+
25
+ ## Resources
26
+ - [UI5 Web Components - README.md](https://github.com/SAP/ui5-webcomponents/blob/master/README.md)
27
+ - [UI5 Web Components - Home Page](https://sap.github.io/ui5-webcomponents)
28
+ - [UI5 Web Components - Playground and API Reference](https://sap.github.io/ui5-webcomponents/playground/)
29
+
30
+ ## Support
31
+ We welcome all comments, suggestions, questions, and bug reports. Please follow our [Support Guidelines](https://github.com/SAP/ui5-webcomponents/blob/master/SUPPORT.md#-content) on how to report an issue, or chat with us in the `#webcomponents` channel of the [OpenUI5 Community Slack](https://join-ui5-slack.herokuapp.com/).
32
+
33
+ ## Contribute
34
+ Please check our [Contribution Guidelines](https://github.com/SAP/ui5-webcomponents/blob/master/docs/6-contributing/02-conventions-and-guidelines.md).
35
+
36
+ ## License
37
+ Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved.
38
+ This file is licensed under the Apache Software License, Version 2.0 except as noted otherwise in the [LICENSE](https://github.com/SAP/ui5-webcomponents/blob/master/LICENSE.txt) file.
package/index.js ADDED
@@ -0,0 +1,168 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const mkdirp = require("mkdirp");
6
+ const prompts = require("prompts");
7
+ const parser = require("npm-config-user-agent-parser");
8
+
9
+ // from where all the files will be copied
10
+ const TEMPLATE_DIR = path.join(`${__dirname}`, `template/`);
11
+
12
+ // String utils
13
+ const capitalizeFirst = str => str.substr(0,1).toUpperCase() + str.substr(1);
14
+ const kebabToCamelCase = string => toCamelCase(string.split("-"));
15
+ const toCamelCase = parts => {
16
+ return parts.map((string, index) => {
17
+ return index === 0 ? string.toLowerCase() : string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
18
+ }).join("");
19
+ };
20
+
21
+ // Validation of user input
22
+ const isNameValid = name => typeof name === "string" && name.match(/^[a-zA-Z0-9\-_]+$/);
23
+ const isPortValid = port => typeof port === "string" && port.match(/^[0-9]+$/);
24
+ const isTagValid = tag => typeof tag === "string" && tag.match(/^[a-z0-9]+?-[a-zA-Z0-9\-_]+?[a-z0-9]$/);
25
+
26
+ // Utils for building the file structure
27
+ const replaceVarsInFileContent = (vars, content) => {
28
+ for (let key in vars) {
29
+ const re = new RegExp(key, "g");
30
+ content = content.replace(re, vars[key]);
31
+ }
32
+ return content;
33
+ };
34
+
35
+ const replaceVarsInFileName = (vars, fileName) => {
36
+ return fileName.replace(/MyFirstComponent/, vars.INIT_PACKAGE_VAR_CLASS_NAME);
37
+ };
38
+
39
+ const copyFile = (vars, sourcePath, destPath) => {
40
+ let content = fs.readFileSync(sourcePath, {encoding: "UTF-8"});
41
+ content = replaceVarsInFileContent(vars, content);
42
+ destPath = replaceVarsInFileName(vars, destPath);
43
+ fs.writeFileSync(destPath, content);
44
+ };
45
+
46
+ const copyFiles = (vars, sourcePath, destPath) => {
47
+ const isDir = fs.lstatSync(sourcePath).isDirectory();
48
+ if (isDir) {
49
+ if (destPath) {
50
+ mkdirp.sync(destPath);
51
+ }
52
+ fs.readdirSync(sourcePath).forEach(file => {
53
+ copyFiles(vars, path.join(sourcePath, file), path.join(destPath, file));
54
+ });
55
+ } else {
56
+ copyFile(vars, sourcePath, destPath);
57
+ }
58
+ };
59
+
60
+ // Main function
61
+ const createWebcomponentsPackage = async () => {
62
+ let response;
63
+
64
+ // Get the name
65
+ let name = process.argv[2];
66
+
67
+ if (!isNameValid(name)) {
68
+ response = await prompts({
69
+ type: "text",
70
+ name: "name",
71
+ message: "Package name:",
72
+ validate: isNameValid,
73
+ });
74
+ name = response.name;
75
+ }
76
+
77
+ // Get the port
78
+ response = await prompts({
79
+ type: "text",
80
+ name: "port",
81
+ message: "Dev server port:",
82
+ validate: isPortValid,
83
+ initial: "8080",
84
+ });
85
+ const port = response.port;
86
+
87
+ // Get the tag
88
+ response = await prompts({
89
+ type: "text",
90
+ name: "tag",
91
+ message: "Demo component name:",
92
+ initial: "my-first-component",
93
+ validate: isTagValid,
94
+ });
95
+ const tag = response.tag;
96
+
97
+ const className = capitalizeFirst(kebabToCamelCase(tag));
98
+
99
+ // All variables that will be replaced in the content of the resources/
100
+ const vars = {
101
+ INIT_PACKAGE_VAR_NAME: name,
102
+ INIT_PACKAGE_VAR_PORT: port,
103
+ INIT_PACKAGE_VAR_TAG: tag,
104
+ INIT_PACKAGE_VAR_CLASS_NAME: className,
105
+ };
106
+
107
+ const packageContent = {
108
+ name,
109
+ version: "0.0.1",
110
+ ui5: {
111
+ webComponentsPackage: true,
112
+ },
113
+ scripts: {
114
+ "clean": "wc-dev clean",
115
+ "lint": "wc-dev lint",
116
+ "start": "wc-dev start",
117
+ "watch": "wc-dev watch",
118
+ "serve": "wc-dev serve",
119
+ "build": "wc-dev build",
120
+ "test": "wc-dev test",
121
+ "create-ui5-element": "wc-create-ui5-element",
122
+ "prepublishOnly": "npm run build",
123
+ },
124
+ exports: {
125
+ "./.port": "./.port",
126
+ "./src/*": "./src/*",
127
+ "./dist/*": "./dist/*",
128
+ "./package.json": "./package.json",
129
+ "./bundle.js": "./bundle.js",
130
+ "./*": "./dist/*",
131
+ },
132
+ "dependencies": {
133
+ "@ui5/webcomponents-base": "1.1.1",
134
+ "@ui5/webcomponents-theming": "1.1.1",
135
+ },
136
+ "devDependencies": {
137
+ "@ui5/webcomponents-tools": "1.1.1",
138
+ "chromedriver": "*",
139
+ },
140
+ };
141
+
142
+ // Update package.json
143
+ const destDir = path.join(`./`, name);
144
+ mkdirp.sync(destDir);
145
+ fs.writeFileSync(path.join(destDir, "package.json"), JSON.stringify(packageContent, null, 2));
146
+ // Copy files
147
+ copyFiles(vars, TEMPLATE_DIR, destDir);
148
+
149
+ console.log("\nPackage successfully created!\nNext steps:\n");
150
+ console.log(`$ cd ${name}`);
151
+
152
+ let userAgentInfo;
153
+ try {
154
+ userAgentInfo = parser(process.env.npm_config_user_agent);
155
+ } catch (e) {}
156
+
157
+ if (userAgentInfo && userAgentInfo.yarn) {
158
+ console.log(`$ yarn`);
159
+ console.log(`$ yarn start`);
160
+ } else {
161
+ console.log(`$ npm i`);
162
+ console.log(`$ npm start`);
163
+ }
164
+
165
+ console.log("\n");
166
+ };
167
+
168
+ createWebcomponentsPackage();
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@ui5/create-webcomponents-package",
3
+ "version": "0.0.0-1929d08ff",
4
+ "description": "UI5 Web Components: create package",
5
+ "author": "SAP SE (https://www.sap.com)",
6
+ "license": "Apache-2.0",
7
+ "private": false,
8
+ "keywords": [
9
+ "openui5",
10
+ "sapui5",
11
+ "ui5"
12
+ ],
13
+ "bin": {
14
+ "create-webcomponents-package": "index.js"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/SAP/ui5-webcomponents.git",
19
+ "directory": "packages/create-package"
20
+ },
21
+ "dependencies": {
22
+ "mkdirp": "^1.0.4",
23
+ "npm-config-user-agent-parser": "^1.0.0",
24
+ "prompts": "^2.4.1"
25
+ }
26
+ }
@@ -0,0 +1,3 @@
1
+ # Note: Changes to this file also must be applied to the top level .eslintignore file.
2
+ dist
3
+ test
@@ -0,0 +1,31 @@
1
+ // used in test pages
2
+ import { renderFinished } from "@ui5/webcomponents-base/dist/Render.js";
3
+
4
+ import { getAnimationMode } from "@ui5/webcomponents-base/dist/config/AnimationMode.js";
5
+ import { getLanguage } from "@ui5/webcomponents-base/dist/config/Language.js";
6
+ import { getCalendarType } from "@ui5/webcomponents-base/dist/config/CalendarType.js";
7
+ import { getTheme, setTheme } from "@ui5/webcomponents-base/dist/config/Theme.js";
8
+ import { getNoConflict, setNoConflict } from "@ui5/webcomponents-base/dist/config/NoConflict.js";
9
+ import { getRTL } from "@ui5/webcomponents-base/dist/config/RTL.js";
10
+ import { getFirstDayOfWeek } from "@ui5/webcomponents-base/dist/config/FormatSettings.js";
11
+
12
+ // Enable additional themes and i18n texts
13
+ import "./dist/Assets.js";
14
+
15
+ // Import your web components here from the dist/ directory
16
+ import "./dist/INIT_PACKAGE_VAR_CLASS_NAME.js";
17
+
18
+ window["sap-ui-webcomponents-bundle"] = {
19
+ renderFinished,
20
+ configuration: {
21
+ getAnimationMode,
22
+ getLanguage,
23
+ getTheme,
24
+ setTheme,
25
+ getNoConflict,
26
+ setNoConflict,
27
+ getCalendarType,
28
+ getRTL,
29
+ getFirstDayOfWeek,
30
+ },
31
+ };
@@ -0,0 +1 @@
1
+ module.exports = require("@ui5/webcomponents-tools/components-package/eslint.js"); // eslint-disable-line
@@ -0,0 +1 @@
1
+ module.exports = require("@ui5/webcomponents-tools/components-package/postcss.components.js"); // eslint-disable-line
@@ -0,0 +1 @@
1
+ module.exports = require("@ui5/webcomponents-tools/components-package/postcss.themes.js"); // eslint-disable-line
@@ -0,0 +1 @@
1
+ module.exports = require("@ui5/webcomponents-tools/components-package/rollup.js"); // eslint-disable-line
@@ -0,0 +1 @@
1
+ module.exports = require("@ui5/webcomponents-tools/components-package/wdio.js"); // eslint-disable-line
@@ -0,0 +1,11 @@
1
+ const getScripts = require("@ui5/webcomponents-tools/components-package/nps.js"); //eslint-disable-line
2
+
3
+ const options = {
4
+ port: INIT_PACKAGE_VAR_PORT,
5
+ };
6
+
7
+ const scripts = getScripts(options);
8
+
9
+ module.exports = {
10
+ scripts,
11
+ };
@@ -0,0 +1,5 @@
1
+ import "@ui5/webcomponents-theming/dist/Assets.js"; // Theming
2
+
3
+ // own INIT_PACKAGE_VAR_NAME package assets
4
+ import "./generated/json-imports/Themes.js";
5
+ import "./generated/json-imports/i18n.js";
@@ -0,0 +1 @@
1
+ <div>This is: INIT_PACKAGE_VAR_TAG. {{pleaseWaitText}}</div>
@@ -0,0 +1,51 @@
1
+ import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
2
+ import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
3
+ import { getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
4
+
5
+ // Template
6
+ import INIT_PACKAGE_VAR_CLASS_NAMETemplate from "./generated/templates/INIT_PACKAGE_VAR_CLASS_NAMETemplate.lit.js";
7
+
8
+ // Styles
9
+ import INIT_PACKAGE_VAR_CLASS_NAMECss from "./generated/themes/INIT_PACKAGE_VAR_CLASS_NAME.css.js";
10
+
11
+ import { PLEASE_WAIT } from "./generated/i18n/i18n-defaults.js";
12
+
13
+ const metadata = {
14
+ tag: "INIT_PACKAGE_VAR_TAG",
15
+ properties: {
16
+ },
17
+ slots: {
18
+ },
19
+ events: {
20
+ },
21
+ };
22
+
23
+ class INIT_PACKAGE_VAR_CLASS_NAME extends UI5Element {
24
+ static get metadata() {
25
+ return metadata;
26
+ }
27
+
28
+ static get render() {
29
+ return litRender;
30
+ }
31
+
32
+ static get template() {
33
+ return INIT_PACKAGE_VAR_CLASS_NAMETemplate;
34
+ }
35
+
36
+ static get styles() {
37
+ return INIT_PACKAGE_VAR_CLASS_NAMECss;
38
+ }
39
+
40
+ static async onDefine() {
41
+ INIT_PACKAGE_VAR_CLASS_NAME.i18nBundle = await getI18nBundle("INIT_PACKAGE_VAR_NAME");
42
+ }
43
+
44
+ get pleaseWaitText() {
45
+ return INIT_PACKAGE_VAR_CLASS_NAME.i18nBundle.getText(PLEASE_WAIT);
46
+ }
47
+ }
48
+
49
+ INIT_PACKAGE_VAR_CLASS_NAME.define();
50
+
51
+ export default INIT_PACKAGE_VAR_CLASS_NAME;
@@ -0,0 +1,2 @@
1
+ #please wait text for the sample component
2
+ PLEASE_WAIT=wait
@@ -0,0 +1 @@
1
+ PLEASE_WAIT=Bitte warten
@@ -0,0 +1 @@
1
+ PLEASE_WAIT=Please wait
@@ -0,0 +1 @@
1
+ PLEASE_WAIT=Espere
@@ -0,0 +1 @@
1
+ PLEASE_WAIT=Patientez.
@@ -0,0 +1,11 @@
1
+ :host {
2
+ border: 2px solid var(--my-component-border-color);
3
+ background-color: var(--sapBackgroundColor);
4
+ color: var(--sapTextColor);
5
+ display: block;
6
+ width: 24rem;
7
+ height: 3rem;
8
+ text-align: center;
9
+ vertical-align: middle;
10
+ line-height: 3rem;
11
+ }
@@ -0,0 +1,3 @@
1
+ :root {
2
+ --my-component-border-color: lightblue;
3
+ }
@@ -0,0 +1,3 @@
1
+ :root {
2
+ --my-component-border-color: black;
3
+ }
@@ -0,0 +1,3 @@
1
+ :root {
2
+ --my-component-border-color: black;
3
+ }
@@ -0,0 +1,3 @@
1
+ :root {
2
+ --my-component-border-color: green;
3
+ }
@@ -0,0 +1,3 @@
1
+ :root {
2
+ --my-component-border-color: blue;
3
+ }
@@ -0,0 +1,3 @@
1
+ :root {
2
+ --my-component-border-color: lightblue;
3
+ }
@@ -0,0 +1,3 @@
1
+ :root {
2
+ --my-component-border-color: gray;
3
+ }
@@ -0,0 +1,54 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
+ <meta charset="utf-8">
7
+
8
+ <title>INIT_PACKAGE_VAR_TAG</title>
9
+ <meta name="viewport" content="width=device-width, initial-scale=1">
10
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
11
+ <meta charset="utf-8">
12
+
13
+ <script data-ui5-config type="application/json">
14
+ {
15
+ "language": "EN"
16
+ }
17
+ </script>
18
+
19
+ <script src="../../resources/bundle.esm.js" type="module"></script>
20
+
21
+ <style>
22
+ code { color: blue; font-size: small; }
23
+ </style>
24
+
25
+ </head>
26
+
27
+ <body>
28
+ <ul>
29
+ <li><a href="?sap-ui-theme=sap_fiori_3">Fiori 3</a></li>
30
+ <li><a href="?sap-ui-theme=sap_fiori_3_dark">Fiori 3 Dark</a></li>
31
+ <li><a href="?sap-ui-theme=sap_fiori_3_hcb">Fiori 3 High Contrast Black</a></li>
32
+ <li><a href="?sap-ui-theme=sap_fiori_3_hcw">Fiori 3 High Contrast White</a></li>
33
+ <li><a href="?sap-ui-theme=sap_belize">Belize</a></li>
34
+ <li><a href="?sap-ui-theme=sap_belize_hcb">Belize High Contrast Black</a></li>
35
+ <li><a href="?sap-ui-theme=sap_belize_hcw">Belize High Contrast White</a></li>
36
+ </ul>
37
+ <br>
38
+ <span>or in the browser console, for example:</span>
39
+ <code>window['sap-ui-webcomponents-bundle'].configuration.setTheme("sap_belize_hcb")</code>
40
+
41
+ <br><br>
42
+
43
+ <a href="?sap-ui-language=en">English</a> |
44
+ <a href="?sap-ui-language=de">German</a> |
45
+ <a href="?sap-ui-language=es">Spanish</a> |
46
+ <a href="?sap-ui-language=fr">French</a>
47
+
48
+ <br><br>
49
+
50
+ <h1>Test your web components here</h1>
51
+ <INIT_PACKAGE_VAR_TAG id="myFirstComponent"></INIT_PACKAGE_VAR_TAG>
52
+ </body>
53
+
54
+ </html>
@@ -0,0 +1,12 @@
1
+ const assert = require("assert");
2
+
3
+ describe("INIT_PACKAGE_VAR_TAG rendering", async () => {
4
+ await browser.url("http://localhost:INIT_PACKAGE_VAR_PORT/test-resources/pages/index.html");
5
+
6
+ it("tests if web component is correctly rendered", async () => {
7
+
8
+ const innerContent = await browser.$("#myFirstComponent").shadow$("div");
9
+
10
+ assert.ok(innerContent, "content rendered");
11
+ });
12
+ });