@ui5/webcomponents-tools 0.0.0-974b11d82 → 0.0.0-97c4a1259
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.
- package/CHANGELOG.md +279 -0
- package/assets-meta.js +9 -6
- package/components-package/eslint.js +34 -28
- package/components-package/nps.js +15 -9
- package/components-package/postcss.components.js +6 -3
- package/components-package/postcss.themes.js +5 -1
- package/components-package/vite.config.js +6 -5
- package/components-package/wdio.js +400 -393
- package/components-package/wdio.sync.js +9 -1
- package/icons-collection/nps.js +2 -2
- package/lib/create-icons/index.js +2 -2
- package/lib/create-illustrations/index.js +14 -0
- package/lib/create-new-component/index.js +71 -104
- package/lib/create-new-component/jsFileContentTemplate.js +73 -0
- package/lib/create-new-component/tsFileContentTemplate.js +80 -0
- package/lib/dev-server/virtual-index-html-plugin.js +1 -2
- package/lib/esm-abs-to-rel/index.js +1 -1
- package/lib/generate-js-imports/illustrations.js +75 -64
- package/lib/hbs2lit/src/compiler.js +9 -6
- package/lib/hbs2lit/src/litVisitor2.js +42 -17
- package/lib/hbs2lit/src/svgProcessor.js +12 -5
- package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +32 -4
- package/lib/hbs2ui5/index.js +21 -4
- package/lib/i18n/toJSON.js +1 -1
- package/lib/jsdoc/preprocess.js +2 -2
- package/lib/postcss-css-to-esm/index.js +3 -3
- package/lib/postcss-css-to-json/index.js +1 -1
- package/lib/postcss-scope-vars/index.js +24 -0
- package/lib/replace-global-core/index.js +1 -1
- package/lib/test-runner/test-runner.js +10 -2
- package/package.json +11 -5
@@ -56,7 +56,15 @@ exports.config = {
|
|
56
56
|
'goog:chromeOptions': {
|
57
57
|
// to run chrome headless the following flags are required
|
58
58
|
// (see https://developers.google.com/web/updates/2017/04/headless-chrome)
|
59
|
-
args: [
|
59
|
+
args: [
|
60
|
+
'--headless',
|
61
|
+
'--start-maximized',
|
62
|
+
'--no-sandbox',
|
63
|
+
'--disable-gpu',
|
64
|
+
'--disable-infobars',
|
65
|
+
'--disable-extensions',
|
66
|
+
'--disable-dev-shm-usage',
|
67
|
+
],
|
60
68
|
// args: ['--disable-gpu'],
|
61
69
|
}
|
62
70
|
}],
|
package/icons-collection/nps.js
CHANGED
@@ -21,7 +21,7 @@ const copyIconAssetsCommand = (options) => {
|
|
21
21
|
return {
|
22
22
|
default: "nps copy.json-imports copy.icon-collection",
|
23
23
|
"json-imports": `node "${LIB}/copy-and-watch/index.js" --silent "src/**/*.js" dist/`,
|
24
|
-
"icon-collection": `node "${LIB}/copy-and-watch/index.js" --silent "src/*.json"
|
24
|
+
"icon-collection": `node "${LIB}/copy-and-watch/index.js" --silent "src/*.json" src/generated/assets/`,
|
25
25
|
}
|
26
26
|
}
|
27
27
|
|
@@ -32,7 +32,7 @@ const copyIconAssetsCommand = (options) => {
|
|
32
32
|
|
33
33
|
options.versions.forEach((v) => {
|
34
34
|
command.default += ` copy.icon-collection${v}`;
|
35
|
-
command[`icon-collection${v}`] = `node "${LIB}/copy-and-watch/index.js" --silent "src/${v}/*.json"
|
35
|
+
command[`icon-collection${v}`] = `node "${LIB}/copy-and-watch/index.js" --silent "src/${v}/*.json" src/generated/assets/${v}/`;
|
36
36
|
});
|
37
37
|
|
38
38
|
return command;
|
@@ -38,11 +38,11 @@ export { pathData, ltr, accData };`;
|
|
38
38
|
|
39
39
|
|
40
40
|
|
41
|
-
const collectionTemplate = (name, versions, fullName) => `import {
|
41
|
+
const collectionTemplate = (name, versions, fullName) => `import { isLegacyThemeFamily } from "@ui5/webcomponents-base/dist/config/Theme.js";
|
42
42
|
import { pathData as pathData${versions[0]}, ltr, accData } from "./${versions[0]}/${name}.js";
|
43
43
|
import { pathData as pathData${versions[1]} } from "./${versions[1]}/${name}.js";
|
44
44
|
|
45
|
-
const pathData =
|
45
|
+
const pathData = isLegacyThemeFamily() ? pathData${versions[0]} : pathData${versions[1]};
|
46
46
|
|
47
47
|
export default "${fullName}";
|
48
48
|
export { pathData, ltr, accData };`;
|
@@ -57,10 +57,20 @@ const generate = async () => {
|
|
57
57
|
const illustrationsPrefix = process.argv[4];
|
58
58
|
const illustrationSet = process.argv[5];
|
59
59
|
const destPath = process.argv[6];
|
60
|
+
const collection = process.argv[7];
|
60
61
|
const fileNamePattern = new RegExp(`${illustrationsPrefix}-.+-(.+).svg`);
|
61
62
|
// collect each illustration name because each one should have Sample.js file
|
62
63
|
const fileNames = new Set();
|
63
64
|
|
65
|
+
try {
|
66
|
+
await fs.access(srcPath);
|
67
|
+
} catch (error) {
|
68
|
+
console.log(`The path ${srcPath} does not exist.`);
|
69
|
+
return Promise.resolve(null);
|
70
|
+
}
|
71
|
+
|
72
|
+
console.log(`Generating illustrations from ${srcPath} to ${destPath}`)
|
73
|
+
|
64
74
|
const svgImportTemplate = svgContent => {
|
65
75
|
return `export default \`${svgContent}\`;`
|
66
76
|
};
|
@@ -95,6 +105,7 @@ import {
|
|
95
105
|
|
96
106
|
const name = "${illustrationName}";
|
97
107
|
const set = "${illustrationSet}";
|
108
|
+
const collection = "${collection}";
|
98
109
|
const title = IM_TITLE_${illustrationNameUpperCase};
|
99
110
|
const subtitle = IM_SUBTITLE_${illustrationNameUpperCase};
|
100
111
|
|
@@ -105,6 +116,7 @@ registerIllustration(name, {
|
|
105
116
|
title,
|
106
117
|
subtitle,
|
107
118
|
set,
|
119
|
+
collection,
|
108
120
|
});
|
109
121
|
|
110
122
|
export {
|
@@ -119,12 +131,14 @@ import spotSvg from "./${illustrationsPrefix}-Spot-${illustrationName}.js";
|
|
119
131
|
|
120
132
|
const name = "${illustrationName}";
|
121
133
|
const set = "${illustrationSet}";
|
134
|
+
const collection = "${collection}";
|
122
135
|
|
123
136
|
registerIllustration(name, {
|
124
137
|
dialogSvg,
|
125
138
|
sceneSvg,
|
126
139
|
spotSvg,
|
127
140
|
set,
|
141
|
+
collection,
|
128
142
|
});
|
129
143
|
|
130
144
|
export {
|
@@ -1,80 +1,30 @@
|
|
1
1
|
const fs = require("fs");
|
2
|
-
|
3
|
-
const
|
4
|
-
|
5
|
-
|
6
|
-
import ${componentName}Template from "./generated/templates/${componentName}Template.lit.js";
|
7
|
-
|
8
|
-
// Styles
|
9
|
-
import ${componentName}Css from "./generated/themes/${componentName}.css.js";
|
2
|
+
const path = require("path");
|
3
|
+
const prompts = require("prompts");
|
4
|
+
const jsFileContentTemplate = require("./jsFileContentTemplate.js");
|
5
|
+
const tsFileContentTemplate = require("./tsFileContentTemplate.js");
|
10
6
|
|
11
7
|
/**
|
12
|
-
*
|
8
|
+
* Hyphanates the given PascalCase string, f.e.:
|
9
|
+
* Foo -> "my-foo" (adds preffix)
|
10
|
+
* FooBar -> "foo-bar"
|
13
11
|
*/
|
14
|
-
const
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
},
|
19
|
-
slots: /** @lends sap.ui.webc.${library}.${componentName}.prototype */ {
|
20
|
-
//
|
21
|
-
},
|
22
|
-
events: /** @lends sap.ui.webc.${library}.${componentName}.prototype */ {
|
23
|
-
//
|
24
|
-
},
|
12
|
+
const hyphaneteComponentName = (componentName) => {
|
13
|
+
const result = componentName.replace(/([a-z])([A-Z])/g, '$1-$2' ).toLowerCase();
|
14
|
+
|
15
|
+
return result.includes("-") ? result : `my-${result}`;
|
25
16
|
};
|
26
17
|
|
27
18
|
/**
|
28
|
-
*
|
29
|
-
*
|
30
|
-
* <h3 class="comment-api-title">Overview</h3>
|
31
|
-
*
|
32
|
-
*
|
33
|
-
* <h3>Usage</h3>
|
34
|
-
*
|
35
|
-
* For the <code>${tagName}</code>
|
36
|
-
* <h3>ES6 Module Import</h3>
|
37
|
-
*
|
38
|
-
* <code>import ${packageName}/dist/${componentName}.js";</code>
|
39
|
-
*
|
40
|
-
* @constructor
|
41
|
-
* @author SAP SE
|
42
|
-
* @alias sap.ui.webc.${library}.${componentName}
|
43
|
-
* @extends sap.ui.webc.base.UI5Element
|
44
|
-
* @tagname ${tagName}
|
45
|
-
* @public
|
19
|
+
* Capitalizes first letter of string.
|
46
20
|
*/
|
47
|
-
|
48
|
-
static get metadata() {
|
49
|
-
return metadata;
|
50
|
-
}
|
51
|
-
|
52
|
-
static get render() {
|
53
|
-
return litRender;
|
54
|
-
}
|
55
|
-
|
56
|
-
static get styles() {
|
57
|
-
return ${componentName}Css;
|
58
|
-
}
|
59
|
-
|
60
|
-
static get template() {
|
61
|
-
return ${componentName}Template;
|
62
|
-
}
|
63
|
-
|
64
|
-
static get dependencies() {
|
65
|
-
return [];
|
66
|
-
}
|
67
|
-
|
68
|
-
static async onDefine() {
|
69
|
-
|
70
|
-
}
|
71
|
-
}
|
72
|
-
|
73
|
-
${componentName}.define();
|
21
|
+
const capitalizeFirstLetter = string => string.charAt(0).toUpperCase() + string.slice(1);
|
74
22
|
|
75
|
-
|
76
|
-
|
77
|
-
|
23
|
+
/**
|
24
|
+
* Validates component name, enforcing PascalCase pattern - Button, MyButton.
|
25
|
+
*/
|
26
|
+
const PascalCasePattern = /^[A-Z][A-Za-z0-9]+$/;
|
27
|
+
const isNameValid = name => typeof name === "string" && PascalCasePattern.test(name);
|
78
28
|
|
79
29
|
const getPackageName = () => {
|
80
30
|
if (!fs.existsSync("./package.json")) {
|
@@ -108,47 +58,64 @@ const getLibraryName = packageName => {
|
|
108
58
|
return packageName.substr("webcomponents-".length);
|
109
59
|
};
|
110
60
|
|
111
|
-
const
|
112
|
-
|
113
|
-
const
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
61
|
+
const generateFiles = (componentName, tagName, library, packageName, isTypeScript) => {
|
62
|
+
componentName = capitalizeFirstLetter(componentName);
|
63
|
+
const filePaths = {
|
64
|
+
"main": isTypeScript
|
65
|
+
? `./src/${componentName}.ts`
|
66
|
+
: `./src/${componentName}.js`,
|
67
|
+
"css": `./src/themes/${componentName}.css`,
|
68
|
+
"template": `./src/${componentName}.hbs`,
|
69
|
+
};
|
70
|
+
|
71
|
+
const FileContentTemplate = isTypeScript
|
72
|
+
? tsFileContentTemplate(componentName, tagName, library, packageName)
|
73
|
+
: jsFileContentTemplate(componentName, tagName, library, packageName);
|
74
|
+
|
75
|
+
fs.writeFileSync(filePaths.main, FileContentTemplate, { flag: "wx+" });
|
76
|
+
fs.writeFileSync(filePaths.css, "", { flag: "wx+" });
|
77
|
+
fs.writeFileSync(filePaths.template, "<div>Hello World</div>", { flag: "wx+" });
|
78
|
+
|
79
|
+
console.log(`Successfully generated ${filePaths.main}`);
|
80
|
+
console.log(`Successfully generated ${filePaths.css}`);
|
81
|
+
console.log(`Successfully generated ${filePaths.template}`);
|
82
|
+
|
83
|
+
// Change the color of the output
|
84
|
+
console.warn('\x1b[33m%s\x1b[0m', `
|
85
|
+
Make sure to import the component in your bundle by using:
|
86
|
+
import "./dist/${componentName}.js";`);
|
122
87
|
}
|
123
88
|
|
124
|
-
|
125
|
-
|
126
|
-
const
|
127
|
-
|
128
|
-
"css": `./src/themes/${componentName}.css`,
|
129
|
-
"hbs": `./src/${componentName}.hbs`,
|
130
|
-
};
|
131
|
-
const sJsFileContentTemplate = jsFileContentTemplate(componentName);
|
89
|
+
// Main function
|
90
|
+
const createWebComponent = async () => {
|
91
|
+
const packageName = getPackageName();
|
92
|
+
const library = getLibraryName(packageName);
|
132
93
|
|
133
|
-
|
134
|
-
|
135
|
-
fs.writeFileSync(filePaths.hbs, "<div>Hello World</div>", { flag: "wx+" });
|
94
|
+
const consoleArguments = process.argv.slice(2);
|
95
|
+
let componentName = consoleArguments[0];
|
136
96
|
|
97
|
+
if (componentName && !isNameValid(componentName)) {
|
98
|
+
throw new Error(`${componentName} is invalid component name. Use only letters (at least two) and start with capital one: Button, MyButton, etc.`);
|
99
|
+
}
|
137
100
|
|
138
|
-
|
139
|
-
|
140
|
-
|
101
|
+
if (!componentName) {
|
102
|
+
const response = await prompts({
|
103
|
+
type: "text",
|
104
|
+
name: "componentName",
|
105
|
+
message: "Please enter a component name:",
|
106
|
+
validate: (value) => isNameValid(value) ? true : "Component name should follow PascalCase naming convention (f.e. Button, MyButton, etc.).",
|
107
|
+
});
|
108
|
+
componentName = response.componentName;
|
109
|
+
|
110
|
+
if (!componentName) {
|
111
|
+
process.exit();
|
112
|
+
}
|
113
|
+
}
|
141
114
|
|
142
|
-
const
|
143
|
-
|
144
|
-
});
|
115
|
+
const isTypeScript = fs.existsSync(path.join(process.cwd(), "tsconfig.json"));
|
116
|
+
const tagName = hyphaneteComponentName(componentName);
|
145
117
|
|
146
|
-
|
147
|
-
|
148
|
-
import ${componentName} from "./dist/${componentName}.js";`);
|
118
|
+
generateFiles(componentName, tagName, library, packageName, isTypeScript);
|
119
|
+
};
|
149
120
|
|
150
|
-
|
151
|
-
console.warn('\x1b[33m%s\x1b[0m', `
|
152
|
-
Component is imported in bundle.common.js.
|
153
|
-
Do NOT forget to sort the file in alphabeticall order.
|
154
|
-
`);
|
121
|
+
createWebComponent();
|
@@ -0,0 +1,73 @@
|
|
1
|
+
const jsFileContentTemplate = (componentName, tagName, library, packageName) => {
|
2
|
+
return `import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
|
3
|
+
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
|
4
|
+
import ${componentName}Template from "./generated/templates/${componentName}Template.lit.js";
|
5
|
+
|
6
|
+
// Styles
|
7
|
+
import ${componentName}Css from "./generated/themes/${componentName}.css.js";
|
8
|
+
|
9
|
+
/**
|
10
|
+
* @public
|
11
|
+
*/
|
12
|
+
const metadata = {
|
13
|
+
tag: "${tagName}",
|
14
|
+
properties: /** @lends sap.ui.webc.${library}.${componentName}.prototype */ {
|
15
|
+
//
|
16
|
+
},
|
17
|
+
slots: /** @lends sap.ui.webc.${library}.${componentName}.prototype */ {
|
18
|
+
//
|
19
|
+
},
|
20
|
+
events: /** @lends sap.ui.webc.${library}.${componentName}.prototype */ {
|
21
|
+
//
|
22
|
+
},
|
23
|
+
};
|
24
|
+
|
25
|
+
/**
|
26
|
+
* @class
|
27
|
+
*
|
28
|
+
* <h3 class="comment-api-title">Overview</h3>
|
29
|
+
*
|
30
|
+
*
|
31
|
+
* <h3>Usage</h3>
|
32
|
+
*
|
33
|
+
* For the <code>${tagName}</code>
|
34
|
+
* <h3>ES6 Module Import</h3>
|
35
|
+
*
|
36
|
+
* <code>import ${packageName}/dist/${componentName}.js";</code>
|
37
|
+
*
|
38
|
+
* @constructor
|
39
|
+
* @author SAP SE
|
40
|
+
* @alias sap.ui.webc.${library}.${componentName}
|
41
|
+
* @extends sap.ui.webc.base.UI5Element
|
42
|
+
* @tagname ${tagName}
|
43
|
+
* @public
|
44
|
+
*/
|
45
|
+
class ${componentName} extends UI5Element {
|
46
|
+
static get metadata() {
|
47
|
+
return metadata;
|
48
|
+
}
|
49
|
+
|
50
|
+
static get render() {
|
51
|
+
return litRender;
|
52
|
+
}
|
53
|
+
|
54
|
+
static get styles() {
|
55
|
+
return ${componentName}Css;
|
56
|
+
}
|
57
|
+
|
58
|
+
static get template() {
|
59
|
+
return ${componentName}Template;
|
60
|
+
}
|
61
|
+
|
62
|
+
static get dependencies() {
|
63
|
+
return [];
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
${componentName}.define();
|
68
|
+
|
69
|
+
export default ${componentName};
|
70
|
+
`;
|
71
|
+
};
|
72
|
+
|
73
|
+
module.exports = jsFileContentTemplate;
|
@@ -0,0 +1,80 @@
|
|
1
|
+
const tsFileContentTemplate = (componentName, tagName, library, packageName) => {
|
2
|
+
return `import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
|
3
|
+
import customElement from "@ui5/webcomponents-base/dist/decorators/customElement.js";
|
4
|
+
import property from "@ui5/webcomponents-base/dist/decorators/property.js";
|
5
|
+
import slot from "@ui5/webcomponents-base/dist/decorators/slot.js";
|
6
|
+
import event from "@ui5/webcomponents-base/dist/decorators/event.js";
|
7
|
+
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
|
8
|
+
|
9
|
+
import ${componentName}Template from "./generated/templates/${componentName}Template.lit.js";
|
10
|
+
|
11
|
+
// Styles
|
12
|
+
import ${componentName}Css from "./generated/themes/${componentName}.css.js";
|
13
|
+
|
14
|
+
/**
|
15
|
+
* @class
|
16
|
+
*
|
17
|
+
* <h3 class="comment-api-title">Overview</h3>
|
18
|
+
*
|
19
|
+
*
|
20
|
+
* <h3>Usage</h3>
|
21
|
+
*
|
22
|
+
* For the <code>${tagName}</code>
|
23
|
+
* <h3>ES6 Module Import</h3>
|
24
|
+
*
|
25
|
+
* <code>import ${packageName}/dist/${componentName}.js";</code>
|
26
|
+
*
|
27
|
+
* @constructor
|
28
|
+
* @author SAP SE
|
29
|
+
* @alias sap.ui.webc.${library}.${componentName}
|
30
|
+
* @extends sap.ui.webc.base.UI5Element
|
31
|
+
* @tagname ${tagName}
|
32
|
+
* @public
|
33
|
+
*/
|
34
|
+
@customElement({
|
35
|
+
tag: "${tagName}",
|
36
|
+
renderer: litRender,
|
37
|
+
styles: ${componentName}Css,
|
38
|
+
template: ${componentName}Template,
|
39
|
+
dependencies: [],
|
40
|
+
})
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Example custom event.
|
44
|
+
* Please keep in mind that all public events should be documented in the API Reference as shown below.
|
45
|
+
*
|
46
|
+
* @event sap.ui.webc.${library}.${componentName}#interact
|
47
|
+
* @public
|
48
|
+
*/
|
49
|
+
@event("interact", { detail: { /* event payload ( optional ) */ } })
|
50
|
+
class ${componentName} extends UI5Element {
|
51
|
+
/**
|
52
|
+
* Defines the value of the component.
|
53
|
+
*
|
54
|
+
* @type {string}
|
55
|
+
* @name sap.ui.webc.${library}.${componentName}.prototype.value
|
56
|
+
* @defaultvalue ""
|
57
|
+
* @public
|
58
|
+
*/
|
59
|
+
@property()
|
60
|
+
value!: string;
|
61
|
+
|
62
|
+
/**
|
63
|
+
* Defines the text of the component.
|
64
|
+
*
|
65
|
+
* @type {Node[]}
|
66
|
+
* @name sap.ui.webc.${library}.${componentName}.prototype.default
|
67
|
+
* @slot
|
68
|
+
* @public
|
69
|
+
*/
|
70
|
+
@slot({ type: Node, "default": true })
|
71
|
+
text!: Array<Node>;
|
72
|
+
}
|
73
|
+
|
74
|
+
${componentName}.define();
|
75
|
+
|
76
|
+
export default ${componentName};
|
77
|
+
`;
|
78
|
+
};
|
79
|
+
|
80
|
+
module.exports = tsFileContentTemplate;
|
@@ -49,7 +49,7 @@ const convertImports = async (srcPath) => {
|
|
49
49
|
|
50
50
|
const generate = async () => {
|
51
51
|
const { globby } = await import("globby");
|
52
|
-
const fileNames = await globby(basePath + "**/*.js");
|
52
|
+
const fileNames = await globby(basePath.replace(/\\/g, "/") + "**/*.js");
|
53
53
|
return Promise.all(fileNames.map(convertImports).filter(x => !!x));
|
54
54
|
};
|
55
55
|
|
@@ -1,72 +1,83 @@
|
|
1
1
|
const fs = require("fs").promises;
|
2
|
-
const path = require(
|
3
|
-
|
4
|
-
const
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
default: throw new Error("[Illustrations] Illustration not found: " + illustrationName);
|
50
|
-
}
|
2
|
+
const path = require("path");
|
3
|
+
|
4
|
+
const generateDynamicImportLines = (fileNames, location, exclusionPatterns = []) => {
|
5
|
+
return fileNames
|
6
|
+
.filter((fileName) => !exclusionPatterns.some((pattern) => fileName.startsWith(pattern)))
|
7
|
+
.map((fileName) => {
|
8
|
+
const illustrationPath = `${location}/${fileName.replace(".js", "")}`;
|
9
|
+
return `\t\tcase "${fileName.replace('.js', '')}": return (await import("${illustrationPath}.js")).default;`;
|
10
|
+
})
|
11
|
+
.join("\n");
|
12
|
+
};
|
13
|
+
|
14
|
+
const generateAvailableIllustrationsArray = (fileNames, exclusionPatterns = []) => {
|
15
|
+
return JSON.stringify(
|
16
|
+
fileNames
|
17
|
+
.filter((fileName) => !exclusionPatterns.some((pattern) => fileName.startsWith(pattern)))
|
18
|
+
.map((fileName) => fileName.replace(".js", ""))
|
19
|
+
);
|
20
|
+
};
|
21
|
+
|
22
|
+
const generateDynamicImportsFileContent = (dynamicImports, availableIllustrations, collection, prefix = "") => {
|
23
|
+
return `import { registerIllustrationLoader } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
|
24
|
+
|
25
|
+
export const loadIllustration = async (illustrationName) => {
|
26
|
+
const collectionAndPrefix = "${collection}/${prefix}";
|
27
|
+
const cleanIllustrationName = illustrationName.startsWith(collectionAndPrefix) ? illustrationName.replace(collectionAndPrefix, "") : illustrationName;
|
28
|
+
switch (cleanIllustrationName) {
|
29
|
+
${dynamicImports}
|
30
|
+
default:
|
31
|
+
throw new Error("[Illustrations] Illustration not found: " + illustrationName);
|
32
|
+
}
|
33
|
+
};
|
34
|
+
|
35
|
+
const loadAndCheck = async (illustrationName) => {
|
36
|
+
const data = await loadIllustration(illustrationName);
|
37
|
+
return data;
|
38
|
+
};
|
39
|
+
|
40
|
+
${availableIllustrations}.forEach((illustrationName) =>
|
41
|
+
registerIllustrationLoader(\`${collection}/${prefix}\${illustrationName}\`, loadAndCheck)
|
42
|
+
);
|
43
|
+
`;
|
44
|
+
};
|
45
|
+
|
46
|
+
const getMatchingFiles = async (folder, pattern) => {
|
47
|
+
const dir = await fs.readdir(folder);
|
48
|
+
return dir.filter((fileName) => fileName.match(pattern));
|
51
49
|
};
|
52
|
-
const loadAndCheck = async (illustrationName) => {
|
53
|
-
const data = await loadIllustration(illustrationName);
|
54
|
-
return data;
|
55
|
-
}
|
56
50
|
|
51
|
+
const generateIllustrations = async (config) => {
|
52
|
+
const { inputFolder, outputFile, collection, location, prefix, filterOut } = config;
|
53
|
+
|
54
|
+
const normalizedInputFolder = path.normalize(inputFolder);
|
55
|
+
const normalizedOutputFile = path.normalize(outputFile);
|
56
|
+
|
57
|
+
const illustrations = await getMatchingFiles(normalizedInputFolder, /^.*\.js$/);
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
const dynamicImports = generateDynamicImportLines(illustrations, location, filterOut);
|
60
|
+
const availableIllustrations = generateAvailableIllustrationsArray(illustrations, filterOut);
|
61
|
+
|
62
|
+
const contentDynamic = generateDynamicImportsFileContent(dynamicImports, availableIllustrations, collection, prefix);
|
63
|
+
|
64
|
+
await fs.mkdir(path.dirname(normalizedOutputFile), { recursive: true });
|
65
|
+
await fs.writeFile(normalizedOutputFile, contentDynamic);
|
66
|
+
|
67
|
+
console.log(`Generated ${normalizedOutputFile}`);
|
68
|
+
};
|
61
69
|
|
62
|
-
|
63
|
-
|
70
|
+
// Parse configuration from command-line arguments
|
71
|
+
const config = {
|
72
|
+
inputFolder: process.argv[2],
|
73
|
+
outputFile: process.argv[3],
|
74
|
+
collection: process.argv[4],
|
75
|
+
location: process.argv[5],
|
76
|
+
prefix: process.argv[6],
|
77
|
+
filterOut: process.argv.slice(7),
|
64
78
|
};
|
65
79
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
.catch(err => {
|
70
|
-
console.error(err);
|
71
|
-
process.exit(1);
|
80
|
+
// Run the generation process
|
81
|
+
generateIllustrations(config).catch((error) => {
|
82
|
+
console.error("Error generating illustrations:", error);
|
72
83
|
});
|