@ui5/create-webcomponents-package 0.0.0-38861c872 → 0.0.0-38f83ffef

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 (34) hide show
  1. package/CHANGELOG.md +1019 -0
  2. package/README.md +8 -15
  3. package/create-package.js +189 -208
  4. package/package.json +3 -1
  5. package/template/.eslintignore +3 -2
  6. package/template/.npsrc.json +3 -0
  7. package/template/cypress/component/MyFirstComponent.cy.tsx +13 -0
  8. package/template/cypress/fixtures/example.json +5 -0
  9. package/template/cypress/support/commands.ts +37 -0
  10. package/template/cypress/support/component-index.html +12 -0
  11. package/template/cypress/support/component.ts +36 -0
  12. package/template/cypress/tsconfig.template.json +19 -0
  13. package/template/cypress.config.ts +10 -0
  14. package/template/env +1 -0
  15. package/template/gitignore +2 -2
  16. package/template/{package-scripts.js → package-scripts.cjs} +0 -1
  17. package/template/package.json +35 -0
  18. package/template/src/Assets.ts +1 -1
  19. package/template/src/MyFirstComponent.ts +16 -20
  20. package/template/src/MyFirstComponentTemplate.tsx +9 -0
  21. package/template/{bundle.esm.js → src/bundle.esm.ts} +4 -5
  22. package/template/test/pages/css/index.css +65 -12
  23. package/template/test/pages/img/logo.png +0 -0
  24. package/template/test/pages/index.html +36 -40
  25. package/template/tsconfig.template.json +14 -0
  26. package/template/vite.config.js +14 -0
  27. package/template/config/wdio.conf.js +0 -1
  28. package/template/src/Assets.js +0 -5
  29. package/template/src/MyFirstComponent.hbs +0 -6
  30. package/template/src/MyFirstComponent.js +0 -82
  31. package/template/src/themes/sap_fiori_3/parameters-bundle.css +0 -3
  32. package/template/test/specs/Demo.spec.js +0 -13
  33. package/template/tsconfig.json +0 -16
  34. /package/template/{.eslintrc.js → .eslintrc.cjs} +0 -0
package/README.md CHANGED
@@ -1,7 +1,4 @@
1
- ![UI5 icon](https://raw.githubusercontent.com/SAP/ui5-webcomponents/main/docs/images/UI5_logo_wide.png)
2
-
3
-
4
- # UI5 Web Components - Create Package
1
+ # ![UI5 icon](https://raw.githubusercontent.com/SAP/ui5-webcomponents/main/docs/images/UI5_logo_water.png)UI5 Web Components - Create Package
5
2
 
6
3
  [![npm Package Version](https://badge.fury.io/js/%40ui5%2Fwebcomponents.svg)](https://www.npmjs.com/package/@ui5/webcomponents)
7
4
 
@@ -18,11 +15,9 @@ Usage:
18
15
  npm init @ui5/webcomponents-package -- [OPTIONS]
19
16
 
20
17
  Options:
21
- --name <string> - defines the package name
22
- --component-name <string> - defines the component class name that will be created in your new package
23
- --tag <string> - defines the tag name of the sample web component that will be created in your new package. The tag will be derived from the component name if not provided.
24
- --enable-typescript - enables TypeScript support for the package
25
- --skip - skips configuration and generates package with a default value for each parameter that wasn't passed
18
+ --name <string> - defines the package name
19
+ --test-setup <"cypress" | "manual"> - defines whether the predefined test setup should be added or it will be configured manually.
20
+ --skip - skips configuration and generates package with a default value for each parameter that wasn't passed
26
21
  ```
27
22
 
28
23
  The script creates a new directory, and fills it with a `package.json` file and all necessary source files, and resources for a new
@@ -34,11 +29,9 @@ components package.
34
29
  Usage:
35
30
  yarn create @ui5/webcomponents-package [OPTIONS]
36
31
  Options:
37
- --name <string> - defines the package name
38
- --component-name <string> - defines the component class name that will be created in your new package
39
- --tag <string> - defines the tag name of the sample web component that will be created in your new package
40
- --enable-typescript - enables TypeScript support for the package
41
- --skip - skips configuration and generates package with a default value for each parameter that wasn't passed
32
+ --name <string> - defines the package name
33
+ --test-setup <"cypress" | "manual"> - defines whether the predefined test setup should be added or it will be configured manually.
34
+ --skip - skips configuration and generates package with a default value for each parameter that wasn't passed
42
35
  ```
43
36
 
44
37
  The script creates a new directory, and fills it with a `package.json` file and all necessary source files, and resources for a new
@@ -47,7 +40,7 @@ components package.
47
40
  ## Resources
48
41
  - [UI5 Web Components - README.md](https://github.com/SAP/ui5-webcomponents/blob/main/README.md)
49
42
  - [UI5 Web Components - Home Page](https://sap.github.io/ui5-webcomponents)
50
- - [UI5 Web Components - Playground and API Reference](https://sap.github.io/ui5-webcomponents/playground/)
43
+ - [UI5 Web Components - Playground and API Reference](https://sap.github.io/ui5-webcomponents/play/)
51
44
 
52
45
  ## Support
53
46
  We welcome all comments, suggestions, questions, and bug reports. Please follow our [Support Guidelines](https://github.com/SAP/ui5-webcomponents/blob/main/SUPPORT.md#-content) on how to report an issue, or chat with us in the `#webcomponents` channel of the [OpenUI5 Community Slack](https://ui5-slack-invite.cfapps.eu10.hana.ondemand.com/).
package/create-package.js CHANGED
@@ -1,217 +1,216 @@
1
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
- const yargs = require("yargs/yargs");
9
- const { hideBin } = require("yargs/helpers");
10
-
2
+ import fs from "fs/promises";
3
+ import path, { dirname } from "path";
4
+ import prompts from "prompts";
5
+ import parser from "npm-config-user-agent-parser";
6
+ import yargs from "yargs/yargs";
7
+ import { hideBin } from "yargs/helpers";
8
+ import { fileURLToPath } from "url";
9
+ import * as prettier from "prettier";
10
+
11
+ const __filename = fileURLToPath(import.meta.url);
12
+ const __dirname = dirname(__filename);
11
13
  const argv = yargs(hideBin(process.argv)).argv;
12
-
13
- const version = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"))).version;
14
-
15
- // from where all the files will be copied
16
- const TEMPLATE_DIR = path.join(`${__dirname}`, `template/`);
17
-
18
- // String utils
19
- const isTSRelatedFile = sourcePath => {
20
- return ["Assets.ts", "MyFirstComponent.ts", "tsconfig.json", "global.d.ts"].some(fileName => sourcePath.includes(fileName));
21
- };
22
- const isJSRelatedFile = sourcePath => {
23
- return ["Assets.js", "MyFirstComponent.js"].some(fileName => sourcePath.includes(fileName));
24
- };
25
- const isGitIgnore = sourcePath => {
26
- return sourcePath.includes("gitignore");
27
- };
28
- const isLogo = sourcePath => {
29
- return sourcePath.includes("logo");
30
- };
31
- const isNPMRC = sourcePath => {
32
- return sourcePath.includes("npmrc");
14
+ const VERSION = JSON.parse(
15
+ await fs.readFile(path.join(__dirname, "package.json")),
16
+ ).version;
17
+
18
+ // Constants
19
+ const SUPPORTED_TEST_SETUPS = ["cypress", "manual"];
20
+ const SRC_DIR = path.join(__dirname, "template");
21
+ const DEST_DIR = process.cwd();
22
+
23
+ const FILES_TO_RENAME = {
24
+ [path.normalize("eslintignore")]: path.normalize(".eslintignore"),
25
+ [path.normalize("eslintrc.cjs")]: path.normalize(".eslintrc.cjs"),
26
+ [path.normalize("npsrc.json")]: path.normalize(".npsrc.json"),
27
+ [path.normalize("npmrc")]: path.normalize(".npmrc"),
28
+ [path.normalize("env")]: path.normalize(".env"),
29
+ [path.normalize("gitignore")]: path.normalize(".gitignore"),
30
+ [path.normalize("tsconfig.template.json")]: path.normalize("tsconfig.json"),
31
+ [path.normalize("cypress/tsconfig.template.json")]: path.normalize("cypress/tsconfig.json")
33
32
  };
33
+ const FILES_TO_COPY = ["test/pages/img/logo.png"];
34
+
35
+ // Validation Patterns
36
+ const PackageNamePattern =
37
+ /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/;
38
+ const TagPattern = /^[a-z0-9]+?-[a-zA-Z0-9\-_]+?[a-z0-9]$/;
39
+
40
+ // Utility Functions
41
+ const isPackageNameValid = name =>
42
+ typeof name === "string" && PackageNamePattern.test(name);
43
+ const isTagValid = tag => typeof tag === "string" && TagPattern.test(tag);
44
+ const isTestSetupValid = setup =>
45
+ typeof setup === "string" && SUPPORTED_TEST_SETUPS.includes(setup);
46
+
47
+ async function collectFiles(dir, fileList = []) {
48
+ const entries = await fs.readdir(dir, { withFileTypes: true });
49
+
50
+ for (const entry of entries) {
51
+ const fullPath = path.join(dir, entry.name);
52
+ if (entry.isDirectory()) {
53
+ await collectFiles(fullPath, fileList);
54
+ } else if (entry.isFile()) {
55
+ fileList.push(fullPath);
56
+ }
57
+ }
34
58
 
35
- // Validation of user input
36
- const ComponentNamePattern = /^[A-Z][A-Za-z0-9]+$/;
37
- const NamespacePattern = /^[a-z][a-z0-9\.\-]+$/;
38
- const isPackageNameValid = name => typeof name === "string" && name.match(/^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/);
39
- const isComponentNameValid = name => typeof name === "string" && ComponentNamePattern.test(name);
40
- const isNamespaceValid = name => typeof name === "string" && NamespacePattern.test(name);
41
- const isTagValid = tag => typeof tag === "string" && tag.match(/^[a-z0-9]+?-[a-zA-Z0-9\-_]+?[a-z0-9]$/);
59
+ return fileList;
60
+ }
42
61
 
43
62
  /**
44
63
  * Hyphanates the given PascalCase string, f.e.:
45
64
  * Foo -> "my-foo" (adds preffix)
46
65
  * FooBar -> "foo-bar"
47
66
  */
48
- const hyphaneteComponentName = (componentName) => {
49
- const result = componentName.replace(/([a-z])([A-Z])/g, '$1-$2' ).toLowerCase();
50
-
67
+ const hyphenateComponentName = componentName => {
68
+ const result = componentName
69
+ .replace(/([a-z])([A-Z])/g, "$1-$2")
70
+ .toLowerCase();
51
71
  return result.includes("-") ? result : `my-${result}`;
52
72
  };
53
73
 
54
- // Utils for building the file structure
55
- const replaceVarsInFileContent = (vars, content) => {
56
- for (let key in vars) {
57
- const re = new RegExp(key, "g");
58
- content = content.replace(re, vars[key]);
59
- }
60
- return content;
61
- };
62
-
63
- const replaceVarsInFileName = (vars, fileName) => {
64
- return fileName.replace(/MyFirstComponent/, vars.INIT_PACKAGE_VAR_CLASS_NAME);
65
- };
74
+ const replacePlaceholders = (content, replacements) =>
75
+ content.replace(/{{(.*?)}}/g, (_, key) => replacements[key.trim()] || "");
66
76
 
67
- const copyFile = (vars, sourcePath, destPath) => {
68
- const ignoreJsRelated = vars.INIT_PACKAGE_VAR_TYPESCRIPT && isJSRelatedFile(sourcePath);
69
- const ignoreTsRelated = !vars.INIT_PACKAGE_VAR_TYPESCRIPT && isTSRelatedFile(sourcePath);
70
-
71
- if (ignoreJsRelated || ignoreTsRelated) {
72
- return;
73
- }
74
-
75
- if (isLogo(sourcePath)) {
76
- fs.copyFileSync(sourcePath, destPath);
77
- return;
78
- }
79
-
80
- let content = fs.readFileSync(sourcePath, { encoding: "UTF-8" });
81
- content = replaceVarsInFileContent(vars, content);
82
- destPath = replaceVarsInFileName(vars, destPath);
83
-
84
- fs.writeFileSync(destPath, content);
85
-
86
- // Rename "gitignore" to ".gitignore" (npm init won't include ".gitignore", so we add it as "gitignore" and rename it later)
87
- if (isGitIgnore(sourcePath)) {
88
- fs.renameSync(destPath, destPath.replace("gitignore", ".gitignore"))
89
- }
90
-
91
- // Rename "npmrc" to ".npmrc" (npm init won't include ".npmrc", so we add it as "npmrc" and rename it later)
92
- if (isNPMRC(sourcePath)) {
93
- fs.renameSync(destPath, destPath.replace("npmrc", ".npmrc"));
94
- }
95
- };
96
-
97
- const copyFiles = (vars, sourcePath, destPath) => {
98
- const isDir = fs.lstatSync(sourcePath).isDirectory();
99
- if (isDir) {
100
- if (destPath) {
101
- mkdirp.sync(destPath);
102
- }
103
- fs.readdirSync(sourcePath).forEach(file => {
104
- copyFiles(vars, path.join(sourcePath, file), path.join(destPath, file));
105
- });
106
- } else {
107
- copyFile(vars, sourcePath, destPath);
108
- }
109
- };
110
-
111
- const generateFilesContent = (packageName, componentName, namespace, typescript, skipSubfolder) => {
112
- const tagName = argv.tag || hyphaneteComponentName(componentName);
113
-
114
- // All variables that will be replaced in the content of the resources/
77
+ const generateFilesContent = async (
78
+ packageName,
79
+ componentName,
80
+ skipSubfolder,
81
+ testSetup,
82
+ ) => {
83
+ // All variables that will be replaced in the content of the template folder/
115
84
  const vars = {
116
- INIT_PACKAGE_VAR_NAMESPACE: namespace, // namespace must be replaced before name
117
85
  INIT_PACKAGE_VAR_NAME: packageName,
118
- INIT_PACKAGE_VAR_TAG: tagName,
86
+ INIT_PACKAGE_VERSION: VERSION,
87
+ INIT_PACKAGE_VAR_TAG: argv.tag || hyphenateComponentName(componentName),
119
88
  INIT_PACKAGE_VAR_CLASS_NAME: componentName,
120
- INIT_PACKAGE_VAR_TYPESCRIPT: typescript,
121
- };
122
-
123
- const packageContent = {
124
- name: packageName,
125
- version: "0.0.1",
126
- ui5: {
127
- webComponentsPackage: true,
128
- },
129
- scripts: {
130
- "clean": "wc-dev clean",
131
- "lint": "wc-dev lint",
132
- "start": "wc-dev start",
133
- "watch": "wc-dev watch",
134
- "build": "wc-dev build",
135
- "test": "wc-dev test",
136
- "create-ui5-element": "wc-create-ui5-element",
137
- "prepublishOnly": "npm run build",
138
- },
139
- exports: {
140
- "./src/*": "./src/*",
141
- "./dist/*": "./dist/*",
142
- "./package.json": "./package.json",
143
- "./bundle.js": "./bundle.js",
144
- "./*": "./dist/*",
145
- },
146
- "dependencies": {
147
- "@ui5/webcomponents-base": version,
148
- "@ui5/webcomponents-theming": version,
149
- },
150
- "devDependencies": {
151
- "@ui5/webcomponents-tools": version,
152
- "chromedriver": "*",
153
- },
89
+ INIT_PACKAGE_CYPRESS_ROOT_TSCONFIG:
90
+ testSetup === "cypress"
91
+ ? `"tsBuildInfoFile": "dist/.tsbuildinfo",\n"rootDir": "src",\n"composite": true,`
92
+ : "",
93
+ INIT_PACKAGE_CYPRESS_DEV_DEPS:
94
+ testSetup === "cypress"
95
+ ? `"@ui5/cypress-ct-ui5-webc": "^0.0.4",\n"cypress": "^13.11.0",`
96
+ : "",
97
+ INIT_PACKAGE_CYPRESS_TEST_COMMANDS:
98
+ testSetup === "cypress"
99
+ ? `"test": "cypress run --component --browser chrome",\n"test:open": "cypress open --component --browser chrome",`
100
+ : "",
101
+ INIT_PACKAGE_CYPRESS_ESLINT_IGNORES:
102
+ testSetup === "cypress" ? `cypress/*\ncypress.config.*` : "",
154
103
  };
155
104
 
156
- if (typescript) {
157
- packageContent.devDependencies.typescript = "^4.9.4";
158
- }
159
-
160
- // Update package.json
161
- let destDir = packageName.includes("@") ? packageName.slice(packageName.lastIndexOf("/") + 1) : packageName;
105
+ const packageBaseName = packageName.includes("@")
106
+ ? packageName.slice(packageName.lastIndexOf("/") + 1)
107
+ : packageName;
108
+ const destDir = skipSubfolder
109
+ ? path.join(DEST_DIR)
110
+ : path.join(DEST_DIR, packageBaseName);
162
111
 
163
- destDir = skipSubfolder ? path.join("./") : path.join("./", destDir);
164
- mkdirp.sync(destDir);
165
- fs.writeFileSync(path.join(destDir, "package.json"), JSON.stringify(packageContent, null, 2));
166
- // Copy files
167
- copyFiles(vars, TEMPLATE_DIR, destDir);
112
+ await processFiles(destDir, vars, testSetup);
168
113
 
169
114
  console.log("\nPackage successfully created!\nNext steps:\n");
170
115
  console.log(`$ cd ${destDir}`);
171
116
 
172
- let userAgentInfo;
173
117
  try {
174
- userAgentInfo = parser(process.env.npm_config_user_agent);
175
- } catch (e) {}
176
-
177
- if (userAgentInfo && userAgentInfo.yarn) {
178
- console.log(`$ yarn`);
179
- console.log(`$ yarn start`);
180
- } else {
181
- console.log(`$ npm i`);
182
- console.log(`$ npm start`);
118
+ const userAgent = parser(process.env.npm_config_user_agent);
119
+ userAgent.yarn
120
+ ? console.log(`$ yarn\n$ yarn start`)
121
+ : console.log(`$ npm i\n$ npm start`);
122
+ } catch {
123
+ console.log(`$ npm i\n$ npm start`);
183
124
  }
184
125
 
185
126
  console.log("\n");
186
127
  };
187
128
 
188
- // Main function
189
- const createWebcomponentsPackage = async () => {
190
- let response;
191
- if (argv.name && !isPackageNameValid(argv.name)) {
192
- throw new Error("The package name should be a string, starting with letter and containing the following symbols [a-z, A-Z, 0-9].");
193
- }
129
+ async function processFiles(destDir, replacements, testSetup) {
130
+ const files = await collectFiles(SRC_DIR);
131
+ const FILE_PATHS_TO_SKIP = [
132
+ testSetup !== "cypress" ? path.normalize("cypress") : undefined,
133
+ ].filter(Boolean);
134
+
135
+ for (const file of files) {
136
+ const relativePath = path.relative(SRC_DIR, file);
137
+ let destPath = path.join(destDir, relativePath);
138
+
139
+ if (FILE_PATHS_TO_SKIP.some(filePath => file.includes(filePath))) {
140
+ // console.log(`Skipped: ${file} -> ${destPath}`);
141
+ continue;
142
+ }
143
+
144
+ // // Component related file based on the user input
145
+ // destPath = destPath.replace(
146
+ // "MyFirstComponent",
147
+ // replacements.INIT_PACKAGE_VAR_CLASS_NAME,
148
+ // );
149
+
150
+ // Files that need to be renamed
151
+ if (FILES_TO_RENAME[relativePath]) {
152
+ destPath = destPath.replace(
153
+ relativePath,
154
+ FILES_TO_RENAME[relativePath],
155
+ );
156
+ }
157
+
158
+ await fs.mkdir(path.dirname(destPath), { recursive: true });
159
+
160
+ if (FILES_TO_COPY.includes(relativePath)) {
161
+ // Image like files that doesn't need proccessing
162
+ await fs.copyFile(file, destPath);
163
+ } else {
164
+ const content = await fs.readFile(file, { encoding: "utf8" });
165
+ const replaced = replacePlaceholders(content, replacements);
166
+ let formatted;
167
+ try {
168
+ formatted = await prettier.format(replaced, {
169
+ useTabs: true,
170
+ tabWidth: 4,
171
+ quoteProps: "consistent",
172
+ arrowParens: "avoid",
173
+ filepath: file,
174
+ });
175
+ // console.log(`Formatted: ${file} -> ${destPath}`);
176
+ } catch {
177
+ // console.log(`Not formatted: ${file} -> ${destPath}`);
178
+ formatted = replaced;
179
+ }
180
+
181
+ await fs.writeFile(destPath, formatted);
182
+ }
194
183
 
195
- if (argv.componentName && !isComponentNameValid(argv.componentName)) {
196
- throw new Error("The component name should be a string, starting with a capital letter [A-Z][a-z], for example: Button, MyButton, etc.");
184
+ // console.log(`Processed: ${file} -> ${destPath}`);
197
185
  }
186
+ }
198
187
 
199
- if (argv.namespace && !isNamespaceValid(argv.namespace)) {
200
- throw new Error("The JSDoc namespace must start with a letter and can only contain small-case letters, numbers, dots and dashes.");
188
+ const createWebcomponentsPackage = async () => {
189
+ let response;
190
+ if (argv.name && !isPackageNameValid(argv.name)) {
191
+ throw new Error(
192
+ "The package name should be a string, starting with letter and containing the following symbols [a-z, A-Z, 0-9].",
193
+ );
201
194
  }
202
195
 
203
- if (argv.tag && !isTagValid(argv.tag) ) {
204
- throw new Error("The tag should be in kebab-case (f.e my-component) and it can't be a single word.");
196
+ if (argv.testSetup && !isTestSetupValid(argv.testSetup)) {
197
+ throw new Error(
198
+ `The test setup should be a string and one of the following options: ${SUPPORTED_TEST_SETUPS.join(", ")}`,
199
+ );
205
200
  }
206
201
 
207
202
  let packageName = argv.name || "my-package";
208
- let componentName = argv.componentName || "MyComponent";
209
- let namespace = argv.namespace || "demo.components";
210
- let typescriptSupport = !!argv.enableTypescript;
203
+ let componentName = "MyFirstComponent";
204
+ let testSetup = argv.testSetup || "manual";
211
205
  const skipSubfolder = !!argv.skipSubfolder;
212
206
 
213
207
  if (argv.skip) {
214
- return generateFilesContent(packageName, componentName, namespace, typescriptSupport, skipSubfolder);
208
+ return generateFilesContent(
209
+ packageName,
210
+ componentName,
211
+ skipSubfolder,
212
+ testSetup,
213
+ );
215
214
  }
216
215
 
217
216
  if (!argv.name) {
@@ -219,53 +218,35 @@ const createWebcomponentsPackage = async () => {
219
218
  type: "text",
220
219
  name: "name",
221
220
  message: "Package name:",
222
- validate: (value) => isPackageNameValid(value) ? true : "Package name should be a string, starting with a letter and containing the following symbols [a-z, A-Z ,0-9, _, -].",
221
+ validate: value =>
222
+ isPackageNameValid(value)
223
+ ? true
224
+ : "Package name should be a string, starting with a letter and containing the following symbols [a-z, A-Z ,0-9, _, -].",
223
225
  });
224
226
  packageName = response.name;
225
227
  }
226
228
 
227
- if (!typescriptSupport) {
229
+ if (!argv.testSetup) {
228
230
  response = await prompts({
229
231
  type: "select",
230
- name: "language",
231
- message: "Project type:",
232
+ name: "testSetup",
233
+ message: "How would you like to set up testing?",
232
234
  choices: [
233
- {
234
- title: "JavaScript",
235
- value: false,
236
- },
237
- {
238
- title: "TypeScript",
239
- value: true,
240
- },
235
+ { title: "Cypress", value: "cypress" },
236
+ { title: "I'll set it up manually", value: "manual" },
241
237
  ],
238
+ initial: 0,
242
239
  });
243
- typescriptSupport = response.language;
244
- }
245
240
 
246
- if (!argv.componentName) {
247
- response = await prompts({
248
- type: "text",
249
- name: "componentName",
250
- message: "Component name:",
251
- initial: "MyComponent",
252
- validate: (value) => isComponentNameValid(value) ? true : "Component name should follow PascalCase naming convention (f.e. Button, MyButton, etc.).",
253
- });
254
- componentName = response.componentName;
255
- }
256
-
257
- if (!argv.namespace) {
258
- response = await prompts({
259
- type: "text",
260
- name: "namespace",
261
- message: "JSDoc namespace:",
262
- initial: "demo.components",
263
- validate: (value) => isNamespaceValid(value) ? true : "The JSDoc namespace must start with a letter and can only contain small-case letters, numbers, dots and dashes.",
264
- });
265
- namespace = response.namespace;
241
+ testSetup = response.testSetup;
266
242
  }
267
243
 
268
- return generateFilesContent(packageName, componentName, namespace, typescriptSupport, skipSubfolder);
244
+ return generateFilesContent(
245
+ packageName,
246
+ componentName,
247
+ skipSubfolder,
248
+ testSetup,
249
+ );
269
250
  };
270
251
 
271
252
  createWebcomponentsPackage();
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@ui5/create-webcomponents-package",
3
- "version": "0.0.0-38861c872",
3
+ "version": "0.0.0-38f83ffef",
4
4
  "description": "UI5 Web Components: create package",
5
5
  "author": "SAP SE (https://www.sap.com)",
6
6
  "license": "Apache-2.0",
7
+ "type": "module",
7
8
  "private": false,
8
9
  "keywords": [
9
10
  "openui5",
@@ -21,6 +22,7 @@
21
22
  "dependencies": {
22
23
  "mkdirp": "^1.0.4",
23
24
  "npm-config-user-agent-parser": "^1.0.0",
25
+ "prettier": "^3.5.3",
24
26
  "prompts": "^2.4.1",
25
27
  "yargs": "^17.5.1"
26
28
  }
@@ -2,5 +2,6 @@
2
2
  dist
3
3
  test
4
4
  src/generated
5
- jsdoc-dist
6
- .eslintrc.js
5
+ .eslintrc.cjs
6
+
7
+ {{INIT_PACKAGE_CYPRESS_ESLINT_IGNORES}}
@@ -0,0 +1,3 @@
1
+ {
2
+ "config": "./package-scripts.cjs"
3
+ }
@@ -0,0 +1,13 @@
1
+ import {{INIT_PACKAGE_VAR_CLASS_NAME}} from "../../src/{{INIT_PACKAGE_VAR_CLASS_NAME}}.js";
2
+
3
+ describe('{{INIT_PACKAGE_VAR_CLASS_NAME}}.cy.tsx', () => {
4
+ it('playground', () => {
5
+ cy.mount(<{{INIT_PACKAGE_VAR_CLASS_NAME}} />)
6
+
7
+ cy.get("[{{INIT_PACKAGE_VAR_TAG}}]")
8
+ .click();
9
+
10
+ cy.get("[{{INIT_PACKAGE_VAR_TAG}}]")
11
+ .should("have.prop", "count", 1)
12
+ })
13
+ })
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "Using fixtures to represent data",
3
+ "email": "hello@cypress.io",
4
+ "body": "Fixtures are a great way to mock data for responses to routes"
5
+ }
@@ -0,0 +1,37 @@
1
+ /// <reference types="cypress" />
2
+ // ***********************************************
3
+ // This example commands.ts shows you how to
4
+ // create various custom commands and overwrite
5
+ // existing commands.
6
+ //
7
+ // For more comprehensive examples of custom
8
+ // commands please read more here:
9
+ // https://on.cypress.io/custom-commands
10
+ // ***********************************************
11
+ //
12
+ //
13
+ // -- This is a parent command --
14
+ // Cypress.Commands.add('login', (email, password) => { ... })
15
+ //
16
+ //
17
+ // -- This is a child command --
18
+ // Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
19
+ //
20
+ //
21
+ // -- This is a dual command --
22
+ // Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
23
+ //
24
+ //
25
+ // -- This will overwrite an existing command --
26
+ // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
27
+ //
28
+ // declare global {
29
+ // namespace Cypress {
30
+ // interface Chainable {
31
+ // login(email: string, password: string): Chainable<void>
32
+ // drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
33
+ // dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
34
+ // visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
35
+ // }
36
+ // }
37
+ // }
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
+ <meta name="viewport" content="width=device-width,initial-scale=1.0">
7
+ <title>Components App</title>
8
+ </head>
9
+ <body>
10
+ <div data-cy-root></div>
11
+ </body>
12
+ </html>
@@ -0,0 +1,36 @@
1
+ // ***********************************************************
2
+ // This example support/component.ts is processed and
3
+ // loaded automatically before your test files.
4
+ //
5
+ // This is a great place to put global configuration and
6
+ // behavior that modifies Cypress.
7
+ //
8
+ // You can change the location of this file or turn off
9
+ // automatically serving support files with the
10
+ // 'supportFile' configuration option.
11
+ //
12
+ // You can read more here:
13
+ // https://on.cypress.io/configuration
14
+ // ***********************************************************
15
+
16
+ // Import commands.js using ES2015 syntax:
17
+ import './commands'
18
+
19
+ import { mount } from '@ui5/cypress-ct-ui5-webc'
20
+
21
+ // Augment the Cypress namespace to include type definitions for
22
+ // your custom command.
23
+ // Alternatively, can be defined in cypress/support/component.d.ts
24
+ // with a <reference path="./component" /> at the top of your spec.
25
+ declare global {
26
+ namespace Cypress {
27
+ interface Chainable {
28
+ mount: typeof mount
29
+ }
30
+ }
31
+ }
32
+
33
+ Cypress.Commands.add('mount', mount)
34
+
35
+ // Example use:
36
+ // cy.mount(MyComponent)