@ui5/webcomponents-tools 0.0.0-f2abb18c2 → 0.0.0-f651a470c
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 +408 -4
- package/README.md +5 -6
- package/assets-meta.js +16 -1
- package/bin/dev.js +1 -5
- package/components-package/eslint.js +34 -0
- package/components-package/nps.js +103 -50
- package/components-package/postcss.components.js +13 -13
- package/components-package/postcss.themes.js +19 -16
- package/components-package/vite.config.js +13 -0
- package/components-package/wdio.js +393 -344
- package/components-package/wdio.sync.js +360 -0
- package/icons-collection/nps.js +51 -10
- package/lib/copy-and-watch/index.js +30 -5
- package/lib/copy-list/index.js +28 -0
- package/lib/create-icons/index.js +124 -52
- package/lib/create-illustrations/index.js +161 -0
- package/lib/create-new-component/index.js +108 -103
- package/lib/create-new-component/jsFileContentTemplate.js +77 -0
- package/lib/create-new-component/tsFileContentTemplate.js +84 -0
- package/lib/dev-server/dev-server.js +66 -0
- package/lib/dev-server/virtual-index-html-plugin.js +52 -0
- package/lib/esm-abs-to-rel/index.js +58 -0
- package/lib/generate-custom-elements-manifest/index.js +327 -0
- package/lib/generate-js-imports/illustrations.js +72 -0
- package/lib/generate-json-imports/i18n.js +75 -30
- package/lib/generate-json-imports/themes.js +62 -24
- package/lib/hbs2lit/src/compiler.js +20 -3
- package/lib/hbs2lit/src/includesReplacer.js +5 -5
- package/lib/hbs2lit/src/litVisitor2.js +77 -14
- package/lib/hbs2lit/src/svgProcessor.js +3 -3
- package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +4 -11
- package/lib/hbs2ui5/index.js +37 -21
- package/lib/i18n/defaults.js +65 -57
- package/lib/i18n/toJSON.js +13 -12
- package/lib/jsdoc/configTypescript.json +29 -0
- package/lib/jsdoc/plugin.js +62 -1
- package/lib/jsdoc/preprocess.js +146 -0
- package/lib/jsdoc/template/publish.js +30 -2
- package/lib/postcss-combine-duplicated-selectors/index.js +178 -0
- package/lib/postcss-css-to-esm/index.js +64 -16
- package/lib/postcss-css-to-json/index.js +31 -11
- package/lib/postcss-new-files/index.js +36 -0
- package/lib/postcss-p/postcss-p.mjs +14 -0
- package/lib/replace-global-core/index.js +25 -0
- package/lib/scoping/get-all-tags.js +1 -8
- package/lib/scoping/lint-src.js +1 -1
- package/lib/scoping/missing-dependencies.js +65 -0
- package/lib/scoping/report-tags-usage.js +28 -0
- package/lib/scoping/scope-test-pages.js +1 -1
- package/lib/test-runner/test-runner.js +71 -0
- package/package.json +51 -53
- package/bin/init-ui5-package.js +0 -3
- package/components-package/rollup.js +0 -147
- package/components-package/serve.json +0 -3
- package/lib/documentation/index.js +0 -143
- package/lib/documentation/templates/api-component-since.js +0 -3
- package/lib/documentation/templates/api-css-variables-section.js +0 -24
- package/lib/documentation/templates/api-events-section.js +0 -35
- package/lib/documentation/templates/api-methods-section.js +0 -26
- package/lib/documentation/templates/api-properties-section.js +0 -40
- package/lib/documentation/templates/api-slots-section.js +0 -28
- package/lib/documentation/templates/template.js +0 -38
- package/lib/init-package/index.js +0 -123
- package/lib/init-package/resources/.eslintignore +0 -3
- package/lib/init-package/resources/bundle.es5.js +0 -25
- package/lib/init-package/resources/bundle.esm.js +0 -34
- package/lib/init-package/resources/config/.eslintrc.js +0 -1
- package/lib/init-package/resources/config/postcss.components/postcss.config.js +0 -1
- package/lib/init-package/resources/config/postcss.themes/postcss.config.js +0 -1
- package/lib/init-package/resources/config/rollup.config.js +0 -1
- package/lib/init-package/resources/config/wdio.conf.js +0 -1
- package/lib/init-package/resources/package-scripts.js +0 -11
- package/lib/init-package/resources/src/Assets.js +0 -5
- package/lib/init-package/resources/src/MyFirstComponent.hbs +0 -1
- package/lib/init-package/resources/src/MyFirstComponent.js +0 -56
- package/lib/init-package/resources/src/i18n/messagebundle.properties +0 -2
- package/lib/init-package/resources/src/i18n/messagebundle_de.properties +0 -1
- package/lib/init-package/resources/src/i18n/messagebundle_en.properties +0 -1
- package/lib/init-package/resources/src/i18n/messagebundle_es.properties +0 -1
- package/lib/init-package/resources/src/i18n/messagebundle_fr.properties +0 -1
- package/lib/init-package/resources/src/themes/MyFirstComponent.css +0 -11
- package/lib/init-package/resources/src/themes/sap_belize/parameters-bundle.css +0 -3
- package/lib/init-package/resources/src/themes/sap_belize_hcb/parameters-bundle.css +0 -3
- package/lib/init-package/resources/src/themes/sap_belize_hcw/parameters-bundle.css +0 -3
- package/lib/init-package/resources/src/themes/sap_fiori_3/parameters-bundle.css +0 -3
- package/lib/init-package/resources/src/themes/sap_fiori_3_dark/parameters-bundle.css +0 -3
- package/lib/init-package/resources/src/themes/sap_fiori_3_hcb/parameters-bundle.css +0 -3
- package/lib/init-package/resources/src/themes/sap_fiori_3_hcw/parameters-bundle.css +0 -3
- package/lib/init-package/resources/test/pages/index.html +0 -56
- package/lib/init-package/resources/test/specs/Demo.spec.js +0 -12
- package/package-lock.json +0 -48
@@ -0,0 +1,84 @@
|
|
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
|
+
static async onDefine() {
|
74
|
+
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
${componentName}.define();
|
79
|
+
|
80
|
+
export default ${componentName};
|
81
|
+
`;
|
82
|
+
};
|
83
|
+
|
84
|
+
module.exports = tsFileContentTemplate;
|
@@ -0,0 +1,66 @@
|
|
1
|
+
const fs = require("fs/promises");
|
2
|
+
const { createServer } = require('vite');
|
3
|
+
const yargs = require('yargs/yargs')
|
4
|
+
const { hideBin } = require('yargs/helpers')
|
5
|
+
|
6
|
+
const argv = yargs(hideBin(process.argv))
|
7
|
+
.alias("c", "config")
|
8
|
+
.argv;
|
9
|
+
|
10
|
+
const startVite = async (port) => {
|
11
|
+
const server = await createServer({
|
12
|
+
configFile: argv.config,
|
13
|
+
server: {
|
14
|
+
port: port,
|
15
|
+
strictPort: true,
|
16
|
+
open: true,
|
17
|
+
host: true,
|
18
|
+
},
|
19
|
+
logLevel: 'info',
|
20
|
+
clearScreen: false,
|
21
|
+
})
|
22
|
+
await server.listen()
|
23
|
+
server.printUrls()
|
24
|
+
return server;
|
25
|
+
};
|
26
|
+
|
27
|
+
const rmPortFile = async () => {
|
28
|
+
// exit handler must be sync
|
29
|
+
try {
|
30
|
+
await fs.rm(".dev-server-port");
|
31
|
+
} catch (e) {}
|
32
|
+
process.exit();
|
33
|
+
}
|
34
|
+
|
35
|
+
["exit", "SIGINT", "SIGUSR1", "SIGUSR2", "uncaughtException", "SIGTERM"].forEach((eventType) => {
|
36
|
+
process.on(eventType, rmPortFile);
|
37
|
+
});
|
38
|
+
|
39
|
+
(async () => {
|
40
|
+
let retries = 10;
|
41
|
+
let port = 8080;
|
42
|
+
while (retries--) {
|
43
|
+
console.log(`taking port ${port}`);
|
44
|
+
await fs.writeFile(".dev-server-port", `${port}`);
|
45
|
+
try {
|
46
|
+
// execSync(command, {stdio: 'pipe'});
|
47
|
+
const server = await startVite(port);
|
48
|
+
if (server) {
|
49
|
+
// server started, don't try other ports
|
50
|
+
break;
|
51
|
+
}
|
52
|
+
} catch (e) {
|
53
|
+
// uncomment for debug
|
54
|
+
// console.log(e.toString());
|
55
|
+
if (e.toString().includes("already in use")) {
|
56
|
+
console.log(`Port ${port} already in use`)
|
57
|
+
port++;
|
58
|
+
continue;
|
59
|
+
}
|
60
|
+
// other error or CTRL-C
|
61
|
+
process.exit();
|
62
|
+
}
|
63
|
+
// no error normal exit
|
64
|
+
// process.exit();
|
65
|
+
}
|
66
|
+
})();
|
@@ -0,0 +1,52 @@
|
|
1
|
+
const virtualIndexPlugin = async () => {
|
2
|
+
const path = await import("path");
|
3
|
+
const { globby } = await import("globby");
|
4
|
+
const files = await globby(["test/pages/**/*.html", "packages/*/test/pages/**/*.html"]);
|
5
|
+
|
6
|
+
const pagesPerFolder = {};
|
7
|
+
files.forEach(file => {
|
8
|
+
let folder = pagesPerFolder[path.dirname(file)] = pagesPerFolder[path.dirname(file)] || [];
|
9
|
+
folder.push(path.basename(file));
|
10
|
+
});
|
11
|
+
|
12
|
+
const rollupInput = {};
|
13
|
+
|
14
|
+
files.forEach(file => {
|
15
|
+
rollupInput[file] = path.resolve(process.cwd(), file);
|
16
|
+
})
|
17
|
+
|
18
|
+
return {
|
19
|
+
name: 'virtual-index-html',
|
20
|
+
config() {
|
21
|
+
return {
|
22
|
+
build: {
|
23
|
+
rollupOptions: {
|
24
|
+
input: rollupInput
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
},
|
29
|
+
configureServer(server) {
|
30
|
+
server.middlewares.use((req, res, next) => {
|
31
|
+
if (req.url === "/") {
|
32
|
+
const folders = Object.keys(pagesPerFolder);
|
33
|
+
|
34
|
+
res.statusCode = 200;
|
35
|
+
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
36
|
+
res.end(`${folders.map(folder => {
|
37
|
+
const pages = pagesPerFolder[folder];
|
38
|
+
return `<h1>${folder}</h1>
|
39
|
+
${pages.map(page => {
|
40
|
+
return `<li><a href='${folder}/${page}'>${page}</a></li>`
|
41
|
+
}).join("")}
|
42
|
+
`
|
43
|
+
}).join("")}`);
|
44
|
+
} else {
|
45
|
+
next();
|
46
|
+
}
|
47
|
+
})
|
48
|
+
},
|
49
|
+
}
|
50
|
+
};
|
51
|
+
|
52
|
+
module.exports = virtualIndexPlugin;
|
@@ -0,0 +1,58 @@
|
|
1
|
+
const esprima = require("esprima");
|
2
|
+
const escodegen = require("escodegen");
|
3
|
+
|
4
|
+
const fs = require("fs").promises;
|
5
|
+
const path = require("path");
|
6
|
+
const basePath = process.argv[2];
|
7
|
+
|
8
|
+
const convertImports = async (srcPath) => {
|
9
|
+
let changed = false;
|
10
|
+
// console.log("scanning imports of", srcPath);
|
11
|
+
let code = (await fs.readFile(srcPath)).toString();
|
12
|
+
const tree = esprima.parseModule(code);
|
13
|
+
const importer = srcPath.replace(basePath, "");
|
14
|
+
const importerDir = path.dirname(importer);
|
15
|
+
// console.log("-> ", importer);
|
16
|
+
tree.body.forEach(node => {
|
17
|
+
if (node.type === "ImportDeclaration") {
|
18
|
+
let importee = node.source.value;
|
19
|
+
if (importee.startsWith(".")) {
|
20
|
+
// add .js extension if missing
|
21
|
+
if (!importee.endsWith(".js")) {
|
22
|
+
node.source.value += ".js"
|
23
|
+
changed = true;
|
24
|
+
}
|
25
|
+
return;
|
26
|
+
}
|
27
|
+
let importeeDir = path.dirname(importee);
|
28
|
+
let importeeFile = path.basename(importee);
|
29
|
+
let relativePath = path.relative(importerDir, importeeDir);
|
30
|
+
if (relativePath.length === 0) {
|
31
|
+
relativePath = "."
|
32
|
+
}
|
33
|
+
if (!relativePath.startsWith(".")) {
|
34
|
+
relativePath = "./" + relativePath;
|
35
|
+
}
|
36
|
+
|
37
|
+
relativePath = relativePath.replace(/\\/g, "/"); // the browser expects unix paths
|
38
|
+
let relativeImport = `${relativePath}/${importeeFile}.js`;
|
39
|
+
// console.log(importee + " --> " + relativeImport);
|
40
|
+
node.source.value = relativeImport;
|
41
|
+
changed = true;
|
42
|
+
}
|
43
|
+
});
|
44
|
+
|
45
|
+
if (changed) {
|
46
|
+
return fs.writeFile(srcPath, escodegen.generate(tree));
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
const generate = async () => {
|
51
|
+
const { globby } = await import("globby");
|
52
|
+
const fileNames = await globby(basePath.replace(/\\/g, "/") + "**/*.js");
|
53
|
+
return Promise.all(fileNames.map(convertImports).filter(x => !!x));
|
54
|
+
};
|
55
|
+
|
56
|
+
generate().then(() => {
|
57
|
+
console.log("Success: Converted absolute imports to relative for files in:", basePath);
|
58
|
+
});
|
@@ -0,0 +1,327 @@
|
|
1
|
+
const fs = require("fs").promises;
|
2
|
+
const path = require("path");
|
3
|
+
// https://github.com/webcomponents/custom-elements-manifest/blob/main/schema.json
|
4
|
+
|
5
|
+
const inputDir = process.argv[2];
|
6
|
+
const outputDir = process.argv[3];
|
7
|
+
|
8
|
+
const camelToKebabMap = new Map();
|
9
|
+
const apiIndex = new Map();
|
10
|
+
const forbiddenAttributeTypes = ["object", "array"];
|
11
|
+
|
12
|
+
const camelToKebabCase = string => {
|
13
|
+
if (!camelToKebabMap.has(string)) {
|
14
|
+
const result = string.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
15
|
+
camelToKebabMap.set(string, result);
|
16
|
+
}
|
17
|
+
return camelToKebabMap.get(string);
|
18
|
+
};
|
19
|
+
|
20
|
+
const generateJavaScriptExport = entity => {
|
21
|
+
return {
|
22
|
+
declaration: generateRefenrece(entity.name),
|
23
|
+
deprecated: !!entity.deprecated,
|
24
|
+
kind: "js",
|
25
|
+
name: "default",
|
26
|
+
};
|
27
|
+
};
|
28
|
+
|
29
|
+
const generateCustomElementExport = entity => {
|
30
|
+
return {
|
31
|
+
declaration: {
|
32
|
+
name: entity.basename,
|
33
|
+
module: `${entity.module}.js`,
|
34
|
+
},
|
35
|
+
deprecated: !!entity.deprecated,
|
36
|
+
kind: "custom-element-definition",
|
37
|
+
name: entity.tagname,
|
38
|
+
};
|
39
|
+
};
|
40
|
+
|
41
|
+
const generateJavaScriptModule = entity => {
|
42
|
+
return {
|
43
|
+
kind: "javascript-module",
|
44
|
+
path: `${entity.basename}.js`,
|
45
|
+
declarations: [
|
46
|
+
generateCustomElementDeclaration(entity),
|
47
|
+
],
|
48
|
+
exports: [
|
49
|
+
generateJavaScriptExport(entity),
|
50
|
+
generateCustomElementExport(entity),
|
51
|
+
],
|
52
|
+
};
|
53
|
+
};
|
54
|
+
|
55
|
+
const generateSingleClassField = classField => {
|
56
|
+
let generatedClassField = {
|
57
|
+
deprecated: !!classField.deprecated,
|
58
|
+
kind: "field",
|
59
|
+
name: classField.name,
|
60
|
+
privacy: classField.visibility,
|
61
|
+
static: !!classField.static,
|
62
|
+
type: generateType(classField.type),
|
63
|
+
};
|
64
|
+
|
65
|
+
if (classField.defaultValue) {
|
66
|
+
generatedClassField.default = classField.defaultValue;
|
67
|
+
}
|
68
|
+
|
69
|
+
if (classField.description) {
|
70
|
+
generatedClassField.description = classField.description;
|
71
|
+
}
|
72
|
+
|
73
|
+
return generatedClassField;
|
74
|
+
};
|
75
|
+
|
76
|
+
const generateSingleParameter = parameter => {
|
77
|
+
let generatedParameter = {
|
78
|
+
deprecated: !!parameter.deprecated,
|
79
|
+
name: parameter.name,
|
80
|
+
type: generateType(parameter.type),
|
81
|
+
};
|
82
|
+
|
83
|
+
if (parameter.description) {
|
84
|
+
generatedParameter.description = parameter.description;
|
85
|
+
}
|
86
|
+
|
87
|
+
if (parameter.optional) {
|
88
|
+
generatedParameter.optional = parameter.optional;
|
89
|
+
}
|
90
|
+
|
91
|
+
return generatedParameter;
|
92
|
+
};
|
93
|
+
|
94
|
+
const generateParameters = (parameters) => {
|
95
|
+
return parameters.reduce((newParametersArray, parameter) => {
|
96
|
+
newParametersArray.push(generateSingleParameter(parameter));
|
97
|
+
|
98
|
+
return newParametersArray;
|
99
|
+
}, []);
|
100
|
+
};
|
101
|
+
|
102
|
+
const generateSingleClassMethod = classMethod => {
|
103
|
+
let generatedClassMethod = {
|
104
|
+
deprecated: !!classMethod.deprecated,
|
105
|
+
kind: "method",
|
106
|
+
name: classMethod.name,
|
107
|
+
privacy: classMethod.visibility,
|
108
|
+
static: classMethod.static,
|
109
|
+
};
|
110
|
+
|
111
|
+
if (classMethod.description) {
|
112
|
+
generatedClassMethod.description = classMethod.description;
|
113
|
+
}
|
114
|
+
|
115
|
+
if (classMethod.parameters && classMethod.parameters.length) {
|
116
|
+
generatedClassMethod.parameters = generateParameters(classMethod.parameters);
|
117
|
+
}
|
118
|
+
|
119
|
+
if (classMethod.returnValue) {
|
120
|
+
generatedClassMethod.return = {
|
121
|
+
type: generateType(classMethod.returnValue.type),
|
122
|
+
};
|
123
|
+
|
124
|
+
if (classMethod.returnValue.description) {
|
125
|
+
generatedClassMethod.return.description = classMethod.returnValue.type;
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
return generatedClassMethod;
|
130
|
+
};
|
131
|
+
|
132
|
+
const generateClassFields = classFields => {
|
133
|
+
return classFields.reduce((newClassFieldsArray, classField) => {
|
134
|
+
newClassFieldsArray.push(generateSingleClassField(classField));
|
135
|
+
|
136
|
+
return newClassFieldsArray;
|
137
|
+
}, []);
|
138
|
+
};
|
139
|
+
|
140
|
+
const generateClassMethods = classMethods => {
|
141
|
+
return classMethods.reduce((newClassMethodsArray, classMethod) => {
|
142
|
+
newClassMethodsArray.push(generateSingleClassMethod(classMethod));
|
143
|
+
|
144
|
+
return newClassMethodsArray;
|
145
|
+
}, []);
|
146
|
+
};
|
147
|
+
|
148
|
+
const generateMembers = (classFields, classMethods) => {
|
149
|
+
return [...generateClassFields(classFields), ...generateClassMethods(classMethods)];
|
150
|
+
};
|
151
|
+
|
152
|
+
const generateType = type => {
|
153
|
+
const dataType = apiIndex.get(type);
|
154
|
+
|
155
|
+
return {
|
156
|
+
text: dataType && dataType.name.includes(".types.") ?
|
157
|
+
filterPublicApi(dataType.properties)
|
158
|
+
.map(prop => `"${prop.name}"`)
|
159
|
+
.join(" | ") : type,
|
160
|
+
};
|
161
|
+
};
|
162
|
+
|
163
|
+
const generateSingleAttribute = attribute => {
|
164
|
+
let generatedAttribute = {
|
165
|
+
default: attribute.defaultValue,
|
166
|
+
deprecated: !!attribute.deprecated,
|
167
|
+
fieldName: attribute.name,
|
168
|
+
name: camelToKebabCase(attribute.name),
|
169
|
+
type: generateType(attribute.type),
|
170
|
+
};
|
171
|
+
|
172
|
+
if (attribute.description) {
|
173
|
+
generatedAttribute.description = attribute.description;
|
174
|
+
}
|
175
|
+
|
176
|
+
return generatedAttribute;
|
177
|
+
};
|
178
|
+
|
179
|
+
const generateAttributes = attributes => {
|
180
|
+
attributes = attributes.reduce((newAttributesArray, attribute) => {
|
181
|
+
newAttributesArray.push(generateSingleAttribute(attribute));
|
182
|
+
|
183
|
+
return newAttributesArray;
|
184
|
+
}, []);
|
185
|
+
|
186
|
+
return attributes;
|
187
|
+
};
|
188
|
+
|
189
|
+
const generateSingleEvent = event => {
|
190
|
+
let generatedEvent = {
|
191
|
+
deprecated: !!event.deprecated,
|
192
|
+
name: event.name,
|
193
|
+
type: event.native === "true" ? "NativeEvent" : "CustomEvent",
|
194
|
+
};
|
195
|
+
|
196
|
+
if (event.description) {
|
197
|
+
generatedEvent.description = event.description;
|
198
|
+
}
|
199
|
+
|
200
|
+
return generatedEvent;
|
201
|
+
};
|
202
|
+
|
203
|
+
const generateEvents = events => {
|
204
|
+
events = events.reduce((newEventsArray, event) => {
|
205
|
+
newEventsArray.push(generateSingleEvent(event));
|
206
|
+
|
207
|
+
return newEventsArray;
|
208
|
+
}, []);
|
209
|
+
|
210
|
+
return events;
|
211
|
+
};
|
212
|
+
|
213
|
+
const generateSingleSlot = slot => {
|
214
|
+
return {
|
215
|
+
deprecated: !!slot.deprecated,
|
216
|
+
description: slot.description,
|
217
|
+
name: slot.name,
|
218
|
+
};
|
219
|
+
};
|
220
|
+
|
221
|
+
const generateSlots = slots => {
|
222
|
+
slots = slots.reduce((newSlotsArray, event) => {
|
223
|
+
newSlotsArray.push(generateSingleSlot(event));
|
224
|
+
|
225
|
+
return newSlotsArray;
|
226
|
+
}, []);
|
227
|
+
|
228
|
+
return slots;
|
229
|
+
};
|
230
|
+
|
231
|
+
const generateCustomElementDeclaration = entity => {
|
232
|
+
let generatedCustomElementDeclaration = {
|
233
|
+
deprecated: !!entity.deprecated,
|
234
|
+
customElement: true,
|
235
|
+
kind: entity.basename,
|
236
|
+
name: entity.basename,
|
237
|
+
tagName: entity.tagname,
|
238
|
+
};
|
239
|
+
|
240
|
+
const slots = filterPublicApi(entity.slots);
|
241
|
+
const events = filterPublicApi(entity.events);
|
242
|
+
const classFields = filterPublicApi(entity.properties);
|
243
|
+
const classMethods = filterPublicApi(entity.methods);
|
244
|
+
const attributes = classFields.filter(property => {
|
245
|
+
return property.noattribute !== "true" && property.readonly !== "true" && !forbiddenAttributeTypes.includes(property.type.toLowerCase());
|
246
|
+
});
|
247
|
+
|
248
|
+
if (slots.length) {
|
249
|
+
generatedCustomElementDeclaration.slots = generateSlots(slots);
|
250
|
+
}
|
251
|
+
|
252
|
+
if (events.length) {
|
253
|
+
generatedCustomElementDeclaration.events = generateEvents(events);
|
254
|
+
}
|
255
|
+
|
256
|
+
if (attributes.length) {
|
257
|
+
generatedCustomElementDeclaration.attributes = generateAttributes(attributes);
|
258
|
+
}
|
259
|
+
|
260
|
+
if (entity.description) {
|
261
|
+
generatedCustomElementDeclaration.description = entity.description;
|
262
|
+
}
|
263
|
+
|
264
|
+
if (classFields.length || classMethods.length) {
|
265
|
+
generatedCustomElementDeclaration.members = generateMembers(classFields, classMethods);
|
266
|
+
}
|
267
|
+
|
268
|
+
if (entity.extends && entity.extends !== "HTMLElement") {
|
269
|
+
generatedCustomElementDeclaration.superclass = generateRefenrece(entity.extends);
|
270
|
+
}
|
271
|
+
|
272
|
+
return generatedCustomElementDeclaration;
|
273
|
+
};
|
274
|
+
|
275
|
+
const generateRefenrece = (entityName) => {
|
276
|
+
let packageName;
|
277
|
+
let basename;
|
278
|
+
|
279
|
+
if (!entityName) {
|
280
|
+
throw new Error("JSDoc error: entity not found in api.json.");
|
281
|
+
}
|
282
|
+
|
283
|
+
if (entityName.includes(".")) {
|
284
|
+
basename = entityName.split(".").pop();
|
285
|
+
} else {
|
286
|
+
basename = entityName
|
287
|
+
}
|
288
|
+
|
289
|
+
if (entityName.includes("sap.ui.webc.main")) {
|
290
|
+
packageName = "@ui5/webcomponents";
|
291
|
+
} else if (entityName.includes("sap.ui.webc.fiori")) {
|
292
|
+
packageName = "@ui5/webcomponents-fiori";
|
293
|
+
} else if (entityName.includes("sap.ui.webc.base")) {
|
294
|
+
packageName = "@ui5/webcomponents-base";
|
295
|
+
}
|
296
|
+
|
297
|
+
return {
|
298
|
+
module: `${basename}.js`,
|
299
|
+
name: `${basename}`,
|
300
|
+
package: packageName,
|
301
|
+
};
|
302
|
+
};
|
303
|
+
|
304
|
+
const filterPublicApi = array => {
|
305
|
+
return (array || []).filter(el => el.visibility === "public");
|
306
|
+
};
|
307
|
+
|
308
|
+
const generate = async () => {
|
309
|
+
const file = JSON.parse(await fs.readFile(path.join(inputDir, "api.json")));
|
310
|
+
let customElementsManifest = {
|
311
|
+
schemaVersion: "1.0.0",
|
312
|
+
readme: "",
|
313
|
+
modules: [],
|
314
|
+
};
|
315
|
+
|
316
|
+
file.symbols.forEach(entity => {
|
317
|
+
if (entity.tagname) {
|
318
|
+
customElementsManifest.modules.push(generateJavaScriptModule(entity));
|
319
|
+
}
|
320
|
+
});
|
321
|
+
|
322
|
+
await fs.writeFile(path.join(outputDir, "custom-elements.json"), JSON.stringify(customElementsManifest));
|
323
|
+
};
|
324
|
+
|
325
|
+
generate().then(() => {
|
326
|
+
console.log("Custom elements manifest generated.");
|
327
|
+
});
|
@@ -0,0 +1,72 @@
|
|
1
|
+
const fs = require("fs").promises;
|
2
|
+
const path = require('path');
|
3
|
+
|
4
|
+
const generate = async () => {
|
5
|
+
const fioriInputFolder = path.normalize(process.argv[2]);
|
6
|
+
const tntInputFolder = path.normalize(process.argv[3]);
|
7
|
+
const outputFile = path.normalize(`${process.argv[4]}/Illustrations.js`);
|
8
|
+
|
9
|
+
const dir = await fs.readdir(fioriInputFolder);
|
10
|
+
const fioriIllustrationsOnFileSystem = dir.map(illustrationName => {
|
11
|
+
const fioriMatches = illustrationName.match(/.*\.js$/);
|
12
|
+
return fioriMatches ? illustrationName : undefined;
|
13
|
+
}).filter(key => !!key);
|
14
|
+
|
15
|
+
const tntDir = await fs.readdir(tntInputFolder);
|
16
|
+
const tntIllustrationsOnFileSystem = tntDir.map(illustrationName => {
|
17
|
+
const tntMatches = illustrationName.match(/.*\.js$/);
|
18
|
+
return tntMatches ? illustrationName : undefined;
|
19
|
+
}).filter(key => !!key);
|
20
|
+
|
21
|
+
// dynamic imports for Fiori illustrations
|
22
|
+
const fioriAvailableIllustrationsArray = `[${fioriIllustrationsOnFileSystem.filter(
|
23
|
+
// skipping the items starting with sapIllus-Dialog, sapIllus-Scene, sapIllus-Spot since they are included in the illustration's js file
|
24
|
+
line => !line.startsWith("sapIllus-Dialog") && !line.startsWith("sapIllus-Scene") && !line.startsWith("sapIllus-Spot") && !line.startsWith("AllIllustrations")).map(illustrationName => `"${illustrationName.replace('.js', '')}"`).join(", ")}]`;
|
25
|
+
|
26
|
+
const fioriDynamicImportLines = fioriIllustrationsOnFileSystem.map(illustrationName =>
|
27
|
+
`\t\tcase "${illustrationName.replace('.js', '')}": return (await import("../../illustrations/${illustrationName}")).default;`).filter(
|
28
|
+
// skipping the items starting with sapIllus-Dialog, sapIllus-Scene, sapIllus-Spot since they are included in the illustration's js file
|
29
|
+
line => !line.startsWith("\t\tcase \"sapIllus-Dialog") && !line.startsWith("\t\tcase \"sapIllus-Scene") && !line.startsWith("\t\tcase \"sapIllus-Spot") && !line.startsWith("\t\tcase \"AllIllustrations")).join("\n");
|
30
|
+
|
31
|
+
// dynamic imports for Tnt illustrations
|
32
|
+
const tntAvailableIllustrationsArray = `[${tntIllustrationsOnFileSystem.filter(
|
33
|
+
// skipping the items starting with tnt-Dialog, tnt-Scene, tnt-Spot since they are included in the illustration's js file
|
34
|
+
line => !line.startsWith("tnt-Dialog") && !line.startsWith("tnt-Scene") && !line.startsWith("tnt-Spot")).map(illustrationName => `"Tnt${illustrationName.replace('.js', '')}"`).join(", ")}]`;
|
35
|
+
|
36
|
+
const tntDynamicImportLines = tntIllustrationsOnFileSystem.map(illustrationName =>
|
37
|
+
`\t\tcase "Tnt${illustrationName.replace('.js', '')}": return (await import("../../illustrations/tnt/${illustrationName}")).default;`).filter(
|
38
|
+
// skipping the items starting with tnt-Dialog, tnt-Scene, tnt-Spot since they are included in the illustration's js file
|
39
|
+
line => !line.startsWith("\t\tcase \"Tnttnt-Dialog") && !line.startsWith("\t\tcase \"Tnttnt-Scene") && !line.startsWith("\t\tcase \"Tnttnt-Spot")).join("\n");
|
40
|
+
|
41
|
+
|
42
|
+
// dynamic imports file content
|
43
|
+
const contentDynamic = `import { registerIllustrationLoader } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
|
44
|
+
|
45
|
+
const loadIllustration = async (illustrationName) => {
|
46
|
+
switch (illustrationName) {
|
47
|
+
${fioriDynamicImportLines}
|
48
|
+
${tntDynamicImportLines}
|
49
|
+
default: throw new Error("[Illustrations] Illustration not found: " + illustrationName);
|
50
|
+
}
|
51
|
+
};
|
52
|
+
const loadAndCheck = async (illustrationName) => {
|
53
|
+
const data = await loadIllustration(illustrationName);
|
54
|
+
return data;
|
55
|
+
}
|
56
|
+
|
57
|
+
|
58
|
+
${fioriAvailableIllustrationsArray}.forEach(illustrationName => registerIllustrationLoader(illustrationName, loadAndCheck));
|
59
|
+
${tntAvailableIllustrationsArray}.forEach(illustrationName => registerIllustrationLoader(illustrationName, loadAndCheck));`;
|
60
|
+
|
61
|
+
|
62
|
+
await fs.mkdir(path.dirname(outputFile), { recursive: true });
|
63
|
+
return Promise.all([fs.writeFile(outputFile, contentDynamic)]);
|
64
|
+
};
|
65
|
+
|
66
|
+
generate().then(() => {
|
67
|
+
console.log("Generated Illustrations.js");
|
68
|
+
})
|
69
|
+
.catch(err => {
|
70
|
+
console.error(err);
|
71
|
+
process.exit(1);
|
72
|
+
});
|