@ui5/webcomponents-tools 0.0.0-0a35d6b3d → 0.0.0-0dd36ca4b
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 +514 -0
- package/assets-meta.js +2 -6
- package/components-package/nps.js +12 -18
- package/components-package/wdio.js +404 -405
- package/icons-collection/nps.js +2 -2
- 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 +83 -45
- package/lib/cem/event.mjs +20 -3
- package/lib/cem/schema-internal.json +3 -0
- package/lib/cem/types-internal.d.ts +550 -786
- package/lib/cem/types.d.ts +520 -655
- package/lib/cem/utils.mjs +49 -20
- package/lib/cem/validate.js +20 -13
- package/lib/create-icons/index.js +8 -6
- package/lib/create-illustrations/index.js +40 -33
- package/lib/create-new-component/index.js +4 -11
- package/lib/create-new-component/tsFileContentTemplate.js +3 -12
- package/lib/css-processors/css-processor-component-styles.mjs +47 -0
- package/lib/css-processors/scope-variables.mjs +3 -0
- package/lib/dev-server/ssr-dom-shim-loader.js +26 -0
- package/lib/generate-js-imports/illustrations.js +9 -9
- package/lib/generate-json-imports/i18n.js +3 -35
- package/lib/generate-json-imports/themes.js +2 -29
- package/lib/i18n/defaults.js +1 -1
- package/lib/scoping/lint-src.js +8 -7
- package/package.json +3 -2
- 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 -61
- 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/replace-global-core/index.js +0 -25
package/lib/cem/utils.mjs
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import fs from "fs";
|
2
2
|
import path from "path";
|
3
3
|
|
4
|
-
let
|
4
|
+
let documentationErrors = new Map();
|
5
5
|
|
6
6
|
const getDeprecatedStatus = (jsdocComment) => {
|
7
7
|
const deprecatedTag = findTag(jsdocComment, "deprecated");
|
@@ -14,22 +14,28 @@ const getDeprecatedStatus = (jsdocComment) => {
|
|
14
14
|
: undefined;
|
15
15
|
};
|
16
16
|
|
17
|
+
const toKebabCase = str => {
|
18
|
+
return str.replaceAll(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? "-" : "") + $.toLowerCase())
|
19
|
+
}
|
20
|
+
|
17
21
|
const normalizeDescription = (description) => {
|
18
22
|
return typeof description === 'string' ? description.replaceAll(/^-\s+|^(\n)+|(\n)+$/g, ""): description;
|
19
23
|
}
|
20
24
|
|
21
|
-
const getTypeRefs = (ts,
|
25
|
+
const getTypeRefs = (ts, node, member) => {
|
22
26
|
const extractTypeRefs = (type) => {
|
23
27
|
if (type?.kind === ts.SyntaxKind.TypeReference) {
|
24
28
|
return type.typeArguments?.length
|
25
29
|
? type.typeArguments.map((typeRef) => typeRef.typeName?.text)
|
26
30
|
: [type.typeName?.text];
|
31
|
+
} else if (type?.kind === ts.SyntaxKind.ArrayType) {
|
32
|
+
return [type.elementType?.typeName?.text];
|
27
33
|
} else if (type?.kind === ts.SyntaxKind.UnionType) {
|
28
34
|
return type.types
|
29
35
|
.map((type) => extractTypeRefs(type))
|
30
36
|
.flat(1);
|
31
37
|
} else if (type?.kind === ts.SyntaxKind.TemplateLiteralType) {
|
32
|
-
if (member
|
38
|
+
if (member?.type) {
|
33
39
|
member.type.text = member.type.text.replaceAll?.(/`|\${|}/g, "");
|
34
40
|
}
|
35
41
|
|
@@ -39,7 +45,7 @@ const getTypeRefs = (ts, classNodeMember, member) => {
|
|
39
45
|
}
|
40
46
|
};
|
41
47
|
|
42
|
-
let typeRefs = extractTypeRefs(
|
48
|
+
let typeRefs = extractTypeRefs(node.type) || node?.typeArguments?.map(n => extractTypeRefs(n)).flat(2);
|
43
49
|
|
44
50
|
if (typeRefs) {
|
45
51
|
typeRefs = typeRefs.filter((e) => !!e);
|
@@ -62,7 +68,7 @@ const getPrivacyStatus = (jsdocComment) => {
|
|
62
68
|
return privacyTag?.tag || "private";
|
63
69
|
};
|
64
70
|
|
65
|
-
const findPackageName = (ts, sourceFile, typeName
|
71
|
+
const findPackageName = (ts, sourceFile, typeName) => {
|
66
72
|
const localStatements = [
|
67
73
|
ts.SyntaxKind.EnumDeclaration,
|
68
74
|
ts.SyntaxKind.InterfaceDeclaration,
|
@@ -102,7 +108,7 @@ const findPackageName = (ts, sourceFile, typeName, packageJSON) => {
|
|
102
108
|
}
|
103
109
|
};
|
104
110
|
|
105
|
-
const findImportPath = (ts, sourceFile, typeName,
|
111
|
+
const findImportPath = (ts, sourceFile, typeName, modulePath) => {
|
106
112
|
const localStatements = [
|
107
113
|
ts.SyntaxKind.EnumDeclaration,
|
108
114
|
ts.SyntaxKind.InterfaceDeclaration,
|
@@ -158,6 +164,8 @@ const normalizeTagType = (type) => {
|
|
158
164
|
return type?.trim();
|
159
165
|
}
|
160
166
|
|
167
|
+
const packageJSON = JSON.parse(fs.readFileSync("./package.json"));
|
168
|
+
|
161
169
|
const getReference = (ts, type, classNode, modulePath) => {
|
162
170
|
let sourceFile = classNode.parent;
|
163
171
|
|
@@ -165,22 +173,19 @@ const getReference = (ts, type, classNode, modulePath) => {
|
|
165
173
|
sourceFile = sourceFile.parent;
|
166
174
|
}
|
167
175
|
|
168
|
-
const packageJSON = JSON.parse(fs.readFileSync("./package.json"));
|
169
|
-
|
170
176
|
const typeName =
|
171
177
|
typeof type === "string"
|
172
178
|
? normalizeTagType(type)
|
173
179
|
: type.class?.expression?.text ||
|
174
180
|
type.typeExpression?.type?.getText() ||
|
175
181
|
type.typeExpression?.type?.elementType?.typeName?.text;
|
176
|
-
const packageName = findPackageName(ts, sourceFile, typeName
|
182
|
+
const packageName = findPackageName(ts, sourceFile, typeName);
|
177
183
|
const importPath = findImportPath(
|
178
184
|
ts,
|
179
185
|
sourceFile,
|
180
186
|
typeName,
|
181
|
-
packageJSON,
|
182
187
|
modulePath
|
183
|
-
);
|
188
|
+
)?.replace(`${packageName}/`, "");
|
184
189
|
|
185
190
|
return packageName && {
|
186
191
|
name: typeName,
|
@@ -317,21 +322,43 @@ const validateJSDocComment = (fieldType, jsdocComment, node, moduleDoc) => {
|
|
317
322
|
}
|
318
323
|
|
319
324
|
if (!isValid) {
|
320
|
-
|
321
|
-
`=== ERROR: Problem found with ${node}'s JSDoc comment in ${moduleDoc.path}: \n\t- @${tag.tag} tag is being used wrong or it's not part of ${fieldType} JSDoc tags`
|
322
|
-
);
|
325
|
+
logDocumentationError(moduleDoc.path, `Incorrect use of @${tag.tag}. Ensure it is part of ${fieldType} JSDoc tags.`)
|
323
326
|
}
|
324
327
|
|
325
328
|
return !!isValid;
|
326
329
|
});
|
327
330
|
};
|
328
331
|
|
329
|
-
const
|
330
|
-
|
331
|
-
|
332
|
+
const logDocumentationError = (modulePath, message) => {
|
333
|
+
let moduleErrors = documentationErrors.get(modulePath);
|
334
|
+
|
335
|
+
if (!moduleErrors) {
|
336
|
+
documentationErrors.set(modulePath, []);
|
337
|
+
moduleErrors = documentationErrors.get(modulePath);
|
338
|
+
}
|
339
|
+
|
340
|
+
moduleErrors.push(message);
|
341
|
+
}
|
342
|
+
|
343
|
+
const displayDocumentationErrors = () => {
|
344
|
+
let errorsCount = 0;
|
345
|
+
[...documentationErrors.keys()].forEach(modulePath => {
|
346
|
+
const moduleErrors = documentationErrors.get(modulePath);
|
347
|
+
|
348
|
+
console.log(`=== ERROR: ${moduleErrors.length > 1 ? `${moduleErrors.length} problems` : "Problem"} found in file: ${modulePath}:`)
|
349
|
+
moduleErrors.forEach(moduleError => {
|
350
|
+
errorsCount++;
|
351
|
+
console.log(`\t- ${moduleError}`)
|
352
|
+
})
|
353
|
+
})
|
354
|
+
|
355
|
+
if(errorsCount) {
|
356
|
+
throw new Error(`Found ${errorsCount} errors in the description of the public API.`);
|
357
|
+
}
|
358
|
+
}
|
332
359
|
|
333
360
|
const formatArrays = (typeText) => {
|
334
|
-
return typeText
|
361
|
+
return typeText?.replaceAll(/(\S+)\[\]/g, "Array<$1>")
|
335
362
|
}
|
336
363
|
|
337
364
|
export {
|
@@ -346,10 +373,12 @@ export {
|
|
346
373
|
hasTag,
|
347
374
|
findTag,
|
348
375
|
findAllTags,
|
349
|
-
getJSDocErrors,
|
350
376
|
getTypeRefs,
|
351
377
|
normalizeDescription,
|
352
378
|
formatArrays,
|
353
379
|
isClass,
|
354
|
-
normalizeTagType
|
380
|
+
normalizeTagType,
|
381
|
+
displayDocumentationErrors,
|
382
|
+
logDocumentationError,
|
383
|
+
toKebabCase
|
355
384
|
};
|
package/lib/cem/validate.js
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
const fs = require('fs');
|
2
2
|
const Ajv = require('ajv');
|
3
3
|
const path = require('path');
|
4
|
+
const yargs = require('yargs/yargs')
|
5
|
+
const { hideBin } = require('yargs/helpers')
|
6
|
+
const argv = yargs(hideBin(process.argv))
|
7
|
+
.argv;
|
4
8
|
|
5
9
|
// Load your JSON schema
|
6
10
|
const extenalSchema = require('./schema.json');
|
@@ -11,6 +15,11 @@ const inputFilePath = path.join(process.cwd(), "dist/custom-elements.json"); //
|
|
11
15
|
const customManifest = fs.readFileSync(inputFilePath, 'utf8');
|
12
16
|
const inputDataInternal = JSON.parse(customManifest);
|
13
17
|
|
18
|
+
inputDataInternal.modules.forEach(moduleDoc => {
|
19
|
+
moduleDoc.exports = moduleDoc.exports.
|
20
|
+
filter(e => moduleDoc.declarations.find(d => d.name === e.declaration.name && ["class", "function", "variable", "enum"].includes(d.kind)) || e.name === "default");
|
21
|
+
})
|
22
|
+
|
14
23
|
const clearProps = (data) => {
|
15
24
|
if (Array.isArray(data)) {
|
16
25
|
for (let i = 0; i < data.length; i++) {
|
@@ -36,28 +45,26 @@ const clearProps = (data) => {
|
|
36
45
|
return data;
|
37
46
|
}
|
38
47
|
|
39
|
-
const inputDataExternal = clearProps(JSON.parse(JSON.stringify(inputDataInternal)));
|
40
|
-
|
41
48
|
const ajv = new Ajv({ allowUnionTypes: true, allError: true })
|
42
|
-
|
43
49
|
let validate = ajv.compile(internalSchema)
|
44
50
|
|
45
51
|
// Validate the JSON data against the schema
|
46
|
-
if (
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
52
|
+
if (argv.dev) {
|
53
|
+
if (validate(inputDataInternal)) {
|
54
|
+
console.log('Internal custom element manifest is validated successfully');
|
55
|
+
} else {
|
56
|
+
throw new Error(`Validation of internal custom elements manifest failed: ${validate.errors}`);
|
57
|
+
}
|
51
58
|
}
|
52
59
|
|
60
|
+
const inputDataExternal = clearProps(JSON.parse(JSON.stringify(inputDataInternal)));
|
53
61
|
validate = ajv.compile(extenalSchema)
|
54
62
|
|
55
63
|
// Validate the JSON data against the schema
|
56
64
|
if (validate(inputDataExternal)) {
|
57
|
-
console.log('
|
65
|
+
console.log('Custom element manifest is validated successfully');
|
58
66
|
fs.writeFileSync(inputFilePath, JSON.stringify(inputDataExternal, null, 2), 'utf8');
|
59
67
|
fs.writeFileSync(inputFilePath.replace("custom-elements", "custom-elements-internal"), JSON.stringify(inputDataInternal, null, 2), 'utf8');
|
60
|
-
} else {
|
61
|
-
|
62
|
-
|
63
|
-
}
|
68
|
+
} else if (argv.dev) {
|
69
|
+
throw new Error(`Validation of public custom elements manifest failed: ${validate.errors}`);
|
70
|
+
}
|
@@ -38,14 +38,16 @@ export { pathData, ltr, accData };`;
|
|
38
38
|
|
39
39
|
|
40
40
|
|
41
|
-
const collectionTemplate = (name, versions, fullName) => `import {
|
41
|
+
const collectionTemplate = (name, versions, fullName) => `import { isLegacyThemeFamilyAsync } 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
|
45
|
+
const getPathData = async() => {
|
46
|
+
return await isLegacyThemeFamilyAsync() ? pathDatav4 : pathDatav5;
|
47
|
+
};
|
46
48
|
|
47
49
|
export default "${fullName}";
|
48
|
-
export {
|
50
|
+
export { getPathData, ltr, accData };`;
|
49
51
|
|
50
52
|
|
51
53
|
const typeDefinitionTemplate = (name, accData, collection) => `declare const pathData: string;
|
@@ -56,13 +58,13 @@ declare const _default: "${collection}/${name}";
|
|
56
58
|
export default _default;
|
57
59
|
export { pathData, ltr, accData };`
|
58
60
|
|
59
|
-
const collectionTypeDefinitionTemplate = (name, accData) => `declare const
|
61
|
+
const collectionTypeDefinitionTemplate = (name, accData) => `declare const getPathData: () => Promise<string>;
|
60
62
|
declare const ltr: boolean;
|
61
63
|
declare const accData: ${accData ? '{ key: string; defaultText: string; }' : null}
|
62
64
|
declare const _default: "${name}";
|
63
65
|
|
64
66
|
export default _default;
|
65
|
-
export {
|
67
|
+
export { getPathData, ltr, accData };`
|
66
68
|
|
67
69
|
|
68
70
|
const svgTemplate = (pathData) => `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
|
@@ -91,7 +93,7 @@ const createIcons = async (file) => {
|
|
91
93
|
|
92
94
|
// For versioned icons collections, the script creates top level (unversioned) module that internally imports the versioned ones.
|
93
95
|
// For example, the top level "@ui5/ui5-webcomponents-icons/dist/accept.js" imports:
|
94
|
-
// - "@ui5/ui5-webcomponents-icons/dist/v5/accept.js"
|
96
|
+
// - "@ui5/ui5-webcomponents-icons/dist/v5/accept.js"
|
95
97
|
// - "@ui5/ui5-webcomponents-icons/dist/v4/accept.js"
|
96
98
|
|
97
99
|
if (json.version) {
|
@@ -59,9 +59,11 @@ const generate = async () => {
|
|
59
59
|
const destPath = process.argv[6];
|
60
60
|
const collection = process.argv[7];
|
61
61
|
const fileNamePattern = new RegExp(`${illustrationsPrefix}-.+-(.+).svg`);
|
62
|
-
// collect each illustration name because each one should have Sample.js file
|
62
|
+
// collect each illustration name because each one should have Sample.js file
|
63
63
|
const fileNames = new Set();
|
64
64
|
|
65
|
+
let dotIllustrationNames = [];
|
66
|
+
|
65
67
|
try {
|
66
68
|
await fs.access(srcPath);
|
67
69
|
} catch (error) {
|
@@ -75,10 +77,16 @@ const generate = async () => {
|
|
75
77
|
return `export default \`${svgContent}\`;`
|
76
78
|
};
|
77
79
|
const svgToJs = async fileName => {
|
78
|
-
const svg = await fs.readFile(path.join(srcPath, fileName), {encoding: "utf-8"});
|
80
|
+
const svg = await fs.readFile(path.join(srcPath, fileName), { encoding: "utf-8" });
|
79
81
|
const fileContent = svgImportTemplate(svg);
|
82
|
+
const fileNameSplitArr = fileName.split('-');
|
80
83
|
fileName = fileName.replace(/\.svg$/, ".js");
|
81
84
|
|
85
|
+
if (fileNameSplitArr[1] === 'Dot') {
|
86
|
+
// we keep the Dot illustration names to import them later. If no Dot is present, Spot will be used
|
87
|
+
dotIllustrationNames.push(fileNameSplitArr[2].split('.')[0]);
|
88
|
+
}
|
89
|
+
|
82
90
|
return fs.writeFile(path.join(destPath, fileName), fileContent);
|
83
91
|
};
|
84
92
|
const illustrationImportTemplate = illustrationName => {
|
@@ -93,59 +101,54 @@ const generate = async () => {
|
|
93
101
|
}
|
94
102
|
|
95
103
|
const illustrationNameUpperCase = illustrationNameForTranslation.toUpperCase();
|
104
|
+
// If no Dot is present, Spot will be imported as Dot
|
105
|
+
const hasDot = dotIllustrationNames.indexOf(illustrationName) !== -1 ? 'Dot' : 'Spot';
|
96
106
|
|
97
|
-
return
|
107
|
+
return `import { registerIllustration } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
|
98
108
|
import dialogSvg from "./${illustrationsPrefix}-Dialog-${illustrationName}.js";
|
99
109
|
import sceneSvg from "./${illustrationsPrefix}-Scene-${illustrationName}.js";
|
100
110
|
import spotSvg from "./${illustrationsPrefix}-Spot-${illustrationName}.js";
|
101
|
-
import {
|
111
|
+
import dotSvg from "./${illustrationsPrefix}-${hasDot}-${illustrationName}.js";${
|
112
|
+
defaultText ? `import {
|
102
113
|
IM_TITLE_${illustrationNameUpperCase},
|
103
114
|
IM_SUBTITLE_${illustrationNameUpperCase},
|
104
|
-
} from "../generated/i18n/i18n-defaults.js"
|
115
|
+
} from "../generated/i18n/i18n-defaults.js";` : ``}
|
105
116
|
|
106
117
|
const name = "${illustrationName}";
|
107
118
|
const set = "${illustrationSet}";
|
108
|
-
const collection = "${collection}"
|
119
|
+
const collection = "${collection}";${defaultText ? `
|
109
120
|
const title = IM_TITLE_${illustrationNameUpperCase};
|
110
|
-
const subtitle = IM_SUBTITLE_${illustrationNameUpperCase}
|
121
|
+
const subtitle = IM_SUBTITLE_${illustrationNameUpperCase};` : ``}
|
111
122
|
|
112
123
|
registerIllustration(name, {
|
113
124
|
dialogSvg,
|
114
125
|
sceneSvg,
|
115
126
|
spotSvg,
|
127
|
+
dotSvg,${defaultText ? `
|
116
128
|
title,
|
117
|
-
subtitle
|
129
|
+
subtitle,` : ``}
|
118
130
|
set,
|
119
131
|
collection,
|
120
132
|
});
|
121
133
|
|
134
|
+
export default "${illustrationSet === "fiori" ? "" : `${illustrationSet}/`}${illustrationName}";
|
122
135
|
export {
|
123
136
|
dialogSvg,
|
124
137
|
sceneSvg,
|
125
138
|
spotSvg,
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
import sceneSvg from "./${illustrationsPrefix}-Scene-${illustrationName}.js";
|
130
|
-
import spotSvg from "./${illustrationsPrefix}-Spot-${illustrationName}.js";
|
131
|
-
|
132
|
-
const name = "${illustrationName}";
|
133
|
-
const set = "${illustrationSet}";
|
134
|
-
const collection = "${collection}";
|
139
|
+
dotSvg,
|
140
|
+
};`
|
141
|
+
};
|
135
142
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
});
|
143
|
+
const illustrationTypeDefinition = illustrationName => {
|
144
|
+
return `declare const dialogSvg: string;
|
145
|
+
declare const sceneSvg: string;
|
146
|
+
declare const spotSvg: string;
|
147
|
+
declare const dotSvg: string;
|
148
|
+
declare const _default: "${illustrationSet === "fiori" ? "" : `${illustrationSet}/`}${illustrationName}";
|
143
149
|
|
144
|
-
export
|
145
|
-
|
146
|
-
sceneSvg,
|
147
|
-
spotSvg,
|
148
|
-
};`
|
150
|
+
export default _default;
|
151
|
+
export { dialogSvg, sceneSvg, spotSvg, dotSvg };`
|
149
152
|
};
|
150
153
|
|
151
154
|
await fs.mkdir(destPath, { recursive: true });
|
@@ -163,11 +166,15 @@ export {
|
|
163
166
|
}
|
164
167
|
});
|
165
168
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
+
return Promise.all(promises).then(() => {
|
170
|
+
const nestedPromises = [];
|
171
|
+
for (let illustrationName of fileNames) {
|
172
|
+
nestedPromises.push(fs.writeFile(path.join(destPath, `${illustrationName}.js`), illustrationImportTemplate(illustrationName)));
|
173
|
+
nestedPromises.push(fs.writeFile(path.join(destPath, `${illustrationName}.d.ts`), illustrationTypeDefinition(illustrationName)));
|
174
|
+
}
|
169
175
|
|
170
|
-
|
176
|
+
return Promise.all(nestedPromises);
|
177
|
+
});
|
171
178
|
};
|
172
179
|
|
173
180
|
generate().then(() => {
|
@@ -58,21 +58,15 @@ const getLibraryName = packageName => {
|
|
58
58
|
return packageName.substr("webcomponents-".length);
|
59
59
|
};
|
60
60
|
|
61
|
-
const generateFiles = (componentName, tagName, library, packageName
|
61
|
+
const generateFiles = (componentName, tagName, library, packageName) => {
|
62
62
|
componentName = capitalizeFirstLetter(componentName);
|
63
63
|
const filePaths = {
|
64
|
-
"main":
|
65
|
-
? `./src/${componentName}.ts`
|
66
|
-
: `./src/${componentName}.js`,
|
64
|
+
"main": `./src/${componentName}.ts`,
|
67
65
|
"css": `./src/themes/${componentName}.css`,
|
68
66
|
"template": `./src/${componentName}.hbs`,
|
69
67
|
};
|
70
68
|
|
71
|
-
|
72
|
-
? tsFileContentTemplate(componentName, tagName, library, packageName)
|
73
|
-
: jsFileContentTemplate(componentName, tagName, library, packageName);
|
74
|
-
|
75
|
-
fs.writeFileSync(filePaths.main, FileContentTemplate, { flag: "wx+" });
|
69
|
+
fs.writeFileSync(filePaths.main, tsFileContentTemplate(componentName, tagName, library, packageName), { flag: "wx+" });
|
76
70
|
fs.writeFileSync(filePaths.css, "", { flag: "wx+" });
|
77
71
|
fs.writeFileSync(filePaths.template, "<div>Hello World</div>", { flag: "wx+" });
|
78
72
|
|
@@ -112,10 +106,9 @@ const createWebComponent = async () => {
|
|
112
106
|
}
|
113
107
|
}
|
114
108
|
|
115
|
-
const isTypeScript = fs.existsSync(path.join(process.cwd(), "tsconfig.json"));
|
116
109
|
const tagName = hyphaneteComponentName(componentName);
|
117
110
|
|
118
|
-
generateFiles(componentName, tagName, library, packageName
|
111
|
+
generateFiles(componentName, tagName, library, packageName);
|
119
112
|
};
|
120
113
|
|
121
114
|
createWebComponent();
|
@@ -22,13 +22,10 @@ import ${componentName}Css from "./generated/themes/${componentName}.css.js";
|
|
22
22
|
* For the <code>${tagName}</code>
|
23
23
|
* <h3>ES6 Module Import</h3>
|
24
24
|
*
|
25
|
-
* <code>import ${packageName}/dist/${componentName}.js";</code>
|
25
|
+
* <code>import "${packageName}/dist/${componentName}.js";</code>
|
26
26
|
*
|
27
27
|
* @constructor
|
28
|
-
* @
|
29
|
-
* @alias sap.ui.webc.${library}.${componentName}
|
30
|
-
* @extends sap.ui.webc.base.UI5Element
|
31
|
-
* @tagname ${tagName}
|
28
|
+
* @extends UI5Element
|
32
29
|
* @public
|
33
30
|
*/
|
34
31
|
@customElement({
|
@@ -43,7 +40,6 @@ import ${componentName}Css from "./generated/themes/${componentName}.css.js";
|
|
43
40
|
* Example custom event.
|
44
41
|
* Please keep in mind that all public events should be documented in the API Reference as shown below.
|
45
42
|
*
|
46
|
-
* @event sap.ui.webc.${library}.${componentName}#interact
|
47
43
|
* @public
|
48
44
|
*/
|
49
45
|
@event("interact", { detail: { /* event payload ( optional ) */ } })
|
@@ -51,9 +47,7 @@ class ${componentName} extends UI5Element {
|
|
51
47
|
/**
|
52
48
|
* Defines the value of the component.
|
53
49
|
*
|
54
|
-
* @
|
55
|
-
* @name sap.ui.webc.${library}.${componentName}.prototype.value
|
56
|
-
* @defaultvalue ""
|
50
|
+
* @default ""
|
57
51
|
* @public
|
58
52
|
*/
|
59
53
|
@property()
|
@@ -62,9 +56,6 @@ class ${componentName} extends UI5Element {
|
|
62
56
|
/**
|
63
57
|
* Defines the text of the component.
|
64
58
|
*
|
65
|
-
* @type {Node[]}
|
66
|
-
* @name sap.ui.webc.${library}.${componentName}.prototype.default
|
67
|
-
* @slot
|
68
59
|
* @public
|
69
60
|
*/
|
70
61
|
@slot({ type: Node, "default": true })
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import { globby } from "globby";
|
2
|
+
import * as esbuild from 'esbuild'
|
3
|
+
import * as fs from "fs";
|
4
|
+
import * as path from "path";
|
5
|
+
import { writeFile, mkdir } from "fs/promises";
|
6
|
+
import scopeVariables from "./scope-variables.mjs";
|
7
|
+
|
8
|
+
const packageJSON = JSON.parse(fs.readFileSync("./package.json"))
|
9
|
+
const inputFiles = await globby("src/styles/*.module.css");
|
10
|
+
const restArgs = process.argv.slice(2);
|
11
|
+
|
12
|
+
let componentStylesPlugin = {
|
13
|
+
name: 'component-styles',
|
14
|
+
setup(build) {
|
15
|
+
build.initialOptions.write = false;
|
16
|
+
|
17
|
+
build.onEnd(result => {
|
18
|
+
result.outputFiles.forEach(async f => {
|
19
|
+
// scoping
|
20
|
+
const newText = scopeVariables(f.text, packageJSON);
|
21
|
+
await mkdir(path.dirname(f.path), {recursive: true});
|
22
|
+
writeFile(f.path, newText);
|
23
|
+
writeFile(f.path.replace(".module.css", ".css"), newText);
|
24
|
+
});
|
25
|
+
})
|
26
|
+
},
|
27
|
+
}
|
28
|
+
|
29
|
+
const config = {
|
30
|
+
entryPoints: inputFiles,
|
31
|
+
outdir: 'dist',
|
32
|
+
outbase: 'src',
|
33
|
+
loader: {
|
34
|
+
".module.css": "global-css"
|
35
|
+
},
|
36
|
+
plugins: [
|
37
|
+
componentStylesPlugin,
|
38
|
+
]
|
39
|
+
};
|
40
|
+
|
41
|
+
if (restArgs.includes("-w")) {
|
42
|
+
let ctx = await esbuild.context(config);
|
43
|
+
await ctx.watch()
|
44
|
+
console.log('watching...')
|
45
|
+
} else {
|
46
|
+
await esbuild.build(config);
|
47
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
const fs = require("fs");
|
2
|
+
|
3
|
+
/**
|
4
|
+
* UI5Elements loads the ssr-dom.js file with a package specifier to use the export conditions
|
5
|
+
* in the package.json so that a shim for the dom can be loaded from SSR environments
|
6
|
+
* This however makes the TS Checker plugin used for development try to load the file from dist as input
|
7
|
+
* This plugin loads an empty file and TS ignores the file completely
|
8
|
+
*/
|
9
|
+
|
10
|
+
const ssrDomShimLoader = async () => {
|
11
|
+
return {
|
12
|
+
name: 'ssr-dom-shim-loader',
|
13
|
+
resolveId(id) {
|
14
|
+
if (id === "@ui5/webcomponents-base/dist/ssr-dom.js") {
|
15
|
+
return "\0shim"
|
16
|
+
}
|
17
|
+
},
|
18
|
+
load(id) {
|
19
|
+
if (id === "\0shim") {
|
20
|
+
return "";
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
24
|
+
};
|
25
|
+
|
26
|
+
module.exports = ssrDomShimLoader;
|
@@ -21,12 +21,12 @@ const generateAvailableIllustrationsArray = (fileNames, exclusionPatterns = [])
|
|
21
21
|
);
|
22
22
|
};
|
23
23
|
|
24
|
-
const generateDynamicImportsFileContent = (dynamicImports, availableIllustrations, collection, prefix = "") => {
|
24
|
+
const generateDynamicImportsFileContent = (dynamicImports, availableIllustrations, collection, set, prefix = "") => {
|
25
25
|
return `// @ts-nocheck
|
26
26
|
import { registerIllustrationLoader } from "@ui5/webcomponents-base/dist/asset-registries/Illustrations.js";
|
27
27
|
|
28
28
|
export const loadIllustration = async (illustrationName) => {
|
29
|
-
const collectionAndPrefix = "${collection}/${prefix}";
|
29
|
+
const collectionAndPrefix = "${set}/${collection}/${prefix}";
|
30
30
|
const cleanIllustrationName = illustrationName.startsWith(collectionAndPrefix) ? illustrationName.replace(collectionAndPrefix, "") : illustrationName;
|
31
31
|
switch (cleanIllustrationName) {
|
32
32
|
${dynamicImports}
|
@@ -41,7 +41,7 @@ const loadAndCheck = async (illustrationName) => {
|
|
41
41
|
};
|
42
42
|
|
43
43
|
${availableIllustrations}.forEach((illustrationName) =>
|
44
|
-
registerIllustrationLoader(\`${collection}/${prefix}\${illustrationName}\`, loadAndCheck)
|
44
|
+
registerIllustrationLoader(\`${set}/${collection}/${prefix}\${illustrationName}\`, loadAndCheck)
|
45
45
|
);
|
46
46
|
`;
|
47
47
|
};
|
@@ -52,7 +52,7 @@ const getMatchingFiles = async (folder, pattern) => {
|
|
52
52
|
};
|
53
53
|
|
54
54
|
const generateIllustrations = async (config) => {
|
55
|
-
const { inputFolder, outputFile, collection, location, prefix, filterOut } = config;
|
55
|
+
const { inputFolder, outputFile, collection, location, prefix, filterOut, set } = config;
|
56
56
|
|
57
57
|
const normalizedInputFolder = path.normalize(inputFolder);
|
58
58
|
const normalizedOutputFile = path.normalize(outputFile);
|
@@ -62,7 +62,7 @@ const generateIllustrations = async (config) => {
|
|
62
62
|
const dynamicImports = await generateDynamicImportLines(illustrations, location, filterOut);
|
63
63
|
const availableIllustrations = generateAvailableIllustrationsArray(illustrations, filterOut);
|
64
64
|
|
65
|
-
const contentDynamic = generateDynamicImportsFileContent(dynamicImports, availableIllustrations, collection, prefix);
|
65
|
+
const contentDynamic = generateDynamicImportsFileContent(dynamicImports, availableIllustrations, collection, set, prefix);
|
66
66
|
|
67
67
|
await fs.mkdir(path.dirname(normalizedOutputFile), { recursive: true });
|
68
68
|
await fs.writeFile(normalizedOutputFile, contentDynamic);
|
@@ -74,10 +74,10 @@ const generateIllustrations = async (config) => {
|
|
74
74
|
const config = {
|
75
75
|
inputFolder: process.argv[2],
|
76
76
|
outputFile: process.argv[3],
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
filterOut: process.argv.slice
|
77
|
+
set: process.argv[4],
|
78
|
+
collection: process.argv[5],
|
79
|
+
location: process.argv[6],
|
80
|
+
filterOut: process.argv.slice[7],
|
81
81
|
};
|
82
82
|
|
83
83
|
// Run the generation process
|