@ui5/webcomponents-tools 0.0.0-c6d8872f3 → 0.0.0-cf069fb29
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 +164 -1
- package/README.md +1 -1
- package/assets-meta.js +149 -0
- package/bin/dev.js +16 -1
- package/components-package/nps.js +73 -34
- package/components-package/postcss.themes.js +5 -2
- package/components-package/rollup-plugins/empty-module.js +15 -0
- package/components-package/rollup.js +155 -50
- package/components-package/wdio.js +100 -64
- package/components-package/wdio.sync.js +360 -0
- package/icons-collection/nps.js +72 -28
- package/lib/copy-and-watch/index.js +122 -0
- package/lib/copy-list/index.js +28 -0
- package/lib/create-icons/index.js +41 -23
- package/lib/create-illustrations/index.js +150 -0
- package/lib/create-new-component/index.js +18 -6
- package/lib/documentation/index.js +43 -21
- package/lib/documentation/templates/template.js +1 -1
- package/lib/esm-abs-to-rel/index.js +54 -0
- package/lib/generate-json-imports/i18n.js +91 -47
- package/lib/generate-json-imports/themes.js +61 -15
- package/lib/hash/config.js +10 -0
- package/lib/hash/generate.js +19 -0
- package/lib/hash/upToDate.js +31 -0
- package/lib/hbs2lit/index.js +2 -4
- package/lib/hbs2lit/src/compiler.js +8 -7
- package/lib/hbs2lit/src/includesReplacer.js +22 -16
- package/lib/hbs2lit/src/litVisitor2.js +44 -8
- package/lib/hbs2lit/src/svgProcessor.js +3 -3
- package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +5 -5
- package/lib/hbs2ui5/index.js +26 -20
- package/lib/i18n/defaults.js +25 -6
- package/lib/i18n/toJSON.js +15 -4
- package/lib/jsdoc/config.json +1 -1
- package/lib/jsdoc/plugin.js +24 -4
- package/lib/jsdoc/template/publish.js +11 -2
- package/lib/polyfill-placeholder/index.js +5 -0
- package/lib/postcss-css-to-esm/index.js +31 -19
- package/lib/postcss-css-to-json/index.js +27 -11
- package/lib/postcss-new-files/index.js +36 -0
- package/lib/replace-global-core/index.js +20 -0
- package/lib/scoping/get-all-tags.js +44 -0
- package/lib/scoping/lint-src.js +31 -0
- package/lib/scoping/scope-test-pages.js +40 -0
- package/lib/serve/index.js +46 -0
- package/{components-package → lib/serve}/serve.json +0 -0
- package/package-lock.json +48 -0
- package/package.json +55 -55
- package/bin/init-ui5-package.js +0 -3
- package/lib/init-package/index.js +0 -119
- 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 -6
- package/lib/init-package/resources/src/Demo.hbs +0 -1
- package/lib/init-package/resources/src/Demo.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/Demo.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/test/pages/index.html +0 -51
- package/lib/init-package/resources/test/specs/Demo.spec.js +0 -12
@@ -0,0 +1,19 @@
|
|
1
|
+
const fs = require("fs");
|
2
|
+
const path = require("path");
|
3
|
+
const process = require("process");
|
4
|
+
const { hashElement } = require("folder-hash");
|
5
|
+
const config = require("./config.js");
|
6
|
+
|
7
|
+
const inputDir = path.normalize(process.argv[2]);
|
8
|
+
const outputFileName = path.normalize(process.argv[3]);
|
9
|
+
|
10
|
+
const generateHash = async (inputDir, outputFileName) => {
|
11
|
+
const result = await hashElement(inputDir, config);
|
12
|
+
const hash = result.hash;
|
13
|
+
fs.writeFileSync(outputFileName, hash);
|
14
|
+
return hash;
|
15
|
+
};
|
16
|
+
|
17
|
+
generateHash(inputDir, outputFileName).then(hash => {
|
18
|
+
console.log(`Generated hash: ${hash}`);
|
19
|
+
});
|
@@ -0,0 +1,31 @@
|
|
1
|
+
const fs = require("fs");
|
2
|
+
const path = require("path");
|
3
|
+
const process = require("process");
|
4
|
+
const { hashElement } = require("folder-hash");
|
5
|
+
const config = require("./config.js");
|
6
|
+
|
7
|
+
const inputDir = path.normalize(process.argv[2]);
|
8
|
+
const hashFileName = path.normalize(process.argv[3]);
|
9
|
+
|
10
|
+
const isUpToDate = async (inputDir, hashFileName) => {
|
11
|
+
// No dist/ directory or no hash file
|
12
|
+
if (!fs.existsSync(inputDir) || !fs.existsSync(hashFileName)) {
|
13
|
+
return false;
|
14
|
+
}
|
15
|
+
|
16
|
+
// Empty hash file
|
17
|
+
const existingHash = `${fs.readFileSync(hashFileName)}`;
|
18
|
+
if (!existingHash) {
|
19
|
+
return false;
|
20
|
+
}
|
21
|
+
|
22
|
+
// Calculate the hash of the dist/ directory
|
23
|
+
const result = await hashElement(inputDir, config);
|
24
|
+
const newHash = result.hash;
|
25
|
+
|
26
|
+
return newHash === existingHash;
|
27
|
+
};
|
28
|
+
|
29
|
+
isUpToDate(inputDir, hashFileName).then(upToDate => {
|
30
|
+
process.exit(upToDate ? 0 : 1); // 0 means success (it is up to date), 1 means failure (must rebuild the dist/)
|
31
|
+
});
|
package/lib/hbs2lit/index.js
CHANGED
@@ -5,13 +5,16 @@ const includesReplacer = require("./includesReplacer");
|
|
5
5
|
const svgProcessor = require("./svgProcessor");
|
6
6
|
|
7
7
|
const removeWhiteSpaces = (source) => {
|
8
|
-
return source
|
8
|
+
return source
|
9
|
+
.replace(/\s*\r*\n+\s*/g, " ") // Replace new lines and all whitespace between them with a space
|
10
|
+
.replace(/\s*<\s*/g, "<") // Strip whitespace round <
|
11
|
+
.replace(/\s*>\s*/g, ">") // Strip whitespace round >
|
12
|
+
.replace(/}}\s+{{/g, "}}{{"); // Remove whitespace between }} and {{
|
9
13
|
};
|
10
14
|
|
11
|
-
const
|
12
|
-
let sPreprocessed =
|
15
|
+
const hbs2lit = (file) => {
|
16
|
+
let sPreprocessed = includesReplacer.replace(file);
|
13
17
|
|
14
|
-
sPreprocessed = await includesReplacer.replace(sPreprocessed, config);
|
15
18
|
sPreprocessed = removeWhiteSpaces(sPreprocessed);
|
16
19
|
|
17
20
|
const ast = Handlebars.parse(sPreprocessed);
|
@@ -34,6 +37,4 @@ const compileString = async (sInput, config) => {
|
|
34
37
|
return result;
|
35
38
|
};
|
36
39
|
|
37
|
-
module.exports =
|
38
|
-
compileString
|
39
|
-
};
|
40
|
+
module.exports = hbs2lit;
|
@@ -1,25 +1,31 @@
|
|
1
1
|
const path = require("path");
|
2
|
-
const
|
3
|
-
const nativeFs = require("fs");
|
2
|
+
const fs = require("fs");
|
4
3
|
|
5
|
-
function replaceIncludes(
|
6
|
-
const
|
7
|
-
|
8
|
-
const inclRegex = /{{>\s*include\s*["']([a-zA-Z.\/]+)["']}}/g;
|
9
|
-
|
10
|
-
async function replacer(match, p1) {
|
11
|
-
const includeContent = await readFile(path.join(config.templatesPath, p1), "utf-8");
|
12
|
-
hbs = hbs.replace(match, includeContent);
|
13
|
-
}
|
4
|
+
function replaceIncludes(file) {
|
5
|
+
const filePath = path.dirname(file);
|
6
|
+
let fileContent = fs.readFileSync(file, "utf-8");
|
14
7
|
|
8
|
+
const inclRegex = /{{>\s*include\s*["'](.+?)["']}}/g;
|
15
9
|
let match;
|
16
|
-
|
17
|
-
while
|
18
|
-
|
10
|
+
|
11
|
+
while((match = inclRegex.exec(fileContent)) !== null) {
|
12
|
+
inclRegex.lastIndex = 0;
|
13
|
+
|
14
|
+
let targetFile = match[1];
|
15
|
+
if (targetFile.startsWith(".")) {
|
16
|
+
// Relative path, f.e. {{>include "./Popup.hbs"}} or {{>include "../partials/Header.hbs"}}
|
17
|
+
targetFile = path.join(filePath, targetFile);
|
18
|
+
} else {
|
19
|
+
// Node module path, f.e. {{>include "@ui5/webcomponents/src/Popup.hbs"}}
|
20
|
+
targetFile = require.resolve(targetFile);
|
21
|
+
}
|
22
|
+
|
23
|
+
fileContent = fileContent.replace(match[0], replaceIncludes(targetFile));
|
19
24
|
}
|
20
|
-
|
25
|
+
|
26
|
+
return fileContent;
|
21
27
|
}
|
22
28
|
|
23
29
|
module.exports = {
|
24
30
|
replace: replaceIncludes
|
25
|
-
};
|
31
|
+
};
|
@@ -5,9 +5,29 @@ const Visitor = Handlebars.Visitor;
|
|
5
5
|
// skip ifDefined for event handlers and boolean attrs
|
6
6
|
let skipIfDefined = false;
|
7
7
|
|
8
|
+
// when true => an HTML node value, when false => an attribute value
|
9
|
+
let isNodeValue = false;
|
10
|
+
|
11
|
+
// when true => the current attribute is "style"
|
12
|
+
let isStyleAttribute = false;
|
13
|
+
|
8
14
|
// matches event handlers @click= and boolean attrs ?disabled=
|
9
15
|
const dynamicAttributeRgx = /\s(\?|@)([a-zA-Z|-]+)="?\s*$/;
|
10
16
|
|
17
|
+
if (!String.prototype.replaceAll) {
|
18
|
+
String.prototype.replaceAll = function(str, newStr){
|
19
|
+
|
20
|
+
// If a regex pattern
|
21
|
+
if (Object.prototype.toString.call(str).toLowerCase() === '[object regexp]') {
|
22
|
+
return this.replace(str, newStr);
|
23
|
+
}
|
24
|
+
|
25
|
+
// If a string
|
26
|
+
return this.replace(new RegExp(str, 'g'), newStr);
|
27
|
+
|
28
|
+
};
|
29
|
+
}
|
30
|
+
|
11
31
|
function HTMLLitVisitor(debug) {
|
12
32
|
this.blockCounter = 0;
|
13
33
|
this.keys = [];
|
@@ -15,7 +35,7 @@ function HTMLLitVisitor(debug) {
|
|
15
35
|
this.result = "";
|
16
36
|
this.mainBlock = "";
|
17
37
|
this.blockPath = "context";
|
18
|
-
this.blockParameters = ["context"];
|
38
|
+
this.blockParameters = ["context", "tags", "suffix"];
|
19
39
|
this.paths = []; //contains all normalized relative paths
|
20
40
|
this.debug = debug;
|
21
41
|
if (this.debug) {
|
@@ -31,7 +51,7 @@ HTMLLitVisitor.prototype.Program = function(program) {
|
|
31
51
|
this.keys.push(key);
|
32
52
|
this.debug && this.blockByNumber.push(key);
|
33
53
|
|
34
|
-
this.blocks[this.currentKey()] = "const " + this.currentKey() + " = (" + this.blockParameters.join(", ") + ") =>
|
54
|
+
this.blocks[this.currentKey()] = "const " + this.currentKey() + " = (" + this.blockParameters.join(", ") + ") => ";
|
35
55
|
|
36
56
|
if (this.keys.length > 1) { //it's a nested block
|
37
57
|
this.blocks[this.prevKey()] += this.currentKey() + "(" + this.blockParameters.join(", ") + ")";
|
@@ -42,7 +62,7 @@ HTMLLitVisitor.prototype.Program = function(program) {
|
|
42
62
|
|
43
63
|
this.blocks[this.currentKey()] += "html`";
|
44
64
|
Visitor.prototype.Program.call(this, program);
|
45
|
-
this.blocks[this.currentKey()] += "`;
|
65
|
+
this.blocks[this.currentKey()] += "`;";
|
46
66
|
|
47
67
|
this.keys.pop(key);
|
48
68
|
};
|
@@ -51,9 +71,24 @@ HTMLLitVisitor.prototype.ContentStatement = function(content) {
|
|
51
71
|
Visitor.prototype.ContentStatement.call(this, content);
|
52
72
|
// let content = content.orgiinal; // attribute="__ attribute = "__ attribute ="__
|
53
73
|
|
54
|
-
|
74
|
+
let contentStatement = content.original;
|
55
75
|
skipIfDefined = !!dynamicAttributeRgx.exec(contentStatement);
|
56
76
|
|
77
|
+
const closingIndex = contentStatement.lastIndexOf(">");
|
78
|
+
const openingIndex = contentStatement.lastIndexOf("<");
|
79
|
+
if (closingIndex !== -1 || openingIndex !== -1) { // Only change isNodeValue whenever < or > is found in the content statement
|
80
|
+
isNodeValue = closingIndex > openingIndex;
|
81
|
+
}
|
82
|
+
|
83
|
+
isStyleAttribute = !isNodeValue && contentStatement.match(/style *= *["']? *$/);
|
84
|
+
|
85
|
+
if (!isStyleAttribute && contentStatement.match(/style=/)) {
|
86
|
+
console.log("WARNING: style hard-coded", contentStatement);
|
87
|
+
}
|
88
|
+
|
89
|
+
// Scope custom element tags
|
90
|
+
contentStatement = contentStatement.replaceAll(/(<\/?\s*)([a-zA-Z0-9_]+-[a-zA-Z0-9_-]+)/g, "$1\${scopeTag(\"$2\", tags, suffix)}");
|
91
|
+
|
57
92
|
this.blocks[this.currentKey()] += contentStatement;
|
58
93
|
};
|
59
94
|
|
@@ -65,13 +100,14 @@ HTMLLitVisitor.prototype.MustacheStatement = function(mustache) {
|
|
65
100
|
} else {
|
66
101
|
const path = normalizePath.call(this, mustache.path.original);
|
67
102
|
const hasCalculatingClasses = path.includes("context.classes");
|
68
|
-
const hasStylesCalculation = path.includes("context.styles");
|
69
103
|
|
70
104
|
let parsedCode = "";
|
71
105
|
|
72
|
-
if (
|
106
|
+
if (isNodeValue && !mustache.escaped) {
|
107
|
+
parsedCode = `\${unsafeHTML(${path})}`;
|
108
|
+
} else if (hasCalculatingClasses) {
|
73
109
|
parsedCode = `\${classMap(${path})}`;
|
74
|
-
} else if (
|
110
|
+
} else if (isStyleAttribute) {
|
75
111
|
parsedCode = `\${styleMap(${path})}`;
|
76
112
|
} else if (skipIfDefined){
|
77
113
|
parsedCode = `\${${path}}`;
|
@@ -135,7 +171,7 @@ function visitEachBlock(block) {
|
|
135
171
|
var bParamAdded = false;
|
136
172
|
visitSubExpression.call(this, block);
|
137
173
|
|
138
|
-
this.blocks[this.currentKey()] += "${ repeat(" + normalizePath.call(this, block.params[0].original) + ",
|
174
|
+
this.blocks[this.currentKey()] += "${ repeat(" + normalizePath.call(this, block.params[0].original) + ", (item, index) => item._id || index, (item, index) => ";
|
139
175
|
this.paths.push(normalizePath.call(this, block.params[0].original));
|
140
176
|
this.blockPath = "item";
|
141
177
|
|
@@ -46,8 +46,8 @@ function getSVGMatches(template) {
|
|
46
46
|
|
47
47
|
function getSVGBlock(input, blockCounter) {
|
48
48
|
return {
|
49
|
-
usage: `\${blockSVG${blockCounter}(context)}`,
|
50
|
-
definition: `\nconst blockSVG${blockCounter} = (context) =>
|
49
|
+
usage: `\${blockSVG${blockCounter}(context, tags, suffix)}`,
|
50
|
+
definition: `\nconst blockSVG${blockCounter} = (context, tags, suffix) => svg\`${input}\`;`,
|
51
51
|
};
|
52
52
|
}
|
53
53
|
|
@@ -55,7 +55,7 @@ function replaceInternalBlocks(template, svgContent) {
|
|
55
55
|
const internalBlocks = svgContent.match(blockrx) || [];
|
56
56
|
|
57
57
|
internalBlocks.forEach(blockName => {
|
58
|
-
const rx = new RegExp(`const ${blockName}.*(html\`)
|
58
|
+
const rx = new RegExp(`const ${blockName}.*(html\`).*;`);
|
59
59
|
template = template.replace(rx, (match, p1) => {
|
60
60
|
return match.replace(p1, "svg\`");
|
61
61
|
});
|
@@ -1,10 +1,10 @@
|
|
1
1
|
const buildRenderer = (controlName, litTemplate) => {
|
2
|
-
return
|
3
|
-
|
4
|
-
|
5
|
-
import { html, svg, repeat, classMap, styleMap } from '@ui5/webcomponents-base/dist/renderer/LitRenderer.js';
|
2
|
+
return `/* eslint no-unused-vars: 0 */
|
3
|
+
import { html, svg, repeat, classMap, styleMap, ifDefined, unsafeHTML, scopeTag } from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
|
4
|
+
|
6
5
|
${litTemplate}
|
7
|
-
|
6
|
+
|
7
|
+
export default block0;`;
|
8
8
|
};
|
9
9
|
|
10
10
|
module.exports = {
|
package/lib/hbs2ui5/index.js
CHANGED
@@ -3,6 +3,8 @@ const getopts = require('getopts');
|
|
3
3
|
const hbs2lit = require('../hbs2lit');
|
4
4
|
const path = require('path');
|
5
5
|
const litRenderer = require('./RenderTemplates/LitRenderer');
|
6
|
+
const recursiveReadDir = require("recursive-readdir");
|
7
|
+
const mkdirp = require('mkdirp');
|
6
8
|
|
7
9
|
const args = getopts(process.argv.slice(2), {
|
8
10
|
alias: {
|
@@ -18,32 +20,34 @@ const args = getopts(process.argv.slice(2), {
|
|
18
20
|
|
19
21
|
const onError = (place) => {
|
20
22
|
console.log(`A problem occoured when reading ${place}. Please recheck passed parameters.`);
|
21
|
-
}
|
23
|
+
};
|
24
|
+
|
22
25
|
const isHandlebars = (fileName) => fileName.indexOf('.hbs') !== -1;
|
23
|
-
const parseFile = (filePath, inputDir, outputDir) => {
|
24
|
-
fs.readFile(filePath, 'utf-8', (err, content) => {
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
const processFile = (file, outputDir) => {
|
28
|
+
const litCode = hbs2lit(file);
|
29
|
+
const absoluteOutputDir = composeAbsoluteOutputDir(file, outputDir);
|
30
|
+
const componentNameMatcher = /(\w+)(\.hbs)/gim;
|
31
|
+
const componentName = componentNameMatcher.exec(file)[1];
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
compiledTemplatesPath: outputDir
|
33
|
-
}).then((litCode) => {
|
34
|
-
const componentNameMatcher = /(\w+)(\.hbs)/gim;
|
35
|
-
const componentName = componentNameMatcher.exec(filePath)[1];
|
33
|
+
writeRenderers(absoluteOutputDir, componentName, litRenderer.generateTemplate(componentName, litCode));
|
34
|
+
};
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
const composeAbsoluteOutputDir = (file, outputDir) => {
|
37
|
+
// (1) Extract the dir structure from the source file path - "src/lvl1/lvl2/MyCompBadge.hbs"
|
38
|
+
// - remove the filename - "src/lvl1/lvl2"
|
39
|
+
// - remove the leading dir - "lvl1/lvl2"
|
40
|
+
const fileDir = file.split(path.sep).slice(1, -1).join(path.sep);
|
41
|
+
|
42
|
+
// (2) Compose full output dir - "dist/generated/templates/lvl1/lvl2"
|
43
|
+
return `${outputDir}${path.sep}${fileDir}`;
|
44
|
+
};
|
41
45
|
|
42
46
|
const wrapDirectory = (directory, outputDir) => {
|
43
47
|
directory = path.normalize(directory);
|
44
48
|
outputDir = path.normalize(outputDir);
|
45
49
|
|
46
|
-
|
50
|
+
recursiveReadDir(directory, (err, files) => {
|
47
51
|
|
48
52
|
if (err) {
|
49
53
|
onError('directory');
|
@@ -51,9 +55,7 @@ const wrapDirectory = (directory, outputDir) => {
|
|
51
55
|
|
52
56
|
files.forEach(fileName => {
|
53
57
|
if (isHandlebars(fileName)) {
|
54
|
-
|
55
|
-
// could be refactored a bit
|
56
|
-
parseFile(directory + fileName, directory, outputDir);
|
58
|
+
processFile(fileName, outputDir);
|
57
59
|
}
|
58
60
|
});
|
59
61
|
})
|
@@ -61,6 +63,10 @@ const wrapDirectory = (directory, outputDir) => {
|
|
61
63
|
|
62
64
|
const writeRenderers = (outputDir, controlName, fileContent) => {
|
63
65
|
try {
|
66
|
+
if (!fs.existsSync(outputDir)) {
|
67
|
+
mkdirp.sync(outputDir);
|
68
|
+
}
|
69
|
+
|
64
70
|
const compiledFilePath = `${outputDir}${path.sep}${controlName}Template.lit.js`;
|
65
71
|
|
66
72
|
// strip DOS line endings because the break the source maps
|
package/lib/i18n/defaults.js
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
const fs = require('fs');
|
2
2
|
const path = require('path');
|
3
3
|
const PropertiesReader = require('properties-reader');
|
4
|
+
const mkdirp = require("mkdirp");
|
5
|
+
const assets = require('../../assets-meta.js');
|
6
|
+
|
7
|
+
const defaultLanguage = assets.languages.default;
|
8
|
+
|
4
9
|
const messageBundle = path.normalize(`${process.argv[2]}/messagebundle.properties`);
|
10
|
+
const messageBundleDefaultLanguage = path.normalize(`${process.argv[2]}/messagebundle_${defaultLanguage}.properties`);
|
5
11
|
const outputFile = path.normalize(`${process.argv[3]}/i18n-defaults.js`);
|
6
12
|
|
7
13
|
if (!messageBundle || !outputFile) {
|
@@ -10,6 +16,13 @@ if (!messageBundle || !outputFile) {
|
|
10
16
|
|
11
17
|
const properties = PropertiesReader(messageBundle)._properties;
|
12
18
|
|
19
|
+
let defaultLanguageProperties;
|
20
|
+
try {
|
21
|
+
defaultLanguageProperties = PropertiesReader(messageBundleDefaultLanguage)._properties;
|
22
|
+
}
|
23
|
+
catch (e) {}
|
24
|
+
|
25
|
+
|
13
26
|
/*
|
14
27
|
* Returns the single text object to enable single export.
|
15
28
|
*
|
@@ -19,7 +32,12 @@ const properties = PropertiesReader(messageBundle)._properties;
|
|
19
32
|
* defaultText: "Card Content",
|
20
33
|
* };
|
21
34
|
*/
|
22
|
-
const getTextInfo = (key, value) =>
|
35
|
+
const getTextInfo = (key, value, defaultLanguageValue) => {
|
36
|
+
let effectiveValue = defaultLanguageValue || value;
|
37
|
+
effectiveValue = effectiveValue.replace(/\"/g, "\\\""); // escape double quotes in translations
|
38
|
+
|
39
|
+
return `const ${key} = {key: "${key}", defaultText: "${effectiveValue}"};`;
|
40
|
+
};
|
23
41
|
|
24
42
|
/*
|
25
43
|
* Returns the complete content of i18n-defaults.js file:
|
@@ -31,13 +49,13 @@ const getTextInfo = (key, value) => `const ${key} = {key: "${key}", defaultText:
|
|
31
49
|
* ARIA_LABEL_CARD_CONTENT,
|
32
50
|
* }
|
33
51
|
*/
|
34
|
-
const getOutputFileContent = (properties) => {
|
52
|
+
const getOutputFileContent = (properties, defaultLanguageProperties) => {
|
35
53
|
const textKeys = Object.keys(properties);
|
36
|
-
const texts = textKeys.map(prop => getTextInfo(prop, properties[prop])).join('');
|
54
|
+
const texts = textKeys.map(prop => getTextInfo(prop, properties[prop], defaultLanguageProperties && defaultLanguageProperties[prop])).join('');
|
37
55
|
|
38
56
|
return `${texts}
|
39
57
|
export {${textKeys.join()}};`;
|
40
|
-
}
|
58
|
+
};
|
41
59
|
|
42
60
|
/*
|
43
61
|
* Writes the i18n-defaults.js.
|
@@ -50,6 +68,7 @@ const writeI18nDefaultsFile = (file, content) => {
|
|
50
68
|
|
51
69
|
console.log(`[i18n]: "${file}" file has been created`);
|
52
70
|
});
|
53
|
-
}
|
71
|
+
};
|
54
72
|
|
55
|
-
|
73
|
+
mkdirp.sync(path.dirname(outputFile));
|
74
|
+
writeI18nDefaultsFile(outputFile, getOutputFileContent(properties, defaultLanguageProperties));
|
package/lib/i18n/toJSON.js
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
*
|
4
4
|
* Execution (note: the paths depends on the the execution context)
|
5
5
|
* node toJSON.js ../../src/assets/i18n ../../dist/generated/assets/i18n
|
6
|
-
*
|
6
|
+
*
|
7
7
|
* The 1st param '../../src/assets/i18n' is the location of messagebundle_*.properties files
|
8
8
|
* The 2nd param './../dist/generated/assets/i18n' is where the JSON files would be written to.
|
9
9
|
*/
|
@@ -11,21 +11,32 @@ const path = require("path");
|
|
11
11
|
const glob = require("glob");
|
12
12
|
const PropertiesReader = require('properties-reader');
|
13
13
|
const fs = require('fs');
|
14
|
+
const assets = require('../../assets-meta.js');
|
15
|
+
const mkdirp = require("mkdirp");
|
16
|
+
|
17
|
+
const allLanguages = assets.languages.all;
|
18
|
+
|
14
19
|
const messagesBundles = path.normalize(`${process.argv[2]}/messagebundle_*.properties`);
|
15
20
|
const messagesJSONDist = path.normalize(`${process.argv[3]}`);
|
16
21
|
|
17
22
|
const convertToJSON = (file) => {
|
18
23
|
const properties = PropertiesReader(file)._properties;
|
19
24
|
const filename = path.basename(file, path.extname(file));
|
25
|
+
const language = filename.match(/^messagebundle_(.*?)$/)[1];
|
26
|
+
if (!allLanguages.includes(language)) {
|
27
|
+
console.log("Not supported language: ", language);
|
28
|
+
return;
|
29
|
+
}
|
20
30
|
const outputFile = path.normalize(`${messagesJSONDist}/${filename}.json`);
|
21
31
|
|
22
32
|
fs.writeFileSync(outputFile, JSON.stringify(properties));
|
23
|
-
console.log(`[i18n]: "${filename}.json" has been generated!`);
|
24
|
-
}
|
33
|
+
// console.log(`[i18n]: "${filename}.json" has been generated!`);
|
34
|
+
};
|
25
35
|
|
36
|
+
mkdirp.sync(messagesJSONDist);
|
26
37
|
glob(messagesBundles, {}, (err, files) => {
|
27
38
|
if (err) {
|
28
39
|
return console.log("No messagebundle files found!");
|
29
40
|
}
|
30
41
|
files.forEach(convertToJSON);
|
31
|
-
});
|
42
|
+
});
|
package/lib/jsdoc/config.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"source": {
|
3
3
|
"include": "src",
|
4
|
-
"excludePattern": "(/|\\\\)library-all\\.js|(/|\\\\).*-preload\\.js|^jquery-.*\\.js|^sap-.*\\.js|.+Renderer\\.lit\\.js|.*library\\.js"
|
4
|
+
"excludePattern": "(/|\\\\)library-all\\.js|(/|\\\\).*-preload\\.js|^jquery-.*\\.js|^sap-.*\\.js|.+Renderer\\.lit\\.js|.*library\\.js|thirdparty"
|
5
5
|
},
|
6
6
|
"opts" : {
|
7
7
|
"recurse": true,
|
package/lib/jsdoc/plugin.js
CHANGED
@@ -29,7 +29,11 @@
|
|
29
29
|
*
|
30
30
|
* appenddocs
|
31
31
|
*
|
32
|
-
*
|
32
|
+
* tagname
|
33
|
+
*
|
34
|
+
* native
|
35
|
+
*
|
36
|
+
* allowPreventDefault
|
33
37
|
*
|
34
38
|
* It furthermore listens to the following JSDoc3 events to implement additional functionality
|
35
39
|
*
|
@@ -2060,9 +2064,11 @@ exports.defineTags = function(dictionary) {
|
|
2060
2064
|
});
|
2061
2065
|
|
2062
2066
|
dictionary.defineTag('slot', {
|
2063
|
-
mustNotHaveValue: true,
|
2064
2067
|
onTagged: function(doclet, tag) {
|
2065
2068
|
doclet.slot = true;
|
2069
|
+
if (tag.value) {
|
2070
|
+
doclet.propertyName = tag.value;
|
2071
|
+
}
|
2066
2072
|
}
|
2067
2073
|
});
|
2068
2074
|
|
@@ -2073,10 +2079,24 @@ exports.defineTags = function(dictionary) {
|
|
2073
2079
|
}
|
2074
2080
|
});
|
2075
2081
|
|
2076
|
-
dictionary.defineTag('
|
2082
|
+
dictionary.defineTag('tagname', {
|
2077
2083
|
mustHaveValue: true,
|
2078
2084
|
onTagged: function(doclet, tag) {
|
2079
|
-
doclet.
|
2085
|
+
doclet.tagname = tag.value;
|
2086
|
+
}
|
2087
|
+
});
|
2088
|
+
|
2089
|
+
dictionary.defineTag('allowPreventDefault', {
|
2090
|
+
mustHaveValue: false,
|
2091
|
+
onTagged: function(doclet, tag) {
|
2092
|
+
doclet.allowPreventDefault = true;
|
2093
|
+
}
|
2094
|
+
});
|
2095
|
+
|
2096
|
+
dictionary.defineTag('native', {
|
2097
|
+
mustHaveValue: false,
|
2098
|
+
onTagged: function(doclet, tag) {
|
2099
|
+
doclet.native = true;
|
2080
2100
|
}
|
2081
2101
|
});
|
2082
2102
|
};
|
@@ -2651,8 +2651,8 @@ function createAPIJSON4Symbol(symbol, omitDefaults) {
|
|
2651
2651
|
|
2652
2652
|
attrib("name", symbol.longname);
|
2653
2653
|
attrib("basename", symbol.name);
|
2654
|
-
if (symbol.
|
2655
|
-
attrib("
|
2654
|
+
if (symbol.tagname) {
|
2655
|
+
attrib("tagname", symbol.tagname);
|
2656
2656
|
}
|
2657
2657
|
if (symbol.appenddocs) {
|
2658
2658
|
attrib("appenddocs", symbol.appenddocs);
|
@@ -2838,6 +2838,9 @@ function createAPIJSON4Symbol(symbol, omitDefaults) {
|
|
2838
2838
|
if (member.slot) {
|
2839
2839
|
tag("property");
|
2840
2840
|
attrib("name", member.name);
|
2841
|
+
if (member.propertyName) {
|
2842
|
+
attrib("propertyName", member.propertyName);
|
2843
|
+
}
|
2841
2844
|
if (member.__ui5.module && member.__ui5.module !== symbol.__ui5.module) {
|
2842
2845
|
attrib("module", member.__ui5.module);
|
2843
2846
|
attrib("export", undefined, '', true);
|
@@ -2879,6 +2882,12 @@ function createAPIJSON4Symbol(symbol, omitDefaults) {
|
|
2879
2882
|
attrib("module", member.__ui5.module);
|
2880
2883
|
attrib("export", undefined, '', true);
|
2881
2884
|
}
|
2885
|
+
if (member.allowPreventDefault) {
|
2886
|
+
attrib("allowPreventDefault", true);
|
2887
|
+
}
|
2888
|
+
if (member.native) {
|
2889
|
+
attrib("native", true);
|
2890
|
+
}
|
2882
2891
|
attrib("visibility", visibility(member), 'public');
|
2883
2892
|
if ( member.scope === 'static' ) {
|
2884
2893
|
attrib("static", true, false, /* raw = */true);
|
@@ -1,33 +1,45 @@
|
|
1
|
-
const postcss = require('postcss');
|
2
1
|
const fs = require('fs');
|
3
2
|
const path = require('path');
|
4
3
|
const mkdirp = require('mkdirp');
|
4
|
+
const assets = require("../../assets-meta.js");
|
5
5
|
|
6
|
-
const
|
7
|
-
return `import "@ui5/webcomponents-theme-base/dist/DefaultTheme.js";
|
8
|
-
|
9
|
-
import { registerThemeProperties } from "@ui5/webcomponents-base/dist/asset-registries/Themes.js";
|
6
|
+
const DEFAULT_THEME = assets.themes.default;
|
10
7
|
|
11
|
-
|
8
|
+
const getDefaultThemeCode = packageName => {
|
9
|
+
return `import { registerThemePropertiesLoader } from "@ui5/webcomponents-base/dist/asset-registries/Themes.js";
|
12
10
|
|
13
|
-
|
11
|
+
import defaultThemeBase from "@ui5/webcomponents-theming/dist/generated/themes/${DEFAULT_THEME}/parameters-bundle.css.js";
|
12
|
+
import defaultTheme from "./${DEFAULT_THEME}/parameters-bundle.css.js";
|
14
13
|
|
14
|
+
registerThemePropertiesLoader("@ui5/webcomponents-theming", "${DEFAULT_THEME}", () => defaultThemeBase);
|
15
|
+
registerThemePropertiesLoader("${packageName}", "${DEFAULT_THEME}", () => defaultTheme);
|
15
16
|
`;
|
16
17
|
};
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
const proccessCSS = css => {
|
20
|
+
css = css.replace(/\.sapThemeMeta[\s\S]*?:root/, ":root");
|
21
|
+
css = css.replace(/\.background-image.*{.*}/, "");
|
22
|
+
css = css.replace(/\.sapContrast[ ]*:root[\s\S]*?}/, "");
|
23
|
+
css = css.replace(/--sapFontUrl.*\);?/, "");
|
24
|
+
return JSON.stringify(css);
|
25
|
+
}
|
24
26
|
|
25
|
-
|
27
|
+
module.exports = function (opts) {
|
28
|
+
opts = opts || {};
|
26
29
|
|
27
|
-
|
30
|
+
return {
|
31
|
+
postcssPlugin: 'postcss-css-to-esm',
|
32
|
+
Once (root) {
|
33
|
+
let css = root.toString();
|
34
|
+
css = proccessCSS(css);
|
28
35
|
|
29
|
-
|
36
|
+
const targetFile = root.source.input.from.replace(`/${opts.toReplace}/`, "/dist/generated/").replace(`\\${opts.toReplace}\\`, "\\dist\\generated\\");
|
37
|
+
mkdirp.sync(path.dirname(targetFile));
|
30
38
|
|
31
|
-
|
32
|
-
|
33
|
-
});
|
39
|
+
const filePath = `${targetFile}.js`;
|
40
|
+
const defaultTheme = opts.includeDefaultTheme ? getDefaultThemeCode(opts.packageName) : ``;
|
41
|
+
fs.writeFileSync(filePath, `${defaultTheme}export default {packageName:"${opts.packageName}",fileName:"${targetFile.substr(targetFile.lastIndexOf("themes"))}",content:${css}}`);
|
42
|
+
}
|
43
|
+
};
|
44
|
+
};
|
45
|
+
module.exports.postcss = true;
|