@ui5/webcomponents-tools 1.3.0 → 1.5.0

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 (45) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +5 -6
  3. package/bin/dev.js +1 -5
  4. package/components-package/nps.js +51 -38
  5. package/components-package/vite.config.js +12 -0
  6. package/components-package/wdio.js +21 -4
  7. package/components-package/wdio.sync.js +1 -1
  8. package/icons-collection/nps.js +1 -7
  9. package/lib/copy-and-watch/index.js +0 -1
  10. package/lib/copy-list/index.js +16 -16
  11. package/lib/create-icons/index.js +82 -72
  12. package/lib/create-illustrations/index.js +101 -90
  13. package/lib/dev-server/dev-server.js +66 -0
  14. package/lib/dev-server/virtual-index-html-plugin.js +52 -0
  15. package/lib/esm-abs-to-rel/index.js +13 -9
  16. package/lib/generate-json-imports/i18n.js +38 -31
  17. package/lib/generate-json-imports/themes.js +31 -24
  18. package/lib/hbs2lit/src/compiler.js +2 -2
  19. package/lib/hbs2lit/src/includesReplacer.js +5 -5
  20. package/lib/hbs2ui5/index.js +37 -21
  21. package/lib/i18n/defaults.js +49 -57
  22. package/lib/i18n/toJSON.js +12 -11
  23. package/lib/postcss-css-to-esm/index.js +13 -1
  24. package/lib/postcss-css-to-json/index.js +12 -1
  25. package/lib/postcss-p/postcss-p.mjs +3 -0
  26. package/lib/replace-global-core/index.js +13 -8
  27. package/lib/scoping/scope-test-pages.js +1 -1
  28. package/lib/test-runner/test-runner.js +63 -0
  29. package/package.json +14 -17
  30. package/components-package/rollup-plugins/empty-module.js +0 -15
  31. package/components-package/rollup.js +0 -150
  32. package/lib/documentation/index.js +0 -165
  33. package/lib/documentation/templates/api-component-since.js +0 -3
  34. package/lib/documentation/templates/api-css-variables-section.js +0 -24
  35. package/lib/documentation/templates/api-events-section.js +0 -35
  36. package/lib/documentation/templates/api-methods-section.js +0 -26
  37. package/lib/documentation/templates/api-properties-section.js +0 -42
  38. package/lib/documentation/templates/api-slots-section.js +0 -28
  39. package/lib/documentation/templates/template.js +0 -39
  40. package/lib/hash/config.js +0 -10
  41. package/lib/hash/generate.js +0 -19
  42. package/lib/hash/upToDate.js +0 -31
  43. package/lib/serve/index.js +0 -46
  44. package/lib/serve/serve.json +0 -3
  45. package/package-lock.json +0 -48
package/CHANGELOG.md CHANGED
@@ -3,6 +3,33 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.5.0](https://github.com/SAP/ui5-webcomponents/compare/v1.4.0...v1.5.0) (2022-07-03)
7
+
8
+ **Note:** Version bump only for package @ui5/webcomponents-tools
9
+
10
+
11
+
12
+
13
+
14
+ # [1.4.0](https://github.com/SAP/ui5-webcomponents/compare/v1.3.1...v1.4.0) (2022-05-25)
15
+
16
+
17
+ ### Features
18
+
19
+ **Note:** Version bump only for package @ui5/webcomponents-icons-tnt
20
+
21
+
22
+
23
+
24
+
25
+ ## [1.3.1](https://github.com/SAP/ui5-webcomponents/compare/v1.3.0...v1.3.1) (2022-04-27)
26
+
27
+ **Note:** Version bump only for package @ui5/webcomponents-tools
28
+
29
+
30
+
31
+
32
+
6
33
  # [1.3.0](https://github.com/SAP/ui5-webcomponents/compare/v1.2.4...v1.3.0) (2022-04-19)
7
34
 
8
35
 
package/README.md CHANGED
@@ -1,24 +1,23 @@
1
- ![UI5 icon](https://raw.githubusercontent.com/SAP/ui5-webcomponents/master/docs/images/UI5_logo_wide.png)
1
+ ![UI5 icon](https://raw.githubusercontent.com/SAP/ui5-webcomponents/main/docs/images/UI5_logo_wide.png)
2
2
 
3
3
  # UI5 Web Components - Tools
4
4
 
5
- [![Travis CI Build Status](https://travis-ci.org/SAP/ui5-webcomponents.svg?branch=master)](https://travis-ci.org/SAP/ui5-webcomponents)
6
5
  [![npm Package Version](https://badge.fury.io/js/%40ui5%2Fwebcomponents.svg)](https://www.npmjs.com/package/@ui5/webcomponents)
7
6
 
8
7
  Provides libraries, configuration files and build artifacts,
9
8
  used by other UI5 Web Components packages, such as `main` and `fiori`.
10
9
 
11
10
  ## Resources
12
- - [UI5 Web Components - README.md](https://github.com/SAP/ui5-webcomponents/blob/master/README.md)
11
+ - [UI5 Web Components - README.md](https://github.com/SAP/ui5-webcomponents/blob/main/README.md)
13
12
  - [UI5 Web Components - Home Page](https://sap.github.io/ui5-webcomponents)
14
13
  - [UI5 Web Components - Playground and API Reference](https://sap.github.io/ui5-webcomponents/playground/)
15
14
 
16
15
  ## Support
17
- 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/).
16
+ 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://join-ui5-slack.herokuapp.com/).
18
17
 
19
18
  ## Contribute
20
- Please check our [Contribution Guidelines](https://github.com/SAP/ui5-webcomponents/blob/master/docs/6-contributing/02-conventions-and-guidelines.md).
19
+ Please check our [Contribution Guidelines](https://github.com/SAP/ui5-webcomponents/blob/main/docs/6-contributing/02-conventions-and-guidelines.md).
21
20
 
22
21
  ## License
23
22
  Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved.
24
- 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.
23
+ 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/main/LICENSE.txt) file.
package/bin/dev.js CHANGED
@@ -10,11 +10,7 @@ if (command === "watch") {
10
10
  command = `watch.${argument}`;
11
11
  }
12
12
  } else if (command === "test") {
13
- if (argument === "--no-server") { // yarn test --no-server
14
- command = `test.run`;
15
- } else if (argument) { // yarn test test/specs/Button.spec.js
16
- command = `test.spec --spec ${argument}`;
17
- }
13
+ command = `test ${process.argv.slice(3).join(" ")}`;
18
14
  }
19
15
 
20
16
  child_process.execSync(`npx nps "${command}"`, {stdio: 'inherit'});
@@ -1,24 +1,47 @@
1
1
  const path = require("path");
2
2
  const fs = require("fs");
3
-
4
3
  const LIB = path.join(__dirname, `../lib/`);
5
- const packageName = JSON.parse(fs.readFileSync("./package.json")).name;
4
+
6
5
 
7
6
  const getScripts = (options) => {
8
7
 
9
- const port = options.port || 8080; // preferred port
10
- const portStep = options.portStep || 1; // step to check for available ports, if preferred port is already used
11
8
  let illustrations = options.illustrationsData || [];
12
-
13
9
  illustrations = illustrations.map(illustration => `node "${LIB}/create-illustrations/index.js" ${illustration.path} ${illustration.defaultText} ${illustration.illustrationsPrefix} ${illustration.set} ${illustration.destinationPath}`);
14
-
15
10
  let illustrationsScript = illustrations.join(" && ");
16
11
 
12
+ let viteConfig;
13
+ if (fs.existsSync("config/vite.config.js")) {
14
+ // old project setup where config file is in separate folder
15
+ viteConfig = "-c config/vite.config.js";
16
+ } else if (fs.existsSync("vite.config.js")) {
17
+ // preferred way of custom configuration in root project folder
18
+ viteConfig = "";
19
+ } else {
20
+ // no custom configuration - use default from tools project
21
+ viteConfig = `-c "${require.resolve("@ui5/webcomponents-tools/components-package/vite.config.js")}"`;
22
+ }
23
+
24
+ let eslintConfig;
25
+ if (fs.existsSync("config/.eslintrc.js")) {
26
+ // old project setup where config file is in separate folder
27
+ eslintConfig = "--config config/.eslintrc.js";
28
+ } else if (fs.existsSync(".eslintrc.js")) {
29
+ // preferred way of custom configuration in root project folder
30
+ eslintConfig = "";
31
+ } else {
32
+ // no custom configuration - use default from tools project
33
+ eslintConfig = `--config "${require.resolve("@ui5/webcomponents-tools/components-package/eslint.js")}"`;
34
+ }
35
+
17
36
  const scripts = {
18
- clean: "rimraf dist && rimraf .port",
19
- lint: "eslint . --config config/.eslintrc.js",
20
- lintfix: "eslint . --config config/.eslintrc.js --fix",
21
- prepare: "nps clean build.templates build.styles build.i18n build.jsonImports copy build.samples build.illustrations",
37
+ clean: 'rimraf dist && rimraf .port && nps "scope.testPages.clean"',
38
+ lint: `eslint . ${eslintConfig}`,
39
+ lintfix: `eslint . ${eslintConfig}`,
40
+ prepare: {
41
+ default: "nps clean prepare.all",
42
+ all: 'concurrently "nps build.templates" "nps build.i18n" "nps prepare.styleRelated" "nps copy" "nps build.api" "nps build.illustrations"',
43
+ styleRelated: "nps build.styles build.jsonImports",
44
+ },
22
45
  build: {
23
46
  default: "nps lint prepare build.bundle",
24
47
  templates: `mkdirp dist/generated/templates && node "${LIB}/hbs2ui5/index.js" -d src/ -o dist/generated/templates`,
@@ -37,26 +60,21 @@ const getScripts = (options) => {
37
60
  themes: `node "${LIB}/generate-json-imports/themes.js" dist/generated/assets/themes dist/generated/json-imports`,
38
61
  i18n: `node "${LIB}/generate-json-imports/i18n.js" dist/generated/assets/i18n dist/generated/json-imports`,
39
62
  },
40
- bundle: "rollup --config config/rollup.config.js",
41
- samples: {
42
- default: "nps build.samples.api build.samples.docs",
43
- api: `jsdoc -c "${LIB}/jsdoc/config.json"`,
44
- docs: `node "${LIB}/documentation/index.js" dist/api.json`,
45
- },
63
+ bundle: `vite build ${viteConfig}`,
64
+ api: `jsdoc -c "${LIB}/jsdoc/config.json"`,
46
65
  illustrations: illustrationsScript
47
66
  },
48
67
  copy: {
49
- default: "nps copy.src copy.props copy.test",
68
+ default: "nps copy.src copy.props",
50
69
  src: `node "${LIB}/copy-and-watch/index.js" --silent "src/**/*.js" dist/`,
51
70
  props: `node "${LIB}/copy-and-watch/index.js" --silent "src/**/*.properties" dist/`,
52
- test: `node "${LIB}/copy-and-watch/index.js" --silent "test/**/*.*" dist/test-resources`,
53
71
  },
54
72
  watch: {
55
- default: 'concurrently "nps watch.templates" "nps watch.samples" "nps watch.test" "nps watch.src" "nps watch.bundle" "nps watch.styles" "nps watch.i18n"',
73
+ default: 'concurrently "nps watch.templates" "nps watch.api" "nps watch.src" "nps watch.styles" "nps watch.i18n" "nps watch.props"',
74
+ devServer: 'concurrently "nps watch.default" "nps watch.bundle"',
56
75
  src: 'nps "copy.src --watch --safe --skip-initial-copy"',
57
76
  props: 'nps "copy.props --watch --safe --skip-initial-copy"',
58
- test: 'nps "copy.test --watch --safe --skip-initial-copy"',
59
- bundle: 'rollup --config config/rollup.config.js -w --environment DEV',
77
+ bundle: `node ${LIB}/dev-server/dev-server.js ${viteConfig}`,
60
78
  styles: {
61
79
  default: 'concurrently "nps watch.styles.themes" "nps watch.styles.components"',
62
80
  themes: 'nps "build.styles.themes -w"',
@@ -67,31 +85,26 @@ const getScripts = (options) => {
67
85
  },
68
86
  },
69
87
  templates: 'chokidar "src/**/*.hbs" -c "nps build.templates"',
70
- samples: 'chokidar "test/**/*.sample.html" -c "nps build.samples"',
88
+ api: 'chokidar "test/**/*.sample.html" -c "nps build.api"',
71
89
  i18n: 'chokidar "src/i18n/messagebundle.properties" -c "nps build.i18n.defaultsjs"'
72
90
  },
73
- dev: 'concurrently "nps serve" "nps watch"',
74
- start: "nps prepare dev",
75
- serve: `node "${LIB}/serve/index.js" --dir="dist/" --port=${port} --portStep=${portStep} --packageName="${packageName}"`,
76
- test: {
77
- // --success first - report the exit code of the test run (first command to finish), as serve is always terminated and has a non-0 exit code
78
- default: 'concurrently "nps serve" "nps test.run" --kill-others --success first',
79
- run: "cross-env WDIO_LOG_LEVEL=error wdio config/wdio.conf.js",
80
- spec: "wdio run config/wdio.conf.js",
81
- },
82
- startWithScope: "nps scope.prepare scope.dev",
91
+ start: "nps prepare watch.devServer",
92
+ test: `node "${LIB}/test-runner/test-runner.js"`,
93
+ "test-suite-1": `node "${LIB}/test-runner/test-runner.js" --suite suite1`,
94
+ "test-suite-2": `node "${LIB}/test-runner/test-runner.js" --suite suite2`,
95
+ startWithScope: "nps scope.prepare scope.watchWithBundle",
83
96
  scope: {
84
97
  prepare: "nps scope.lint prepare scope.testPages",
85
98
  lint: `node "${LIB}/scoping/lint-src.js"`,
86
99
  testPages: {
87
100
  default: "nps scope.testPages.clean scope.testPages.copy scope.testPages.replace",
88
- clean: "rimraf dist/test-resources/pages/scoped",
89
- copy: `node "${LIB}/copy-and-watch/index.js" --silent "dist/test-resources/pages/**/*" dist/test-resources/scoped`,
90
- replace: `node "${LIB}/scoping/scope-test-pages.js" dist/test-resources/scoped demo`,
101
+ clean: "rimraf test/pages/scoped",
102
+ copy: `node "${LIB}/copy-and-watch/index.js" --silent "test/pages/**/*" test/pages/scoped`,
103
+ replace: `node "${LIB}/scoping/scope-test-pages.js" test/pages/scoped demo`,
91
104
  },
92
- dev: 'concurrently "nps serve" "nps scope.watch"',
93
- watch: 'concurrently "nps watch.templates" "nps watch.samples" "nps watch.test" "nps watch.src" "nps watch.props" "nps scope.bundle" "nps watch.styles"',
94
- bundle: 'rollup --config config/rollup.config.js -w --environment DEV,SCOPE'
105
+ watchWithBundle: 'concurrently "nps scope.watch" "nps scope.bundle" ',
106
+ watch: 'concurrently "nps watch.templates" "nps watch.api" "nps watch.test" "nps watch.src" "nps watch.props" "nps watch.styles"',
107
+ bundle: `node ${LIB}/dev-server/dev-server.js ${viteConfig}`,
95
108
  }
96
109
  };
97
110
 
@@ -0,0 +1,12 @@
1
+ // vite.config.js
2
+ const { defineConfig } = require('vite');
3
+ const virtualIndex = require("../lib/dev-server/virtual-index-html-plugin.js");
4
+
5
+ module.exports = defineConfig(async () => {
6
+ return {
7
+ build: {
8
+ emptyOutDir: false,
9
+ },
10
+ plugins: [await virtualIndex()],
11
+ }
12
+ });
@@ -50,7 +50,7 @@ exports.config = {
50
50
  // maxInstances can get overwritten per capability. So if you have an in-house Selenium
51
51
  // grid with only 5 firefox instances available you can make sure that not more than
52
52
  // 5 instances get started at a time.
53
- maxInstances: process.env.TRAVIS ? 1 : 5,
53
+ maxInstances: 5,
54
54
  //
55
55
  browserName: 'chrome',
56
56
  'goog:chromeOptions': {
@@ -82,7 +82,7 @@ exports.config = {
82
82
  // with `/`, the base url gets prepended, not including the path portion of your baseUrl.
83
83
  // If your `url` parameter starts without a scheme or `/` (like `some/path`), the base url
84
84
  // gets prepended directly.
85
- baseUrl: undefined, // This is important since WDIO 7+ does not accept an empty string for baseUrl
85
+ baseUrl: 'http://localhost:4567', // This is important since WDIO 7+ does not accept an empty string for baseUrl
86
86
  path: '',
87
87
  //
88
88
  // Default timeout for all waitFor* commands.
@@ -99,7 +99,14 @@ exports.config = {
99
99
  // Services take over a specific job you don't want to take care of. They enhance
100
100
  // your test setup with almost no effort. Unlike plugins, they don't add new
101
101
  // commands. Instead, they hook themselves up into the test process.
102
- services: ['chromedriver'],
102
+ services: ['chromedriver', 'devtools',
103
+ ['static-server', {
104
+ folders: [
105
+ { mount: '/', path: './dist' },
106
+ ],
107
+ port: '4567',
108
+ }],
109
+ ],
103
110
  // options
104
111
  chromeDriverArgs: ['--port=9515'], // default
105
112
  // Framework you want to run your specs with.
@@ -316,7 +323,6 @@ exports.config = {
316
323
  "click",
317
324
  "doubleClick",
318
325
  "dragAndDrop",
319
- "keys",
320
326
  "pause",
321
327
  "removeAttribute", // custom
322
328
  "scrollIntoView",
@@ -327,10 +333,21 @@ exports.config = {
327
333
  "touchAction",
328
334
  "url",
329
335
  ];
336
+
337
+ const waitForWithDelay = [
338
+ "keys",
339
+ ];
340
+
330
341
  if (waitFor.includes(commandName)) {
331
342
  await browser.executeAsync(function (done) {
332
343
  window["sap-ui-webcomponents-bundle"].renderFinished().then(done);
333
344
  });
345
+ } else if (waitForWithDelay.includes(commandName)) {
346
+ await browser.executeAsync(function (done) {
347
+ setTimeout(() => {
348
+ window["sap-ui-webcomponents-bundle"].renderFinished().then(done);
349
+ }, 10);
350
+ });
334
351
  }
335
352
  },
336
353
  /**
@@ -50,7 +50,7 @@ exports.config = {
50
50
  // maxInstances can get overwritten per capability. So if you have an in-house Selenium
51
51
  // grid with only 5 firefox instances available you can make sure that not more than
52
52
  // 5 instances get started at a time.
53
- maxInstances: process.env.TRAVIS ? 1 : 5,
53
+ maxInstances: 5,
54
54
  //
55
55
  browserName: 'chrome',
56
56
  'goog:chromeOptions': {
@@ -1,9 +1,4 @@
1
1
  const path = require("path");
2
- const resolve = require("resolve");
3
-
4
- const generateHash = resolve.sync("@ui5/webcomponents-tools/lib/hash/generate.js");
5
- const hashIsUpToDate = resolve.sync("@ui5/webcomponents-tools/lib/hash/upToDate.js");
6
- const UP_TO_DATE = `node "${hashIsUpToDate}" dist/ hash.txt && echo "Up to date."`;
7
2
 
8
3
  const LIB = path.join(__dirname, `../lib/`);
9
4
 
@@ -51,7 +46,7 @@ const getScripts = (options) => {
51
46
  clean: "rimraf dist",
52
47
  copy: copyAssetsCmd,
53
48
  build: {
54
- default: `${UP_TO_DATE} || nps clean copy build.i18n build.icons build.jsonImports hash`,
49
+ default: `nps clean copy build.i18n build.icons build.jsonImports`,
55
50
  i18n: {
56
51
  default: "nps build.i18n.defaultsjs build.i18n.json",
57
52
  defaultsjs: `mkdirp dist/generated/i18n && node "${LIB}/i18n/defaults.js" src/i18n dist/generated/i18n`,
@@ -63,7 +58,6 @@ const getScripts = (options) => {
63
58
  },
64
59
  icons: createJSImportsCmd,
65
60
  },
66
- hash: `node "${generateHash}" dist/ hash.txt`,
67
61
  };
68
62
 
69
63
  return scripts;
@@ -27,7 +27,6 @@ const path = require('path');
27
27
  const chokidar = require('chokidar');
28
28
  const glob = require('glob');
29
29
  const globParent = require('glob-parent');
30
- require('colors');
31
30
 
32
31
  /* CODE */
33
32
 
@@ -1,28 +1,28 @@
1
- const fs = require("fs");
1
+ const fs = require("fs").promises;
2
2
  const path = require("path");
3
- const mkdirp = require("mkdirp");
4
3
 
5
4
  const fileList = process.argv[2];
6
5
  const dest = process.argv[3];
7
6
  const src = "../../node_modules/@openui5/sap.ui.core/src/";
8
7
 
9
- const filesToCopy = fs.readFileSync(fileList).toString();
10
- // console.log(filesToCopy);
8
+ const generate = async () => {
9
+ const filesToCopy = (await fs.readFile(fileList)).toString();
10
+ // console.log(filesToCopy);
11
11
 
12
- // Support full-line comments starting with # in the used-modules.txt file
13
- const shouldCopy = file => file.length && !file.startsWith("#");
12
+ // Support full-line comments starting with # in the used-modules.txt file
13
+ const shouldCopy = file => file.length && !file.startsWith("#");
14
14
 
15
- const trimFile = file => file.trim();
15
+ const trimFile = file => file.trim();
16
16
 
17
- filesToCopy.split("\n").map(trimFile).filter(shouldCopy).forEach(async moduleName => {
18
- const srcPath = path.join(src, moduleName);
19
- const destPath = path.join(dest, moduleName);
17
+ return filesToCopy.split("\n").map(trimFile).filter(shouldCopy).map(async moduleName => {
18
+ const srcPath = path.join(src, moduleName);
19
+ const destPath = path.join(dest, moduleName);
20
20
 
21
- await mkdirp(path.dirname(destPath));
22
- fs.copyFile(srcPath, destPath, (err) => {
23
- if (err) {
24
- throw err;
25
- }
26
- console.log(`${destPath} created.`);
21
+ await fs.mkdir(path.dirname(destPath), { recursive: true });
22
+ return fs.copyFile(srcPath, destPath);
27
23
  });
24
+ };
25
+
26
+ generate().then(() => {
27
+ console.log("Files copied.");
28
28
  });
@@ -1,72 +1,82 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const mkdirp = require("mkdirp");
4
-
5
- const collectionName = process.argv[2] || "SAP-icons";
6
- const collectionVersion = process.argv[3];
7
- const srcFile = collectionVersion ? path.normalize(`src/${collectionVersion}/${collectionName}.json`) : path.normalize(`src/${collectionName}.json`);
8
- const destDir = collectionVersion ? path.normalize(`dist/${collectionVersion}/`) : path.normalize("dist/");
9
-
10
- mkdirp.sync(destDir);
11
-
12
- const iconTemplate = (name, pathData, ltr, collection, packageName) => `import { registerIcon } from "@ui5/webcomponents-base/dist/asset-registries/Icons.js";
13
-
14
- const name = "${name}";
15
- const pathData = "${pathData}";
16
- const ltr = ${ltr};
17
- const collection = "${collection}";
18
- const packageName = "${packageName}";
19
-
20
- registerIcon(name, { pathData, ltr, collection, packageName });
21
-
22
- export default { pathData };`;
23
-
24
-
25
- const iconAccTemplate = (name, pathData, ltr, accData, collection, packageName) => `import { registerIcon } from "@ui5/webcomponents-base/dist/asset-registries/Icons.js";
26
- import { ${accData.key} } from "../generated/i18n/i18n-defaults.js";
27
-
28
- const name = "${name}";
29
- const pathData = "${pathData}";
30
- const ltr = ${ltr};
31
- const accData = ${accData.key};
32
- const collection = "${collection}";
33
- const packageName = "${packageName}";
34
-
35
- registerIcon(name, { pathData, ltr, accData, collection, packageName });
36
-
37
- export default { pathData, accData };`;
38
-
39
-
40
-
41
- const collectionTemplate = (name) => `import { isThemeFamily } from "@ui5/webcomponents-base/dist/config/Theme.js";
42
- import pathDataV4 from "./v5/${name}.js";
43
- import pathDataV5 from "./v4/${name}.js";
44
- const pathData = isThemeFamily("sap_horizon") ? pathDataV5 : pathDataV4;
45
- export default { pathData };`;
46
-
47
-
48
- const svgTemplate = (pathData) => `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
49
- <path d="${pathData}"/>
50
- </svg>`;
51
-
52
- const createIcons = (file) => {
53
- const json = JSON.parse(fs.readFileSync(file));
54
-
55
- for (let name in json.data) {
56
- const iconData = json.data[name];
57
- const pathData = iconData.path;
58
- const ltr = !!iconData.ltr;
59
- const acc = iconData.acc;
60
-
61
- const content = acc ? iconAccTemplate(name, pathData, ltr, acc, json.collection, json.packageName) : iconTemplate(name, pathData, ltr, json.collection, json.packageName);
62
-
63
- fs.writeFileSync(path.join(destDir, `${name}.js`), content);
64
- fs.writeFileSync(path.join(destDir, `${name}.svg`), svgTemplate(pathData));
65
-
66
- if (json.version) {
67
- fs.writeFileSync(path.join(path.normalize("dist/"), `${name}.js`), collectionTemplate(name));
68
- }
69
- }
70
- };
71
-
72
- createIcons(srcFile);
1
+ const fs = require("fs").promises;
2
+ const path = require("path");
3
+
4
+ const collectionName = process.argv[2] || "SAP-icons";
5
+ const collectionVersion = process.argv[3];
6
+ const srcFile = collectionVersion ? path.normalize(`src/${collectionVersion}/${collectionName}.json`) : path.normalize(`src/${collectionName}.json`);
7
+ const destDir = collectionVersion ? path.normalize(`dist/${collectionVersion}/`) : path.normalize("dist/");
8
+
9
+ const iconTemplate = (name, pathData, ltr, collection, packageName) => `import { registerIcon } from "@ui5/webcomponents-base/dist/asset-registries/Icons.js";
10
+
11
+ const name = "${name}";
12
+ const pathData = "${pathData}";
13
+ const ltr = ${ltr};
14
+ const accData = null;
15
+ const collection = "${collection}";
16
+ const packageName = "${packageName}";
17
+
18
+ registerIcon(name, { pathData, ltr, collection, packageName });
19
+
20
+ export default "${name}";
21
+ export { pathData, ltr, accData };`;
22
+
23
+
24
+ const iconAccTemplate = (name, pathData, ltr, accData, collection, packageName) => `import { registerIcon } from "@ui5/webcomponents-base/dist/asset-registries/Icons.js";
25
+ import { ${accData.key} } from "../generated/i18n/i18n-defaults.js";
26
+
27
+ const name = "${name}";
28
+ const pathData = "${pathData}";
29
+ const ltr = ${ltr};
30
+ const accData = ${accData.key};
31
+ const collection = "${collection}";
32
+ const packageName = "${packageName}";
33
+
34
+ registerIcon(name, { pathData, ltr, accData, collection, packageName });
35
+
36
+ export default "${name}";
37
+ export { pathData, ltr, accData };`;
38
+
39
+
40
+
41
+ const collectionTemplate = (name) => `import { isThemeFamily } from "@ui5/webcomponents-base/dist/config/Theme.js";
42
+ import {pathData as pathDataV5, ltr, accData} from "./v5/${name}.js";
43
+ import {pathData as pathDataV4} from "./v4/${name}.js";
44
+
45
+ const pathData = isThemeFamily("sap_horizon") ? pathDataV5 : pathDataV4;
46
+
47
+ export default "${name}";
48
+ export { pathData, ltr, accData };`;
49
+
50
+
51
+ const svgTemplate = (pathData) => `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
52
+ <path d="${pathData}"/>
53
+ </svg>`;
54
+
55
+ const createIcons = async (file) => {
56
+ await fs.mkdir(destDir, { recursive: true });
57
+
58
+ const json = JSON.parse(await fs.readFile(file));
59
+
60
+ const promises = [];
61
+ for (let name in json.data) {
62
+ const iconData = json.data[name];
63
+ const pathData = iconData.path;
64
+ const ltr = !!iconData.ltr;
65
+ const acc = iconData.acc;
66
+
67
+ const content = acc ? iconAccTemplate(name, pathData, ltr, acc, json.collection, json.packageName) : iconTemplate(name, pathData, ltr, json.collection, json.packageName);
68
+
69
+ promises.push(fs.writeFile(path.join(destDir, `${name}.js`), content));
70
+ promises.push(fs.writeFile(path.join(destDir, `${name}.svg`), svgTemplate(pathData)));
71
+
72
+ if (json.version) {
73
+ promises.push(fs.writeFile(path.join(path.normalize("dist/"), `${name}.js`), collectionTemplate(name)));
74
+ }
75
+ }
76
+
77
+ return Promise.all(promises);
78
+ };
79
+
80
+ createIcons(srcFile).then(() => {
81
+ console.log("Icons created.");
82
+ });