@ui5/webcomponents-tools 0.0.0-9e104af01 → 0.0.0-a289c53b5

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.
@@ -8,7 +8,9 @@ const generate = async () => {
8
8
 
9
9
  const messageBundle = path.normalize(`${process.argv[2]}/messagebundle.properties`);
10
10
  const messageBundleDefaultLanguage = path.normalize(`${process.argv[2]}/messagebundle_${defaultLanguage}.properties`);
11
- const outputFile = path.normalize(`${process.argv[3]}/i18n-defaults.js`);
11
+ const tsMode = process.env.UI5_TS === "true"; // In Typescript mode, we output .ts files and set the required types, otherwise - output pure .js files
12
+
13
+ const outputFile = path.normalize(`${process.argv[3]}/i18n-defaults.${tsMode ? "ts": "js"}`);
12
14
 
13
15
  if (!messageBundle || !outputFile) {
14
16
  return;
@@ -45,6 +47,9 @@ const generate = async () => {
45
47
  let effectiveValue = defaultLanguageValue || value;
46
48
  effectiveValue = effectiveValue.replace(/\"/g, "\\\""); // escape double quotes in translations
47
49
 
50
+ if (tsMode) {
51
+ return `const ${key}: I18nText = {key: "${key}", defaultText: "${effectiveValue}"};`;
52
+ }
48
53
  return `const ${key} = {key: "${key}", defaultText: "${effectiveValue}"};`;
49
54
  };
50
55
 
@@ -62,7 +67,9 @@ const generate = async () => {
62
67
  const textKeys = Object.keys(properties);
63
68
  const texts = textKeys.map(prop => getTextInfo(prop, properties[prop], defaultLanguageProperties && defaultLanguageProperties[prop])).join('');
64
69
 
65
- return `${texts}
70
+ // tabs are intentionally mixed to have proper identation in the produced file
71
+ return `${tsMode ? `import { I18nText } from "@ui5/webcomponents-base/dist/i18nBundle.js";` : ""}
72
+ ${texts}
66
73
  export {${textKeys.join()}};`;
67
74
  };
68
75
 
@@ -34,7 +34,7 @@ const convertToJSON = async (file) => {
34
34
  const generate = async () => {
35
35
  const { globby } = await import("globby");
36
36
  await fs.mkdir(messagesJSONDist, { recursive: true });
37
- const files = await globby(messagesBundles);
37
+ const files = await globby(messagesBundles.replace(/\\/g, "/"));
38
38
  return Promise.all(files.map(convertToJSON));
39
39
  };
40
40
 
@@ -8,7 +8,7 @@ const sourceDir = process.argv[3];
8
8
  const preprocessTypes = async () => {
9
9
  try {
10
10
  const { globby } = await import("globby");
11
- const fileNames = await globby(inputDir + "**/types/*.js");
11
+ const fileNames = await globby(inputDir.replace(/\\/g, "/") + "**/types/*.js");
12
12
 
13
13
  return Promise.all(fileNames.map(processTypeFile));
14
14
  } catch(e) {
@@ -63,7 +63,7 @@ const preprocessComponents = async () => {
63
63
 
64
64
  try {
65
65
  const { globby } = await import("globby");
66
- const fileNames = await globby(sourceDir + "/*.ts");
66
+ const fileNames = await globby(sourceDir.replace(/\\/g, "/") + "/*.ts");
67
67
 
68
68
  return Promise.all(fileNames.map(processComponentFile));
69
69
  } catch(e) {
@@ -11,11 +11,38 @@ const getDefaultThemeCode = packageName => {
11
11
  import defaultThemeBase from "@ui5/webcomponents-theming/dist/generated/themes/${DEFAULT_THEME}/parameters-bundle.css.js";
12
12
  import defaultTheme from "./${DEFAULT_THEME}/parameters-bundle.css.js";
13
13
 
14
- registerThemePropertiesLoader("@ui5/webcomponents-theming", "${DEFAULT_THEME}", () => defaultThemeBase);
15
- registerThemePropertiesLoader("${packageName}", "${DEFAULT_THEME}", () => defaultTheme);
14
+ registerThemePropertiesLoader("@ui5/webcomponents-theming", "${DEFAULT_THEME}", async () => defaultThemeBase);
15
+ registerThemePropertiesLoader("${packageName}", "${DEFAULT_THEME}", async () => defaultTheme);
16
16
  `;
17
17
  };
18
18
 
19
+ const getFileContent = (tsMode, targetFile, packageName, css, includeDefaultTheme) => {
20
+ if (tsMode) {
21
+ return getTSContent(targetFile, packageName, css, includeDefaultTheme);
22
+ }
23
+
24
+ return getJSContent(targetFile, packageName, css, includeDefaultTheme);
25
+ }
26
+
27
+ const getTSContent = (targetFile, packageName, css, includeDefaultTheme) => {
28
+ const typeImport = "import type { StyleData } from \"@ui5/webcomponents-base/dist/types.js\";"
29
+ const defaultTheme = includeDefaultTheme ? getDefaultThemeCode(packageName) : "";
30
+
31
+ // tabs are intentionally mixed to have proper identation in the produced file
32
+ return `${typeImport}
33
+ ${defaultTheme}
34
+ const styleData: StyleData = {packageName:"${packageName}",fileName:"${targetFile.substr(targetFile.lastIndexOf("themes"))}",content:${css}};
35
+ export default styleData;
36
+ `;
37
+ }
38
+
39
+ const getJSContent = (targetFile, packageName, css, includeDefaultTheme) => {
40
+ const defaultTheme = includeDefaultTheme ? getDefaultThemeCode(packageName) : "";
41
+
42
+ return `${defaultTheme}export default {packageName:"${packageName}",fileName:"${targetFile.substr(targetFile.lastIndexOf("themes"))}",content:${css}}`
43
+ }
44
+
45
+
19
46
  const proccessCSS = css => {
20
47
  css = css.replace(/\.sapThemeMeta[\s\S]*?:root/, ":root");
21
48
  css = css.replace(/\.background-image.*{.*}/, "");
@@ -27,18 +54,23 @@ const proccessCSS = css => {
27
54
  module.exports = function (opts) {
28
55
  opts = opts || {};
29
56
 
57
+ const packageName = opts.packageName;
58
+ const includeDefaultTheme = opts.includeDefaultTheme;
59
+ const toReplace = opts.toReplace;
60
+
30
61
  return {
31
62
  postcssPlugin: 'postcss-css-to-esm',
32
63
  Once (root) {
64
+ const tsMode = process.env.UI5_TS === "true";
65
+
33
66
  let css = root.toString();
34
67
  css = proccessCSS(css);
35
68
 
36
- const targetFile = root.source.input.from.replace(`/${opts.toReplace}/`, "/dist/generated/").replace(`\\${opts.toReplace}\\`, "\\dist\\generated\\");
69
+ const targetFile = root.source.input.from.replace(`/${toReplace}/`, "/src/generated/").replace(`\\${toReplace}\\`, "\\src\\generated\\");
37
70
  mkdirp.sync(path.dirname(targetFile));
38
71
 
39
- const filePath = `${targetFile}.js`;
40
- const defaultTheme = opts.includeDefaultTheme ? getDefaultThemeCode(opts.packageName) : ``;
41
-
72
+ const filePath = `${targetFile}.${tsMode ? "ts" : "js"}`;
73
+
42
74
  // it seems slower to read the old content, but writing the same content with no real changes
43
75
  // (as in initial build and then watch mode) will cause an unnecessary dev server refresh
44
76
  let oldContent = "";
@@ -47,7 +79,8 @@ module.exports = function (opts) {
47
79
  } catch (e) {
48
80
  // file not found
49
81
  }
50
- const content = `${defaultTheme}export default {packageName:"${opts.packageName}",fileName:"${targetFile.substr(targetFile.lastIndexOf("themes"))}",content:${css}}`
82
+
83
+ const content = getFileContent(tsMode, targetFile, packageName, css, includeDefaultTheme);
51
84
  if (content !== oldContent) {
52
85
  fs.writeFileSync(filePath, content);
53
86
  }
@@ -16,7 +16,7 @@ const replaceGlobalCoreUsage = async (srcPath) => {
16
16
 
17
17
  const generate = async () => {
18
18
  const { globby } = await import("globby");
19
- const fileNames = await globby(basePath + "**/*.js");
19
+ const fileNames = await globby(basePath.replace(/\\/g, "/") + "**/*.js");
20
20
  return Promise.all(fileNames.map(replaceGlobalCoreUsage).filter(x => !!x));
21
21
  };
22
22
 
@@ -1,6 +1,7 @@
1
1
  const child_process = require("child_process");
2
2
  const { readFileSync } = require("fs");
3
3
  const path = require("path");
4
+ const fs = require("fs");
4
5
 
5
6
  // search for dev-server port
6
7
  // start in current folder
@@ -23,7 +24,7 @@ while (true) {
23
24
  // check if we are in a monorepo and extract path from package.json
24
25
  let packageRepositoryPath = "";
25
26
  const pkg = require(path.join(process.cwd(), "package.json"));
26
- packageRepositoryPath = pkg.repository.directory;
27
+ packageRepositoryPath = pkg.repository ? pkg.repository.directory : "";
27
28
 
28
29
  // construct base url
29
30
  // use devServerPort if a dev server is running, otherwise let the baseUrl in the wdio config be used
@@ -57,7 +58,14 @@ if (process.argv.length > 3) {
57
58
  restParams = process.argv.slice(2).join(" ");
58
59
  }
59
60
 
61
+ let wdioConfig = "";
62
+ if (fs.existsSync("config/wdio.conf.cjs")) {
63
+ wdioConfig = "config/wdio.conf.cjs";
64
+ } else if (fs.existsSync("config/wdio.conf.js")) {
65
+ wdioConfig = "config/wdio.conf.js";
66
+ }
67
+
60
68
  // run wdio with calculated parameters
61
- const cmd = `yarn cross-env WDIO_LOG_LEVEL=error wdio config/wdio.conf.js ${spec} ${baseUrl} ${restParams}`;
69
+ const cmd = `yarn cross-env WDIO_LOG_LEVEL=error wdio ${wdioConfig} ${spec} ${baseUrl} ${restParams}`;
62
70
  console.log(`executing: ${cmd}`);
63
71
  child_process.execSync(cmd, {stdio: 'inherit'});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ui5/webcomponents-tools",
3
- "version": "0.0.0-9e104af01",
3
+ "version": "0.0.0-a289c53b5",
4
4
  "description": "UI5 Web Components: webcomponents.tools",
5
5
  "author": "SAP SE (https://www.sap.com)",
6
6
  "license": "Apache-2.0",
@@ -62,12 +62,18 @@
62
62
  "resolve": "^1.20.0",
63
63
  "rimraf": "^3.0.2",
64
64
  "slash": "3.0.0",
65
- "vite": "^2.9.12",
65
+ "vite": "^3.0.4",
66
66
  "wdio-chromedriver-service": "^7.3.2",
67
67
  "zx": "^4.3.0"
68
68
  },
69
69
  "peerDependencies": {
70
- "chromedriver": "*"
70
+ "chromedriver": "*",
71
+ "typescript": "^4.9.4"
72
+ },
73
+ "peerDependenciesMeta": {
74
+ "typescript": {
75
+ "optional": true
76
+ }
71
77
  },
72
78
  "devDependencies": {
73
79
  "yargs": "^17.5.1"