@ui5/webcomponents-tools 0.0.0-f24ff9019 → 0.0.0-f42e7c18c
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 +955 -0
- package/README.md +3 -6
- package/assets-meta.js +5 -3
- package/components-package/cypress/support/commands.js +39 -0
- package/components-package/cypress/support/component-index.html +17 -0
- package/components-package/cypress/support/component.d.ts +23 -0
- package/components-package/cypress/support/component.js +34 -0
- package/components-package/cypress.config.js +19 -0
- package/components-package/eslint.js +90 -28
- package/components-package/nps.js +53 -45
- package/components-package/postcss.components.js +1 -24
- package/components-package/postcss.themes.js +1 -30
- package/components-package/wdio.js +415 -405
- package/icons-collection/nps.js +7 -5
- package/lib/amd-to-es6/index.js +102 -0
- package/lib/amd-to-es6/no-remaining-require.js +33 -0
- package/lib/cem/custom-elements-manifest.config.mjs +527 -0
- package/lib/cem/event.mjs +168 -0
- package/lib/cem/schema-internal.json +1413 -0
- package/lib/cem/schema.json +1098 -0
- package/lib/cem/types-internal.d.ts +808 -0
- package/lib/cem/types.d.ts +736 -0
- package/lib/cem/utils.mjs +408 -0
- package/lib/cem/validate.js +70 -0
- package/lib/create-icons/index.js +8 -6
- package/lib/create-illustrations/index.js +40 -33
- package/lib/create-new-component/index.js +4 -13
- package/lib/create-new-component/tsFileContentTemplate.js +4 -13
- package/lib/css-processors/css-processor-components.mjs +77 -0
- package/lib/css-processors/css-processor-themes.mjs +79 -0
- package/lib/css-processors/scope-variables.mjs +49 -0
- package/lib/{postcss-css-to-esm/index.js → css-processors/shared.mjs} +36 -50
- package/lib/dev-server/custom-hot-update-plugin.js +4 -4
- package/lib/dev-server/{dev-server.js → dev-server.mjs} +4 -4
- package/lib/generate-js-imports/illustrations.js +17 -14
- package/lib/generate-json-imports/i18n.js +45 -61
- package/lib/generate-json-imports/themes.js +16 -33
- package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +12 -7
- package/lib/hbs2ui5/index.js +3 -3
- package/lib/i18n/defaults.js +3 -2
- package/lib/postcss-combine-duplicated-selectors/index.js +12 -5
- package/lib/remove-dev-mode/remove-dev-mode.mjs +37 -0
- package/lib/scoping/get-all-tags.js +10 -3
- package/lib/scoping/lint-src.js +8 -7
- package/lib/scoping/scope-test-pages.js +2 -1
- package/package.json +19 -11
- package/tsconfig.json +16 -0
- package/types/index.d.ts +1 -0
- package/components-package/wdio.sync.js +0 -368
- package/lib/create-new-component/jsFileContentTemplate.js +0 -73
- package/lib/esm-abs-to-rel/index.js +0 -58
- package/lib/generate-custom-elements-manifest/index.js +0 -327
- package/lib/jsdoc/config.json +0 -29
- package/lib/jsdoc/configTypescript.json +0 -29
- package/lib/jsdoc/plugin.js +0 -2468
- package/lib/jsdoc/preprocess.js +0 -146
- package/lib/jsdoc/template/publish.js +0 -4120
- package/lib/postcss-css-to-json/index.js +0 -47
- package/lib/postcss-new-files/index.js +0 -36
- package/lib/postcss-p/postcss-p.mjs +0 -14
- package/lib/postcss-scope-vars/index.js +0 -24
- package/lib/replace-global-core/index.js +0 -25
package/icons-collection/nps.js
CHANGED
@@ -41,22 +41,24 @@ const copyIconAssetsCommand = (options) => {
|
|
41
41
|
const getScripts = (options) => {
|
42
42
|
const createJSImportsCmd = createIconImportsCommand(options);
|
43
43
|
const copyAssetsCmd = copyIconAssetsCommand(options);
|
44
|
-
const tsCommand = options.
|
45
|
-
const tsCrossEnv = options.
|
44
|
+
const tsCommand = !options.legacy ? "tsc --build" : "";
|
45
|
+
const tsCrossEnv = !options.legacy ? "cross-env UI5_TS=true" : "";
|
46
46
|
|
47
47
|
const scripts = {
|
48
48
|
clean: "rimraf dist && rimraf src/generated",
|
49
49
|
copy: copyAssetsCmd,
|
50
|
+
generate: `${tsCrossEnv} nps clean copy build.i18n build.icons build.jsonImports copyjson`,
|
51
|
+
copyjson: "copy-and-watch \"src/generated/**/*.json\" dist/generated/",
|
50
52
|
build: {
|
51
53
|
default: `${tsCrossEnv} nps clean copy build.i18n typescript build.icons build.jsonImports`,
|
52
54
|
i18n: {
|
53
55
|
default: "nps build.i18n.defaultsjs build.i18n.json",
|
54
56
|
defaultsjs: `mkdirp dist/generated/i18n && node "${LIB}/i18n/defaults.js" src/i18n src/generated/i18n`,
|
55
|
-
json: `mkdirp
|
57
|
+
json: `mkdirp src/generated/assets/i18n && node "${LIB}/i18n/toJSON.js" src/i18n src/generated/assets/i18n`,
|
56
58
|
},
|
57
59
|
jsonImports: {
|
58
|
-
default: "mkdirp
|
59
|
-
i18n: `node "${LIB}/generate-json-imports/i18n.js"
|
60
|
+
default: "mkdirp src/generated/json-imports && nps build.jsonImports.i18n",
|
61
|
+
i18n: `node "${LIB}/generate-json-imports/i18n.js" src/generated/assets/i18n src/generated/json-imports`,
|
60
62
|
},
|
61
63
|
icons: createJSImportsCmd,
|
62
64
|
},
|
@@ -0,0 +1,102 @@
|
|
1
|
+
const fs = require("fs").promises;
|
2
|
+
const path = require("path");
|
3
|
+
const basePath = process.argv[2];
|
4
|
+
const babelCore = require("@babel/core");
|
5
|
+
const babelParser = require("@babel/parser");
|
6
|
+
const babelGenerator = require("@babel/generator").default;
|
7
|
+
const replaceAsync = require('replace-in-file');
|
8
|
+
|
9
|
+
const convertSAPUIDefineToDefine = async (filePath) => {
|
10
|
+
return replaceAsync({
|
11
|
+
files: filePath,
|
12
|
+
processor: (input) => {
|
13
|
+
return input.replace("sap.ui.define", "define").replace(", /* bExport= */ false", "").replace(", /* bExport= */ true", "");
|
14
|
+
}
|
15
|
+
})
|
16
|
+
}
|
17
|
+
|
18
|
+
const convertAmdToEs6 = async (code) => {
|
19
|
+
return (await babelCore.transformAsync(code, {
|
20
|
+
plugins: [['babel-plugin-amd-to-esm', {}]]
|
21
|
+
})).code;
|
22
|
+
}
|
23
|
+
|
24
|
+
const convertAbsImportsToRelative = (filePath, code) => {
|
25
|
+
let changed = false;
|
26
|
+
// console.log("File processing started: ", srcPath);
|
27
|
+
|
28
|
+
if (code.includes("import(")) {
|
29
|
+
// esprima can't parse this, but it's from the project files
|
30
|
+
return;
|
31
|
+
}
|
32
|
+
|
33
|
+
const tree = babelParser.parse(code, { sourceType: "module" });
|
34
|
+
const importer = filePath.replace(basePath, "");
|
35
|
+
const importerDir = path.dirname(importer);
|
36
|
+
// console.log("Importer -> ", importer);
|
37
|
+
|
38
|
+
tree?.program?.body?.forEach(node => {
|
39
|
+
if (node.type === "ImportDeclaration") {
|
40
|
+
let importee = node.source.value;
|
41
|
+
// console.log(importee);
|
42
|
+
if (importee.startsWith(".")) {
|
43
|
+
// add .js extension if missing
|
44
|
+
if (!importee.endsWith(".js")) {
|
45
|
+
node.source.value += ".js"
|
46
|
+
changed = true;
|
47
|
+
}
|
48
|
+
return;
|
49
|
+
}
|
50
|
+
let importeeDir = path.dirname(importee);
|
51
|
+
let importeeFile = path.basename(importee);
|
52
|
+
let relativePath = path.relative(importerDir, importeeDir);
|
53
|
+
if (relativePath.length === 0) {
|
54
|
+
relativePath = "."
|
55
|
+
}
|
56
|
+
if (!relativePath.startsWith(".")) {
|
57
|
+
relativePath = "./" + relativePath;
|
58
|
+
}
|
59
|
+
|
60
|
+
relativePath = relativePath.replace(/\\/g, "/"); // the browser expects unix paths
|
61
|
+
let relativeImport = `${relativePath}/${importeeFile}.js`;
|
62
|
+
// console.log(importee + " --> " + relativeImport);
|
63
|
+
node.source.value = relativeImport;
|
64
|
+
changed = true;
|
65
|
+
}
|
66
|
+
});
|
67
|
+
|
68
|
+
return changed ? babelGenerator(tree).code : code;
|
69
|
+
}
|
70
|
+
|
71
|
+
const replaceGlobalCoreUsage = (filePath, code) => {
|
72
|
+
if (!filePath.includes("Configuration")) {
|
73
|
+
const replaced = code.replace(/sap\.ui\.getCore\(\)/g, `Core`);
|
74
|
+
return code !== replaced ? `import Core from 'sap/ui/core/Core';${replaced}` : code;
|
75
|
+
}
|
76
|
+
|
77
|
+
return code;
|
78
|
+
};
|
79
|
+
|
80
|
+
const transformAmdToES6Module = async (filePath) => {
|
81
|
+
await convertSAPUIDefineToDefine(filePath);
|
82
|
+
|
83
|
+
let code = (await fs.readFile(filePath)).toString();
|
84
|
+
|
85
|
+
code = await convertAmdToEs6(code);
|
86
|
+
|
87
|
+
code = replaceGlobalCoreUsage(filePath, code);
|
88
|
+
|
89
|
+
code = convertAbsImportsToRelative(filePath, code);
|
90
|
+
|
91
|
+
return fs.writeFile(filePath, code);
|
92
|
+
}
|
93
|
+
|
94
|
+
const transformAmdToES6Modules = async () => {
|
95
|
+
const { globby } = await import("globby");
|
96
|
+
const fileNames = await globby(basePath.replace(/\\/g, "/") + "**/*.js");
|
97
|
+
return Promise.all(fileNames.map(transformAmdToES6Module).filter(x => !!x));
|
98
|
+
};
|
99
|
+
|
100
|
+
transformAmdToES6Modules().then(() => {
|
101
|
+
console.log("Success: all amd modules are transformed to es6!");
|
102
|
+
});
|
@@ -0,0 +1,33 @@
|
|
1
|
+
const fs = require("fs").promises;
|
2
|
+
const path = require("path");
|
3
|
+
const basePath = process.argv[2];
|
4
|
+
const babelCore = require("@babel/core");
|
5
|
+
const babelParser = require("@babel/parser");
|
6
|
+
const babelGenerator = require("@babel/generator").default;
|
7
|
+
const walk = require("estree-walk");
|
8
|
+
|
9
|
+
const checkHasRequire = (filePath, code) => {
|
10
|
+
code = code.replace(/sap\.ui\.require/g, "unhandledRequire");
|
11
|
+
|
12
|
+
const tree = babelParser.parse(code, { sourceType: "module" });
|
13
|
+
walk(tree, {
|
14
|
+
CallExpression: function (node) {
|
15
|
+
if (node.type === "CallExpression" && node?.callee?.name === "unhandledRequire") {
|
16
|
+
throw new Error(`sap.ui.require found in ${filePath}`);
|
17
|
+
}
|
18
|
+
}
|
19
|
+
});
|
20
|
+
}
|
21
|
+
|
22
|
+
const checkFile = async (filePath) => {
|
23
|
+
let code = (await fs.readFile(filePath)).toString();
|
24
|
+
checkHasRequire(filePath, code);
|
25
|
+
}
|
26
|
+
|
27
|
+
const checkAll = async () => {
|
28
|
+
const { globby } = await import("globby");
|
29
|
+
const fileNames = await globby(basePath.replace(/\\/g, "/") + "**/*.js");
|
30
|
+
return Promise.all(fileNames.map(checkFile).filter(x => !!x));
|
31
|
+
};
|
32
|
+
|
33
|
+
checkAll();
|
@@ -0,0 +1,527 @@
|
|
1
|
+
import { parse } from "comment-parser";
|
2
|
+
import processEvent from "./event.mjs";
|
3
|
+
import path from "path";
|
4
|
+
import fs from 'fs';
|
5
|
+
import {
|
6
|
+
getDeprecatedStatus,
|
7
|
+
getExperimentalStatus,
|
8
|
+
getSinceStatus,
|
9
|
+
getPrivacyStatus,
|
10
|
+
getReference,
|
11
|
+
validateJSDocComment,
|
12
|
+
findDecorator,
|
13
|
+
findAllDecorators,
|
14
|
+
hasTag,
|
15
|
+
findTag,
|
16
|
+
findAllTags,
|
17
|
+
getTypeRefs,
|
18
|
+
normalizeDescription,
|
19
|
+
formatArrays,
|
20
|
+
isClass,
|
21
|
+
normalizeTagType,
|
22
|
+
logDocumentationError,
|
23
|
+
displayDocumentationErrors,
|
24
|
+
toKebabCase
|
25
|
+
} from "./utils.mjs";
|
26
|
+
import { generateCustomData } from "cem-plugin-vs-code-custom-data-generator";
|
27
|
+
import { customElementJetBrainsPlugin } from "custom-element-jet-brains-integration";
|
28
|
+
|
29
|
+
const packageJSON = JSON.parse(fs.readFileSync("./package.json"));
|
30
|
+
|
31
|
+
const extractClassNodeJSDoc = node => {
|
32
|
+
const fileContent = node.getFullText();
|
33
|
+
const allJSDocsRegExp = new RegExp(`\\/\\*\\*(.|\\n)+?\\s+\\*\\/`, "gm");
|
34
|
+
let allJSDocs = [...fileContent.matchAll(allJSDocsRegExp)];
|
35
|
+
allJSDocs = allJSDocs.map(match => match[0]); // all /** ..... */ comments
|
36
|
+
|
37
|
+
// Find where the class is defined in the original file
|
38
|
+
const tsClassDefinitionRegExp = new RegExp(`^\\s*(abstract\\s*)?class [\\w\\d_]+`, "gm");
|
39
|
+
let tsClassDefinitionMatch = fileContent.match(tsClassDefinitionRegExp);
|
40
|
+
if (!tsClassDefinitionMatch) {
|
41
|
+
return; // no class defined in this .ts file
|
42
|
+
}
|
43
|
+
const tsClassDefinition = tsClassDefinitionMatch[0];
|
44
|
+
const tsClassDefinitionIndex = fileContent.indexOf(tsClassDefinition);
|
45
|
+
|
46
|
+
return allJSDocs.find(JSDoc => {
|
47
|
+
return isClass(JSDoc) && (fileContent.indexOf(JSDoc) < tsClassDefinitionIndex)
|
48
|
+
});
|
49
|
+
}
|
50
|
+
|
51
|
+
function processClass(ts, classNode, moduleDoc) {
|
52
|
+
const className = classNode?.name?.text;
|
53
|
+
const currClass = moduleDoc?.declarations?.find(declaration => declaration?.name === className);
|
54
|
+
const currClassJSdoc = extractClassNodeJSDoc(classNode);
|
55
|
+
|
56
|
+
if (!currClassJSdoc) return;
|
57
|
+
|
58
|
+
const customElementDecorator = findDecorator(classNode, "customElement");
|
59
|
+
const classParsedJsDoc = parse(currClassJSdoc, { spacing: 'preserve' })[0];
|
60
|
+
|
61
|
+
validateJSDocComment("class", classParsedJsDoc, classNode.name?.text, moduleDoc);
|
62
|
+
|
63
|
+
const decoratorArg = customElementDecorator?.expression?.arguments[0];
|
64
|
+
currClass.tagName = decoratorArg?.text || (decoratorArg?.properties.find(property => property.name.text === "tag")?.initializer?.text);
|
65
|
+
currClass.customElement = !!customElementDecorator || className === "UI5Element" || undefined;
|
66
|
+
currClass.kind = "class";
|
67
|
+
currClass.deprecated = getDeprecatedStatus(classParsedJsDoc);
|
68
|
+
currClass._ui5experimental = getExperimentalStatus(classParsedJsDoc);
|
69
|
+
currClass._ui5since = getSinceStatus(classParsedJsDoc);
|
70
|
+
currClass._ui5privacy = getPrivacyStatus(classParsedJsDoc);
|
71
|
+
currClass._ui5abstract = hasTag(classParsedJsDoc, "abstract") ? true : undefined;
|
72
|
+
currClass.description = normalizeDescription(classParsedJsDoc.description || findTag(classParsedJsDoc, "class")?.description);
|
73
|
+
currClass._ui5implements = findAllTags(classParsedJsDoc, "implements")
|
74
|
+
.map(tag => {
|
75
|
+
const correctInterfaceDescription = classNode?.heritageClauses?.some(heritageClause => {
|
76
|
+
return heritageClause?.types?.some(type => type.expression?.text === normalizeTagType(tag.type));
|
77
|
+
});
|
78
|
+
|
79
|
+
if (!correctInterfaceDescription) {
|
80
|
+
logDocumentationError(moduleDoc.path, `@interface {${tag.type}} tag is used, but the class doesn't implement the corresponding interface`)
|
81
|
+
}
|
82
|
+
|
83
|
+
return getReference(ts, normalizeTagType(tag.type), classNode, moduleDoc.path)
|
84
|
+
})
|
85
|
+
.filter(Boolean);
|
86
|
+
|
87
|
+
|
88
|
+
if (hasTag(classParsedJsDoc, "extends")) {
|
89
|
+
const superclassTag = findTag(classParsedJsDoc, "extends");
|
90
|
+
currClass.superclass = getReference(ts, superclassTag.name, classNode, moduleDoc.path);
|
91
|
+
|
92
|
+
if (classNode?.heritageClauses?.[0]?.types?.[0]?.expression?.text !== superclassTag.name) {
|
93
|
+
logDocumentationError(moduleDoc.path, `@extends ${superclassTag.name} is used, but the class doesn't extend the corresponding superclass`)
|
94
|
+
}
|
95
|
+
|
96
|
+
if (currClass.superclass?.name === "UI5Element") {
|
97
|
+
currClass.customElement = true;
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
if (!currClass._ui5implements.length) delete currClass._ui5implements;
|
102
|
+
|
103
|
+
// Slots
|
104
|
+
|
105
|
+
// Slots without accessort (defined in class comment)
|
106
|
+
if (hasTag(classParsedJsDoc, "slot") && currClass.slots) {
|
107
|
+
const slotTags = findAllTags(classParsedJsDoc, "slot");
|
108
|
+
|
109
|
+
currClass.slots.forEach(slot => {
|
110
|
+
const tag = slotTags.find(tag => tag.name === slot.name);
|
111
|
+
|
112
|
+
const typeRefs = (normalizeTagType(tag.type)
|
113
|
+
?.replaceAll(/Array<|>|\[\]/g, "")
|
114
|
+
?.split("|")
|
115
|
+
?.map(e => getReference(ts, e.trim(), classNode, moduleDoc.path)).filter(Boolean));
|
116
|
+
|
117
|
+
slot._ui5privacy = "public";
|
118
|
+
slot._ui5type = { text: formatArrays(normalizeTagType(tag.type)) };
|
119
|
+
slot.description = normalizeDescription(tag.description)
|
120
|
+
|
121
|
+
if (typeRefs && typeRefs.length) {
|
122
|
+
slot._ui5type.references = typeRefs;
|
123
|
+
}
|
124
|
+
|
125
|
+
delete slot.type
|
126
|
+
})
|
127
|
+
}
|
128
|
+
|
129
|
+
// Events
|
130
|
+
currClass.events = findAllDecorators(classNode, "event")
|
131
|
+
?.map(event => processEvent(ts, event, classNode, moduleDoc));
|
132
|
+
|
133
|
+
const filename = classNode.getSourceFile().fileName;
|
134
|
+
const sourceFile = typeProgram.getSourceFile(filename);
|
135
|
+
const tsProgramClassNode = sourceFile.statements.find(statement => ts.isClassDeclaration(statement) && statement.name?.text === classNode.name?.text);
|
136
|
+
|
137
|
+
// Slots (with accessor), methods and fields
|
138
|
+
for (let i = 0; i < (currClass.members?.length || 0); i++) {
|
139
|
+
const member = currClass.members[i];
|
140
|
+
const classNodeMember = classNode.members?.find(nodeMember => nodeMember.name?.text === member?.name && nodeMember.jsDoc?.[0]);
|
141
|
+
const classNodeMemberJSdoc = classNodeMember?.jsDoc?.[0];
|
142
|
+
|
143
|
+
if (!classNodeMember || !classNodeMemberJSdoc) continue;
|
144
|
+
|
145
|
+
const memberParsedJsDoc = parse(classNodeMemberJSdoc?.getText())[0];
|
146
|
+
|
147
|
+
member._ui5since = getSinceStatus(memberParsedJsDoc);
|
148
|
+
member.deprecated === "true" && (member.deprecated = true)
|
149
|
+
|
150
|
+
// Slots with accessors are treated like fields by the tool, so we have to convert them into slots.
|
151
|
+
if (member.kind === "field") {
|
152
|
+
const slotDecorator = findDecorator(classNodeMember, "slot");
|
153
|
+
validateJSDocComment(slotDecorator ? "slot" : (member.readonly ? "getter" : "field"), memberParsedJsDoc, classNodeMember.name?.text, moduleDoc);
|
154
|
+
|
155
|
+
const typeRefs = (getTypeRefs(ts, classNodeMember, member)
|
156
|
+
?.map(e => getReference(ts, e, classNodeMember, moduleDoc.path)).filter(Boolean)) || [];
|
157
|
+
|
158
|
+
if (member.type?.text) {
|
159
|
+
member.type.text = formatArrays(member.type.text);
|
160
|
+
}
|
161
|
+
|
162
|
+
if (member.type && typeRefs.length) {
|
163
|
+
member.type.references = typeRefs;
|
164
|
+
}
|
165
|
+
|
166
|
+
if (slotDecorator) {
|
167
|
+
if (!currClass.slots) currClass.slots = [];
|
168
|
+
|
169
|
+
const slot = currClass.members.splice(i, 1)[0];
|
170
|
+
const defaultProperty = slotDecorator.expression?.arguments?.[0]?.properties?.find(property => property.name.text === "default");
|
171
|
+
|
172
|
+
// name of the default slot declared with decorator will be overriden so we to provide it's accessor name
|
173
|
+
if (defaultProperty && defaultProperty.initializer?.kind === ts.SyntaxKind.TrueKeyword) {
|
174
|
+
slot._ui5propertyName = slot.name;
|
175
|
+
slot.name = "default";
|
176
|
+
}
|
177
|
+
|
178
|
+
// Slots don't have type, privacy and kind, so we have do convert them and to clean unused props
|
179
|
+
member._ui5type = member.type;
|
180
|
+
member._ui5privacy = member.privacy;
|
181
|
+
delete member.type;
|
182
|
+
delete member.privacy;
|
183
|
+
delete slot.kind;
|
184
|
+
|
185
|
+
currClass.slots.push(slot);
|
186
|
+
i--;
|
187
|
+
} else {
|
188
|
+
const propertyDecorator = findDecorator(classNodeMember, "property");
|
189
|
+
|
190
|
+
if (propertyDecorator) {
|
191
|
+
member._ui5noAttribute = propertyDecorator?.expression?.arguments[0]?.properties?.find(property => property.name.text === "noAttribute")?.initializer?.kind === ts.SyntaxKind.TrueKeyword || undefined;
|
192
|
+
}
|
193
|
+
|
194
|
+
if (currClass.customElement && member.privacy === "public") {
|
195
|
+
const tsProgramMember = tsProgramClassNode.members.find(m => ts.isPropertyDeclaration(m) && m.name?.text === member.name);
|
196
|
+
const attributeValue = typeChecker.typeToString(typeChecker.getTypeAtLocation(tsProgramMember), tsProgramMember);
|
197
|
+
|
198
|
+
if (attributeValue === "boolean" && member.default === "true") {
|
199
|
+
logDocumentationError(moduleDoc.path, `Boolean properties must be initialzed to false. [${member.name}] property of class [${className}] is intialized to \`true\``)
|
200
|
+
}
|
201
|
+
|
202
|
+
if (!member.type) {
|
203
|
+
logDocumentationError(moduleDoc.path, `Public properties must have type. The type of [${member.name}] property is not determinated automatically. Please check it.`)
|
204
|
+
}
|
205
|
+
|
206
|
+
currClass.attributes.push({
|
207
|
+
description: member.description,
|
208
|
+
name: toKebabCase(member.name),
|
209
|
+
default: member.default,
|
210
|
+
fieldName: member.name,
|
211
|
+
type: { text: attributeValue },
|
212
|
+
deprecated: member.deprecated
|
213
|
+
})
|
214
|
+
}
|
215
|
+
|
216
|
+
if (hasTag(memberParsedJsDoc, "formProperty")) {
|
217
|
+
member._ui5formProperty = true;
|
218
|
+
}
|
219
|
+
|
220
|
+
const formEventsTag = findTag(memberParsedJsDoc, "formEvents");
|
221
|
+
if (formEventsTag) {
|
222
|
+
const tagValue = formEventsTag.description ? `${formEventsTag.name} ${formEventsTag.description}` : formEventsTag.name;
|
223
|
+
member._ui5formEvents = tagValue.trim().replaceAll(/\s+/g, ",");
|
224
|
+
}
|
225
|
+
|
226
|
+
const defaultTag = findTag(memberParsedJsDoc, "default");
|
227
|
+
if (defaultTag) {
|
228
|
+
const tagValue = defaultTag.source?.[0]?.tokens?.name || defaultTag.source?.[0]?.tokens?.description || defaultTag.source?.[0]?.tokens?.type || "";
|
229
|
+
member.default = tagValue;
|
230
|
+
}
|
231
|
+
|
232
|
+
if (member.privacy === "public" && !member.default) {
|
233
|
+
logDocumentationError(moduleDoc.path, `Missing default value for '${member.name}'.`)
|
234
|
+
}
|
235
|
+
|
236
|
+
// Getters are treated as fields so they should not have return, instead of return they should have default value defined with @default
|
237
|
+
if (member.readonly) {
|
238
|
+
if (member.privacy === "public" && !member.type) {
|
239
|
+
logDocumentationError(moduleDoc.path, `Missing return type for read-only field '${member.name}'.`)
|
240
|
+
}
|
241
|
+
|
242
|
+
delete member.return;
|
243
|
+
}
|
244
|
+
}
|
245
|
+
} else if (member.kind === "method") {
|
246
|
+
validateJSDocComment("method", memberParsedJsDoc, classNodeMember.name?.text, moduleDoc);
|
247
|
+
|
248
|
+
member.parameters?.forEach(param => {
|
249
|
+
// Treat every parameter that has respective @param tag as public
|
250
|
+
param._ui5privacy = findAllTags(memberParsedJsDoc, "param").some(tag => tag.name === param.name) ? "public" : "private";
|
251
|
+
if (param._ui5privacy === "public") {
|
252
|
+
const paramNode = classNodeMember.parameters?.find(parameter => parameter.name?.text === param.name);
|
253
|
+
let type;
|
254
|
+
|
255
|
+
if (param.optional) {
|
256
|
+
const filename = classNode.getSourceFile().fileName;
|
257
|
+
|
258
|
+
const sourceFile = typeProgram.getSourceFile(filename);
|
259
|
+
const tsProgramClassNode = sourceFile.statements.find(statement => ts.isClassDeclaration(statement) && statement.name?.text === classNode.name?.text);
|
260
|
+
const tsProgramMember = tsProgramClassNode.members.find(m => ts.isMethodDeclaration(m) && m.name?.text === member.name);
|
261
|
+
const tsProgramParameter = tsProgramMember.parameters.find(p => ts.isParameter(p) && p.name?.text === param.name);
|
262
|
+
|
263
|
+
if (tsProgramParameter) {
|
264
|
+
const typeName = typeChecker.typeToString(typeChecker.getTypeAtLocation(tsProgramParameter), tsProgramParameter);
|
265
|
+
|
266
|
+
if (!param.type) {
|
267
|
+
param.type = {};
|
268
|
+
param.type.text = typeName;
|
269
|
+
}
|
270
|
+
|
271
|
+
type = typeName.replaceAll(/Array<|>|\[\]/g, "")
|
272
|
+
?.split("|");
|
273
|
+
}
|
274
|
+
}
|
275
|
+
|
276
|
+
const typeRefs = ((type || getTypeRefs(ts, (type || paramNode), param))
|
277
|
+
?.map(typeRef => getReference(ts, typeRef, classNodeMember, moduleDoc.path)).filter(Boolean)) || [];
|
278
|
+
|
279
|
+
if (typeRefs.length) {
|
280
|
+
param.type.references = typeRefs;
|
281
|
+
}
|
282
|
+
}
|
283
|
+
});
|
284
|
+
|
285
|
+
if (member.return) {
|
286
|
+
const returnTag = findTag(memberParsedJsDoc, "returns");
|
287
|
+
member.return.description = returnTag?.description ? `${returnTag.name} ${returnTag.description}` : returnTag?.name;
|
288
|
+
member.return.type.text = formatArrays(classNodeMember?.type?.getFullText?.()?.trim());
|
289
|
+
const typeRefs = (getTypeRefs(ts, classNodeMember, member.return)
|
290
|
+
?.map(typeRef => getReference(ts, typeRef, classNodeMember, moduleDoc.path)).filter(Boolean)) || [];
|
291
|
+
|
292
|
+
if (typeRefs.length) {
|
293
|
+
member.return.type.references = typeRefs;
|
294
|
+
}
|
295
|
+
|
296
|
+
if (member.privacy === "public" && !member.return.type.text) {
|
297
|
+
logDocumentationError(moduleDoc.path, `Missing return type for function '${member.name}'.`)
|
298
|
+
}
|
299
|
+
} else if (member.privacy === "public") {
|
300
|
+
logDocumentationError(moduleDoc.path, `Missing return type for function '${member.name}'.`)
|
301
|
+
}
|
302
|
+
}
|
303
|
+
}
|
304
|
+
}
|
305
|
+
|
306
|
+
function processInterface(ts, interfaceNode, moduleDoc) {
|
307
|
+
const interfaceJSdoc = interfaceNode?.jsDoc?.[0];
|
308
|
+
const interfaceName = interfaceNode?.name?.text;
|
309
|
+
|
310
|
+
if (!interfaceJSdoc) return;
|
311
|
+
|
312
|
+
const interfaceParsedJsDoc = parse(interfaceJSdoc?.getText(), { spacing: 'preserve' })[0];
|
313
|
+
|
314
|
+
validateJSDocComment("interface", interfaceParsedJsDoc, interfaceNode.name?.text, moduleDoc);
|
315
|
+
|
316
|
+
moduleDoc.declarations.push({
|
317
|
+
kind: "interface",
|
318
|
+
name: interfaceName,
|
319
|
+
description: normalizeDescription(interfaceParsedJsDoc?.description),
|
320
|
+
_ui5experimental: getExperimentalStatus(interfaceParsedJsDoc),
|
321
|
+
_ui5privacy: getPrivacyStatus(interfaceParsedJsDoc),
|
322
|
+
_ui5since: getSinceStatus(interfaceParsedJsDoc),
|
323
|
+
deprecated: getDeprecatedStatus(interfaceParsedJsDoc),
|
324
|
+
});
|
325
|
+
}
|
326
|
+
|
327
|
+
function processEnum(ts, enumNode, moduleDoc) {
|
328
|
+
const enumJSdoc = enumNode?.jsDoc?.[0];
|
329
|
+
const enumName = enumNode?.name?.text;
|
330
|
+
|
331
|
+
if (!enumJSdoc) return;
|
332
|
+
|
333
|
+
const enumParsedJsDoc = parse(enumJSdoc?.getText(), { spacing: 'preserve' })[0];
|
334
|
+
|
335
|
+
validateJSDocComment("enum", enumParsedJsDoc, enumNode.name?.text, moduleDoc);
|
336
|
+
|
337
|
+
const result = {
|
338
|
+
kind: "enum",
|
339
|
+
name: enumName,
|
340
|
+
description: normalizeDescription(enumJSdoc?.comment),
|
341
|
+
_ui5experimental: getExperimentalStatus(enumParsedJsDoc),
|
342
|
+
_ui5privacy: getPrivacyStatus(enumParsedJsDoc),
|
343
|
+
_ui5since: getSinceStatus(enumParsedJsDoc),
|
344
|
+
deprecated: getDeprecatedStatus(enumParsedJsDoc) || undefined,
|
345
|
+
members: (enumNode?.members || []).map(member => {
|
346
|
+
const memberJSdoc = member?.jsDoc?.[0];
|
347
|
+
|
348
|
+
if (!memberJSdoc) return;
|
349
|
+
|
350
|
+
const memberParsedJsDoc = parse(memberJSdoc?.getText())[0];
|
351
|
+
|
352
|
+
validateJSDocComment("enum", memberParsedJsDoc, member.name?.text, moduleDoc);
|
353
|
+
|
354
|
+
return {
|
355
|
+
kind: "field",
|
356
|
+
static: true,
|
357
|
+
privacy: getPrivacyStatus(memberParsedJsDoc),
|
358
|
+
_ui5since: getSinceStatus(memberParsedJsDoc),
|
359
|
+
description: memberJSdoc?.comment,
|
360
|
+
default: member.initializer?.text,
|
361
|
+
deprecated: getDeprecatedStatus(memberParsedJsDoc),
|
362
|
+
name: member.name?.text,
|
363
|
+
readonly: true,
|
364
|
+
};
|
365
|
+
}).filter(Boolean),
|
366
|
+
};
|
367
|
+
|
368
|
+
moduleDoc.declarations.push(result);
|
369
|
+
}
|
370
|
+
|
371
|
+
const processPublicAPI = object => {
|
372
|
+
if (!object) {
|
373
|
+
return true;
|
374
|
+
}
|
375
|
+
const keys = Object.keys(object);
|
376
|
+
if (!keys.includes("privacy") && !keys.includes("_ui5privacy")) {
|
377
|
+
return true;
|
378
|
+
}
|
379
|
+
for (const key of keys) {
|
380
|
+
if ((key === "privacy" && object[key] !== "public") || (key === "_ui5privacy" && object[key] !== "public")) {
|
381
|
+
return true;
|
382
|
+
} else if (typeof object[key] === "object") {
|
383
|
+
if (key === "cssParts" || key === "attributes" || key === "_ui5implements") {
|
384
|
+
continue;
|
385
|
+
}
|
386
|
+
|
387
|
+
if (Array.isArray(object[key])) {
|
388
|
+
for (let i = 0; i < object[key].length; i++) {
|
389
|
+
const shouldRemove = processPublicAPI(object[key][i]);
|
390
|
+
if (shouldRemove) {
|
391
|
+
object[key].splice(i, 1);
|
392
|
+
i--;
|
393
|
+
}
|
394
|
+
}
|
395
|
+
if (object[key].length === 0) {
|
396
|
+
delete object[key];
|
397
|
+
}
|
398
|
+
}
|
399
|
+
}
|
400
|
+
}
|
401
|
+
return false;
|
402
|
+
};
|
403
|
+
|
404
|
+
let typeChecker;
|
405
|
+
let typeProgram;
|
406
|
+
|
407
|
+
export default {
|
408
|
+
globs: ["src/!(*generated)/*.ts", "src/!(*bundle)*.ts"],
|
409
|
+
outdir: 'dist',
|
410
|
+
overrideModuleCreation: ({ ts, globs }) => {
|
411
|
+
typeProgram = ts.createProgram(globs, {
|
412
|
+
noEmitOnError: false,
|
413
|
+
allowJs: true,
|
414
|
+
experimentalDecorators: true,
|
415
|
+
target: 99,
|
416
|
+
downlevelIteration: true,
|
417
|
+
module: 99,
|
418
|
+
strictNullChecks: true,
|
419
|
+
moduleResolution: 2,
|
420
|
+
esModuleInterop: true,
|
421
|
+
noEmit: true,
|
422
|
+
pretty: true,
|
423
|
+
allowSyntheticDefaultImports: true,
|
424
|
+
allowUnreachableCode: true,
|
425
|
+
allowUnusedLabels: true,
|
426
|
+
skipLibCheck: true,
|
427
|
+
});
|
428
|
+
typeChecker = typeProgram.getTypeChecker();
|
429
|
+
|
430
|
+
return globs.map((glob) => {
|
431
|
+
const fullPath = path.resolve(process.cwd(), glob);
|
432
|
+
const source = fs.readFileSync(fullPath).toString();
|
433
|
+
|
434
|
+
return ts.createSourceFile(glob, source, ts.ScriptTarget.ES2015, true);
|
435
|
+
});
|
436
|
+
},
|
437
|
+
plugins: [
|
438
|
+
{
|
439
|
+
name: 'my-plugin',
|
440
|
+
analyzePhase({ ts, node, moduleDoc }) {
|
441
|
+
switch (true) {
|
442
|
+
case ts.isClassDeclaration(node):
|
443
|
+
processClass(ts, node, moduleDoc);
|
444
|
+
break;
|
445
|
+
case ts.isEnumDeclaration(node):
|
446
|
+
processEnum(ts, node, moduleDoc);
|
447
|
+
break;
|
448
|
+
case ts.isInterfaceDeclaration(node):
|
449
|
+
processInterface(ts, node, moduleDoc);
|
450
|
+
break;
|
451
|
+
}
|
452
|
+
},
|
453
|
+
moduleLinkPhase({ moduleDoc }) {
|
454
|
+
for (let i = 0; i < moduleDoc.declarations.length; i++) {
|
455
|
+
const shouldRemove = processPublicAPI(moduleDoc.declarations[i]) || ["function", "variable"].includes(moduleDoc.declarations[i].kind)
|
456
|
+
if (shouldRemove) {
|
457
|
+
moduleDoc.declarations.splice(i, 1);
|
458
|
+
i--;
|
459
|
+
}
|
460
|
+
}
|
461
|
+
|
462
|
+
moduleDoc.path = moduleDoc.path?.replace(/^src/, "dist").replace(/\.ts$/, ".js");
|
463
|
+
|
464
|
+
moduleDoc.exports = moduleDoc.exports.
|
465
|
+
filter(e => !(e.kind === "custom-element-definition" && !moduleDoc.declarations?.find(d => d.name === e.name)?.tagName))
|
466
|
+
|
467
|
+
moduleDoc.exports.forEach(e => {
|
468
|
+
const classNode = moduleDoc.declarations.find(c => c.name === e.declaration.name);
|
469
|
+
|
470
|
+
if (e.declaration && e.declaration.module) {
|
471
|
+
e.declaration.module = e.declaration.module.replace(/^src/, "dist").replace(/\.ts$/, ".js");
|
472
|
+
}
|
473
|
+
|
474
|
+
if (classNode?.customElement && classNode.tagName && e.kind !== "custom-element-definition") {
|
475
|
+
moduleDoc.exports.push({
|
476
|
+
kind: "custom-element-definition",
|
477
|
+
name: classNode.tagName,
|
478
|
+
declaration: {
|
479
|
+
name: e.declaration.name,
|
480
|
+
module: e.declaration.module
|
481
|
+
}
|
482
|
+
})
|
483
|
+
}
|
484
|
+
})
|
485
|
+
|
486
|
+
const typeReferences = new Set();
|
487
|
+
const registerTypeReference = reference => typeReferences.add(JSON.stringify(reference))
|
488
|
+
|
489
|
+
moduleDoc.declarations.forEach(declaration => {
|
490
|
+
["events", "slots", "members"].forEach(memberType => {
|
491
|
+
declaration[memberType]?.forEach(member => {
|
492
|
+
if (member.type?.references) {
|
493
|
+
member.type.references.forEach(registerTypeReference)
|
494
|
+
} else if (member._ui5type?.references) {
|
495
|
+
member._ui5type.references.forEach(registerTypeReference)
|
496
|
+
} else if (member.kind === "method") {
|
497
|
+
member.return?.type?.references?.forEach(registerTypeReference)
|
498
|
+
|
499
|
+
member.parameters?.forEach(parameter => {
|
500
|
+
parameter.type?.references?.forEach(registerTypeReference)
|
501
|
+
})
|
502
|
+
}
|
503
|
+
})
|
504
|
+
})
|
505
|
+
});
|
506
|
+
|
507
|
+
typeReferences.forEach(reference => {
|
508
|
+
reference = JSON.parse(reference);
|
509
|
+
if (reference.package === packageJSON?.name && reference.module === moduleDoc.path) {
|
510
|
+
const hasExport = moduleDoc.exports.some(e => e.declaration?.name === reference.name && e.declaration?.module === reference.module)
|
511
|
+
|
512
|
+
if (!hasExport) {
|
513
|
+
logDocumentationError(moduleDoc.path?.replace(/^dist/, "src").replace(/\.js$/, ".ts"), `Type '${reference.name}' is used to describe a public API but is not exported.`,)
|
514
|
+
}
|
515
|
+
}
|
516
|
+
})
|
517
|
+
},
|
518
|
+
packageLinkPhase({ context }) {
|
519
|
+
if (context.dev) {
|
520
|
+
displayDocumentationErrors();
|
521
|
+
}
|
522
|
+
}
|
523
|
+
},
|
524
|
+
generateCustomData({ outdir: "dist", cssFileName: null, cssPropertiesDocs: false }),
|
525
|
+
customElementJetBrainsPlugin({ outdir: "dist", cssFileName: null, cssPropertiesDocs: false })
|
526
|
+
],
|
527
|
+
};
|